diff --git a/fdbclient/DatabaseContext.h b/fdbclient/DatabaseContext.h index 8d2cbf21d8..5ee6d9a7a0 100644 --- a/fdbclient/DatabaseContext.h +++ b/fdbclient/DatabaseContext.h @@ -437,6 +437,10 @@ public: // Requests to the storage server will no longer be duplicated to its pair TSS. void removeTssMapping(StorageServerInterface const& ssi); + // Used for template code + using TransactionT = ReadYourWritesTransaction; + Reference createTransaction(); + private: std::unordered_map> watchMap; }; diff --git a/fdbclient/NativeAPI.actor.cpp b/fdbclient/NativeAPI.actor.cpp index c2c8ecd6d5..a1b808293a 100644 --- a/fdbclient/NativeAPI.actor.cpp +++ b/fdbclient/NativeAPI.actor.cpp @@ -6534,3 +6534,7 @@ ACTOR Future setPerpetualStorageWiggle(Database cx, bool enable, LockAware } return Void(); } + +Reference DatabaseContext::createTransaction() { + return makeReference(Database(Reference::addRef(this))); +} diff --git a/fdbclient/TagThrottle.actor.h b/fdbclient/TagThrottle.actor.h index 9a471a266a..522d37f7b0 100644 --- a/fdbclient/TagThrottle.actor.h +++ b/fdbclient/TagThrottle.actor.h @@ -244,6 +244,9 @@ extern const KeyRef tagThrottleCountKey; namespace ThrottleApi { +// The template functions can be called with Native API like DatabaseContext, Transaction/ReadYourWritesTransaction +// or using IClientAPI like IDatabase, ITransaction + ACTOR template Future getValidAutoEnabled(Reference tr) { state bool result; diff --git a/fdbserver/Ratekeeper.actor.cpp b/fdbserver/Ratekeeper.actor.cpp index 847862803c..a0de0c8c95 100644 --- a/fdbserver/Ratekeeper.actor.cpp +++ b/fdbserver/Ratekeeper.actor.cpp @@ -23,6 +23,7 @@ #include "fdbrpc/FailureMonitor.h" #include "fdbrpc/Smoother.h" #include "fdbrpc/simulator.h" +#include "fdbclient/DatabaseContext.h" #include "fdbclient/ReadYourWrites.h" #include "fdbclient/TagThrottle.actor.h" #include "fdbserver/Knobs.h" @@ -527,7 +528,7 @@ struct RatekeeperLimits { context(context) {} }; -struct GrvProxyInfo { +struct GRVProxyInfo { int64_t totalTransactions; int64_t batchTransactions; uint64_t lastThrottledTagChangeId; @@ -535,7 +536,7 @@ struct GrvProxyInfo { double lastUpdateTime; double lastTagPushTime; - GrvProxyInfo() + GRVProxyInfo() : totalTransactions(0), batchTransactions(0), lastThrottledTagChangeId(0), lastUpdateTime(0), lastTagPushTime(0) { } }; @@ -547,7 +548,7 @@ struct RatekeeperData { Map storageQueueInfo; Map tlogQueueInfo; - std::map grvProxyInfo; + std::map grvProxyInfo; Smoother smoothReleasedTransactions, smoothBatchReleasedTransactions, smoothTotalDurableBytes; HealthMetrics healthMetrics; DatabaseConfiguration configuration; @@ -597,7 +598,7 @@ struct RatekeeperData { autoThrottlingEnabled(false) { expiredTagThrottleCleanup = recurring( [this]() { - Reference db = makeReference(this->db); + Reference db = Reference::addRef(this->db.getPtr()); ThrottleApi::expire(db); }, SERVER_KNOBS->TAG_THROTTLE_EXPIRED_CLEANUP_INTERVAL); @@ -946,7 +947,7 @@ void tryAutoThrottleTag(RatekeeperData* self, TagSet tags; tags.addTag(tag); - Reference db = makeReference(self->db); + Reference db = Reference::addRef(self->db.getPtr()); self->addActor.send(ThrottleApi::throttleTags(db, tags, clientRate.get(), diff --git a/fdbserver/workloads/TagThrottleApi.actor.cpp b/fdbserver/workloads/TagThrottleApi.actor.cpp index 2a4094989a..97d0207a89 100644 --- a/fdbserver/workloads/TagThrottleApi.actor.cpp +++ b/fdbserver/workloads/TagThrottleApi.actor.cpp @@ -78,7 +78,7 @@ struct TagThrottleApiWorkload : TestWorkload { state TransactionPriority priority = deterministicRandom()->randomChoice(allTransactionPriorities); state double rate = deterministicRandom()->random01() * 20; state double duration = 1 + deterministicRandom()->random01() * 19; - state Reference db = makeReference(cx); + state Reference db = Reference::addRef(cx.getPtr()); TagSet tagSet; tagSet.addTag(tag); @@ -138,7 +138,7 @@ struct TagThrottleApiWorkload : TestWorkload { } } - state Reference db = makeReference(cx); + state Reference db = Reference::addRef(cx.getPtr()); bool removed = wait(ThrottleApi::unthrottleTags(db, tagSet, throttleType, priority)); if (removed) { ASSERT(erased || !throttleType.present() || throttleType.get() == TagThrottleType::AUTO); @@ -154,7 +154,7 @@ struct TagThrottleApiWorkload : TestWorkload { Database cx, std::map, TagThrottleInfo> const* manuallyThrottledTags) { - state Reference db = makeReference(cx); + state Reference db = Reference::addRef(cx.getPtr()); std::vector tags = wait(ThrottleApi::getThrottledTags(db, CLIENT_KNOBS->TOO_MANY)); int manualThrottledTags = 0; @@ -188,7 +188,7 @@ struct TagThrottleApiWorkload : TestWorkload { } ACTOR Future getRecommendedTags(TagThrottleApiWorkload* self, Database cx) { - state Reference db = makeReference(cx); + state Reference db = Reference::addRef(cx.getPtr()); std::vector tags = wait(ThrottleApi::getRecommendedTags(db, CLIENT_KNOBS->TOO_MANY)); for (auto& tag : tags) { @@ -205,7 +205,7 @@ struct TagThrottleApiWorkload : TestWorkload { deterministicRandom()->coinflip() ? Optional() : deterministicRandom()->randomChoice(allTransactionPriorities); - state Reference db = makeReference(cx); + state Reference db = Reference::addRef(cx.getPtr()); bool unthrottled = wait(ThrottleApi::unthrottleAll(db, throttleType, priority)); if (!throttleType.present() || throttleType.get() == TagThrottleType::MANUAL) { bool unthrottleExpected = false; @@ -233,7 +233,7 @@ struct TagThrottleApiWorkload : TestWorkload { } ACTOR Future enableAutoThrottling(TagThrottleApiWorkload* self, Database cx) { - state Reference db = makeReference(cx); + state Reference db = Reference::addRef(cx.getPtr()); if (deterministicRandom()->coinflip()) { wait(ThrottleApi::enableAuto(db, true)); self->autoThrottleEnabled = true; diff --git a/fdbserver/workloads/WriteTagThrottling.actor.cpp b/fdbserver/workloads/WriteTagThrottling.actor.cpp index a6ff0f5d7a..a9170f122c 100644 --- a/fdbserver/workloads/WriteTagThrottling.actor.cpp +++ b/fdbserver/workloads/WriteTagThrottling.actor.cpp @@ -94,7 +94,7 @@ struct WriteTagThrottlingWorkload : KVWorkload { std::string description() const override { return WriteTagThrottlingWorkload::NAME; } ACTOR static Future _setup(Database cx, WriteTagThrottlingWorkload* self) { - state Reference db = makeReference(cx); + state Reference db = Reference::addRef(cx.getPtr()); ASSERT(CLIENT_KNOBS->MAX_TAGS_PER_TRANSACTION >= MIN_TAGS_PER_TRANSACTION && CLIENT_KNOBS->MAX_TRANSACTION_TAG_LENGTH >= MIN_TRANSACTION_TAG_LENGTH); if (self->populateData) { @@ -307,7 +307,7 @@ struct WriteTagThrottlingWorkload : KVWorkload { } ACTOR static Future throttledTagUpdater(Database cx, WriteTagThrottlingWorkload* self) { state std::vector tags; - state Reference db = makeReference(cx); + state Reference db = Reference::addRef(cx.getPtr()); loop { wait(delay(1.0)); wait(store(tags, ThrottleApi::getThrottledTags(db, CLIENT_KNOBS->TOO_MANY, true)));