spec/support/cluster_tools.rb
# The recommended guidance for changing a primary is:
#
# - turn off election handoff
# - pick a server to be the new primary
# - set the target's priority to 10, existing primary's priority to 1,
#   other servers' priorities to 0
# - call step down on the existing primary
# - call step up on the target in a loop until it becomes the primary
The recommended guidance for changing a primary is:
turn off election handoff
pick a server to be the new primary
set the target's priority to 10, existing primary's priority to 1,
other servers' priorities to 0
call step down on the existing primary
call step up on the target in a loop until it becomes the primary
The recommended guidance for changing a primary is : turn off election handoff pick a server to be the new primary set the target ' s priority to 10 existing primary ' s priority to 1 other servers ' priorities to 0 call step down on the existing primary call step up on the target in a loop until it becomes the primary
def change_primary
    start = Time.now
    existing_primary = admin_client.cluster.next_primary
    existing_primary_address = existing_primary.address
    target = admin_client.cluster.servers_list.detect do |server|
      !server.arbiter? && server.address != existing_primary_address
    end
    cfg = get_rs_config
    cfg['members'].each do |member|
      member['priority'] = case member['host']
      when existing_primary_address.to_s
        1
      when target.address.to_s
        10
      else
        0
      end
    end
    set_rs_config(cfg)
    if unfreeze_server(target.address)
      return
    end
    step_down
    persistently_step_up(target.address)
    new_primary = admin_client.cluster.next_primary
    puts "#{Time.now} [CT] Primary changed to #{new_primary.address}. Time to change primaries: #{Time.now - start}"
  end
def change_primary start = Time . now existing_primary = admin_client . cluster . next_primary existing_primary_address = existing_primary . address target = admin_client . cluster . servers_list . detect do | server | ! server . arbiter? && server . address != existing_primary_address end cfg = get_rs_config cfg [ 'members' ] . each do | member | member [ 'priority' ] = case member [ 'host' ] when existing_primary_address . to_s 1 when target . address . to_s 10 else 0 end end set_rs_config ( cfg ) if unfreeze_server ( target . address ) return end step_down persistently_step_up ( target . address ) new_primary = admin_client . cluster . next_primary puts "#{Time.now} [CT] Primary changed to #{new_primary.address}. Time to change primaries: #{Time.now - start}" end
The recommended guidance for changing a primary is:
 turn off election handoff
 pick a server to be the new primary
 set the target's priority to 10, existing primary's priority to 1,
other servers' priorities to 0
 call step down on the existing primary
 call step up on the target in a loop until it becomes the primary
The recommended guidance for changing a primary is : turn off election handoff pick a server to be the new primary set the target ' s priority to 10 existing primary ' s priority to 1 other servers ' priorities to 0 call step down on the existing primary call step up on the target in a loop until it becomes the primary
# Target server self-elected as primary, no further action is needed.