Permalink
Browse files

added rebalance logic after clustering servers

  • Loading branch information...
ronniedada committed Aug 24, 2013
1 parent 6519d13 commit fa5303028dd9b705b1978a5db1e4c992eeb5cc4d
Showing with 40 additions and 0 deletions.
  1. +16 −0 cookbooks/couchbase/metadata.json
  2. +24 −0 cookbooks/couchbase/recipes/setup-2.1.1.rb
@@ -84,6 +84,22 @@
"display_name": "Cluster Tag",
"required": "optional"
},
"db_couchbase/cluster/rebalance_count": {
"description": "Set this to an integer to have the cluster automatically rebalance itself after 'X' number of joins - Most useful to set this to the total number of nodes expected in the cluster. Setting it to 0 will only add the node to cluster without doing rebalance",
"recipes": [
"couchbase::default",
"couchbase::setup-2.0.0",
"couchbase::setup-2.0.1",
"couchbase::setup-2.1.0",
"couchbase::setup-2.1.1",
"couchbase::restore-2.1.1"
],
"calculated": false,
"type": "string",
"default": "0",
"display_name": "Rebalance Count",
"required": "optional"
},
"db_couchbase/bucket/name": {
"description": "Bucket Name",
"recipes": [
@@ -165,6 +165,30 @@
log("clustering - skipped, no cluster_tag")
end
# rebalance if certain conditions been met
rebalance_count = node[:db_couchbase][:cluster][:rebalance_count]
num_nodes = known_hosts.split("\n").length
if rebalance_count > num_nodes
log("rebalancing: (rebalance_count = #{rebalance_count}) > (num_nodes = #{num_nodes}")
log("/opt/couchbase/bin/couchbase-cli rebalance" +
" -u #{node[:db_couchbase][:cluster][:username]}" +
" -p #{node[:db_couchbase][:cluster][:username]}" +
" -c localhost:8091")
begin
execute "rebalance cluster" do
commmand("/opt/couchbase/bin/couchbase-cli rebalance" +
" -u #{node[:db_couchbase][:cluster][:username]}" +
" -p #{node[:db_couchbase][:cluster][:username]}" +
" -c localhost:8091")
action :run
rescue Exception => e
log e
end
else
log("exiting due to insufficient amount of known nodes")
exit(0)
end
# create bucket
log("sleep 30 && /opt/couchbase/bin/couchbase-cli bucket-create" +
" -c 127.0.0.1:8091" +

0 comments on commit fa53030

Please sign in to comment.