[SERVER-45699] using timestamp in document replacement in stitch support library apply update Created: 22/Jan/20  Updated: 29/Oct/23  Resolved: 25/Jan/20

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

Type: Bug Priority: Major - P3
Reporter: Michael O'Brien Assignee: Eric Daniels (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

Repro (using go code to call the library):
https://evergreen.mongodb.com/filediff/5e287175e3c331169e2aab5e/?file_name=mongo%2Fupdate_test.go&patch_number=0

Sprint: Query 2020-02-10
Participants:

 Description   

Stack trace:

    at /opt/mongodbtoolchain/revisions/9b224ef3e13ae2094ba3c865966ac238660d9552/stow/gcc-v3.fo3/include/c++/8.2.0/x86_64-mongodb-linux/bits/gthr-default.h:748
#15 lock (this=0x0) at /opt/mongodbtoolchain/revisions/9b224ef3e13ae2094ba3c865966ac238660d9552/stow/gcc-v3.fo3/include/c++/8.2.0/bits/std_mutex.h:103
#16 lock_guard (__m=..., this=<synthetic pointer>) at /opt/mongodbtoolchain/revisions/9b224ef3e13ae2094ba3c865966ac238660d9552/stow/gcc-v3.fo3/include/c++/8.2.0/bits/std_mutex.h:162
#17 mongo::LogicalClock::reserveTicks(unsigned long) () at src/mongo/db/logical_clock.cpp:102
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Relevant code that seems to crash is here:

ObjectReplaceExecutor::ObjectReplaceExecutor(BSONObj replacement)
    : _replacementDoc(replacement.getOwned()), _containsId(false) {
    // Replace all zero-valued timestamps with the current time and check for the existence of _id.
    for (auto&& elem : _replacementDoc) {
        // Do not change the _id field.
        if (elem.fieldNameStringData() == kIdFieldName) {
            _containsId = true;
            continue;
        }
        if (elem.type() == BSONType::bsonTimestamp) {
            auto timestampView = DataView(const_cast<char*>(elem.value()));
            // We don't need to do an endian-safe read here, because 0 is 0 either way.
            unsigned long long timestamp = timestampView.read<unsigned long long>();
            if (timestamp == 0) {
                ServiceContext* service = getGlobalServiceContext();
                auto ts = LogicalClock::get(service)->reserveTicks(1).asTimestamp();
                timestampView.write(tagLittleEndian(ts.asULL()));
            }
        }
    }
}

Seems like LogicalClock::get(service) is returning nullptr when it enters the codepath via the stitch support lib.



 Comments   
Comment by Githook User [ 25/Jan/20 ]

Author:

{'username': 'edaniels', 'name': 'Eric Daniels', 'email': 'eric@erdaniels.com'}

Message: SERVER-45699 - Set LogicalClock on Stitch support library ServiceContext
Branch: master
https://github.com/mongodb/mongo/commit/b569f3769de0d771dc29adaa4a3d0f79010eddc7

Comment by Eric Daniels (Inactive) [ 22/Jan/20 ]

I believe it can fail here too (current_date_node.cpp):

void setValue(mutablebson::Element* element, bool typeIsDate) {
    if (typeIsDate) {
        invariant(element->setValueDate(mongo::jsTime()));
    } else {
        invariant(element->setValueTimestamp(
            LogicalClock::get(getGlobalServiceContext())->reserveTicks(1).asTimestamp()));
    }
}

Generated at Thu Feb 08 05:09:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.