Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/mongolly
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ module Mongolly
mongo_start_command: nil,
mongo_stop_command: nil,
config_server_ssh_user: nil,
config_server_ssh_keypath: nil
config_server_ssh_keypath: nil,
balancer_wait: nil
}

File.open( config_path, "w" ) do |f|
Expand Down
12 changes: 8 additions & 4 deletions lib/mongolly/extensions/mongo/mongo_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'retries'

class Mongo::MongoClient
MAX_DISABLE_BALANCER_WAIT = 60*8 # 8 Minutes
DEFAULT_BALANCER_WAIT = 60*8 # 8 Minutes
REPLICA_SNAPSHOT_THRESHOLD = 60*5 # 5 Minutes
REPLICA_SNAPSHOT_PREFER_HIDDEN = true

Expand All @@ -14,6 +14,8 @@ def snapshot_ebs(options={})
options[:volume_tag] ||= 'mongolly'
options[:backup_key] ||= (0...8).map{65.+(rand(25)).chr}.join

@balancer_wait = (options[:balancer_wait] || DEFAULT_BALANCER_WAIT).to_i

@ec2 = AWS::EC2.new(access_key_id: options[:access_key_id], secret_access_key: options[:secret_access_key], region: options[:region])

if mongos?
Expand Down Expand Up @@ -114,13 +116,13 @@ def with_config_server_stopped(options={})
def with_disabled_balancing
begin
disable_balancing
term_time = Time.now + MAX_DISABLE_BALANCER_WAIT
term_time = Time.now + @balancer_wait
while !@mongolly_dry_run && (Time.now < term_time) && balancer_active?
@mongolly_logger.info "Balancer active, sleeping for 10s (#{(term_time - Time.now).round}s remaining)"
sleep 10
end
if !@mongolly_dry_run && balancer_active?
raise RuntimeError.new "Unable to disable balancer within #{MAX_DISABLE_BALANCER_WAIT}s"
raise RuntimeError.new "Unable to disable balancer within #{@balancer_wait}s"
end
@mongolly_logger.debug "With shard balancing disabled..."
yield
Expand Down Expand Up @@ -195,7 +197,9 @@ def shards

def replica_set_connection(hosts, options)
db = Mongo::MongoReplicaSetClient.new(hosts)
db['admin'].authenticate(options[:db_username], options[:db_password])
if options[:db_username] && options[:db_password]
db['admin'].authenticate(options[:db_username], options[:db_password])
end
return db
end

Expand Down