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:
Roman Gershman 2024-04-16 19:23:50 +03:00 committed by GitHub
parent 4fe00a071e
commit 8030ee96b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 175 additions and 157 deletions

View file

@ -173,21 +173,19 @@ class RoundRobinSharder {
static fb2::Mutex mutex_;
};
bool HasContendedLocks(unsigned shard_id, Transaction* trx, const DbTable* table) {
auto is_contended = [table](string_view key) {
return table->trans_locks.Find(key)->IsContended();
};
bool HasContendedLocks(ShardId shard_id, Transaction* trx, const DbTable* table) {
auto is_contended = [table](LockTag tag) { return table->trans_locks.Find(tag)->IsContended(); };
if (trx->IsMulti()) {
auto keys = trx->GetMultiKeys();
for (string_view key : keys) {
if (Shard(key, shard_set->size()) == shard_id && is_contended(key))
if (Shard(key, shard_set->size()) == shard_id && is_contended(LockTag{key}))
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(KeyLockArgs::GetLockKey(lock_args.args[i])))
if (is_contended(LockTag{lock_args.args[i]}))
return true;
}
}
@ -868,7 +866,7 @@ void EngineShardSet::TEST_EnableCacheMode() {
ShardId Shard(string_view v, ShardId shard_num) {
if (ClusterConfig::IsShardedByTag()) {
v = ClusterConfig::KeyTag(v);
v = LockTagOptions::instance().Tag(v);
}
XXH64_hash_t hash = XXH64(v.data(), v.size(), 120577240643ULL);