Remove duplicate Knobs::reset code
This commit is contained in:
parent
d7692b628f
commit
01eab20fc0
|
@ -249,11 +249,6 @@ void ClientKnobs::initialize(bool randomize) {
|
|||
// clang-format on
|
||||
}
|
||||
|
||||
void ClientKnobs::reset() {
|
||||
explicitlySetKnobs.clear();
|
||||
initialize();
|
||||
}
|
||||
|
||||
TEST_CASE("/fdbclient/knobs/initialize") {
|
||||
// This test depends on TASKBUCKET_TIMEOUT_VERSIONS being defined as a constant multiple of CORE_VERSIONSPERSECOND
|
||||
ClientKnobs clientKnobs;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "flow/Knobs.h"
|
||||
#include "flow/flow.h"
|
||||
|
||||
class ClientKnobs : public Knobs {
|
||||
class ClientKnobs : public Knobs<ClientKnobs> {
|
||||
public:
|
||||
int TOO_MANY; // FIXME: this should really be split up so we can control these more specifically
|
||||
|
||||
|
@ -232,7 +232,6 @@ public:
|
|||
|
||||
ClientKnobs();
|
||||
void initialize(bool randomize = false);
|
||||
void reset();
|
||||
};
|
||||
|
||||
extern std::unique_ptr<ClientKnobs> globalClientKnobs;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
class SimpleConfigTransactionImpl {
|
||||
Standalone<VectorRef<ConfigMutationRef>> mutations;
|
||||
Future<Version> version;
|
||||
Key description;
|
||||
ConfigTransactionInterface cti;
|
||||
int numRetries{ 0 };
|
||||
bool committed{ false };
|
||||
|
@ -73,7 +74,7 @@ class SimpleConfigTransactionImpl {
|
|||
auto commitTime = now();
|
||||
for (auto& mutation : self->mutations) {
|
||||
mutation.setTimestamp(commitTime);
|
||||
// TODO: Update description
|
||||
mutation.setDescription(self->description);
|
||||
}
|
||||
wait(self->cti.commit.getReply(ConfigTransactionCommitRequest(version, self->mutations)));
|
||||
self->committed = true;
|
||||
|
@ -87,7 +88,12 @@ public:
|
|||
cti = ConfigTransactionInterface(coordinators[0]);
|
||||
}
|
||||
|
||||
SimpleConfigTransactionImpl(ConfigTransactionInterface const& cti) : cti(cti) {}
|
||||
|
||||
void set(KeyRef key, ValueRef value) {
|
||||
if (key == "\xff\xff/description"_sr) {
|
||||
description = value;
|
||||
}
|
||||
mutations.push_back_deep(mutations.arena(), ConfigMutationRef::createConfigMutation(key, value));
|
||||
}
|
||||
|
||||
|
@ -223,4 +229,7 @@ void SimpleConfigTransaction::getWriteConflicts(KeyRangeMap<bool>* result) {}
|
|||
SimpleConfigTransaction::SimpleConfigTransaction(ClusterConnectionString const& ccs)
|
||||
: impl(std::make_unique<SimpleConfigTransactionImpl>(ccs)) {}
|
||||
|
||||
SimpleConfigTransaction::SimpleConfigTransaction(ConfigTransactionInterface const& cti)
|
||||
: impl(std::make_unique<SimpleConfigTransactionImpl>(cti)) {}
|
||||
|
||||
SimpleConfigTransaction::~SimpleConfigTransaction() = default;
|
||||
|
|
|
@ -34,6 +34,7 @@ class SimpleConfigTransaction final : public ISingleThreadTransaction, public Fa
|
|||
std::unique_ptr<class SimpleConfigTransactionImpl> impl;
|
||||
|
||||
public:
|
||||
SimpleConfigTransaction(ConfigTransactionInterface const&);
|
||||
SimpleConfigTransaction(ClusterConnectionString const&);
|
||||
~SimpleConfigTransaction();
|
||||
void setVersion(Version) override { throw client_invalid_operation(); }
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
*/
|
||||
|
||||
#include "fdbclient/CoordinationInterface.h"
|
||||
#include "fdbclient/SimpleConfigTransaction.h"
|
||||
#include "fdbserver/ConfigBroadcaster.h"
|
||||
#include "fdbserver/IConfigDatabaseNode.h"
|
||||
#include "fdbserver/LocalConfiguration.h"
|
||||
#include "fdbclient/Tuple.h"
|
||||
#include "flow/UnitTest.h"
|
||||
|
@ -292,3 +294,18 @@ TEST_CASE("/fdbserver/ConfigDB/ConfigBroadcaster/CheckpointedUpdates") {
|
|||
wait(waitUntilTestLongMatches(localConfigurationB, 300));
|
||||
return Void();
|
||||
}
|
||||
|
||||
TEST_CASE("/fdbserver/ConfigDB/ConfigBroadcaster/Transaction/Set") {
|
||||
state ConfigTransactionInterface cti;
|
||||
state SimpleConfigTransaction tr1(cti);
|
||||
state SimpleConfigTransaction tr2(cti);
|
||||
state SimpleConfigDatabaseNode node("./");
|
||||
state ActorCollection actors(false);
|
||||
actors.add(node.serve(cti));
|
||||
Tuple tuple;
|
||||
tuple << "class-A"_sr
|
||||
<< "test_long"_sr;
|
||||
tr1.set(tuple.pack(), "100"_sr);
|
||||
wait(tr1.commit());
|
||||
return Void();
|
||||
}
|
||||
|
|
|
@ -727,8 +727,3 @@ void ServerKnobs::initialize(bool randomize, ClientKnobs* clientKnobs, bool isSi
|
|||
clientKnobs->INIT_MID_SHARD_BYTES = MIN_SHARD_BYTES;
|
||||
}
|
||||
}
|
||||
|
||||
void ServerKnobs::reset(ClientKnobs* clientKnobs) {
|
||||
explicitlySetKnobs.clear();
|
||||
initialize(false, clientKnobs);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
// Disk queue
|
||||
static const int _PAGE_SIZE = 4096;
|
||||
|
||||
class ServerKnobs : public Knobs {
|
||||
class ServerKnobs : public Knobs<ServerKnobs> {
|
||||
public:
|
||||
// Versions
|
||||
int64_t VERSIONS_PER_SECOND;
|
||||
|
@ -656,7 +656,6 @@ public:
|
|||
|
||||
ServerKnobs();
|
||||
void initialize(bool randomize = false, ClientKnobs* clientKnobs = nullptr, bool isSimulated = false);
|
||||
void reset(ClientKnobs* clientKnobs = nullptr);
|
||||
};
|
||||
|
||||
extern std::unique_ptr<ServerKnobs> globalServerKnobs;
|
||||
|
|
|
@ -208,10 +208,10 @@ class LocalConfigurationImpl : public NonCopyable {
|
|||
testKnobs.initialize();
|
||||
}
|
||||
|
||||
void resetKnobs() {
|
||||
flowKnobs.reset();
|
||||
clientKnobs.reset();
|
||||
serverKnobs.reset(&clientKnobs);
|
||||
void resetKnobs(bool randomize = false, bool isSimulated = false) {
|
||||
flowKnobs.reset(randomize, isSimulated);
|
||||
clientKnobs.reset(randomize);
|
||||
serverKnobs.reset(randomize, &clientKnobs, isSimulated);
|
||||
testKnobs.reset();
|
||||
}
|
||||
|
||||
|
@ -413,11 +413,6 @@ void TestKnobs::initialize() {
|
|||
init(TEST_STRING, "");
|
||||
}
|
||||
|
||||
void TestKnobs::reset() {
|
||||
explicitlySetKnobs.clear();
|
||||
initialize();
|
||||
}
|
||||
|
||||
bool TestKnobs::operator==(TestKnobs const& rhs) const {
|
||||
return (TEST_LONG == rhs.TEST_LONG) && (TEST_INT == rhs.TEST_INT) && (TEST_DOUBLE == rhs.TEST_DOUBLE) &&
|
||||
(TEST_BOOL == rhs.TEST_BOOL) && (TEST_STRING == rhs.TEST_STRING);
|
||||
|
@ -429,7 +424,7 @@ bool TestKnobs::operator!=(TestKnobs const& rhs) const {
|
|||
|
||||
namespace {
|
||||
|
||||
class TestKnobs2 : public Knobs {
|
||||
class TestKnobs2 : public Knobs<TestKnobs2> {
|
||||
public:
|
||||
int64_t TEST2_LONG;
|
||||
int TEST2_INT;
|
||||
|
@ -446,11 +441,6 @@ public:
|
|||
}
|
||||
|
||||
TestKnobs2() { initialize(); }
|
||||
|
||||
void reset() {
|
||||
explicitlySetKnobs.clear();
|
||||
initialize();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "flow/Arena.h"
|
||||
#include "flow/Knobs.h"
|
||||
|
||||
class TestKnobs : public Knobs {
|
||||
class TestKnobs : public Knobs<TestKnobs> {
|
||||
public:
|
||||
TestKnobs();
|
||||
int64_t TEST_LONG;
|
||||
|
@ -38,7 +38,6 @@ public:
|
|||
bool operator==(TestKnobs const&) const;
|
||||
bool operator!=(TestKnobs const&) const;
|
||||
void initialize();
|
||||
void reset();
|
||||
};
|
||||
|
||||
class LocalConfiguration {
|
||||
|
|
|
@ -252,7 +252,7 @@ static std::string toLower(std::string const& name) {
|
|||
return lower_name;
|
||||
}
|
||||
|
||||
bool Knobs::setKnob(std::string const& knob, std::string const& value) {
|
||||
bool KnobsCollection::setKnob(std::string const& knob, std::string const& value) {
|
||||
explicitlySetKnobs.insert(toLower(knob));
|
||||
if (double_knobs.count(knob)) {
|
||||
double v;
|
||||
|
@ -308,42 +308,42 @@ bool Knobs::setKnob(std::string const& knob, std::string const& value) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void Knobs::initKnob(double& knob, double value, std::string const& name) {
|
||||
void KnobsCollection::initKnob(double& knob, double value, std::string const& name) {
|
||||
if (!explicitlySetKnobs.count(toLower(name))) {
|
||||
knob = value;
|
||||
double_knobs[toLower(name)] = &knob;
|
||||
}
|
||||
}
|
||||
|
||||
void Knobs::initKnob(int64_t& knob, int64_t value, std::string const& name) {
|
||||
void KnobsCollection::initKnob(int64_t& knob, int64_t value, std::string const& name) {
|
||||
if (!explicitlySetKnobs.count(toLower(name))) {
|
||||
knob = value;
|
||||
int64_knobs[toLower(name)] = &knob;
|
||||
}
|
||||
}
|
||||
|
||||
void Knobs::initKnob(int& knob, int value, std::string const& name) {
|
||||
void KnobsCollection::initKnob(int& knob, int value, std::string const& name) {
|
||||
if (!explicitlySetKnobs.count(toLower(name))) {
|
||||
knob = value;
|
||||
int_knobs[toLower(name)] = &knob;
|
||||
}
|
||||
}
|
||||
|
||||
void Knobs::initKnob(std::string& knob, const std::string& value, const std::string& name) {
|
||||
void KnobsCollection::initKnob(std::string& knob, const std::string& value, const std::string& name) {
|
||||
if (!explicitlySetKnobs.count(toLower(name))) {
|
||||
knob = value;
|
||||
string_knobs[toLower(name)] = &knob;
|
||||
}
|
||||
}
|
||||
|
||||
void Knobs::initKnob(bool& knob, bool value, std::string const& name) {
|
||||
void KnobsCollection::initKnob(bool& knob, bool value, std::string const& name) {
|
||||
if (!explicitlySetKnobs.count(toLower(name))) {
|
||||
knob = value;
|
||||
bool_knobs[toLower(name)] = &knob;
|
||||
}
|
||||
}
|
||||
|
||||
void Knobs::trace() const {
|
||||
void KnobsCollection::trace() const {
|
||||
for (auto& k : double_knobs)
|
||||
TraceEvent("Knob").detail("Name", k.first.c_str()).detail("Value", *k.second);
|
||||
for (auto& k : int_knobs)
|
||||
|
@ -355,8 +355,3 @@ void Knobs::trace() const {
|
|||
for (auto& k : bool_knobs)
|
||||
TraceEvent("Knob").detail("Name", k.first.c_str()).detail("Value", *k.second);
|
||||
}
|
||||
|
||||
void FlowKnobs::reset() {
|
||||
explicitlySetKnobs.clear();
|
||||
initialize();
|
||||
}
|
||||
|
|
31
flow/Knobs.h
31
flow/Knobs.h
|
@ -29,16 +29,11 @@
|
|||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
class Knobs {
|
||||
public:
|
||||
bool setKnob(std::string const& name,
|
||||
std::string const& value); // Returns true if the knob name is known, false if it is unknown
|
||||
void trace() const;
|
||||
|
||||
class KnobsCollection {
|
||||
protected:
|
||||
Knobs() = default;
|
||||
Knobs(Knobs const&) = delete;
|
||||
Knobs& operator=(Knobs const&) = delete;
|
||||
KnobsCollection() = default;
|
||||
KnobsCollection(KnobsCollection const&) = delete;
|
||||
KnobsCollection& operator=(KnobsCollection const&) = delete;
|
||||
void initKnob(double& knob, double value, std::string const& name);
|
||||
void initKnob(int64_t& knob, int64_t value, std::string const& name);
|
||||
void initKnob(int& knob, int value, std::string const& name);
|
||||
|
@ -51,9 +46,24 @@ protected:
|
|||
std::map<std::string, std::string*> string_knobs;
|
||||
std::map<std::string, bool*> bool_knobs;
|
||||
std::set<std::string> explicitlySetKnobs;
|
||||
|
||||
public:
|
||||
bool setKnob(std::string const& name,
|
||||
std::string const& value); // Returns true if the knob name is known, false if it is unknown
|
||||
void trace() const;
|
||||
};
|
||||
|
||||
class FlowKnobs : public Knobs {
|
||||
template <class T>
|
||||
class Knobs : public KnobsCollection {
|
||||
public:
|
||||
template <class... Args>
|
||||
void reset(Args&&... args) {
|
||||
explicitlySetKnobs.clear();
|
||||
static_cast<T*>(this)->initialize(std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
class FlowKnobs : public Knobs<FlowKnobs> {
|
||||
public:
|
||||
int AUTOMATIC_TRACE_DUMP;
|
||||
double PREVENT_FAST_SPIN_DELAY;
|
||||
|
@ -260,7 +270,6 @@ public:
|
|||
|
||||
FlowKnobs();
|
||||
void initialize(bool randomize = false, bool isSimulated = false);
|
||||
void reset();
|
||||
};
|
||||
|
||||
extern std::unique_ptr<FlowKnobs> globalFlowKnobs;
|
||||
|
|
Loading…
Reference in New Issue