RUBY-184 fsync lock helpers
This commit is contained in:
parent
a1565b3ac8
commit
4141331f79
|
@ -211,6 +211,24 @@ module Mongo
|
|||
end
|
||||
end
|
||||
|
||||
# Fsync, then lock the mongod process against writes. Use this to get
|
||||
# the datafiles in a state safe for snapshotting, backing up, etc.
|
||||
#
|
||||
# @return [BSON::OrderedHash] the command response
|
||||
def lock!
|
||||
cmd = BSON::OrderedHash.new
|
||||
cmd[:fsync] = 1
|
||||
cmd[:lock] = true
|
||||
self['admin'].command(cmd)
|
||||
end
|
||||
|
||||
# Unlock a previously fsync-locked mongod process.
|
||||
#
|
||||
# @return [BSON::OrderedHash] command response
|
||||
def unlock!
|
||||
self['admin']['$cmd.sys.unlock'].find_one
|
||||
end
|
||||
|
||||
# Apply each of the saved database authentications.
|
||||
#
|
||||
# @return [Boolean] returns true if authentications exist and succeeed, false
|
||||
|
|
|
@ -143,6 +143,24 @@ class TestConnection < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_fsync_lock
|
||||
@mongo.lock!
|
||||
assert_equal 1, @mongo['admin']['$cmd.sys.inprog'].find_one['fsyncLock'], "Not fsync-locked"
|
||||
assert_equal "unlock requested", @mongo.unlock!['info']
|
||||
unlocked = false
|
||||
counter = 0
|
||||
while counter < 5
|
||||
if @mongo['admin']['$cmd.sys.inprog'].find_one['fsyncLock'].nil?
|
||||
unlocked = true
|
||||
break
|
||||
else
|
||||
sleep(1)
|
||||
counter += 1
|
||||
end
|
||||
end
|
||||
assert unlocked, "mongod failed to unlock"
|
||||
end
|
||||
|
||||
context "Saved authentications" do
|
||||
setup do
|
||||
@conn = Mongo::Connection.new
|
||||
|
|
Loading…
Reference in New Issue