elasticsearch-rails-ha 1.0.4 → 1.0.5

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: c3edf0960f65de6832e0838da6ff9fa2c064b022
4
- data.tar.gz: b673ce9d56d28dec663d6ae4a3351d0f6b12104a
3
+ metadata.gz: 748bbb4ee4cc9113f20ec87b005eef323820e2dd
4
+ data.tar.gz: 790fb673db28fe20541f83adf4de318ee6a32672
5
5
  SHA512:
6
- metadata.gz: cc334e3f30141418397bf0a0cffe3ece7bf7e2eea5793c462df8cc9477d1adf58696e463e6f272f98cde3280f47beac5159b50449c0a83947019d8d74f962e1f
7
- data.tar.gz: 4e599b2d3c396a90493ca4a7421cf003ee5e8c18b038085610ae65533b701d11dc6aa582bb76f2b0bbae6ff152f8b11a2a4877ad1bea8eed3174dd83bbca6a61
6
+ metadata.gz: 6349e7e66da0a4c339349fefd249d0f5714fdf85ac80b27a40552c84de1fb77f2551118a1c74f2914d214ea8b5aa87def419ea67df226e8ceda2431527a2d3ae
7
+ data.tar.gz: 4a67410a828da167f67a7ef4938dc7f1e4926ae608e587808d5862b616a8dc541700206d19cd3466621bb9a6c0a1bf941aca7549cbdfa20dc8d805f039b94a89
@@ -31,23 +31,23 @@ module Elasticsearch
31
31
  end
32
32
 
33
33
  def promote(live_index_name=klass.index_name)
34
- @live_index_name = live_index_name
34
+ @live_index_name = live_index_name || klass.index_name
35
35
 
36
36
  # the renaming actions (performed atomically by ES)
37
37
  rename_actions = [
38
38
  { remove: { index: stage_aliased_to, alias: stage_index_name } },
39
- { add: { index: stage_index_name, alias: live_index_name } }
39
+ { add: { index: stage_index_name, alias: @live_index_name } }
40
40
  ]
41
41
 
42
42
  # zap any existing index known as index_name,
43
43
  # but do it conditionally since it is reasonable that it does not exist.
44
44
  to_delete = []
45
- existing_live_index = es_client.indices.get_aliases(index: live_index_name)
45
+ existing_live_index = es_client.indices.get_aliases(index: @live_index_name)
46
46
  existing_live_index.each do |k,v|
47
47
 
48
48
  # if the index is merely aliased, remove its alias as part of the aliasing transaction.
49
- if k != klass.index_name
50
- rename_actions.unshift({ remove: { index: k, alias: live_index_name } })
49
+ if k != @live_index_name
50
+ rename_actions.unshift({ remove: { index: k, alias: @live_index_name } })
51
51
 
52
52
  # mark it for deletion when we've successfully updated aliases
53
53
  to_delete.push k
@@ -56,7 +56,7 @@ module Elasticsearch
56
56
  # this is a real, unaliased index with this name, so it must be deleted.
57
57
  # (This usually happens the first time we implement the aliasing scheme against
58
58
  # an existing installation.)
59
- es_client.indices.delete index: live_index_name rescue false
59
+ es_client.indices.delete index: @live_index_name rescue false
60
60
  end
61
61
  end
62
62
 
@@ -82,18 +82,23 @@ module Elasticsearch
82
82
  def stage_aliased_to
83
83
  # find the newest tmp index to which staged is aliased.
84
84
  # we need this because we want to re-alias it.
85
+ aliased_to = find_newest_alias_for(stage_index_name)
86
+ end
87
+
88
+ def find_newest_alias_for(the_index_name)
85
89
  aliased_to = nil
86
- stage_aliases = es_client.indices.get_aliases(index: stage_index_name)
87
- stage_aliases.each do |k,v|
90
+ aliases = es_client.indices.get_aliases(index: the_index_name)
91
+ aliases.each do |k,v|
92
+ next unless k.match(tmp_index_pattern)
88
93
  aliased_to ||= k
89
- stage_tstamp = aliased_to.match(tmp_index_pattern)[1]
94
+ alias_tstamp = aliased_to.match(tmp_index_pattern)[1]
90
95
  k_tstamp = k.match(tmp_index_pattern)[1]
91
- if Time.parse(stage_tstamp) < Time.parse(k_tstamp)
96
+ if Time.parse(alias_tstamp) < Time.parse(k_tstamp)
92
97
  aliased_to = k
93
98
  end
94
99
  end
95
100
  if !aliased_to
96
- raise "Cannot identify index aliased to by '#{stage_index_name}'"
101
+ raise "Cannot identify index aliased to by '#{the_index_name}'"
97
102
  end
98
103
  aliased_to
99
104
  end
@@ -19,6 +19,11 @@ module Elasticsearch
19
19
  @verbose = opts[:verbose]
20
20
  @scope = opts[:scope]
21
21
 
22
+ # make sure klass is not a simple string
23
+ if @klass.is_a?(String)
24
+ @klass = @klass.constantize
25
+ end
26
+
22
27
  # calculate array of offsets based on nprocs
23
28
  @total_expected = klass.count
24
29
  @pool_size = (@total_expected / @nprocs.to_f).ceil
@@ -54,7 +54,7 @@ namespace :elasticsearch do
54
54
  klass = ENV['CLASS'] or fail "CLASS required"
55
55
  stager = Elasticsearch::Rails::HA::IndexStager.new(klass)
56
56
  stager.promote(ENV['INDEX'])
57
- puts "[#{Time.now.utc.iso8601}] #{klass} promoted #{stage_index_name} to #{stager.live_index_name}"
57
+ puts "[#{Time.now.utc.iso8601}] #{klass} promoted #{stager.stage_index_name} to #{stager.live_index_name}"
58
58
  end
59
59
 
60
60
  end
@@ -1,7 +1,7 @@
1
1
  module Elasticsearch
2
2
  module Rails
3
3
  module HA
4
- VERSION = '1.0.4'
4
+ VERSION = '1.0.5'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-rails-ha
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Karman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-01 00:00:00.000000000 Z
11
+ date: 2016-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch-model