From 138932c12fd0718474af327ca024c2e5e573eec8 Mon Sep 17 00:00:00 2001 From: "A.J. Beamon" Date: Wed, 5 Jan 2022 11:26:43 -0800 Subject: [PATCH] Fixed a memory bug in the watch map. A few other formatting tweaks, etc. --- fdbclient/DatabaseContext.h | 2 +- fdbclient/NativeAPI.actor.cpp | 19 +++++++++++-------- fdbclient/NativeAPI.actor.h | 2 -- .../workloads/ReadHotDetection.actor.cpp | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/fdbclient/DatabaseContext.h b/fdbclient/DatabaseContext.h index a2dced3211..d0401b46da 100644 --- a/fdbclient/DatabaseContext.h +++ b/fdbclient/DatabaseContext.h @@ -533,7 +533,7 @@ public: EventCacheHolder connectToDatabaseEventCacheHolder; private: - std::unordered_map> watchMap; + std::unordered_map> watchMap; }; #endif diff --git a/fdbclient/NativeAPI.actor.cpp b/fdbclient/NativeAPI.actor.cpp index 5dd37c9983..c0c5b065b0 100644 --- a/fdbclient/NativeAPI.actor.cpp +++ b/fdbclient/NativeAPI.actor.cpp @@ -1912,9 +1912,8 @@ Reference DatabaseContext::getWatchMetadata(KeyRef key) const { } KeyRef DatabaseContext::setWatchMetadata(Reference metadata) { - KeyRef keyRef = metadata->parameters->key; - watchMap[keyRef] = metadata; - return keyRef; + watchMap[metadata->parameters->key] = metadata; + return metadata->parameters->key; } void DatabaseContext::deleteWatchMetadata(KeyRef key) { @@ -2974,14 +2973,18 @@ ACTOR Future watchStorageServerResp(KeyRef key, Database cx) { if (!metadata.isValid()) return Void(); - if (watchVersion >= metadata->parameters->version) { // case 1: version_1 (SS) >= version_2 (map) + // case 1: version_1 (SS) >= version_2 (map) + if (watchVersion >= metadata->parameters->version) { cx->deleteWatchMetadata(key); if (metadata->watchPromise.canBeSet()) metadata->watchPromise.send(watchVersion); - } else { // ABA happens + } + // ABA happens + else { TEST(true); // ABA issue where the version returned from the server is less than the version in the map - if (metadata->watchPromise.getFutureReferenceCount() == - 1) { // case 2: version_1 < version_2 and future_count == 1 + + // case 2: version_1 < version_2 and future_count == 1 + if (metadata->watchPromise.getFutureReferenceCount() == 1) { cx->deleteWatchMetadata(key); } } @@ -3067,7 +3070,7 @@ Future getWatchFuture(Database cx, Reference parameters) // recreate in SS) else if (parameters->version > metadata->parameters->version) { TEST(true); // Setting a watch that has a different value than the one in the map but a higher version (newer) - cx->deleteWatchMetadata(parameters->key.contents()); + cx->deleteWatchMetadata(parameters->key); metadata->watchPromise.send(parameters->version); metadata->watchFutureSS.cancel(); diff --git a/fdbclient/NativeAPI.actor.h b/fdbclient/NativeAPI.actor.h index f5a840dfa1..da5960ad2a 100644 --- a/fdbclient/NativeAPI.actor.h +++ b/fdbclient/NativeAPI.actor.h @@ -252,8 +252,6 @@ struct TransactionState : ReferenceCounted { std::shared_ptr> conflictingKeys; // Only available so that Transaction can have a default constructor, for use in state variables - TransactionState() {} - TransactionState(TaskPriority taskID, SpanID spanID) : taskID(taskID), spanID(spanID) {} TransactionState(Database cx, TaskPriority taskID, SpanID spanID, Reference trLogInfo) diff --git a/fdbserver/workloads/ReadHotDetection.actor.cpp b/fdbserver/workloads/ReadHotDetection.actor.cpp index 28054cec55..2bba376132 100644 --- a/fdbserver/workloads/ReadHotDetection.actor.cpp +++ b/fdbserver/workloads/ReadHotDetection.actor.cpp @@ -98,7 +98,7 @@ struct ReadHotDetectionWorkload : TestWorkload { loop { state Transaction tr(cx); try { - StorageMetrics sm = wait(tr.getDatabase()->getStorageMetrics(self->wholeRange, 100)); + StorageMetrics sm = wait(cx->getStorageMetrics(self->wholeRange, 100)); // TraceEvent("RHDCheckPhaseLog") // .detail("KeyRangeSize", sm.bytes) // .detail("KeyRangeReadBandwith", sm.bytesReadPerKSecond);