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

@ -174,18 +174,18 @@ class RoundRobinSharder {
};
bool HasContendedLocks(ShardId shard_id, Transaction* trx, const DbTable* table) {
auto is_contended = [table](LockTag tag) { return table->trans_locks.Find(tag)->IsContended(); };
auto is_contended = [table](LockFp fp) { return table->trans_locks.Find(fp)->IsContended(); };
if (trx->IsMulti()) {
auto keys = trx->GetMultiKeys();
for (string_view key : keys) {
if (Shard(key, shard_set->size()) == shard_id && is_contended(LockTag{key}))
auto fps = trx->GetMultiFps();
for (const auto& [sid, fp] : fps) {
if (sid == shard_id && is_contended(fp))
return true;
}
} else {
KeyLockArgs lock_args = trx->GetLockArgs(shard_id);
for (size_t i = 0; i < lock_args.args.size(); i += lock_args.key_step) {
if (is_contended(LockTag{lock_args.args[i]}))
for (size_t i = 0; i < lock_args.fps.size(); ++i) {
if (is_contended(lock_args.fps[i]))
return true;
}
}