diff options
Diffstat (limited to 'src/mongo/db/range_deleter_mock_env.cpp')
-rw-r--r-- | src/mongo/db/range_deleter_mock_env.cpp | 178 |
1 files changed, 86 insertions, 92 deletions
diff --git a/src/mongo/db/range_deleter_mock_env.cpp b/src/mongo/db/range_deleter_mock_env.cpp index f831c746ceb..1ee01d6a19a 100644 --- a/src/mongo/db/range_deleter_mock_env.cpp +++ b/src/mongo/db/range_deleter_mock_env.cpp @@ -34,125 +34,119 @@ namespace mongo { - using std::set; - using std::string; +using std::set; +using std::string; - bool DeletedRangeCmp::operator()(const DeletedRange& lhs, - const DeletedRange& rhs) const { - const int nsComp = lhs.ns.compare(rhs.ns); +bool DeletedRangeCmp::operator()(const DeletedRange& lhs, const DeletedRange& rhs) const { + const int nsComp = lhs.ns.compare(rhs.ns); - if (nsComp < 0) { - return true; - } - - if (nsComp > 0) { - return false; - } - - return compareRanges(lhs.min, lhs.max, rhs.min, rhs.max) < 0; + if (nsComp < 0) { + return true; } - RangeDeleterMockEnv::RangeDeleterMockEnv(): - _pauseDelete(false), - _pausedCount(0), - _getCursorsCallCount(0) { - - setGlobalServiceContext(stdx::make_unique<ServiceContextNoop>()); + if (nsComp > 0) { + return false; } - void RangeDeleterMockEnv::addCursorId(StringData ns, CursorId id) { - stdx::lock_guard<stdx::mutex> sl(_cursorMapMutex); - _cursorMap[ns.toString()].insert(id); - } + return compareRanges(lhs.min, lhs.max, rhs.min, rhs.max) < 0; +} - void RangeDeleterMockEnv::removeCursorId(StringData ns, CursorId id) { - stdx::lock_guard<stdx::mutex> sl(_cursorMapMutex); - _cursorMap[ns.toString()].erase(id); - } +RangeDeleterMockEnv::RangeDeleterMockEnv() + : _pauseDelete(false), _pausedCount(0), _getCursorsCallCount(0) { + setGlobalServiceContext(stdx::make_unique<ServiceContextNoop>()); +} - void RangeDeleterMockEnv::pauseDeletes() { - stdx::lock_guard<stdx::mutex> sl(_pauseDeleteMutex); - _pauseDelete = true; - } +void RangeDeleterMockEnv::addCursorId(StringData ns, CursorId id) { + stdx::lock_guard<stdx::mutex> sl(_cursorMapMutex); + _cursorMap[ns.toString()].insert(id); +} - void RangeDeleterMockEnv::resumeOneDelete() { - stdx::lock_guard<stdx::mutex> sl(_pauseDeleteMutex); - _pauseDelete = false; - _pausedCV.notify_one(); - } +void RangeDeleterMockEnv::removeCursorId(StringData ns, CursorId id) { + stdx::lock_guard<stdx::mutex> sl(_cursorMapMutex); + _cursorMap[ns.toString()].erase(id); +} - void RangeDeleterMockEnv::waitForNthGetCursor(uint64_t nthCall) { - stdx::unique_lock<stdx::mutex> sl(_envStatMutex); - while (_getCursorsCallCount < nthCall) { - _cursorsCallCountUpdatedCV.wait(sl); - } - } +void RangeDeleterMockEnv::pauseDeletes() { + stdx::lock_guard<stdx::mutex> sl(_pauseDeleteMutex); + _pauseDelete = true; +} - void RangeDeleterMockEnv::waitForNthPausedDelete(uint64_t nthPause) { - stdx::unique_lock<stdx::mutex> sl(_pauseDeleteMutex); - while(_pausedCount < nthPause) { - _pausedDeleteChangeCV.wait(sl); - } - } +void RangeDeleterMockEnv::resumeOneDelete() { + stdx::lock_guard<stdx::mutex> sl(_pauseDeleteMutex); + _pauseDelete = false; + _pausedCV.notify_one(); +} - bool RangeDeleterMockEnv::deleteOccured() const { - stdx::lock_guard<stdx::mutex> sl(_deleteListMutex); - return !_deleteList.empty(); +void RangeDeleterMockEnv::waitForNthGetCursor(uint64_t nthCall) { + stdx::unique_lock<stdx::mutex> sl(_envStatMutex); + while (_getCursorsCallCount < nthCall) { + _cursorsCallCountUpdatedCV.wait(sl); } +} - DeletedRange RangeDeleterMockEnv::getLastDelete() const { - stdx::lock_guard<stdx::mutex> sl(_deleteListMutex); - return _deleteList.back(); +void RangeDeleterMockEnv::waitForNthPausedDelete(uint64_t nthPause) { + stdx::unique_lock<stdx::mutex> sl(_pauseDeleteMutex); + while (_pausedCount < nthPause) { + _pausedDeleteChangeCV.wait(sl); } +} - bool RangeDeleterMockEnv::deleteRange(OperationContext* txn, - const RangeDeleteEntry& taskDetails, - long long int* deletedDocs, - string* errMsg) { +bool RangeDeleterMockEnv::deleteOccured() const { + stdx::lock_guard<stdx::mutex> sl(_deleteListMutex); + return !_deleteList.empty(); +} - { - stdx::unique_lock<stdx::mutex> sl(_pauseDeleteMutex); - bool wasInitiallyPaused = _pauseDelete; +DeletedRange RangeDeleterMockEnv::getLastDelete() const { + stdx::lock_guard<stdx::mutex> sl(_deleteListMutex); + return _deleteList.back(); +} - if (_pauseDelete) { - _pausedCount++; - _pausedDeleteChangeCV.notify_one(); - } +bool RangeDeleterMockEnv::deleteRange(OperationContext* txn, + const RangeDeleteEntry& taskDetails, + long long int* deletedDocs, + string* errMsg) { + { + stdx::unique_lock<stdx::mutex> sl(_pauseDeleteMutex); + bool wasInitiallyPaused = _pauseDelete; - while (_pauseDelete) { - _pausedCV.wait(sl); - } + if (_pauseDelete) { + _pausedCount++; + _pausedDeleteChangeCV.notify_one(); + } - _pauseDelete = wasInitiallyPaused; + while (_pauseDelete) { + _pausedCV.wait(sl); } - { - stdx::lock_guard<stdx::mutex> sl(_deleteListMutex); + _pauseDelete = wasInitiallyPaused; + } - DeletedRange entry; - entry.ns = taskDetails.options.range.ns; - entry.min = taskDetails.options.range.minKey.getOwned(); - entry.max = taskDetails.options.range.maxKey.getOwned(); - entry.shardKeyPattern = taskDetails.options.range.keyPattern.getOwned(); + { + stdx::lock_guard<stdx::mutex> sl(_deleteListMutex); - _deleteList.push_back(entry); - } + DeletedRange entry; + entry.ns = taskDetails.options.range.ns; + entry.min = taskDetails.options.range.minKey.getOwned(); + entry.max = taskDetails.options.range.maxKey.getOwned(); + entry.shardKeyPattern = taskDetails.options.range.keyPattern.getOwned(); - return true; + _deleteList.push_back(entry); } - void RangeDeleterMockEnv::getCursorIds( - OperationContext* txn, StringData ns, set<CursorId>* in) { - { - stdx::lock_guard<stdx::mutex> sl(_cursorMapMutex); - const set<CursorId>& _cursors = _cursorMap[ns.toString()]; - std::copy(_cursors.begin(), _cursors.end(), inserter(*in, in->begin())); - } + return true; +} - { - stdx::lock_guard<stdx::mutex> sl(_envStatMutex); - _getCursorsCallCount++; - _cursorsCallCountUpdatedCV.notify_one(); - } +void RangeDeleterMockEnv::getCursorIds(OperationContext* txn, StringData ns, set<CursorId>* in) { + { + stdx::lock_guard<stdx::mutex> sl(_cursorMapMutex); + const set<CursorId>& _cursors = _cursorMap[ns.toString()]; + std::copy(_cursors.begin(), _cursors.end(), inserter(*in, in->begin())); } + + { + stdx::lock_guard<stdx::mutex> sl(_envStatMutex); + _getCursorsCallCount++; + _cursorsCallCountUpdatedCV.notify_one(); + } +} } |