Skip to content

Commit

Permalink
added rebalance logic after clustering servers
Browse files Browse the repository at this point in the history
  • Loading branch information
ronniedada committed Aug 24, 2013
1 parent 6519d13 commit fa53030
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cookbooks/couchbase/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
24 changes: 24 additions & 0 deletions cookbooks/couchbase/recipes/setup-2.1.1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down

0 comments on commit fa53030

Please sign in to comment.