update TagThrottleApiWorkload
This commit is contained in:
parent
ec56e1f286
commit
f94a78ff03
|
@ -26,13 +26,18 @@
|
|||
#include "flow/actorcompiler.h" // This must be the last #include.
|
||||
|
||||
struct TagThrottleApiWorkload : TestWorkload {
|
||||
int apiVersion;
|
||||
bool autoThrottleEnabled;
|
||||
double testDuration;
|
||||
|
||||
constexpr static const char* NAME = "TagThrottleApi";
|
||||
|
||||
TagThrottleApiWorkload(WorkloadContext const& wcx) : TestWorkload(wcx) {
|
||||
testDuration = getOption( options, LiteralStringRef("testDuration"), 10.0 );
|
||||
autoThrottleEnabled = SERVER_KNOBS->AUTO_TAG_THROTTLING_ENABLED;
|
||||
}
|
||||
|
||||
virtual std::string description() { return "TagThrottleApi"; }
|
||||
virtual std::string description() { return TagThrottleApiWorkload::NAME; }
|
||||
|
||||
virtual Future<Void> setup(Database const& cx) {
|
||||
DatabaseContext::debugUseTags = true;
|
||||
|
@ -40,6 +45,20 @@ struct TagThrottleApiWorkload : TestWorkload {
|
|||
}
|
||||
|
||||
virtual Future<Void> start(Database const& cx) {
|
||||
// choose a version to check compatibility.
|
||||
double choice = deterministicRandom()->random01();
|
||||
if(choice < 0.3) {
|
||||
apiVersion = 630;
|
||||
}
|
||||
else if(choice < 0.7){
|
||||
apiVersion = 700;
|
||||
}
|
||||
else {
|
||||
apiVersion = Database::API_VERSION_LATEST;
|
||||
}
|
||||
TraceEvent("VersionStampApiVersion").detail("ApiVersion", apiVersion);
|
||||
cx->apiVersion = apiVersion;
|
||||
|
||||
if (this->clientId != 0) return Void();
|
||||
return timeout(runThrottleApi(this, cx), testDuration, Void());
|
||||
}
|
||||
|
@ -76,7 +95,7 @@ struct TagThrottleApiWorkload : TestWorkload {
|
|||
tagSet.addTag(tag);
|
||||
|
||||
try {
|
||||
wait(ThrottleApi::throttleTags(cx, tagSet, rate, duration, TagThrottleType::MANUAL, priority));
|
||||
wait(ThrottleApi::throttleTags(cx, tagSet, rate, duration, TagThrottleType::MANUAL, priority, Optional<double>(), TagThrottledReason::MANUAL));
|
||||
}
|
||||
catch(Error &e) {
|
||||
state Error err = e;
|
||||
|
@ -88,7 +107,9 @@ struct TagThrottleApiWorkload : TestWorkload {
|
|||
throw err;
|
||||
}
|
||||
|
||||
manuallyThrottledTags->insert_or_assign(std::make_pair(tag, priority), TagThrottleInfo(tag, TagThrottleType::MANUAL, priority, rate, now() + duration, duration));
|
||||
manuallyThrottledTags->insert_or_assign(
|
||||
std::make_pair(tag, priority), TagThrottleInfo(tag, TagThrottleType::MANUAL, priority, rate,
|
||||
now() + duration, duration, TagThrottledReason::MANUAL));
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
@ -127,19 +148,26 @@ struct TagThrottleApiWorkload : TestWorkload {
|
|||
return Void();
|
||||
}
|
||||
|
||||
ACTOR Future<Void> getTags(Database cx, std::map<std::pair<TransactionTag, TransactionPriority>, TagThrottleInfo> const* manuallyThrottledTags) {
|
||||
ACTOR Future<Void> getTags(TagThrottleApiWorkload* self, Database cx, std::map<std::pair<TransactionTag, TransactionPriority>, TagThrottleInfo> const* manuallyThrottledTags) {
|
||||
std::vector<TagThrottleInfo> tags = wait(ThrottleApi::getThrottledTags(cx, CLIENT_KNOBS->TOO_MANY));
|
||||
|
||||
int manualThrottledTags = 0;
|
||||
int activeAutoThrottledTags = 0;
|
||||
for(auto &tag : tags) {
|
||||
if(tag.throttleType == TagThrottleType::MANUAL) {
|
||||
if(tag.throttleType == TagThrottleType::AUTO) {
|
||||
ASSERT(self->autoThrottleEnabled);
|
||||
}
|
||||
else if(tag.throttleType == TagThrottleType::MANUAL) {
|
||||
ASSERT(manuallyThrottledTags->find(std::make_pair(tag.tag, tag.priority)) != manuallyThrottledTags->end());
|
||||
++manualThrottledTags;
|
||||
}
|
||||
else if(tag.expirationTime > now()) {
|
||||
++activeAutoThrottledTags;
|
||||
}
|
||||
|
||||
if(self->apiVersion == 630) {
|
||||
ASSERT(tag.reason == TagThrottledReason::UNSET);
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT(manualThrottledTags <= SERVER_KNOBS->MAX_MANUAL_THROTTLED_TRANSACTION_TAGS);
|
||||
|
@ -158,6 +186,18 @@ struct TagThrottleApiWorkload : TestWorkload {
|
|||
return Void();
|
||||
}
|
||||
|
||||
ACTOR Future<Void> getRecommendedTags(TagThrottleApiWorkload* self, Database cx) {
|
||||
std::vector<TagThrottleInfo> tags = wait(ThrottleApi::getRecommendedTags(cx, CLIENT_KNOBS->TOO_MANY));
|
||||
|
||||
for(auto& tag : tags) {
|
||||
ASSERT(tag.throttleType == TagThrottleType::AUTO);
|
||||
if(self->apiVersion == 630) {
|
||||
ASSERT(tag.reason == TagThrottledReason::UNSET);
|
||||
}
|
||||
}
|
||||
return Void();
|
||||
}
|
||||
|
||||
ACTOR Future<Void> unthrottleTagGroup(Database cx, std::map<std::pair<TransactionTag, TransactionPriority>, TagThrottleInfo> *manuallyThrottledTags) {
|
||||
state Optional<TagThrottleType> throttleType = TagThrottleApiWorkload::randomTagThrottleType();
|
||||
state Optional<TransactionPriority> priority = deterministicRandom()->coinflip() ? Optional<TransactionPriority>() : deterministicRandom()->randomChoice(allTransactionPriorities);
|
||||
|
@ -190,15 +230,17 @@ struct TagThrottleApiWorkload : TestWorkload {
|
|||
return Void();
|
||||
}
|
||||
|
||||
ACTOR Future<Void> enableAutoThrottling(Database cx) {
|
||||
ACTOR Future<Void> enableAutoThrottling(TagThrottleApiWorkload* self, Database cx) {
|
||||
if(deterministicRandom()->coinflip()) {
|
||||
wait(ThrottleApi::enableAuto(cx, true));
|
||||
self->autoThrottleEnabled = true;
|
||||
if(deterministicRandom()->coinflip()) {
|
||||
bool unthrottled = wait(ThrottleApi::unthrottleAll(cx, TagThrottleType::AUTO, Optional<TransactionPriority>()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
wait(ThrottleApi::enableAuto(cx, false));
|
||||
self->autoThrottleEnabled = false;
|
||||
}
|
||||
|
||||
return Void();
|
||||
|
@ -210,7 +252,7 @@ struct TagThrottleApiWorkload : TestWorkload {
|
|||
double delayTime = deterministicRandom()->random01() * 5;
|
||||
wait(delay(delayTime));
|
||||
|
||||
state int action = deterministicRandom()->randomInt(0, 5);
|
||||
state int action = deterministicRandom()->randomInt(0, 6);
|
||||
|
||||
if(action == 0) {
|
||||
wait(self->throttleTag(cx, &manuallyThrottledTags));
|
||||
|
@ -219,16 +261,19 @@ struct TagThrottleApiWorkload : TestWorkload {
|
|||
wait(self->unthrottleTag(cx, &manuallyThrottledTags));
|
||||
}
|
||||
else if(action == 2) {
|
||||
wait(self->getTags(cx, &manuallyThrottledTags));
|
||||
wait(self->getTags(self, cx, &manuallyThrottledTags));
|
||||
}
|
||||
else if(action == 3) {
|
||||
wait(self->unthrottleTagGroup(cx, &manuallyThrottledTags));
|
||||
}
|
||||
else if(action == 4) {
|
||||
wait(self->enableAutoThrottling(cx));
|
||||
wait(self->enableAutoThrottling(self, cx));
|
||||
}
|
||||
else if(action == 5) {
|
||||
wait(self->getRecommendedTags(self, cx));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
WorkloadFactory<TagThrottleApiWorkload> TagThrottleApiWorkloadFactory("TagThrottleApi");
|
||||
WorkloadFactory<TagThrottleApiWorkload> TagThrottleApiWorkloadFactory(TagThrottleApiWorkload::NAME);
|
||||
|
|
Loading…
Reference in New Issue