From 899b6267aeac23a87db8db6afb6741960bd357fa Mon Sep 17 00:00:00 2001 From: "A.J. Beamon" Date: Tue, 28 Jun 2022 13:45:10 -0700 Subject: [PATCH] Update key backed types to support a templated Codec. This required updating the existing Codec to convert from objects into byte strings through tuples. --- fdbclient/BackupAgent.actor.h | 40 ++--- fdbclient/FileBackupAgent.actor.cpp | 2 +- fdbclient/KeyBackedTypes.h | 239 +++++++++++++++------------- fdbclient/TaskBucket.h | 4 +- fdbserver/ApplyMetadataMutation.cpp | 6 +- fdbserver/MoveKeys.actor.cpp | 2 +- fdbserver/TSSMappingUtil.actor.cpp | 4 +- fdbserver/storageserver.actor.cpp | 4 +- 8 files changed, 161 insertions(+), 140 deletions(-) diff --git a/fdbclient/BackupAgent.actor.h b/fdbclient/BackupAgent.actor.h index 0e72d1da5f..9ec7f23cda 100644 --- a/fdbclient/BackupAgent.actor.h +++ b/fdbclient/BackupAgent.actor.h @@ -359,12 +359,14 @@ public: }; template <> -inline Tuple Codec::pack(FileBackupAgent::ERestoreState const& val) { - return Tuple().append(val); +inline Standalone TupleCodec::pack( + FileBackupAgent::ERestoreState const& val) { + return Tuple().append(val).pack(); } template <> -inline FileBackupAgent::ERestoreState Codec::unpack(Tuple const& val) { - return (FileBackupAgent::ERestoreState)val.getInt(0); +inline FileBackupAgent::ERestoreState TupleCodec::unpack( + Standalone const& val) { + return (FileBackupAgent::ERestoreState)Tuple::unpack(val).getInt(0); } class DatabaseBackupAgent : public BackupAgentBase { @@ -575,12 +577,12 @@ ACTOR Future cleanupBackup(Database cx, DeleteData deleteData); using EBackupState = BackupAgentBase::EnumState; template <> -inline Tuple Codec::pack(EBackupState const& val) { - return Tuple().append(static_cast(val)); +inline Standalone TupleCodec::pack(EBackupState const& val) { + return Tuple().append(static_cast(val)).pack(); } template <> -inline EBackupState Codec::unpack(Tuple const& val) { - return static_cast(val.getInt(0)); +inline EBackupState TupleCodec::unpack(Standalone const& val) { + return static_cast(Tuple::unpack(val).getInt(0)); } // Key backed tags are a single-key slice of the TagUidMap, defined below. @@ -678,7 +680,7 @@ public: throw restore_error(); // Validation contition is that the uidPair key must be exactly {u, false} TaskBucket::setValidationCondition( - task, KeyBackedTag(tag.get(), p).key, Codec::pack({ u, false }).pack()); + task, KeyBackedTag(tag.get(), p).key, TupleCodec::pack({ u, false })); return Void(); }); } @@ -724,7 +726,7 @@ protected: }; template <> -inline Tuple Codec>::pack(Reference const& bc) { +inline Standalone TupleCodec>::pack(Reference const& bc) { Tuple tuple; tuple.append(StringRef(bc->getURL())); @@ -740,21 +742,23 @@ inline Tuple Codec>::pack(Reference -inline Reference Codec>::unpack(Tuple const& val) { - ASSERT(val.size() >= 1); - auto url = val.getString(0).toString(); +inline Reference TupleCodec>::unpack(Standalone const& val) { + Tuple t = Tuple::unpack(val); + ASSERT(t.size() >= 1); + + auto url = t.getString(0).toString(); Optional encryptionKeyFileName; - if (val.size() > 1 && !val.getString(1).empty()) { - encryptionKeyFileName = val.getString(1).toString(); + if (t.size() > 1 && !t.getString(1).empty()) { + encryptionKeyFileName = t.getString(1).toString(); } Optional proxy; - if (val.size() > 2 && !val.getString(2).empty()) { - proxy = val.getString(2).toString(); + if (t.size() > 2 && !t.getString(2).empty()) { + proxy = t.getString(2).toString(); } return IBackupContainer::openContainer(url, proxy, encryptionKeyFileName); diff --git a/fdbclient/FileBackupAgent.actor.cpp b/fdbclient/FileBackupAgent.actor.cpp index d9b0468d31..ad6dc9b2b4 100644 --- a/fdbclient/FileBackupAgent.actor.cpp +++ b/fdbclient/FileBackupAgent.actor.cpp @@ -5434,7 +5434,7 @@ public: try { // We must get a commit version so add a conflict range that won't likely cause conflicts // but will ensure that the transaction is actually submitted. - tr.addWriteConflictRange(backupConfig.snapshotRangeDispatchMap().space.range()); + tr.addWriteConflictRange(backupConfig.snapshotRangeDispatchMap().subspace); wait(lockDatabase(&tr, randomUid)); wait(tr.commit()); commitVersion = tr.getCommittedVersion(); diff --git a/fdbclient/KeyBackedTypes.h b/fdbclient/KeyBackedTypes.h index f02327f29f..0b4e16f6d1 100644 --- a/fdbclient/KeyBackedTypes.h +++ b/fdbclient/KeyBackedTypes.h @@ -32,108 +32,110 @@ #include "flow/genericactors.actor.h" #include "flow/serialize.h" -// Codec is a utility struct to convert a type to and from a Tuple. It is used by the template -// classes below like KeyBackedProperty and KeyBackedMap to convert key parts and values -// from various types to Value strings and back. +// TupleCodec is a utility struct to convert a type to and from a value using Tuple encoding. +// It is used by the template classes below like KeyBackedProperty and KeyBackedMap to convert +// key parts and values from various types to Value strings and back. // New types can be supported either by writing a new specialization or adding these // methods to the type so that the default specialization can be used: -// static T T::unpack(Tuple const &t) -// Tuple T::pack() const -// Since Codec is a struct, partial specialization can be used, such as the std::pair +// static T T::unpack(Standalone const& val) +// Standalone T::pack(T const& val) const +// Since TupleCodec is a struct, partial specialization can be used, such as the std::pair // partial specialization below allowing any std::pair where T1 and T2 are already -// supported by Codec. +// supported by TupleCodec. template -struct Codec { - static inline Tuple pack(T const& val) { return val.pack(); } - static inline T unpack(Tuple const& t) { return T::unpack(t); } +struct TupleCodec { + static inline Standalone pack(T const& val) { return val.pack().pack(); } + static inline T unpack(Standalone const& val) { return T::unpack(Tuple::unpack(val)); } }; // If T is Tuple then conversion is simple. template <> -inline Tuple Codec::pack(Tuple const& val) { - return val; +inline Standalone TupleCodec::pack(Tuple const& val) { + return val.pack(); } template <> -inline Tuple Codec::unpack(Tuple const& val) { - return val; +inline Tuple TupleCodec::unpack(Standalone const& val) { + return Tuple::unpack(val); } template <> -inline Tuple Codec::pack(int64_t const& val) { - return Tuple().append(val); +inline Standalone TupleCodec::pack(int64_t const& val) { + return Tuple().append(val).pack(); } template <> -inline int64_t Codec::unpack(Tuple const& val) { - return val.getInt(0); +inline int64_t TupleCodec::unpack(Standalone const& val) { + return Tuple::unpack(val).getInt(0); } template <> -inline Tuple Codec::pack(bool const& val) { - return Tuple().append(val ? 1 : 0); +inline Standalone TupleCodec::pack(bool const& val) { + return Tuple().append(val ? 1 : 0).pack(); } template <> -inline bool Codec::unpack(Tuple const& val) { - return val.getInt(0) == 1; +inline bool TupleCodec::unpack(Standalone const& val) { + return Tuple::unpack(val).getInt(0) == 1; } template <> -inline Tuple Codec>::pack(Standalone const& val) { - return Tuple().append(val); +inline Standalone TupleCodec>::pack(Standalone const& val) { + return Tuple().append(val).pack(); } template <> -inline Standalone Codec>::unpack(Tuple const& val) { - return val.getString(0); +inline Standalone TupleCodec>::unpack(Standalone const& val) { + return Tuple::unpack(val).getString(0); } template <> -inline Tuple Codec::pack(UID const& val) { - return Codec>::pack(BinaryWriter::toValue(val, Unversioned())); +inline Standalone TupleCodec::pack(UID const& val) { + return TupleCodec>::pack(BinaryWriter::toValue(val, Unversioned())); } template <> -inline UID Codec::unpack(Tuple const& val) { - return BinaryReader::fromStringRef(Codec>::unpack(val), Unversioned()); +inline UID TupleCodec::unpack(Standalone const& val) { + return BinaryReader::fromStringRef(TupleCodec>::unpack(val), Unversioned()); } -// This is backward compatible with Codec> +// This is backward compatible with TupleCodec> template <> -inline Tuple Codec::pack(std::string const& val) { - return Tuple().append(StringRef(val)); +inline Standalone TupleCodec::pack(std::string const& val) { + return Tuple().append(StringRef(val)).pack(); } template <> -inline std::string Codec::unpack(Tuple const& val) { - return val.getString(0).toString(); +inline std::string TupleCodec::unpack(Standalone const& val) { + return Tuple::unpack(val).getString(0).toString(); } -// Partial specialization to cover all std::pairs as long as the component types are Codec compatible +// Partial specialization to cover all std::pairs as long as the component types are TupleCodec compatible template -struct Codec> { - static Tuple pack(typename std::pair const& val) { - return Tuple().append(Codec::pack(val.first)).append(Codec::pack(val.second)); +struct TupleCodec> { + static Standalone pack(typename std::pair const& val) { + // Packing a concatenated tuple is the same as concatenating two packed tuples + return TupleCodec::pack(val.first).withSuffix(TupleCodec::pack(val.second)); } - static std::pair unpack(Tuple const& t) { + static std::pair unpack(Standalone const& val) { + Tuple t = Tuple::unpack(val); ASSERT(t.size() == 2); - return { Codec::unpack(t.subTuple(0, 1)), Codec::unpack(t.subTuple(1, 2)) }; + return { TupleCodec::unpack(t.subTupleRawString(0)), + TupleCodec::unpack(t.subTupleRawString(1)) }; } }; template -struct Codec> { - static Tuple pack(typename std::vector const& val) { +struct TupleCodec> { + static Standalone pack(typename std::vector const& val) { Tuple t; for (T item : val) { - Tuple itemTuple = Codec::pack(item); // fdbclient doesn't support nested tuples yet. For now, flatten the tuple into StringRef - t.append(itemTuple.pack()); + t.append(TupleCodec::pack(item)); } - return t; + return t.pack(); } - static std::vector unpack(Tuple const& t) { + static std::vector unpack(Standalone const& val) { + Tuple t = Tuple::unpack(val); std::vector v; for (int i = 0; i < t.size(); i++) { - Tuple itemTuple = Tuple::unpack(t.getString(i)); - v.push_back(Codec::unpack(itemTuple)); + v.push_back(TupleCodec::unpack(t.getString(i))); } return v; @@ -141,17 +143,18 @@ struct Codec> { }; template <> -inline Tuple Codec::pack(KeyRange const& val) { - return Tuple().append(val.begin).append(val.end); +inline Standalone TupleCodec::pack(KeyRange const& val) { + return Tuple().append(val.begin).append(val.end).pack(); } template <> -inline KeyRange Codec::unpack(Tuple const& val) { - return KeyRangeRef(val.getString(0), val.getString(1)); +inline KeyRange TupleCodec::unpack(Standalone const& val) { + Tuple t = Tuple::unpack(val); + return KeyRangeRef(t.getString(0), t.getString(1)); } // Convenient read/write access to a single value of type T stored at key // Even though 'this' is not actually mutated, methods that change the db key are not const. -template +template > class KeyBackedProperty { public: KeyBackedProperty(KeyRef key) : key(key) {} @@ -162,9 +165,10 @@ public: Snapshot snapshot = Snapshot::False) const { typename transaction_future_type>::type getFuture = tr->get(key, snapshot); - return holdWhile(getFuture, map(safeThreadFutureToFuture(getFuture), [](Optional const& val) -> Optional { + return holdWhile(getFuture, + map(safeThreadFutureToFuture(getFuture), [](Optional const& val) -> Optional { if (val.present()) - return Codec::unpack(Tuple::unpack(val.get())); + return Codec::unpack(val.get()); return {}; })); } @@ -227,7 +231,7 @@ public: template typename std::enable_if, void>::type set(Transaction tr, T const& val) { - return tr->set(key, Codec::pack(val).pack()); + return tr->set(key, Codec::pack(val)); } template @@ -248,7 +252,7 @@ public: Key key; }; -// This is just like KeyBackedProperty but instead of using Codec for conversion to/from values it +// This is just like KeyBackedProperty but instead of using a Codec for conversion to/from values it // uses BinaryReader and BinaryWriter. This enables allows atomic ops with integer types, and also // allows reading and writing of existing keys which use BinaryReader/Writer. template @@ -260,7 +264,8 @@ public: Future> get(Transaction tr, Snapshot snapshot = Snapshot::False) const { typename transaction_future_type>::type getFuture = tr->get(key, snapshot); - return holdWhile(getFuture, map(safeThreadFutureToFuture(getFuture), [](Optional const& val) -> Optional { + return holdWhile(getFuture, + map(safeThreadFutureToFuture(getFuture), [](Optional const& val) -> Optional { if (val.present()) return BinaryReader::fromStringRef(val.get(), Unversioned()); return {}; @@ -293,10 +298,13 @@ public: // Convenient read/write access to a sorted map of KeyType to ValueType under prefix // Even though 'this' is not actually mutated, methods that change db keys are not const. -template +template , + typename ValueCodec = TupleCodec<_ValueType>> class KeyBackedMap { public: - KeyBackedMap(KeyRef prefix) : space(prefix) {} + KeyBackedMap(KeyRef prefix) : subspace(prefixRange(prefix)) {} typedef _KeyType KeyType; typedef _ValueType ValueType; @@ -311,19 +319,20 @@ public: int limit, Snapshot snapshot = Snapshot::False, Reverse reverse = Reverse::False) const { - Subspace s = space; // 'this' could be invalid inside lambda + Key prefix = subspace.begin; // 'this' could be invalid inside lambda - Key beginKey = begin.present() ? s.pack(Codec::pack(begin.get())) : s.range().begin; - Key endKey = end.present() ? s.pack(Codec::pack(end.get())) : s.range().end; + Key beginKey = begin.present() ? prefix.withSuffix(KeyCodec::pack(begin.get())) : subspace.begin; + Key endKey = end.present() ? prefix.withSuffix(KeyCodec::pack(end.get())) : subspace.end; typename transaction_future_type::type getRangeFuture = tr->getRange(KeyRangeRef(beginKey, endKey), GetRangeLimits(limit), snapshot, reverse); - return holdWhile(getRangeFuture, map(safeThreadFutureToFuture(getRangeFuture), [s](RangeResult const& kvs) -> PairsType { + return holdWhile(getRangeFuture, + map(safeThreadFutureToFuture(getRangeFuture), [prefix](RangeResult const& kvs) -> PairsType { PairsType results; for (int i = 0; i < kvs.size(); ++i) { - KeyType key = Codec::unpack(s.unpack(kvs[i].key)); - ValueType val = Codec::unpack(Tuple::unpack(kvs[i].value)); + KeyType key = KeyCodec::unpack(kvs[i].key.removePrefix(prefix)); + ValueType val = ValueCodec::unpack(kvs[i].value); results.push_back(PairType(key, val)); } return results; @@ -333,43 +342,47 @@ public: template Future> get(Transaction tr, KeyType const& key, Snapshot snapshot = Snapshot::False) const { typename transaction_future_type>::type getFuture = - tr->get(space.pack(Codec::pack(key)), snapshot); + tr->get(subspace.begin.withSuffix(KeyCodec::pack(key)), snapshot); - return holdWhile(getFuture, map(safeThreadFutureToFuture(getFuture), [](Optional const& val) -> Optional { - if (val.present()) - return Codec::unpack(Tuple::unpack(val.get())); - return {}; - })); + return holdWhile( + getFuture, map(safeThreadFutureToFuture(getFuture), [](Optional const& val) -> Optional { + if (val.present()) + return ValueCodec::unpack(val.get()); + return {}; + })); } // Returns a Property that can be get/set that represents key's entry in this this. - KeyBackedProperty getProperty(KeyType const& key) const { return space.pack(Codec::pack(key)); } + KeyBackedProperty getProperty(KeyType const& key) const { + return subspace.begin.withSuffix(KeyCodec::pack(key)); + } // Returns the expectedSize of the set key template int set(Transaction tr, KeyType const& key, ValueType const& val) { - Key k = space.pack(Codec::pack(key)); - Value v = Codec::pack(val).pack(); + Key k = subspace.begin.withSuffix(KeyCodec::pack(key)); + Value v = ValueCodec::pack(val); tr->set(k, v); return k.expectedSize() + v.expectedSize(); } template void erase(Transaction tr, KeyType const& key) { - return tr->clear(space.pack(Codec::pack(key))); + return tr->clear(subspace.begin.withSuffix(KeyCodec::pack(key))); } template void erase(Transaction tr, KeyType const& begin, KeyType const& end) { - return tr->clear(KeyRangeRef(space.pack(Codec::pack(begin)), space.pack(Codec::pack(end)))); + return tr->clear(KeyRangeRef(subspace.begin.withSuffix(KeyCodec::pack(begin)), + subspace.begin.withSuffix(KeyCodec::pack(end)))); } template void clear(Transaction tr) { - return tr->clear(space.range()); + return tr->clear(subspace); } - Subspace space; + KeyRange subspace; }; // Convenient read/write access to a single value of type T stored at key @@ -385,11 +398,13 @@ public: Snapshot snapshot = Snapshot::False) const { typename transaction_future_type>::type getFuture = tr->get(key, snapshot); - return holdWhile(getFuture, map(safeThreadFutureToFuture(getFuture), [vo = versionOptions](Optional const& val) -> Optional { - if (val.present()) - return ObjectReader::fromStringRef(val.get(), vo); - return {}; - })); + return holdWhile( + getFuture, + map(safeThreadFutureToFuture(getFuture), [vo = versionOptions](Optional const& val) -> Optional { + if (val.present()) + return ObjectReader::fromStringRef(val.get(), vo); + return {}; + })); } // Get property's value or defaultValue if it doesn't exist @@ -474,10 +489,11 @@ public: // Convenient read/write access to a sorted map of KeyType to ValueType under key prefix // ValueType is encoded / decoded with ObjectWriter/ObjectReader // Even though 'this' is not actually mutated, methods that change db keys are not const. -template +template > class KeyBackedObjectMap { public: - KeyBackedObjectMap(KeyRef prefix, VersionOptions versionOptions) : space(prefix), versionOptions(versionOptions) {} + KeyBackedObjectMap(KeyRef prefix, VersionOptions versionOptions) + : subspace(prefixRange(prefix)), versionOptions(versionOptions) {} typedef _KeyType KeyType; typedef _ValueType ValueType; @@ -491,8 +507,8 @@ public: int limit, Snapshot snapshot = Snapshot::False, Reverse reverse = Reverse::False) const { - Key beginKey = begin.present() ? space.pack(Codec::pack(begin.get())) : space.range().begin; - Key endKey = end.present() ? space.pack(Codec::pack(end.get())) : space.range().end; + Key beginKey = begin.present() ? subspace.begin.withSuffix(KeyCodec::pack(begin.get())) : subspace.begin; + Key endKey = end.present() ? subspace.begin.withSuffix(KeyCodec::pack(end.get())) : subspace.end; typename transaction_future_type::type getRangeFuture = tr->getRange(KeyRangeRef(beginKey, endKey), GetRangeLimits(limit), snapshot, reverse); @@ -502,7 +518,7 @@ public: map(safeThreadFutureToFuture(getRangeFuture), [self = *this](RangeResult const& kvs) -> PairsType { PairsType results; for (int i = 0; i < kvs.size(); ++i) { - KeyType key = Codec::unpack(self.space.unpack(kvs[i].key)); + KeyType key = KeyCodec::unpack(kvs[i].key.removePrefix(self.subspace.begin)); ValueType val = ObjectReader::fromStringRef(kvs[i].value, self.versionOptions); results.push_back(PairType(key, val)); } @@ -513,7 +529,7 @@ public: template Future> get(Transaction tr, KeyType const& key, Snapshot snapshot = Snapshot::False) const { typename transaction_future_type>::type getFuture = - tr->get(space.pack(Codec::pack(key)), snapshot); + tr->get(subspace.begin.withSuffix(KeyCodec::pack(key)), snapshot); return holdWhile(getFuture, map(safeThreadFutureToFuture(getFuture), @@ -526,46 +542,47 @@ public: // Returns a Property that can be get/set that represents key's entry in this this. KeyBackedObjectProperty getProperty(KeyType const& key) const { - return KeyBackedObjectProperty(space.pack(Codec::pack(key)), + return KeyBackedObjectProperty(subspace.begin.withSuffix(KeyCodec::pack(key)), versionOptions); } // Returns the expectedSize of the set key template int set(Transaction tr, KeyType const& key, ValueType const& val) { - Key k = space.pack(Codec::pack(key)); + Key k = subspace.begin.withSuffix(KeyCodec::pack(key)); Value v = ObjectWriter::toValue(val, versionOptions); tr->set(k, v); return k.expectedSize() + v.expectedSize(); } - Key serializeKey(KeyType const& key) { return space.pack(Codec::pack(key)); } + Key serializeKey(KeyType const& key) { return subspace.begin.withSuffix(KeyCodec::pack(key)); } Value serializeValue(ValueType const& val) { return ObjectWriter::toValue(val, versionOptions); } template void erase(Transaction tr, KeyType const& key) { - return tr->clear(space.pack(Codec::pack(key))); + return tr->clear(subspace.begin.withSuffix(KeyCodec::pack(key))); } template void erase(Transaction tr, KeyType const& begin, KeyType const& end) { - return tr->clear(KeyRangeRef(space.pack(Codec::pack(begin)), space.pack(Codec::pack(end)))); + return tr->clear(KeyRangeRef(subspace.begin.withSuffix(KeyCodec::pack(begin)), + subspace.begin.withSuffix(KeyCodec::pack(end)))); } template void clear(Transaction tr) { - return tr->clear(space.range()); + return tr->clear(subspace); } - Subspace space; + KeyRange subspace; VersionOptions versionOptions; }; -template +template > class KeyBackedSet { public: - KeyBackedSet(KeyRef key) : space(key) {} + KeyBackedSet(KeyRef key) : subspace(prefixRange(key)) {} typedef _ValueType ValueType; typedef std::vector Values; @@ -577,18 +594,18 @@ public: int limit, Snapshot snapshot = Snapshot::False, Reverse reverse = Reverse::False) const { - Subspace s = space; // 'this' could be invalid inside lambda - Key beginKey = begin.present() ? s.pack(Codec::pack(begin.get())) : space.range().begin; - Key endKey = end.present() ? s.pack(Codec::pack(end.get())) : space.range().end; + Key prefix = subspace.begin; // 'this' could be invalid inside lambda + Key beginKey = begin.present() ? prefix.withSuffix(Codec::pack(begin.get())) : subspace.begin; + Key endKey = end.present() ? prefix.withSuffix(Codec::pack(end.get())) : subspace.end; typename transaction_future_type::type getRangeFuture = tr->getRange(KeyRangeRef(beginKey, endKey), GetRangeLimits(limit), snapshot, reverse); return holdWhile(getRangeFuture, - map(safeThreadFutureToFuture(getRangeFuture), [s](RangeResult const& kvs) -> Values { + map(safeThreadFutureToFuture(getRangeFuture), [prefix](RangeResult const& kvs) -> Values { Values results; for (int i = 0; i < kvs.size(); ++i) { - results.push_back(Codec::unpack(s.unpack(kvs[i].key))); + results.push_back(Codec::unpack(kvs[i].key.removePrefix(prefix))); } return results; })); @@ -597,7 +614,7 @@ public: template Future exists(Transaction tr, ValueType const& val, Snapshot snapshot = Snapshot::False) const { typename transaction_future_type>::type getFuture = - tr->get(space.pack(Codec::pack(val)), snapshot); + tr->get(subspace.begin.withSuffix(Codec::pack(val)), snapshot); return holdWhile(getFuture, map(safeThreadFutureToFuture(getFuture), [](Optional const& val) -> bool { return val.present(); @@ -607,26 +624,26 @@ public: // Returns the expectedSize of the set key template int insert(Transaction tr, ValueType const& val) { - Key k = space.pack(Codec::pack(val)); + Key k = subspace.begin.withSuffix(Codec::pack(val)); tr->set(k, StringRef()); return k.expectedSize(); } template void erase(Transaction tr, ValueType const& val) { - return tr->clear(space.pack(Codec::pack(val))); + return tr->clear(subspace.begin.withSuffix(Codec::pack(val))); } template void erase(Transaction tr, ValueType const& begin, ValueType const& end) { return tr->clear( - KeyRangeRef(space.pack(Codec::pack(begin)), space.pack(Codec::pack(end)))); + KeyRangeRef(subspace.begin.withSuffix(Codec::pack(begin)), subspace.begin.withSuffix(Codec::pack(end)))); } template void clear(Transaction tr) { - return tr->clear(space.range()); + return tr->clear(subspace); } - Subspace space; + KeyRange subspace; }; diff --git a/fdbclient/TaskBucket.h b/fdbclient/TaskBucket.h index c87a353797..b7e6091d0f 100644 --- a/fdbclient/TaskBucket.h +++ b/fdbclient/TaskBucket.h @@ -103,8 +103,8 @@ template class TaskParam { public: TaskParam(StringRef key) : key(key) {} - T get(Reference task) const { return Codec::unpack(Tuple::unpack(task->params[key])); } - void set(Reference task, T const& val) const { task->params[key] = Codec::pack(val).pack(); } + T get(Reference task) const { return TupleCodec::unpack(task->params[key]); } + void set(Reference task, T const& val) const { task->params[key] = TupleCodec::pack(val); } bool exists(Reference task) const { return task->params.find(key) != task->params.end(); } T getOrDefault(Reference task, const T defaultValue = T()) const { if (!exists(task)) diff --git a/fdbserver/ApplyMetadataMutation.cpp b/fdbserver/ApplyMetadataMutation.cpp index b8cbf6c613..c24695a8c0 100644 --- a/fdbserver/ApplyMetadataMutation.cpp +++ b/fdbserver/ApplyMetadataMutation.cpp @@ -390,8 +390,8 @@ private: } // Normally uses key backed map, so have to use same unpacking code here. - UID ssId = Codec::unpack(Tuple::unpack(m.param1.removePrefix(tssMappingKeys.begin))); - UID tssId = Codec::unpack(Tuple::unpack(m.param2)); + UID ssId = TupleCodec::unpack(m.param1.removePrefix(tssMappingKeys.begin)); + UID tssId = TupleCodec::unpack(m.param2); if (!initialCommit) { txnStateStore->set(KeyValueRef(m.param1, m.param2)); } @@ -970,7 +970,7 @@ private: ASSERT(rangeToClear.singleKeyRange()); // Normally uses key backed map, so have to use same unpacking code here. - UID ssId = Codec::unpack(Tuple::unpack(m.param1.removePrefix(tssMappingKeys.begin))); + UID ssId = TupleCodec::unpack(m.param1.removePrefix(tssMappingKeys.begin)); if (!initialCommit) { txnStateStore->clear(rangeToClear); } diff --git a/fdbserver/MoveKeys.actor.cpp b/fdbserver/MoveKeys.actor.cpp index 068338d05c..bb51451581 100644 --- a/fdbserver/MoveKeys.actor.cpp +++ b/fdbserver/MoveKeys.actor.cpp @@ -1538,7 +1538,7 @@ void seedShardServers(Arena& arena, CommitTransactionRef& tr, std::vector::pack(s.id()).pack(); + Key uidRef = TupleCodec::pack(s.id()); tr.set(arena, uidRef.withPrefix(tssMappingKeys.begin), uidRef); } } diff --git a/fdbserver/TSSMappingUtil.actor.cpp b/fdbserver/TSSMappingUtil.actor.cpp index 47d81d3672..e501b58998 100644 --- a/fdbserver/TSSMappingUtil.actor.cpp +++ b/fdbserver/TSSMappingUtil.actor.cpp @@ -44,8 +44,8 @@ ACTOR Future readTSSMapping(Transaction* tr, std::mapTOO_MANY); for (auto& it : mappingList) { - state UID ssId = Codec::unpack(Tuple::unpack(it.key.removePrefix(tssMappingKeys.begin))); - UID tssId = Codec::unpack(Tuple::unpack(it.value)); + state UID ssId = TupleCodec::unpack(it.key.removePrefix(tssMappingKeys.begin)); + UID tssId = TupleCodec::unpack(it.value); Optional v = wait(tr->get(serverListKeyFor(tssId))); (*tssMapping)[ssId] = decodeServerListValue(v.get()); } diff --git a/fdbserver/storageserver.actor.cpp b/fdbserver/storageserver.actor.cpp index e973f8d22c..443f9cada3 100644 --- a/fdbserver/storageserver.actor.cpp +++ b/fdbserver/storageserver.actor.cpp @@ -6851,12 +6851,12 @@ private: } else if (m.param1.substr(1).startsWith(tssMappingKeys.begin) && (m.type == MutationRef::SetValue || m.type == MutationRef::ClearRange)) { if (!data->isTss()) { - UID ssId = Codec::unpack(Tuple::unpack(m.param1.substr(1).removePrefix(tssMappingKeys.begin))); + UID ssId = TupleCodec::unpack(m.param1.substr(1).removePrefix(tssMappingKeys.begin)); ASSERT(ssId == data->thisServerID); // Add ss pair id change to mutation log to make durable auto& mLV = data->addVersionToMutationLog(data->data().getLatestVersion()); if (m.type == MutationRef::SetValue) { - UID tssId = Codec::unpack(Tuple::unpack(m.param2)); + UID tssId = TupleCodec::unpack(m.param2); data->setSSWithTssPair(tssId); data->addMutationToMutationLog(mLV, MutationRef(MutationRef::SetValue,