Use DatabaseContext instead of Database in template functions

This commit is contained in:
Chaoguang Lin 2021-08-17 20:02:25 +00:00
parent bf0d0598dc
commit 179c313e08
6 changed files with 25 additions and 13 deletions

View File

@ -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<TransactionT> createTransaction();
private:
std::unordered_map<KeyRef, Reference<WatchMetadata>> watchMap;
};

View File

@ -6534,3 +6534,7 @@ ACTOR Future<Void> setPerpetualStorageWiggle(Database cx, bool enable, LockAware
}
return Void();
}
Reference<DatabaseContext::TransactionT> DatabaseContext::createTransaction() {
return makeReference<ReadYourWritesTransaction>(Database(Reference<DatabaseContext>::addRef(this)));
}

View File

@ -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 <class Tr>
Future<bool> getValidAutoEnabled(Reference<Tr> tr) {
state bool result;

View File

@ -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<UID, StorageQueueInfo> storageQueueInfo;
Map<UID, TLogQueueInfo> tlogQueueInfo;
std::map<UID, GrvProxyInfo> grvProxyInfo;
std::map<UID, GRVProxyInfo> grvProxyInfo;
Smoother smoothReleasedTransactions, smoothBatchReleasedTransactions, smoothTotalDurableBytes;
HealthMetrics healthMetrics;
DatabaseConfiguration configuration;
@ -597,7 +598,7 @@ struct RatekeeperData {
autoThrottlingEnabled(false) {
expiredTagThrottleCleanup = recurring(
[this]() {
Reference<Database> db = makeReference<Database>(this->db);
Reference<DatabaseContext> db = Reference<DatabaseContext>::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<Database> db = makeReference<Database>(self->db);
Reference<DatabaseContext> db = Reference<DatabaseContext>::addRef(self->db.getPtr());
self->addActor.send(ThrottleApi::throttleTags(db,
tags,
clientRate.get(),

View File

@ -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<Database> db = makeReference<Database>(cx);
state Reference<DatabaseContext> db = Reference<DatabaseContext>::addRef(cx.getPtr());
TagSet tagSet;
tagSet.addTag(tag);
@ -138,7 +138,7 @@ struct TagThrottleApiWorkload : TestWorkload {
}
}
state Reference<Database> db = makeReference<Database>(cx);
state Reference<DatabaseContext> db = Reference<DatabaseContext>::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<std::pair<TransactionTag, TransactionPriority>, TagThrottleInfo> const* manuallyThrottledTags) {
state Reference<Database> db = makeReference<Database>(cx);
state Reference<DatabaseContext> db = Reference<DatabaseContext>::addRef(cx.getPtr());
std::vector<TagThrottleInfo> tags = wait(ThrottleApi::getThrottledTags(db, CLIENT_KNOBS->TOO_MANY));
int manualThrottledTags = 0;
@ -188,7 +188,7 @@ struct TagThrottleApiWorkload : TestWorkload {
}
ACTOR Future<Void> getRecommendedTags(TagThrottleApiWorkload* self, Database cx) {
state Reference<Database> db = makeReference<Database>(cx);
state Reference<DatabaseContext> db = Reference<DatabaseContext>::addRef(cx.getPtr());
std::vector<TagThrottleInfo> tags = wait(ThrottleApi::getRecommendedTags(db, CLIENT_KNOBS->TOO_MANY));
for (auto& tag : tags) {
@ -205,7 +205,7 @@ struct TagThrottleApiWorkload : TestWorkload {
deterministicRandom()->coinflip() ? Optional<TransactionPriority>()
: deterministicRandom()->randomChoice(allTransactionPriorities);
state Reference<Database> db = makeReference<Database>(cx);
state Reference<DatabaseContext> db = Reference<DatabaseContext>::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<Void> enableAutoThrottling(TagThrottleApiWorkload* self, Database cx) {
state Reference<Database> db = makeReference<Database>(cx);
state Reference<DatabaseContext> db = Reference<DatabaseContext>::addRef(cx.getPtr());
if (deterministicRandom()->coinflip()) {
wait(ThrottleApi::enableAuto(db, true));
self->autoThrottleEnabled = true;

View File

@ -94,7 +94,7 @@ struct WriteTagThrottlingWorkload : KVWorkload {
std::string description() const override { return WriteTagThrottlingWorkload::NAME; }
ACTOR static Future<Void> _setup(Database cx, WriteTagThrottlingWorkload* self) {
state Reference<Database> db = makeReference<Database>(cx);
state Reference<DatabaseContext> db = Reference<DatabaseContext>::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<Void> throttledTagUpdater(Database cx, WriteTagThrottlingWorkload* self) {
state std::vector<TagThrottleInfo> tags;
state Reference<Database> db = makeReference<Database>(cx);
state Reference<DatabaseContext> db = Reference<DatabaseContext>::addRef(cx.getPtr());
loop {
wait(delay(1.0));
wait(store(tags, ThrottleApi::getThrottledTags(db, CLIENT_KNOBS->TOO_MANY, true)));