Storage Engine API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
wiredtiger_prepare_conflict.h
Go to the documentation of this file.
1 
30 #pragma once
31 
32 #include "mongo/db/curop.h"
33 #include "mongo/db/operation_context.h"
36 #include "mongo/util/fail_point_service.h"
37 
38 namespace mongo {
39 
40 // When set, returns simulates returning WT_PREPARE_CONFLICT on WT cursor read operations.
41 MONGO_FAIL_POINT_DECLARE(WTPrepareConflictForReads);
42 
46 void wiredTigerPrepareConflictLog(int attempt);
47 
55 template <typename F>
56 int wiredTigerPrepareConflictRetry(OperationContext* opCtx, F&& f) {
57  invariant(opCtx);
58 
59  auto recoveryUnit = WiredTigerRecoveryUnit::get(opCtx);
60  int attempts = 0;
61  while (true) {
62  attempts++;
63  // If the failpoint is enabled, don't call the function, just simulate a conflict.
64  int ret =
65  MONGO_FAIL_POINT(WTPrepareConflictForReads) ? WT_PREPARE_CONFLICT : WT_READ_CHECK(f());
66 
67  if (ret != WT_PREPARE_CONFLICT)
68  return ret;
69 
70  ++CurOp::get(opCtx)->debug().prepareReadConflicts;
72  // Wait on the session cache to signal that a unit of work has been committed or aborted.
73  recoveryUnit->getSessionCache()->waitUntilPreparedUnitOfWorkCommitsOrAborts(opCtx);
74  }
75 }
76 } // namespace mongo
#define WT_READ_CHECK(x)
Identical to WT_OP_CHECK except this is checked on cursor seeks/advancement.
Definition: wiredtiger_record_store.h:62
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
MONGO_FAIL_POINT_DECLARE(WTPrepareConflictForReads)
int wiredTigerPrepareConflictRetry(OperationContext *opCtx, F &&f)
Runs the argument function f as many times as needed for f to return an error other than WT_PREPARE_C...
Definition: wiredtiger_prepare_conflict.h:56
static WiredTigerRecoveryUnit * get(OperationContext *opCtx)
Definition: wiredtiger_recovery_unit.h:139
void wiredTigerPrepareConflictLog(int attempts)
Logs a message with the number of prepare conflict retry attempts.
Definition: wiredtiger_prepare_conflict.cpp:44
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80