aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2015-02-23 19:39:44 -0800
committerRobin H. Johnson <robbat2@gentoo.org>2015-02-23 19:39:44 -0800
commit51aea5a8f68dc5d4a49e6795ff83d439c7f03942 (patch)
tree4be59ea42217f14303e900d7bcebd5b9cdbfe904
parentAlmost ready for real state. (diff)
downloadbackend-51aea5a8f68dc5d4a49e6795ff83d439c7f03942.tar.gz
backend-51aea5a8f68dc5d4a49e6795ff83d439c7f03942.tar.bz2
backend-51aea5a8f68dc5d4a49e6795ff83d439c7f03942.zip
Working index status check!
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-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)