mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
chore: preparation step for lock fingerprints (#2899)
The main change here is introduction of the strong type LockTag that differentiates from a string_view key. Also, some testing improvements to improve the footprint of the next PR. Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
parent
4fe00a071e
commit
8030ee96b5
18 changed files with 175 additions and 157 deletions
|
@ -48,6 +48,7 @@ using RdbTypeFreqMap = absl::flat_hash_map<unsigned, size_t>;
|
|||
constexpr DbIndex kInvalidDbId = DbIndex(-1);
|
||||
constexpr ShardId kInvalidSid = ShardId(-1);
|
||||
constexpr DbIndex kMaxDbId = 1024; // Reasonable starting point.
|
||||
using LockFp = uint64_t; // a key fingerprint used by the LockTable.
|
||||
|
||||
class CommandId;
|
||||
class Transaction;
|
||||
|
@ -59,14 +60,14 @@ struct LockTagOptions {
|
|||
char close_locktag = '}';
|
||||
unsigned skip_n_end_delimiters = 0;
|
||||
std::string prefix;
|
||||
|
||||
// Returns the tag according to the rules defined by this options object.
|
||||
std::string_view Tag(std::string_view key) const;
|
||||
|
||||
static const LockTagOptions& instance();
|
||||
};
|
||||
|
||||
struct KeyLockArgs {
|
||||
static LockTagOptions GetLockTagOptions();
|
||||
|
||||
// Before acquiring and releasing keys, one must "normalize" them via GetLockKey().
|
||||
static std::string_view GetLockKey(std::string_view key);
|
||||
|
||||
DbIndex db_index = 0;
|
||||
ArgSlice args;
|
||||
unsigned key_step = 1;
|
||||
|
@ -117,6 +118,33 @@ struct OpArgs {
|
|||
}
|
||||
};
|
||||
|
||||
// A strong type for a lock tag. Helps to disambiguide between keys and the parts of the
|
||||
// keys that are used for locking.
|
||||
class LockTag {
|
||||
std::string_view str_;
|
||||
|
||||
public:
|
||||
using is_stackonly = void; // marks that this object does not use heap.
|
||||
|
||||
LockTag() = default;
|
||||
explicit LockTag(std::string_view key);
|
||||
|
||||
explicit operator std::string_view() const {
|
||||
return str_;
|
||||
}
|
||||
|
||||
LockFp Fingerprint() const;
|
||||
|
||||
// To make it hashable.
|
||||
template <typename H> friend H AbslHashValue(H h, const LockTag& tag) {
|
||||
return H::combine(std::move(h), tag.str_);
|
||||
}
|
||||
|
||||
bool operator==(const LockTag& o) const {
|
||||
return str_ == o.str_;
|
||||
}
|
||||
};
|
||||
|
||||
// Record non auto journal command with own txid and dbid.
|
||||
void RecordJournal(const OpArgs& op_args, std::string_view cmd, ArgSlice args,
|
||||
uint32_t shard_cnt = 1, bool multi_commands = false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue