elasticsearch-indexstager 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e053be4eb446c0d947f6c73033aced841a80e9b4
4
- data.tar.gz: a0da2e598bf71f151012e91e1a76c85088ee942f
3
+ metadata.gz: 2e73491d3ba2e305ab074aed57062767b46c29d8
4
+ data.tar.gz: 3595bc3ba4fcf7f4901a6cac98c94dd5c843cea5
5
5
  SHA512:
6
- metadata.gz: 951fe36de54f59c564a1eee642362b669c4b84dbda32e9f71a7200fb599ccf891d7c35477e82b7763e2fe998c00930a181ec578b44a50e6da1254da52e09fa17
7
- data.tar.gz: e24b2c128bb726ce758bdcead24f4650553ebbb67a543405bd59c5cc039a20f5061293e250b04202b7702e32cdecf291d792cc6f3f823de44aa3c3a611f5ede6
6
+ metadata.gz: 9de82f1bc5a545de2a13af08a4330745e504c7f3207f85a538d584a2056f174a39c4c32d9f96faffad9901113c64494c667c73f29ecdf517439ed6c35908de67
7
+ data.tar.gz: 44df44aa561454f8f94cd96cfbf1d17248a85771ec4ece88441ea799ae90b5e22463b932f919862cb5ca1775ce44dc94f958899bbce159a3d34b2fd5294de8c2
@@ -2,7 +2,7 @@ require 'securerandom'
2
2
 
3
3
  module Elasticsearch
4
4
  class IndexStager
5
- VERSION = '1.1.1'
5
+ VERSION = '1.1.2'
6
6
 
7
7
  attr_reader :index_name, :es_client
8
8
 
@@ -64,24 +64,7 @@ module Elasticsearch
64
64
  end
65
65
  end
66
66
 
67
- if live_index_exists
68
- new_name = @live_index_name + '-pre-staged-original'
69
-
70
- # make a copy
71
- es_client.reindex body: { source: { index: @live_index_name }, dest: { index: new_name } }
72
-
73
- # make sure the copy exists before we delete the original
74
- tries = 0
75
- while( tries < 10 ) do
76
- indices = ESHelper.client.indices.get_aliases.keys
77
- break if indices.include?(new_name)
78
- tries += 1
79
- sleep(1)
80
- end
81
-
82
- # delete the original
83
- es_client.indices.delete index: @live_index_name rescue false
84
- end
67
+ rename_live_index if live_index_exists
85
68
 
86
69
  # re-alias
87
70
  es_client.indices.update_aliases body: { actions: rename_actions }
@@ -94,6 +77,38 @@ module Elasticsearch
94
77
 
95
78
  private
96
79
 
80
+ def rename_live_index
81
+ # if the live index exists but is empty, it fill fail to reindex (rename)
82
+ # so catch that case and just delete it.
83
+ idx_stats = es_client.indices.stats index: @live_index_name, docs: true
84
+ num_docs = idx_stats['indices'][@live_index_name]['total']['docs']['count']
85
+ if num_docs.to_i == 0
86
+ es_client.indices.delete index: @live_index_name
87
+ return
88
+ end
89
+
90
+ new_name = @live_index_name + '-pre-staged-original'
91
+ renamed = { source: { index: @live_index_name }, dest: { index: new_name } }
92
+
93
+ # make a copy
94
+ es_client.reindex refresh: true, wait_for_completion: true, body: renamed
95
+
96
+ # make sure the copy exists before we delete the original
97
+ tries = 0
98
+ rename_ok = false
99
+ while( tries < 10 ) do
100
+ es_client.indices.refresh index: new_name rescue false
101
+ indices = es_client.indices.get_aliases.keys
102
+ break if rename_ok = indices.include?(new_name)
103
+ tries += 1
104
+ sleep(1)
105
+ end
106
+ raise "Failed to rename #{@live_index_name} -> #{new_name}" unless rename_ok
107
+
108
+ # delete the original
109
+ es_client.indices.delete index: @live_index_name
110
+ end
111
+
97
112
  def tmp_index_pattern
98
113
  /#{index_name}_(\d{14})-\w{8}$/
99
114
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-indexstager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Karman
@@ -44,42 +44,42 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '12.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '12.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '3.7'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '3.7'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: elasticsearch-extensions
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '6.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '6.0'
83
83
  description: manage Elasticsearch indexes using staging pattern
84
84
  email:
85
85
  - karpet@peknet.com