Remove KnobValueRef::Clear class

This commit is contained in:
sfc-gh-tclinkenbeard 2021-06-02 21:36:34 -07:00
parent 4c059670a0
commit 03be6ce8da
11 changed files with 60 additions and 43 deletions

View File

@ -1,4 +1,3 @@
/*
* CommitProxyInterface.h
*

View File

@ -24,10 +24,15 @@
ConfigKey ConfigKeyRef::decodeKey(KeyRef const& key) {
auto tuple = Tuple::unpack(key);
ASSERT(tuple.size() == 2); // TODO: Fail gracefully
if (tuple.size() != 2) {
throw invalid_config_db_key();
}
if (tuple.getType(0) == Tuple::NULL_TYPE) {
return ConfigKeyRef({}, tuple.getString(1));
} else {
if (tuple.getType(0) != Tuple::BYTES || tuple.getType(1) != Tuple::BYTES) {
throw invalid_config_db_key();
}
return ConfigKeyRef(tuple.getString(0), tuple.getString(1));
}
}
@ -42,3 +47,31 @@ TEST_CASE("/fdbclient/ConfigDB/ConfigKey/EncodeDecode") {
ASSERT(unpacked.knobName == "test_long"_sr);
return Void();
}
TEST_CASE("/fdbclient/ConfigDB/ConfigKey/DecodeFailure1") {
try {
Tuple tuple;
tuple << "s1"_sr
<< "s2"_sr
<< "s3"_sr;
auto unpacked = ConfigKeyRef::decodeKey(tuple.pack());
} catch (Error& e) {
ASSERT_EQ(e.code(), error_code_invalid_config_db_key);
return Void();
}
ASSERT(false);
return Void();
}
TEST_CASE("/fdbclient/ConfigDB/ConfigKey/DecodeFailure2") {
try {
Tuple tuple;
tuple << "s1"_sr << 5;
auto unpacked = ConfigKeyRef::decodeKey(tuple.pack());
} catch (Error& e) {
ASSERT_EQ(e.code(), error_code_invalid_config_db_key);
return Void();
}
ASSERT(false);
return Void();
}

View File

@ -26,16 +26,11 @@
#include "fdbclient/FDBTypes.h"
class KnobValueRef {
// TODO: Should use optional instead
struct Clear {
template <class Ar>
void serialize(Ar&) {}
};
std::variant<Clear, int, double, int64_t, bool, ValueRef> value;
std::variant<int, double, int64_t, bool, ValueRef> value;
template <class T>
explicit KnobValueRef(T const& v) : value(std::in_place_type<T>, v) {}
explicit KnobValueRef(Arena& arena, ValueRef& v) : value(std::in_place_type<ValueRef>, arena, v) {}
explicit KnobValueRef(Arena& arena, ValueRef const& v) : value(std::in_place_type<ValueRef>, arena, v) {}
struct CreatorFunc {
Standalone<KnobValueRef> operator()(NoKnobFound const&) const {
@ -53,7 +48,6 @@ class KnobValueRef {
};
struct ToStringFunc {
std::string operator()(Clear const& v) const { return "<clear>"; }
std::string operator()(int v) const { return format("%d", v); }
std::string operator()(int64_t v) const { return format("%ld", v); }
std::string operator()(bool v) const { return format("%d", v); }
@ -72,10 +66,6 @@ class KnobValueRef {
bool operator()(T const& v) const {
return knobs->setKnob(*knobName, v);
}
bool operator()(Clear const& v) const {
ASSERT(false);
return false;
}
bool operator()(StringRef const& v) const { return knobs->setKnob(*knobName, v.toString()); }
};
@ -92,8 +82,6 @@ public:
static Standalone<KnobValueRef> create(ParsedKnobValue const& v) { return std::visit(CreatorFunc{}, v); }
bool isSet() const { return !std::holds_alternative<Clear>(value); }
size_t expectedSize() const {
return std::holds_alternative<KeyRef>(value) ? std::get<KeyRef>(value).expectedSize() : 0;
}
@ -161,17 +149,18 @@ inline bool operator<(ConfigKeyRef const& lhs, ConfigKeyRef const& rhs) {
class ConfigMutationRef {
ConfigKeyRef key;
KnobValueRef value;
// Empty value means this is a clear mutation
Optional<KnobValueRef> value;
public:
static constexpr FileIdentifier file_identifier = 7219528;
ConfigMutationRef() = default;
explicit ConfigMutationRef(Arena& arena, ConfigKeyRef key, KnobValueRef value)
explicit ConfigMutationRef(Arena& arena, ConfigKeyRef key, Optional<KnobValueRef> value)
: key(arena, key), value(arena, value) {}
explicit ConfigMutationRef(ConfigKeyRef key, KnobValueRef value) : key(key), value(value) {}
explicit ConfigMutationRef(ConfigKeyRef key, Optional<KnobValueRef> value) : key(key), value(value) {}
ConfigKeyRef getKey() const { return key; }
@ -179,11 +168,11 @@ public:
KeyRef getKnobName() const { return key.knobName; }
KnobValueRef getValue() const { return value; }
KnobValueRef getValue() const { return value.get(); }
ConfigMutationRef(Arena& arena, ConfigMutationRef const& rhs) : key(arena, rhs.key), value(arena, rhs.value) {}
bool isSet() const { return value.isSet(); }
bool isSet() const { return value.present(); }
static Standalone<ConfigMutationRef> createConfigMutation(KeyRef encodedKey, KnobValueRef value) {
auto key = ConfigKeyRef::decodeKey(encodedKey);

View File

@ -68,11 +68,6 @@ void PaxosConfigTransaction::clear(KeyRef const& key) {
ASSERT(false);
}
void PaxosConfigTransaction::clear(KeyRangeRef const& key) {
// TODO: Implememnt
ASSERT(false);
}
Future<Void> PaxosConfigTransaction::commit() {
// TODO: Implememnt
ASSERT(false);

View File

@ -45,7 +45,7 @@ public:
bool snapshot = false,
bool reverse = false) override;
void set(KeyRef const& key, ValueRef const& value) override;
void clear(KeyRangeRef const&) override;
void clear(KeyRangeRef const&) override { throw client_invalid_operation(); }
void clear(KeyRef const&) override;
Future<Void> commit() override;
Version getCommittedVersion() const override;

View File

@ -34,7 +34,6 @@ class SimpleConfigTransactionImpl {
int numRetries{ 0 };
bool committed{ false };
Optional<UID> dID;
Promise<Void> resetPromise; // TODO: Make this a field of ISingleThreadTransaction?
ACTOR static Future<Version> getReadVersion(SimpleConfigTransactionImpl* self) {
if (self->dID.present()) {
@ -129,7 +128,7 @@ public:
// TODO: Throw error if decoding fails
ConfigKey configKey = ConfigKeyRef::decodeKey(key);
auto knobValue = KnobCollection::parseKnobValue(configKey.knobName.toString(), value.toString(), true);
toCommit.mutations.emplace_back_deep(toCommit.arena, ConfigKeyRef::decodeKey(key), knobValue);
toCommit.mutations.emplace_back_deep(toCommit.arena, ConfigKeyRef::decodeKey(key), knobValue.contents());
}
}
@ -137,7 +136,8 @@ public:
if (key == configTransactionDescriptionKey) {
toCommit.annotation.description = ""_sr;
} else {
toCommit.mutations.emplace_back_deep(toCommit.arena, ConfigKeyRef::decodeKey(key), KnobValue{});
toCommit.mutations.emplace_back_deep(
toCommit.arena, ConfigKeyRef::decodeKey(key), Optional<KnobValueRef>{});
}
}
@ -239,11 +239,6 @@ void SimpleConfigTransaction::clear(KeyRef const& key) {
impl->clear(key);
}
void SimpleConfigTransaction::clear(KeyRangeRef const& keys) {
// TODO: Implement
ASSERT(false);
}
Future<Void> SimpleConfigTransaction::commit() {
return impl->commit();
}

View File

@ -61,7 +61,7 @@ public:
void checkDeferredError() const override;
int64_t getApproximateSize() const override;
void set(KeyRef const&, ValueRef const&) override;
void clear(KeyRangeRef const&) override;
void clear(KeyRangeRef const&) override { throw client_invalid_operation(); }
void clear(KeyRef const&) override;
void fullReset();

View File

@ -411,12 +411,14 @@ Standalone<VectorRef<VersionedConfigMutationRef>> getTestChanges(Version version
Standalone<VectorRef<VersionedConfigMutationRef>> changes;
if (includeGlobalMutation) {
ConfigKey key = ConfigKeyRef({}, "test_long"_sr);
ConfigMutation mutation = ConfigMutationRef(key, KnobValueRef::create(int64_t{ 5 }));
auto value = KnobValue::create(int64_t{ 5 });
ConfigMutation mutation = ConfigMutationRef(key, value.contents());
changes.emplace_back_deep(changes.arena(), version, mutation);
}
{
ConfigKey key = ConfigKeyRef("class-A"_sr, "test_long"_sr);
ConfigMutation mutation = ConfigMutationRef(key, KnobValueRef::create(int64_t{ 5 }));
auto value = KnobValue::create(int64_t{ 5 });
ConfigMutation mutation = ConfigMutationRef(key, value.contents());
changes.emplace_back_deep(changes.arena(), version, mutation);
}
return changes;

View File

@ -44,7 +44,7 @@ void appendVersionedMutation(Standalone<VectorRef<VersionedConfigMutationRef>>&
Version version,
Optional<KeyRef> configClass,
KeyRef knobName,
KnobValueRef knobValue) {
Optional<KnobValueRef> knobValue) {
auto configKey = ConfigKeyRef(configClass, knobName);
auto mutation = ConfigMutationRef(configKey, knobValue);
versionedMutations.emplace_back_deep(versionedMutations.arena(), version, mutation);
@ -184,7 +184,7 @@ class LocalConfigEnvironment {
ReadFromLocalConfigEnvironment readFrom;
Version lastWrittenVersion{ 0 };
Future<Void> addMutation(Optional<KeyRef> configClass, KnobValueRef value) {
Future<Void> addMutation(Optional<KeyRef> configClass, Optional<KnobValueRef> value) {
Standalone<VectorRef<VersionedConfigMutationRef>> versionedMutations;
appendVersionedMutation(versionedMutations, ++lastWrittenVersion, configClass, "test_long"_sr, value);
return readFrom.getMutableLocalConfiguration().addChanges(versionedMutations, lastWrittenVersion);
@ -201,7 +201,8 @@ public:
Future<Void> getError() const { return Never(); }
Future<Void> clear(Optional<KeyRef> configClass) { return addMutation(configClass, {}); }
Future<Void> set(Optional<KeyRef> configClass, int64_t value) {
return addMutation(configClass, KnobValueRef::create(value));
auto knobValue = KnobValueRef::create(value);
return addMutation(configClass, knobValue.contents());
}
void check(Optional<int64_t> value) const { return readFrom.checkImmediate(value); }
};
@ -233,7 +234,10 @@ public:
Future<Void> setup() { return setup(this); }
void set(Optional<KeyRef> configClass, int64_t value) { addMutation(configClass, KnobValueRef::create(value)); }
void set(Optional<KeyRef> configClass, int64_t value) {
auto knobValue = KnobValueRef::create(value);
addMutation(configClass, knobValue.contents());
}
void clear(Optional<KeyRef> configClass) { addMutation(configClass, {}); }

View File

@ -60,7 +60,6 @@ public:
}
ConfigClassSet getConfigClassSet() const { return ConfigClassSet(configPath); }
void set(Optional<KeyRef> configClass, KeyRef knobName, KnobValueRef value) {
ASSERT(value.isSet());
configClassToKnobToValue[configClass.castTo<Key>()][knobName] = value;
}
void remove(Optional<KeyRef> configClass, KeyRef knobName) {

View File

@ -151,6 +151,7 @@ ERROR( invalid_cache_eviction_policy, 2024, "Invalid cache eviction policy, only
ERROR( network_cannot_be_restarted, 2025, "Network can only be started once" )
ERROR( blocked_from_network_thread, 2026, "Detected a deadlock in a callback called from the network thread" )
ERROR( invalid_config_db_range_read, 2027, "Invalid configuration database range read" )
ERROR( invalid_config_db_key, 2028, "Invalid configuration database key provided" )
ERROR( incompatible_protocol_version, 2100, "Incompatible protocol version" )
ERROR( transaction_too_large, 2101, "Transaction exceeds byte limit" )