Manage global flow knobs with global knob collection

This commit is contained in:
sfc-gh-tclinkenbeard 2021-06-09 22:33:00 -07:00
parent 83a0e473e8
commit c272304e60
13 changed files with 60 additions and 35 deletions

View File

@ -3704,12 +3704,12 @@ int main(int argc, char* argv[]) {
}
}
g_knobs = IKnobCollection::create(IKnobCollection::Type::CLIENT, Randomize::NO, IsSimulated::NO);
IKnobCollection::setGlobalKnobCollection(IKnobCollection::Type::CLIENT, Randomize::NO, IsSimulated::NO);
auto& g_knobs = IKnobCollection::getMutableGlobalKnobCollection();
for (const auto& [knobName, knobValueString] : knobs) {
try {
auto knobValue = g_knobs->parseKnobValue(knobName, knobValueString);
g_knobs->setKnob(knobName, knobValue);
auto knobValue = g_knobs.parseKnobValue(knobName, knobValueString);
g_knobs.setKnob(knobName, knobValue);
} catch (Error& e) {
if (e.code() == error_code_invalid_option_value) {
fprintf(stderr,
@ -3731,7 +3731,7 @@ int main(int argc, char* argv[]) {
}
// Reinitialize knobs in order to update knobs that are dependent on explicitly set knobs
g_knobs->initialize(Randomize::NO, IsSimulated::NO);
g_knobs.initialize(Randomize::NO, IsSimulated::NO);
if (trace) {
if (!traceLogGroup.empty())

View File

@ -3008,10 +3008,11 @@ struct CLIOptions {
return;
}
auto& g_knobs = IKnobCollection::getMutableGlobalKnobCollection();
for (const auto& [knobName, knobValueString] : knobs) {
try {
auto knobValue = g_knobs->parseKnobValue(knobName, knobValueString);
g_knobs->setKnob(knobName, knobValue);
auto knobValue = g_knobs.parseKnobValue(knobName, knobValueString);
g_knobs.setKnob(knobName, knobValue);
} catch (Error& e) {
if (e.code() == error_code_invalid_option_value) {
fprintf(stderr,
@ -3033,7 +3034,7 @@ struct CLIOptions {
}
// Reinitialize knobs in order to update knobs that are dependent on explicitly set knobs
g_knobs->initialize(Randomize::YES, IsSimulated::NO);
g_knobs.initialize(Randomize::NO, IsSimulated::NO);
}
int processArg(CSimpleOpt& args) {
@ -4832,7 +4833,7 @@ int main(int argc, char** argv) {
registerCrashHandler();
g_knobs = IKnobCollection::create(IKnobCollection::Type::CLIENT, Randomize::NO, IsSimulated::NO);
IKnobCollection::setGlobalKnobCollection(IKnobCollection::Type::CLIENT, Randomize::NO, IsSimulated::NO);
#ifdef __unixish__
struct sigaction act;

View File

@ -71,5 +71,18 @@ KnobValue IKnobCollection::parseKnobValue(std::string const& knobName, std::stri
UNSTOPPABLE_ASSERT(false);
}
std::unique_ptr<IKnobCollection> g_knobs =
std::unique_ptr<IKnobCollection> IKnobCollection::globalKnobCollection =
IKnobCollection::create(IKnobCollection::Type::CLIENT, Randomize::NO, IsSimulated::NO);
void IKnobCollection::setGlobalKnobCollection(Type type, Randomize randomize, IsSimulated isSimulated) {
globalKnobCollection = create(type, randomize, isSimulated);
FLOW_KNOBS = &globalKnobCollection->getFlowKnobs();
}
IKnobCollection const& IKnobCollection::getGlobalKnobCollection() {
return *globalKnobCollection;
}
IKnobCollection& IKnobCollection::getMutableGlobalKnobCollection() {
return *globalKnobCollection;
}

View File

@ -28,6 +28,8 @@
#include "flow/Knobs.h"
class IKnobCollection {
static std::unique_ptr<IKnobCollection> globalKnobCollection;
public:
enum class Type {
CLIENT,
@ -35,6 +37,7 @@ public:
TEST,
};
static std::unique_ptr<IKnobCollection> create(Type, Randomize, IsSimulated);
virtual void initialize(Randomize randomize, IsSimulated isSimulated) = 0;
virtual void reset(Randomize randomize, IsSimulated isSimulated) = 0;
virtual FlowKnobs const& getFlowKnobs() const = 0;
@ -47,7 +50,8 @@ public:
// Result indicates whether or not knob was successfully set:
virtual bool trySetKnob(std::string const& knobName, KnobValueRef const& knobValue) = 0;
void setKnob(std::string const& knobName, KnobValueRef const& knobValue);
static std::unique_ptr<IKnobCollection> create(Type, Randomize, IsSimulated);
};
extern std::unique_ptr<IKnobCollection> g_knobs;
static void setGlobalKnobCollection(Type, Randomize, IsSimulated);
static IKnobCollection const& getGlobalKnobCollection();
static IKnobCollection& getMutableGlobalKnobCollection();
};

View File

@ -22,4 +22,4 @@
#include "fdbclient/IKnobCollection.h"
#define CLIENT_KNOBS (&g_knobs->getClientKnobs())
#define CLIENT_KNOBS (&IKnobCollection::getGlobalKnobCollection().getClientKnobs())

View File

@ -1870,8 +1870,8 @@ void setNetworkOption(FDBNetworkOptions::Option option, Optional<StringRef> valu
std::string knobValueString = optionValue.substr(eq + 1);
try {
auto knobValue = g_knobs->parseKnobValue(knobName, knobValueString);
g_knobs->setKnob(knobName, knobValue);
auto knobValue = IKnobCollection::parseKnobValue(knobName, knobValueString, IKnobCollection::Type::CLIENT);
IKnobCollection::getMutableGlobalKnobCollection().setKnob(knobName, knobValue);
} catch (Error& e) {
TraceEvent(SevWarnAlways, "UnrecognizedKnob").detail("Knob", knobName.c_str());
fprintf(stderr, "FoundationDB client ignoring unrecognized knob option '%s'\n", knobName.c_str());

View File

@ -22,4 +22,4 @@
#include "fdbclient/IKnobCollection.h"
#define SERVER_KNOBS (&g_knobs->getServerKnobs())
#define SERVER_KNOBS (&IKnobCollection::getGlobalKnobCollection().getServerKnobs())

View File

@ -130,11 +130,11 @@ class LocalConfigurationImpl {
std::unique_ptr<IKnobCollection> testKnobCollection;
IKnobCollection& getKnobs() {
return testKnobCollection ? *testKnobCollection : *g_knobs;
return testKnobCollection ? *testKnobCollection : IKnobCollection::getMutableGlobalKnobCollection();
}
IKnobCollection const& getKnobs() const {
return testKnobCollection ? *testKnobCollection : *g_knobs;
return testKnobCollection ? *testKnobCollection : IKnobCollection::getGlobalKnobCollection();
}
CounterCollection cc;

View File

@ -1646,18 +1646,20 @@ int main(int argc, char* argv[]) {
enableBuggify(opts.buggifyEnabled, BuggifyType::General);
g_knobs = IKnobCollection::create(IKnobCollection::Type::SERVER,
Randomize::YES,
role == ServerRole::Simulation ? IsSimulated::YES : IsSimulated::NO);
g_knobs->setKnob("log_directory", KnobValue::create(opts.logFolder));
IKnobCollection::setGlobalKnobCollection(IKnobCollection::Type::SERVER,
Randomize::YES,
role == ServerRole::Simulation ? IsSimulated::YES : IsSimulated::NO);
IKnobCollection::getMutableGlobalKnobCollection().setKnob("log_directory", KnobValue::create(opts.logFolder));
if (role != ServerRole::Simulation) {
g_knobs->setKnob("commit_batches_mem_bytes_hard_limit", KnobValue::create(int64_t{ opts.memLimit }));
IKnobCollection::getMutableGlobalKnobCollection().setKnob("commit_batches_mem_bytes_hard_limit",
KnobValue::create(int64_t{ opts.memLimit }));
}
for (const auto& [knobName, knobValueString] : opts.knobs) {
try {
auto knobValue = g_knobs->parseKnobValue(knobName, knobValueString);
g_knobs->setKnob(knobName, knobValue);
auto& g_knobs = IKnobCollection::getMutableGlobalKnobCollection();
auto knobValue = g_knobs.parseKnobValue(knobName, knobValueString);
g_knobs.setKnob(knobName, knobValue);
} catch (Error& e) {
if (e.code() == error_code_invalid_option_value) {
fprintf(stderr,
@ -1677,9 +1679,11 @@ int main(int argc, char* argv[]) {
}
}
}
g_knobs->setKnob("server_mem_limit", KnobValue::create(int64_t{ opts.memLimit }));
IKnobCollection::getMutableGlobalKnobCollection().setKnob("server_mem_limit",
KnobValue::create(int64_t{ opts.memLimit }));
// Reinitialize knobs in order to update knobs that are dependent on explicitly set knobs
g_knobs->initialize(Randomize::YES, role == ServerRole::Simulation ? IsSimulated::YES : IsSimulated::NO);
IKnobCollection::getMutableGlobalKnobCollection().initialize(
Randomize::YES, role == ServerRole::Simulation ? IsSimulated::YES : IsSimulated::NO);
// evictionPolicyStringToEnum will throw an exception if the string is not recognized as a valid
EvictablePageCache::evictionPolicyStringToEnum(FLOW_KNOBS->CACHE_EVICTION_POLICY);

View File

@ -218,8 +218,8 @@ struct ClientTransactionProfileCorrectnessWorkload : TestWorkload {
Future<Void> setup(Database const& cx) override {
if (clientId == 0) {
auto knobValue = g_knobs->parseKnobValue("csi_status_delay", "2.0"); // 2 seconds
g_knobs->setKnob("csi_status_delay", knobValue);
IKnobCollection::getMutableGlobalKnobCollection().setKnob("csi_status_delay",
KnobValueRef::create(double{ 2.0 })); // 2 seconds
return changeProfilingParameters(cx, trInfoSizeLimit, samplingProbability);
}
return Void();

View File

@ -51,8 +51,10 @@ struct LowLatencyWorkload : TestWorkload {
Future<Void> setup(Database const& cx) override {
if (g_network->isSimulated()) {
g_knobs->setKnob("min_delay_cc_worst_fit_candidacy_seconds", KnobValueRef::create(double{5.0}));
g_knobs->setKnob("max_delay_cc_worst_fit_candidacy_seconds", KnobValueRef::create(double{10.0}));
IKnobCollection::getMutableGlobalKnobCollection().setKnob("min_delay_cc_worst_fit_candidacy_seconds",
KnobValueRef::create(double{ 5.0 }));
IKnobCollection::getMutableGlobalKnobCollection().setKnob("max_delay_cc_worst_fit_candidacy_seconds",
KnobValueRef::create(double{ 10.0 }));
}
return Void();
}

View File

@ -27,7 +27,8 @@ FlowKnobs::FlowKnobs(Randomize randomize, IsSimulated isSimulated) {
initialize(randomize, isSimulated);
}
FlowKnobs globalFlowKnobs(Randomize::NO, IsSimulated::NO);
FlowKnobs bootstrapGlobalFlowKnobs(Randomize::NO, IsSimulated::NO);
FlowKnobs const* FLOW_KNOBS = &bootstrapGlobalFlowKnobs;
#define init(knob, value) initKnob(knob, value, #knob)

View File

@ -285,7 +285,7 @@ public:
void initialize(Randomize, IsSimulated);
};
extern FlowKnobs globalFlowKnobs;
#define FLOW_KNOBS (static_cast<FlowKnobs const*>(&globalFlowKnobs))
extern FlowKnobs bootstrapGlobalFlowKnobs;
extern FlowKnobs const* FLOW_KNOBS;
#endif