From 2c49df47526aca35a866b7968bfa939a901eaa02 Mon Sep 17 00:00:00 2001 From: gregs Date: Sun, 8 May 2011 12:47:52 -0400 Subject: [PATCH] always require double-check before forcing locks - sync6 fix --- client/distlock.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/client/distlock.cpp b/client/distlock.cpp index 2bfd7e5fa01..4dfad71208a 100644 --- a/client/distlock.cpp +++ b/client/distlock.cpp @@ -651,6 +651,9 @@ namespace mongo { << lockName << causedBy( e ), 13660); } + // Lock forced, reset our timer + if(_lockTimeout > 0) + _lastPingCheck = make_tuple(string(""), 0, 0, OID()); } else { @@ -688,16 +691,18 @@ namespace mongo { << lockName << causedBy( e ), 13660); } + // Lock re-entered, reset our timer + // Not strictly necessary, but helpful for small timeouts where thread scheduling is significant. + // This ensures that a force can only happen after one unsuccessful force or reacquire attempt. + if(_lockTimeout > 0) + _lastPingCheck = make_tuple(string(""), 0, 0, OID()); + log( logLvl - 1 ) << "re-entered distributed lock '" << lockName << "'" << endl; *other = o; other->getOwned(); conn.done(); return true; } - // Lock forced, reset our timer - if(_lockTimeout > 0) - _lastPingCheck = make_tuple(string(""), 0, 0, OID()); - log( logLvl - 1 ) << "lock '" << lockName << "' successfully forced" << endl; // We don't need the ts value in the query, since we will only ever replace locks with state=0.