Skip to content

Commit 8d3388b

Browse files
committed
SERVER-20418 Make sure that we always start the distlock pinger when running with mirrored config servers
1 parent ca39291 commit 8d3388b

File tree

6 files changed

+32
-65
lines changed

6 files changed

+32
-65
lines changed

src/mongo/dbtests/framework.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
#include "mongo/dbtests/dbtests.h"
4646
#include "mongo/dbtests/framework_options.h"
4747
#include "mongo/s/catalog/catalog_manager.h"
48-
#include "mongo/s/grid.h"
4948
#include "mongo/s/catalog/legacy/legacy_dist_lock_manager.h"
49+
#include "mongo/s/grid.h"
5050
#include "mongo/stdx/mutex.h"
5151
#include "mongo/util/assert_util.h"
5252
#include "mongo/util/exit.h"
@@ -77,20 +77,10 @@ int runDbTests(int argc, char** argv) {
7777
auto connectHook = stdx::make_unique<CustomConnectHook>(txn.get());
7878
ConnectionString::setConnectionHook(connectHook.get());
7979
ON_BLOCK_EXIT([] { ConnectionString::setConnectionHook(nullptr); });
80+
LegacyDistLockManager::disablePinger();
8081
ShardingState::get(txn.get())->initialize(txn.get(), "$dummy:10000");
8182
}
8283

83-
// Note: ShardingState::initialize also initializes the distLockMgr.
84-
{
85-
auto txn = cc().makeOperationContext();
86-
auto distLockMgr = dynamic_cast<LegacyDistLockManager*>(
87-
grid.forwardingCatalogManager()->getDistLockManager());
88-
if (distLockMgr) {
89-
distLockMgr->enablePinger(false);
90-
}
91-
}
92-
93-
9484
int ret = unittest::Suite::run(frameworkGlobalParams.suites,
9585
frameworkGlobalParams.filter,
9686
frameworkGlobalParams.runsPerTest);

