elastics-admin 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/elastics-admin.rb +10 -1
- data/lib/elastics/admin_live_reindex.rb +26 -10
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.2
|
data/lib/elastics-admin.rb
CHANGED
@@ -4,4 +4,13 @@ require 'elastics/admin_live_reindex'
|
|
4
4
|
|
5
5
|
Elastics::LIB_PATHS << File.dirname(__FILE__)
|
6
6
|
|
7
|
-
|
7
|
+
redis_installed = Gem::Specification.respond_to?(:find_all_by_name) ?
|
8
|
+
Gem::Specification::find_all_by_name('redis').any? :
|
9
|
+
Gem.available?('redis')
|
10
|
+
|
11
|
+
if redis_installed
|
12
|
+
require 'redis'
|
13
|
+
Elastics::Conf.redis = $redis || ::Redis.current
|
14
|
+
end
|
15
|
+
|
16
|
+
Elastics::Conf.optimize_indexing = true
|
@@ -32,11 +32,8 @@ module Elastics
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def init
|
35
|
-
|
36
|
-
|
37
|
-
rescue LoadError
|
38
|
-
raise MissingRedisError, 'The live-reindex feature rely on redis. Please, install redis and the "redis" gem.'
|
39
|
-
end
|
35
|
+
raise MissingRedisError, 'The live-reindex feature rely on redis. Please, install redis and the "redis" gem.' \
|
36
|
+
unless Conf.redis.class.to_s == 'Redis'
|
40
37
|
raise MissingAppIdError, 'You must set the Elastics::Configuration.app_id, and be sure you deploy it before live-reindexing.' \
|
41
38
|
if Conf.app_id.nil? || Conf.app_id.empty?
|
42
39
|
raise LiveReindexInProgressError, %(It looks like the live-reindex of "#{Conf.app_id}" is in progress (PID #{get(:pid)}). If you are sure that there is no live-reindex in progress, please run the "elastics:admin:reset_redis_keys APP_ID=#{Conf.app_id}" rake task and retry.) \
|
@@ -107,7 +104,14 @@ module Elastics
|
|
107
104
|
if @ensure_indices && !@ensure_indices.include?(base)
|
108
105
|
prefixed = @prefix + base
|
109
106
|
unless @indices.include?(base)
|
110
|
-
|
107
|
+
unless Elastics.exist?(:index => prefixed)
|
108
|
+
Conf.indices.create_index(base, prefixed)
|
109
|
+
if Conf.optimize_indexing
|
110
|
+
@refresh_intervals[index] = Elastics.get_index_settings(:index => prefixed)[prefixed]['settings']['index.refresh_interval']
|
111
|
+
Elastics.put_index_settings(:index => prefixed,
|
112
|
+
:data => {:index => {:refresh_interval => '-1'}})
|
113
|
+
end
|
114
|
+
end
|
111
115
|
@indices |= [base]
|
112
116
|
end
|
113
117
|
prefixed
|
@@ -127,9 +131,10 @@ module Elastics
|
|
127
131
|
Prompter.say_warning 'WARNING: Safe reindex is disabled!' if opts[:verbose]
|
128
132
|
end
|
129
133
|
Redis.init
|
130
|
-
@indices
|
131
|
-
@
|
132
|
-
@
|
134
|
+
@indices = []
|
135
|
+
@refresh_intervals = {} if Conf.optimize_indexing
|
136
|
+
@prefix = Time.now.strftime('%Y%m%d%H%M%S_')
|
137
|
+
@ensure_indices = nil
|
133
138
|
|
134
139
|
unless opts[:on_stop_indexing] == false || Conf.on_stop_indexing == false
|
135
140
|
@stop_indexing ||= Conf.on_stop_indexing || raise(MissingStopIndexingProcError, 'The on_stop_indexing block is not set.')
|
@@ -169,10 +174,21 @@ module Elastics
|
|
169
174
|
|
170
175
|
# deletes the old indices and create the aliases to the new
|
171
176
|
@indices.each do |index|
|
177
|
+
prefixed = @prefix + index
|
178
|
+
if Conf.optimize_indexing
|
179
|
+
Prompter.say_notice "Optimizing index #{prefixed}..." if opts[:verbose]
|
180
|
+
# reset the refresh_interval
|
181
|
+
Elastics.put_index_settings(:index => prefixed,
|
182
|
+
:data => {:index => {:refresh_interval => (@refresh_intervals[index] || '1s')}})
|
183
|
+
# optimize the index
|
184
|
+
Elastics.optimize_index(:index => prefixed,
|
185
|
+
:params => {:max_num_segments => 5})
|
186
|
+
end
|
187
|
+
Prompter.say_notice "Swapping to index #{prefixed}..." if opts[:verbose]
|
172
188
|
Elastics.delete_index :index => index,
|
173
189
|
:raise => false # may not exist
|
174
190
|
Elastics.post_index_aliases :actions => [{ :add => { :alias => index,
|
175
|
-
:index =>
|
191
|
+
:index => prefixed } }]
|
176
192
|
end
|
177
193
|
# after the execution of this method the user should deploy the new code and then resume the regular app processing
|
178
194
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastics-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: elastics-client
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - '='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.1.
|
21
|
+
version: 1.1.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.1.
|
29
|
+
version: 1.1.2
|
30
30
|
description: Provides binary and rake tasks to dump, load and optionally rename indices.
|
31
31
|
Implements live-reindex with hot-swap of old code/index with new code/index.
|
32
32
|
email: dd.nexus@gmail.com
|