summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@mongodb.com>2019-06-26 06:42:49 +1000
committerLuke Chen <luke.chen@mongodb.com>2019-07-12 11:56:17 +1000
commitb583a5704eaf895facadaf470ddd9cf2bfe6270e (patch)
treec775446789533a62a0bd951d05a88bd105d09972
parent98285cd9c36ac995a0207012c6742c2cefc03dd4 (diff)
downloadmongo-b583a5704eaf895facadaf470ddd9cf2bfe6270e.tar.gz
SERVER-41913 Avoid in-place modify operations for logged collections.
(cherry picked from commit 8b1d5ef199d881ab4fce61e585006436e9e6d2d1) (cherry picked from commit abf661c2657e08a53c4fd13d939b4587ddaf734d)
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp14
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h2
2 files changed, 11 insertions, 5 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index cdd9999a7c1..73a1bedb803 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -629,6 +629,10 @@ WiredTigerRecordStore::WiredTigerRecordStore(WiredTigerKVEngine* kvEngine,
_engineName(params.engineName),
_isCapped(params.isCapped),
_isEphemeral(params.isEphemeral),
+ _isLogged(WiredTigerUtil::useTableLogging(
+ NamespaceString(ns()),
+ getGlobalReplSettings().usingReplSets() ||
+ repl::ReplSettings::shouldRecoverFromOplogAsStandalone())),
_isOplog(NamespaceString::oplog(params.ns)),
_cappedMaxSize(params.cappedMaxSize),
_cappedMaxSizeSlack(std::min(params.cappedMaxSize / 10, int64_t(16 * 1024 * 1024))),
@@ -661,10 +665,7 @@ WiredTigerRecordStore::WiredTigerRecordStore(WiredTigerKVEngine* kvEngine,
}
if (!params.isReadOnly) {
- bool replicatedWrites = getGlobalReplSettings().usingReplSets() ||
- repl::ReplSettings::shouldRecoverFromOplogAsStandalone();
- uassertStatusOK(WiredTigerUtil::setTableLogging(
- ctx, _uri, WiredTigerUtil::useTableLogging(NamespaceString(ns()), replicatedWrites)));
+ uassertStatusOK(WiredTigerUtil::setTableLogging(ctx, _uri, _isLogged));
}
if (_isOplog) {
@@ -1380,12 +1381,15 @@ Status WiredTigerRecordStore::updateRecord(OperationContext* opCtx,
// Check if we should modify rather than doing a full update. Look for deltas for documents
// larger than 1KB, up to 16 changes representing up to 10% of the data.
+ //
+ // Skip modify for logged tables: don't trust WiredTiger's recovery with operations that are not
+ // idempotent.
const int kMinLengthForDiff = 1024;
const int kMaxEntries = 16;
const int kMaxDiffBytes = len / 10;
bool skip_update = false;
- if (len > kMinLengthForDiff && len <= old_length + kMaxDiffBytes) {
+ if (!_isLogged && len > kMinLengthForDiff && len <= old_length + kMaxDiffBytes) {
int nentries = kMaxEntries;
std::vector<WT_MODIFY> entries(nentries);
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h
index 7dde9f06265..b9311de399c 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h
@@ -340,6 +340,8 @@ private:
const bool _isCapped;
// True if the storage engine is an in-memory storage engine
const bool _isEphemeral;
+ // True if WiredTiger is logging updates to this table
+ const bool _isLogged;
// True if the namespace of this record store starts with "local.oplog.", and false otherwise.
const bool _isOplog;
int64_t _cappedMaxSize;