@wohali I am using the following two ruby scripts to move shards: first to move 
the shards to the new node, second one to update cluster metadata to not look 
for those shards in the old one.

`
def http_call (uri_string, username = '', password = '', data_json = {}, verb = 
'Get')
    uri = URI.parse(uri_string)
    http = Net::HTTP.new(uri.host,uri.port)
        if verb == 'Put'
          request = Net::HTTP::Put.new(uri.request_uri)
          request.body = data_json
        else
          request = Net::HTTP::Get.new(uri.request_uri)
        end
    request.basic_auth(username, password)
    response = http.request(request)
    response_json = JSON.parse response.body
end

all_dbs_response_json = http_call "http://127.0.0.1:5984/_all_dbs";, 
admin_username, admin_password

all_dbs_response_json.each do |db|
  print "\n#{db}\n"
  info_about_db_response_json = http_call "http://127.0.0.1:5986/_dbs/#{db}";, 
admin_username, admin_password

 #swap by_node information
  if info_about_db_response_json["by_node"].has_key? node_out
     info_about_db_response_json["by_node"][node_in] = 
info_about_db_response_json["by_node"][node_out]
  else
     next
  end

  #replace outgoing nodes in each shard of by_range dictionary
  info_about_db_response_json["by_range"].each do |shard, nodes|
    if nodes.include? node_out and not nodes.include? node_in
      nodes.push(node_in)
    end
  end

  new_changelog = ["add", node_in]
  info_about_db_response_json["changelog"].push(new_changelog)
  info_about_db_response_json_after = http_call 
"http://127.0.0.1:5986/_dbs/#{db}";, admin_username, admin_password, 
info_about_db_response_json.to_json, 'Put'
end`

`all_dbs_response_json.each do |db|
  print "\n#{db}\n"
  info_about_db_response_json = http_call "http://127.0.0.1:5986/_dbs/#{db}";, 
admin_username, admin_password

 #swap by_node information
  if info_about_db_response_json["by_node"].has_key? node_out
     info_about_db_response_json["by_node"].delete(node_out)
  else
     next
  end

  #replace outgoing nodes in each shard of by_range dictionary
  info_about_db_response_json["by_range"].each do |shard, nodes|
    if nodes.include? node_out
      nodes.delete(node_out)
    end
  end
  new_changelog = ["delete", node_out]
  info_about_db_response_json["changelog"].push(new_changelog)
  info_about_db_response_json_after = http_call 
"http://127.0.0.1:5986/_dbs/#{db}";, admin_username, admin_password, 
info_about_db_response_json.to_json, 'Put'
end`

`print hello`

[ Full content available at: https://github.com/apache/couchdb/issues/1611 ]
This message was relayed via gitbox.apache.org for [email protected]

Reply via email to