diff options
author | Randolph Tan <randolph@10gen.com> | 2015-06-03 16:05:09 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2015-06-08 21:31:27 -0400 |
commit | ac349d5d3bb607ba9fe2981b8b0181520408751a (patch) | |
tree | a09060f10da29242cb1cdd9f49a3b27454ff5c6b /src/mongo/s/catalog/replset_dist_lock_manager.cpp | |
parent | 60654439cb99b7a3e6cf4db470b7dadc89acfdb5 (diff) | |
download | mongo-ac349d5d3bb607ba9fe2981b8b0181520408751a.tar.gz |
SERVER-18525 Implement background ping and unlock for replSets distlock manager
Diffstat (limited to 'src/mongo/s/catalog/replset_dist_lock_manager.cpp')
-rw-r--r-- | src/mongo/s/catalog/replset_dist_lock_manager.cpp | 135 |
1 files changed, 0 insertions, 135 deletions
diff --git a/src/mongo/s/catalog/replset_dist_lock_manager.cpp b/src/mongo/s/catalog/replset_dist_lock_manager.cpp deleted file mode 100644 index 475d56983c2..00000000000 --- a/src/mongo/s/catalog/replset_dist_lock_manager.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/** - * Copyright (C) 2015 MongoDB 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 <http://www.gnu.org/licenses/>. - * - * 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/replset_dist_lock_manager.h" - -#include "mongo/base/status.h" -#include "mongo/base/status_with.h" -#include "mongo/s/catalog/dist_lock_catalog.h" -#include "mongo/s/type_locks.h" -#include "mongo/util/concurrency/thread_name.h" -#include "mongo/util/log.h" -#include "mongo/util/mongoutils/str.h" -#include "mongo/util/timer.h" - -namespace mongo { - - using std::string; - using std::unique_ptr; - using stdx::chrono::milliseconds; - - ReplSetDistLockManager::ReplSetDistLockManager(StringData processID, - unique_ptr<DistLockCatalog> catalog): - _processID(processID.toString()), - _catalog(std::move(catalog)) { - } - - ReplSetDistLockManager::~ReplSetDistLockManager() = default; - - void ReplSetDistLockManager::startUp() { - // TODO - } - - void ReplSetDistLockManager::shutDown() { - // TODO - } - - StatusWith<DistLockManager::ScopedDistLock> ReplSetDistLockManager::lock( - StringData name, - StringData whyMessage, - milliseconds waitFor, - milliseconds lockTryInterval) { - - Timer timer; - Timer msgTimer; - - while (waitFor <= milliseconds::zero() || timer.millis() < waitFor.count()) { - OID lockSessionID = OID::gen(); - string who = str::stream() << _processID << ":" << getThreadName(); - auto lockResult = _catalog->grabLock(name, - lockSessionID, - who, - _processID, - Date_t::now(), - whyMessage); - - auto status = lockResult.getStatus(); - const auto& lockDoc = lockResult.getValue(); - - if (!status.isOK()) { - // An error occurred but the write might have actually been applied on the - // other side. Schedule an unlock to clean it up just in case. - queueUnlock(lockSessionID); - return status; - } - - string errmsg; - if (lockDoc.isValid(&errmsg)) { - // Lock is acquired since findAndModify was able to successfully modify - // the lock document. - return ScopedDistLock(lockSessionID, this); - } - - // TODO: implement lock overtaking here. - - if (waitFor == milliseconds::zero()) break; - - // Periodically message for debugging reasons - if (msgTimer.seconds() > 10) { - LOG(0) << "waited " << timer.seconds() << "s for distributed lock " << name - << " for " << whyMessage; - - msgTimer.reset(); - } - - milliseconds timeRemaining = - std::max(milliseconds::zero(), waitFor - milliseconds(timer.millis())); - sleepmillis(std::min(lockTryInterval, timeRemaining).count()); - } - - return {ErrorCodes::LockBusy, str::stream() << "timed out waiting for " << name}; - } - - void ReplSetDistLockManager::unlock(const DistLockHandle& lockHandle) { - queueUnlock(lockHandle); - } - - Status ReplSetDistLockManager::checkStatus(const DistLockHandle& lockHandle) { - invariant(false); - return {ErrorCodes::InternalError, "not yet implemented"}; - } - - void ReplSetDistLockManager::queueUnlock(const OID& lockSessionID) { - // TODO: make this asynchronous - auto unlockStatus = _catalog->unlock(lockSessionID); - } -} |