aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/storage.rb')
-rw-r--r--lib/storage.rb37
1 files changed, 11 insertions, 26 deletions
diff --git a/lib/storage.rb b/lib/storage.rb
index 7ec0861..4135971 100644
--- a/lib/storage.rb
+++ b/lib/storage.rb
@@ -5,28 +5,25 @@ require 'pp'
module Ag::Storage
module_function
- def index_states(indexname)
- status = $es.indices.status(index: indexname)
- states = status['indices'][indexname]['shards'].map do |key,array|
- array.map do |v|
- v['routing']['state']
- end.flatten
- end.flatten
+ def index_status(indexname)
+ $es.cluster.health(level: :indices)['indices'][indexname]['status']
end
+
def index_ready?(indexname)
- states = index_states(indexname)
- not_ready = states.include? 'INITIALIZING' or states.include? 'RELOCATING'
- return !not_ready
- pp $es.cluster.health(level: indices)
+ status = index_status(indexname)
+ # if you call index_status twice, you might get different results!
+ return status == 'green' or status == 'yellow'
end
# Throws Elasticsearch::Transport::Transport::Errors::NotFound
# if the list does not exist
def delete_index(list)
- $es.indices.delete index: 'ml-' + list
+ $es.indices.delete(index: 'ml-' + list)
end
- def create_index(list)
+ # Create an index for list
+ # sleep in 5ms intervals until it is ready
+ def create_index(list, sleeptime: 0.005)
indexname = 'ml-' + list
$es.indices.create(
index: indexname,
@@ -103,20 +100,8 @@ module Ag::Storage
}
})
- pp $es.cluster.health(level: indices)
# Give elasticsearch some time to process the new index
- status = $es.indices.status(index: indexname)
- while $es.cluster.health['status'] != 'green' do
- pp status
- pp status['indices'][indexname]['shards']
- status = status['indices'][indexname]['shards'].map do |k,v|
- v[0]['routing']['state']
- end
- pp status
- sleep 0.01
- status = $es.indices.status(index: indexname)
- end
- pp $es.indices.status(index: indexname)
+ sleep sleeptime while not index_ready?(indexname)
end
def get_content(message, filename)