Skip to content

Instantly share code, notes, and snippets.

@thanosa75
Created June 20, 2013 09:51
Show Gist options
  • Save thanosa75/5821569 to your computer and use it in GitHub Desktop.
Save thanosa75/5821569 to your computer and use it in GitHub Desktop.
fsyncLock and Unlock are stackable!!
mongo localhost:27018
MongoDB shell version: 2.4.3
connecting to: localhost:27018/test
dev-mcs-01:SECONDARY> serverIsLocked = function () {
... var co = db.currentOp();
... if (co && co.fsyncLock) {
... return true;
... }
... return false;
... }
function () {
var co = db.currentOp();
if (co && co.fsyncLock) {
return true;
}
return false;
}
dev-mcs-01:SECONDARY> serverIsLocked()
false <---- the server reports not locked
dev-mcs-01:SECONDARY> db.fsyncLock()
{
"info" : "now locked against writes, use db.fsyncUnlock() to unlock",
"seeAlso" : "http://dochub.mongodb.org/core/fsynccommand",
"ok" : 1
}
dev-mcs-01:SECONDARY> serverIsLocked()
true <---- server is now LOCKED
dev-mcs-01:SECONDARY> db.fsyncUnlock()
{ "ok" : 1, "info" : "unlock completed" }
dev-mcs-01:SECONDARY> serverIsLocked()
false <---- server is UNLOCKED, all cool.
dev-mcs-01:SECONDARY> db.fsyncLock()
{
"info" : "now locked against writes, use db.fsyncUnlock() to unlock",
"seeAlso" : "http://dochub.mongodb.org/core/fsynccommand",
"ok" : 1
} <---- one lock
dev-mcs-01:SECONDARY> db.fsyncLock()
{
"info" : "now locked against writes, use db.fsyncUnlock() to unlock",
"seeAlso" : "http://dochub.mongodb.org/core/fsynccommand",
"ok" : 1
} <---- two locks
dev-mcs-01:SECONDARY> db.fsyncLock()
{
"info" : "now locked against writes, use db.fsyncUnlock() to unlock",
"seeAlso" : "http://dochub.mongodb.org/core/fsynccommand",
"ok" : 1
} <---- three locks
dev-mcs-01:SECONDARY> serverIsLocked()
true <---- server is locked, cool!!!
dev-mcs-01:SECONDARY> db.fsyncUnlock()
{ "ok" : 1, "info" : "unlock completed" }
dev-mcs-01:SECONDARY> serverIsLocked()
true <---- NOT COOL, fsyncUnlock() reports "unlock completed" and "ok" : 1 but not unlocked!!!!
dev-mcs-01:SECONDARY> db.fsyncUnlock()
{ "ok" : 1, "info" : "unlock completed" }
dev-mcs-01:SECONDARY> serverIsLocked()
true <---- NOT COOL, fsyncUnlock() reports "unlock completed" and "ok" : 1 but not unlocked!!!!
dev-mcs-01:SECONDARY> db.fsyncUnlock()
{ "ok" : 1, "info" : "unlock completed" }
dev-mcs-01:SECONDARY> serverIsLocked()
false <---- 3 locks need 3 unlocks!!!!!! NOT MENTIONED ANYWHERE!!!!!!
dev-mcs-01:SECONDARY> db.fsyncUnlock()
{ "ok" : 0, "errmsg" : "not locked" }
dev-mcs-01:SECONDARY>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment