diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2018-03-09 15:45:08 -0500 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2018-03-13 18:54:52 -0400 |
commit | a1b194059660d78afba0d8750231f48e4f77f2a6 (patch) | |
tree | cd8d34fa5475ed56250294a20d08861e2f12c496 /src/mongo/db/op_observer.cpp | |
parent | bed7bb44a9cd84da56631b3a83437fc18ed46e3d (diff) | |
download | mongo-a1b194059660d78afba0d8750231f48e4f77f2a6.tar.gz |
SERVER-29908 Move more libraries from sharding into sharding_api_d/sharding_runtime_d
Diffstat (limited to 'src/mongo/db/op_observer.cpp')
-rw-r--r-- | src/mongo/db/op_observer.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/mongo/db/op_observer.cpp b/src/mongo/db/op_observer.cpp index 7e0532b2225..87ce0fcfcfa 100644 --- a/src/mongo/db/op_observer.cpp +++ b/src/mongo/db/op_observer.cpp @@ -26,9 +26,12 @@ * it in the license file. */ +#include "mongo/platform/basic.h" + #include "mongo/db/op_observer.h" #include "mongo/db/operation_context.h" + namespace mongo { namespace { const auto getOpObserverTimes = OperationContext::declareDecoration<OpObserver::Times>(); @@ -38,4 +41,29 @@ auto OpObserver::Times::get(OperationContext* const opCtx) -> Times& { return getOpObserverTimes(opCtx); } +OpObserver::ReservedTimes::ReservedTimes(OperationContext* const opCtx) + : _times(Times::get(opCtx)) { + // Every time that a `ReservedTimes` scope object is instantiated, we have to track if there was + // a potentially recursive call. When there was no `OpObserver` chain being executed before this + // instantiation, we should have an empty `reservedOpTimes` vector. + if (!_times._recursionDepth++) { + invariant(_times.reservedOpTimes.empty()); + } + + invariant(_times._recursionDepth > 0); + invariant(_times._recursionDepth == 1 || !opCtx->writesAreReplicated()); +} + +OpObserver::ReservedTimes::~ReservedTimes() { + // Every time the `ReservedTimes` guard goes out of scope, this indicates one fewer level of + // recursion in the `OpObserver` registered chain. + if (!--_times._recursionDepth) { + // When the depth hits 0, the `OpObserver` is considered to have finished, and therefore the + // `reservedOpTimes` state needs to be reset. + _times.reservedOpTimes.clear(); + } + + invariant(_times._recursionDepth >= 0); +} + } // namespace mongo |