src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ Status CatalogManagerLegacy::init(const ConnectionString& configDBCS,
206206

207207
_distLockManager =
208208
stdx::make_unique<LegacyDistLockManager>(_configServerConnectionString, distLockProcessId);
209-
_distLockManager->startUp();
210209

211210
{
212211
stdx::lock_guard<stdx::mutex> lk(_mutex);
@@ -223,17 +222,14 @@ Status CatalogManagerLegacy::startup(OperationContext* txn, bool allowNetworking
223222
return Status::OK();
224223
}
225224

226-
if (!allowNetworking) {
227-
// Config servers shouldn't call dbHash on themselves and shards don't need to
228-
// run the checker.
229-
_started = true;
230-
return Status::OK();
225+
if (allowNetworking) {
226+
Status status = _startConfigServerChecker();
227+
if (!status.isOK()) {
228+
return status;
229+
}
231230
}
232231

233-
Status status = _startConfigServerChecker();
234-
if (!status.isOK()) {
235-
return status;
236-
}
232+
_distLockManager->startUp();
237233

238234
_started = true;
239235
return Status::OK();

src/mongo/s/catalog/legacy/legacy_dist_lock_manager.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,20 @@ const stdx::chrono::seconds kDefaultSocketTimeout(30);
4949
const milliseconds kDefaultPingInterval(30 * 1000);
5050
} // unnamed namespace
5151

52+
bool LegacyDistLockManager::_pingerEnabled = true;
53+
5254
LegacyDistLockManager::LegacyDistLockManager(ConnectionString configServer,
5355
const std::string& processId)
54-
: _configServer(std::move(configServer)),
55-
_processId(processId),
56-
_isStopped(false),
57-
_pingerEnabled(true) {}
56+
: _configServer(std::move(configServer)), _processId(processId), _isStopped(false) {}
5857

5958
void LegacyDistLockManager::startUp() {
6059
stdx::lock_guard<stdx::mutex> sl(_mutex);
6160
invariant(!_pinger);
6261
_pinger = stdx::make_unique<LegacyDistLockPinger>();
62+
63+
if (_pingerEnabled) {
64+
uassertStatusOK(_pinger->startup(_configServer, _processId, kDefaultPingInterval));
65+
}
6366
}
6467

6568
void LegacyDistLockManager::shutDown(OperationContext* txn, bool allowNetworking) {
@@ -93,13 +96,6 @@ StatusWith<DistLockManager::ScopedDistLock> LegacyDistLockManager::lock(
9396
if (_isStopped) {
9497
return Status(ErrorCodes::LockBusy, "legacy distlock manager is stopped");
9598
}
96-
97-
if (_pingerEnabled) {
98-
auto pingStatus = _pinger->startPing(*(distLock.get()), kDefaultPingInterval);
99-
if (!pingStatus.isOK()) {
100-
return pingStatus;
101-
}
102-
}
10399
}
104100

105101
auto lastStatus =
@@ -227,11 +223,6 @@ Status LegacyDistLockManager::checkStatus(OperationContext* txn, const DistLockH
227223
return distLock->checkStatus(durationCount<Seconds>(kDefaultSocketTimeout));
228224
}
229225

230-
void LegacyDistLockManager::enablePinger(bool enable) {
231-
stdx::lock_guard<stdx::mutex> sl(_mutex);
232-
_pingerEnabled = enable;
233-
}
234-
235226
void LegacyDistLockManager::unlockAll(OperationContext* txn, const std::string& processID) {
236227
fassertFailed(34367); // Only supported for CSRS
237228
}

src/mongo/s/catalog/legacy/legacy_dist_lock_manager.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ class LegacyDistLockManager : public DistLockManager {
6363

6464
virtual void unlockAll(OperationContext* txn, const std::string& processID) override;
6565

66-
// For testing only.
67-
void enablePinger(bool enable);
66+
// For testing only. Must be called before any calls to startUp().
67+
static void disablePinger() {
68+
_pingerEnabled = false;
69+
}
6870

6971
protected:
7072
virtual void unlock(OperationContext* txn,
@@ -85,8 +87,6 @@ class LegacyDistLockManager : public DistLockManager {
8587
std::unique_ptr<LegacyDistLockPinger> _pinger;
8688

8789
bool _isStopped;
88-
89-
// For testing only.
90-
bool _pingerEnabled;
90+
static bool _pingerEnabled;
9191
};
9292
}

src/mongo/s/catalog/legacy/legacy_dist_lock_pinger.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,10 @@ void LegacyDistLockPinger::distLockPingThread(ConnectionString addr,
220220
}
221221
}
222222

223-
Status LegacyDistLockPinger::startPing(const DistributedLock& lock,
224-
stdx::chrono::milliseconds sleepTime) {
225-
const ConnectionString& conn = lock.getRemoteConnection();
226-
const string& processId = lock.getProcessId();
227-
string pingID = pingThreadId(conn, processId);
223+
Status LegacyDistLockPinger::startup(const ConnectionString& configServerConnectionString,
224+
const std::string& processID,
225+
Milliseconds sleepTime) {
226+
string pingID = pingThreadId(configServerConnectionString, processID);
228227

229228
{
230229
// Make sure we don't start multiple threads for a process id.
@@ -239,22 +238,11 @@ Status LegacyDistLockPinger::startPing(const DistributedLock& lock,
239238
return Status::OK();
240239
}
241240

242-
// Check the config server clock skew.
243-
if (lock.isRemoteTimeSkewed()) {
244-
return Status(ErrorCodes::DistributedClockSkewed,
245-
str::stream() << "clock skew of the cluster " << conn.toString()
246-
<< " is too far out of bounds "
247-
<< "to allow distributed locking.");
248-
}
249-
}
250-
251-
{
252-
stdx::lock_guard<stdx::mutex> lk(_mutex);
253241
stdx::thread thread(stdx::bind(&LegacyDistLockPinger::distLockPingThread,
254242
this,
255-
conn,
243+
configServerConnectionString,
256244
getJSTimeVirtualThreadSkew(),
257-
processId,
245+
processID,
258246
sleepTime));
259247
_pingThreads.insert(std::make_pair(pingID, std::move(thread)));
260248

src/mongo/s/catalog/legacy/legacy_dist_lock_pinger.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ class LegacyDistLockPinger {
5050
LegacyDistLockPinger() = default;
5151

5252
/**
53-
* Starts pinging the process id for the given lock.
54-
* Note: this pinger does not support calling startPing on a lock that has previously
55-
* been stopped by a call to stopPing on its underlying processId.
53+
* Starts the pinger thread for a given processID.
54+
* Note: this pinger does not support being started up after it was stopped, either by a call
55+
* to stopPing or shutdown.
5656
*/
57-
Status startPing(const DistributedLock& lock, Milliseconds sleepTime);
57+
Status startup(const ConnectionString& configServerConnectionString,
58+
const std::string& processID,
59+
Milliseconds sleepTime);
5860

5961
/**
6062
* Adds a distributed lock that has the given id to the unlock list. The unlock list

0 commit comments

Comments
 (0)