summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordi Olivares Provencio <jordi.olivares-provencio@mongodb.com>2022-02-04 16:29:41 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-04 17:47:05 +0000
commitbdb266d2b2149d0ccf0a89d7856f8e46205fdb07 (patch)
tree28fe5cc528f2b74265c9ad1da662b3cba325614a
parent14b9051a791865503f3b101a62c0903f5c15a4a8 (diff)
downloadmongo-bdb266d2b2149d0ccf0a89d7856f8e46205fdb07.tar.gz
Revert "SERVER-62791 Modify setTimestamp to use stack allocation"
This reverts commit 3f0788882675f8e4893a9c5ebbcee4716ed436fa.
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.cpp12
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp34
2 files changed, 9 insertions, 37 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.cpp
index c3421f81987..1ad70b3d11b 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.cpp
@@ -91,16 +91,10 @@ WiredTigerBeginTxnBlock::~WiredTigerBeginTxnBlock() {
Status WiredTigerBeginTxnBlock::setReadSnapshot(Timestamp readTimestamp) {
invariant(_rollback);
- // Avoid heap allocation in favour of a stack allocation for the configuration string.
- constexpr auto configFmtString = "read_timestamp={:x}";
- constexpr auto numBytesRequired = std::char_traits<char>::length(configFmtString) +
- (sizeof(decltype(readTimestamp.asULL())) * 2) + 1;
- std::array<char, numBytesRequired> configString;
- auto end =
- fmt::format_to(configString.begin(), FMT_STRING(configFmtString), readTimestamp.asULL());
- *end = '\0';
+ std::string readTSConfigString = "read_timestamp={:x}"_format(readTimestamp.asULL());
- return wtRCToStatus(_session->timestamp_transaction(_session, configString.begin()), _session);
+ return wtRCToStatus(_session->timestamp_transaction(_session, readTSConfigString.c_str()),
+ _session);
}
void WiredTigerBeginTxnBlock::done() {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
index ad930b5c698..cf6d0313988 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
@@ -45,9 +45,6 @@
#include "mongo/util/stacktrace.h"
#include "mongo/util/testing_proctor.h"
-#include <fmt/compile.h>
-#include <fmt/format.h>
-
namespace mongo {
namespace {
@@ -471,39 +468,27 @@ void WiredTigerRecoveryUnit::_txnClose(bool commit) {
int wtRet;
if (commit) {
- // Avoid heap allocation in favour of a stack allocation for the commit string.
- constexpr auto commitTimestampFmtString = "commit_timestamp={:X},";
- constexpr auto durableTimestampFmtString = "durable_timestamp={:X}";
- constexpr auto bytesRequired = std::char_traits<char>::length(commitTimestampFmtString) +
- (sizeof(decltype(_commitTimestamp.asULL())) * 2) +
- std::char_traits<char>::length(durableTimestampFmtString) +
- (sizeof(decltype(_durableTimestamp.asULL())) * 2) + 1;
- std::array<char, bytesRequired> conf;
- auto end = conf.begin();
+ StringBuilder conf;
if (!_commitTimestamp.isNull()) {
// There is currently no scenario where it is intentional to commit before the current
// read timestamp.
invariant(_readAtTimestamp.isNull() || _commitTimestamp >= _readAtTimestamp);
if (MONGO_likely(!doUntimestampedWritesForIdempotencyTests.shouldFail())) {
- end = fmt::format_to(
- conf.begin(), FMT_STRING(commitTimestampFmtString), _commitTimestamp.asULL());
+ conf << "commit_timestamp=" << unsignedHex(_commitTimestamp.asULL()) << ",";
}
_isTimestamped = true;
}
if (!_durableTimestamp.isNull()) {
- end = fmt::format_to(
- end, FMT_STRING(durableTimestampFmtString), _durableTimestamp.asULL());
+ conf << "durable_timestamp=" << unsignedHex(_durableTimestamp.asULL());
}
if (_mustBeTimestamped) {
invariant(_isTimestamped);
}
- *end = '\0';
-
- wtRet = s->commit_transaction(s, conf.begin());
+ wtRet = s->commit_transaction(s, conf.str().c_str());
LOGV2_DEBUG(
22412, 3, "WT commit_transaction", "snapshotId"_attr = getSnapshotId().toNumber());
@@ -849,15 +834,8 @@ Status WiredTigerRecoveryUnit::setTimestamp(Timestamp timestamp) {
return Status::OK();
}
- // Avoid heap allocation in favour of a stack allocation.
- constexpr auto formatString = "commit_timestamp={:X}";
- constexpr auto bytesToAllocate = std::char_traits<char>::length(formatString) +
- (sizeof(decltype(timestamp.asULL())) * 2) + 1;
- std::array<char, bytesToAllocate> conf;
- auto end = fmt::format_to(conf.begin(), FMT_COMPILE(formatString), timestamp.asULL());
- // Manual null-termination
- *end = '\0';
- auto rc = session->timestamp_transaction(session, conf.begin());
+ const std::string conf = "commit_timestamp=" + unsignedHex(timestamp.asULL());
+ auto rc = session->timestamp_transaction(session, conf.c_str());
if (rc == 0) {
_isTimestamped = true;
}