chore: get rid of lock keys (#2894)

* chore: get rid of lock keys

1. Introduce LockTag a type representing the part of the key that is used for locking.
2. Hash keys once in each transaction.
3. Expose swap_memory_bytes metric.

---------

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2024-04-21 11:34:42 +03:00 committed by GitHub
parent 9b9c32c91d
commit 2ff7ff9841
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 136 additions and 133 deletions

View file

@ -362,11 +362,13 @@ class DbSlice {
void OnCbFinish();
bool Acquire(IntentLock::Mode m, const KeyLockArgs& lock_args);
void Release(IntentLock::Mode m, const KeyLockArgs& lock_args);
// Returns true if the key can be locked under m. Does not lock.
bool CheckLock(IntentLock::Mode m, DbIndex dbid, std::string_view key) const;
bool CheckLock(IntentLock::Mode mode, DbIndex dbid, uint64_t fp) const;
bool CheckLock(IntentLock::Mode mode, DbIndex dbid, std::string_view key) const {
return CheckLock(mode, dbid, LockTag(key).Fingerprint());
}
size_t db_array_size() const {
return db_arr_.size();
@ -448,8 +450,8 @@ class DbSlice {
}
// Test hook to inspect last locked keys.
absl::flat_hash_set<std::string_view> TEST_GetLastLockedKeys() const {
return uniq_keys_;
const auto& TEST_GetLastLockedFps() const {
return uniq_fps_;
}
void RegisterWatchedKey(DbIndex db_indx, std::string_view key,
@ -477,9 +479,6 @@ class DbSlice {
void PerformDeletion(Iterator del_it, DbTable* table);
void PerformDeletion(PrimeIterator del_it, DbTable* table);
// Releases a single tag.
void ReleaseNormalized(IntentLock::Mode m, DbIndex db_index, LockTag tag);
private:
void PreUpdate(DbIndex db_ind, Iterator it);
void PostUpdate(DbIndex db_ind, Iterator it, std::string_view key, size_t orig_size);
@ -552,7 +551,7 @@ class DbSlice {
DbTableArray db_arr_;
// Used in temporary computations in Acquire/Release.
mutable absl::flat_hash_set<std::string_view> uniq_keys_;
mutable absl::flat_hash_set<uint64_t> uniq_fps_;
// ordered from the smallest to largest version.
std::vector<std::pair<uint64_t, ChangeCallback>> change_cb_;