[SERVER-29250] change WiredTigerRecordStore::updateWithDamages to use WiredTiger's WT_CURSOR.modify support Created: 17/May/17  Updated: 30/Oct/23  Resolved: 31/Jul/17

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 3.5.11

Type: Improvement Priority: Major - P3
Reporter: Keith Bostic (Inactive) Assignee: Keith Bostic (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on WT-2972 Add interface allowing partial update... Closed
Backwards Compatibility: Fully Compatible
Sprint: Storage 2017-05-29, Storage 2017-06-19, Storage 2017-07-10, Storage 2017-07-31, Storage 2017-08-21
Participants:
Linked BF Score: 0

 Description   

Change WiredTigerRecordStore::updateWithDamages to use WiredTiger's WT_CURSOR.modify support.

The following change passes the storage_wiredtiger_record_store_test test.

diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index e9f7787..3b4f4a4 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -1449,7 +1449,7 @@ Status WiredTigerRecordStore::updateRecord(OperationContext* opCtx,
 }
 
 bool WiredTigerRecordStore::updateWithDamagesSupported() const {
-    return false;
+    return true;
 }
 
 StatusWith<RecordData> WiredTigerRecordStore::updateWithDamages(
@@ -1458,7 +1458,36 @@ StatusWith<RecordData> WiredTigerRecordStore::updateWithDamages(
     const RecordData& oldRec,
     const char* damageSource,
     const mutablebson::DamageVector& damages) {
-    MONGO_UNREACHABLE;
+
+    int nentries = damages.size();
+    mutablebson::DamageVector::const_iterator where = damages.begin();
+    const mutablebson::DamageVector::const_iterator end = damages.end();
+    WT_MODIFY entries[nentries];
+    for (u_int i = 0; where != end; ++i, ++where) {
+       entries[i].data.data = damageSource + where->sourceOffset;
+       entries[i].data.size = where->size;
+       entries[i].offset = where->targetOffset;
+       entries[i].size = where->size;
+    }
+
+    WiredTigerCursor curwrap(_uri, _tableId, true, opCtx);
+    curwrap.assertInActiveTxn();
+    WT_CURSOR* c = curwrap.get();
+    invariant(c);
+    c->set_key(c, _makeKey(id));
+
+    // The test harness calls us with empty damage vectors which WiredTiger doesn't allow.
+    if (nentries == 0)
+       invariantWTOK(WT_OP_CHECK(c->search(c)));
+    else
+       invariantWTOK(WT_OP_CHECK(c->modify(c, entries, nentries)));
+
+    WT_ITEM value;
+    invariantWTOK(c->get_value(c, &value));
+
+    SharedBuffer data = SharedBuffer::allocate(value.size);
+    memcpy(data.get(), value.data, value.size);
+    return RecordData(data, value.size);
 }



 Comments   
Comment by Githook User [ 27/Jul/17 ]

Author:

{'email': 'keith.bostic@mongodb.com', 'username': 'keithbostic', 'name': 'Keith Bostic'}

Message: SERVER-29250 change WiredTigerRecordStore::updateWithDamages to use WiredTiger's WT_CURSOR.modify support
Branch: master
https://github.com/mongodb/mongo/commit/743eaeacf0866ffeda630da479363874cc5f6d36

Comment by Keith Bostic (Inactive) [ 17/May/17 ]

In storage/kv/kv_engine_test_snapshots.cpp there's some additional code which I think is likely to break:

TEST_F(SnapshotManagerTests, UpdateAndDelete) {
    if (!snapshotManager)
        return;  // This test is only for engines that DO support SnapshotMangers.      
            
    // Snapshot variables are named according to the state of the record.
    auto snapBeforeInsert = prepareAndCreateSnapshot();
        
    auto id = insertRecordAndCommit("Dog");
    auto snapDog = prepareAndCreateSnapshot();
 
    updateRecordAndCommit(id, "Cat");
    auto snapCat = prepareAndCreateSnapshot();
        
    // Untested since no engine currently supports both updateWithDamanges and snapshots.
    ASSERT(!rs->updateWithDamagesSupported());

Generated at Thu Feb 08 04:20:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.