// distlock_test.cpp
/* Copyright 2009 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
* As a special exception, the copyright holders give permission to link the
* code of portions of this program with the OpenSSL library under certain
* conditions as described in each individual source file and distribute
* linked combinations including the program with the OpenSSL library. You
* must comply with the GNU Affero General Public License in all respects
* for all of the code used other than as permitted herein. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you do not
* wish to do so, delete this exception statement from your version. If you
* delete this exception statement from all source files in the program,
* then also delete it in the license file.
*/
#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding
#include "mongo/platform/basic.h"
#include "mongo/s/catalog/legacy/distlock.h"
#include
#include
#include
#include "mongo/base/init.h"
#include "mongo/client/connpool.h"
#include "mongo/db/auth/action_set.h"
#include "mongo/db/auth/action_type.h"
#include "mongo/db/auth/privilege.h"
#include "mongo/db/commands.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/s/catalog/legacy/legacy_dist_lock_pinger.h"
#include "mongo/stdx/thread.h"
#include "mongo/util/bson_util.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/log.h"
#include "mongo/util/timer.h"
// Modify some config options for the RNG, since they cause MSVC to fail
#include
#if defined(BOOST_MSVC) && defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
#undef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
#define BOOST_RNG_HACK
#endif
// Well, sort-of cross-platform RNG
#include
#ifdef BOOST_RNG_HACK
#define BOOST_NO_MEMBER_TEMPLATE_FRIENDS
#undef BOOST_RNG_HACK
#endif
#include
#include
// TODO: Make a method in BSONObj if useful, don't modify for now
#define string_field(obj, name, def) (obj.hasField(name) ? obj[name].String() : def)
#define number_field(obj, name, def) (obj.hasField(name) ? obj[name].Number() : def)
namespace mongo {
using std::shared_ptr;
using std::endl;
using std::string;
using std::stringstream;
using std::vector;
/**
* Stress test distributed lock by running multiple threads to contend with a single lock.
* Also has an option to make some thread terminate while holding the lock and have some
* other thread take over it after takeoverMS has elapsed. Note that this test does not check
* whether the lock was eventually overtaken and this is only valid if the LockPinger frequency
* is faster than takeoverMS.
*
* Note: Running concurrent instances of this command is not recommended as it can result in
* more frequent pings. And this effectively weakens the stress test.
*
* {
* _testDistLockWithSkew: 1,
*
* lockName: ,
* host: ,
* seed: ,
* numThreads: ,
*
* takeoverMS: ,
* wait: