Skip to content

Commit 3a6ff80

Browse files
lock names usage correction (#2591)
1 parent 2c454f8 commit 3a6ff80

File tree

11 files changed

+78
-54
lines changed

11 files changed

+78
-54
lines changed

ydb/core/tx/columnshard/data_locks/locks/abstract.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#pragma once
22
#include <ydb/library/accessor/accessor.h>
3-
#include <vector>
3+
4+
#include <util/generic/string.h>
5+
6+
#include <optional>
47
#include <memory>
8+
#include <vector>
59

610
namespace NKikimr::NOlap {
711
class TPortionInfo;
@@ -12,29 +16,31 @@ namespace NKikimr::NOlap::NDataLocks {
1216

1317
class ILock {
1418
private:
19+
YDB_READONLY_DEF(TString, LockName);
1520
YDB_READONLY_FLAG(ReadOnly, false);
1621
protected:
17-
virtual bool DoIsLocked(const TPortionInfo& portion) const = 0;
18-
virtual bool DoIsLocked(const TGranuleMeta& granule) const = 0;
22+
virtual std::optional<TString> DoIsLocked(const TPortionInfo& portion) const = 0;
23+
virtual std::optional<TString> DoIsLocked(const TGranuleMeta& granule) const = 0;
1924
virtual bool DoIsEmpty() const = 0;
2025
public:
21-
ILock(const bool isReadOnly = false)
22-
: ReadOnlyFlag(isReadOnly)
26+
ILock(const TString& lockName, const bool isReadOnly = false)
27+
: LockName(lockName)
28+
, ReadOnlyFlag(isReadOnly)
2329
{
2430

2531
}
2632

2733
virtual ~ILock() = default;
2834

29-
bool IsLocked(const TPortionInfo& portion, const bool readOnly = false) const {
35+
std::optional<TString> IsLocked(const TPortionInfo& portion, const bool readOnly = false) const {
3036
if (IsReadOnly() && readOnly) {
31-
return false;
37+
return {};
3238
}
3339
return DoIsLocked(portion);
3440
}
35-
bool IsLocked(const TGranuleMeta& g, const bool readOnly = false) const {
41+
std::optional<TString> IsLocked(const TGranuleMeta& g, const bool readOnly = false) const {
3642
if (IsReadOnly() && readOnly) {
37-
return false;
43+
return {};
3844
}
3945
return DoIsLocked(g);
4046
}

ydb/core/tx/columnshard/data_locks/locks/composite.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ class TCompositeLock: public ILock {
88
using TBase = ILock;
99
std::vector<std::shared_ptr<ILock>> Locks;
1010
protected:
11-
virtual bool DoIsLocked(const TPortionInfo& portion) const override {
11+
virtual std::optional<TString> DoIsLocked(const TPortionInfo& portion) const override {
1212
for (auto&& i : Locks) {
13-
if (i->IsLocked(portion)) {
14-
return true;
13+
if (auto lockName = i->IsLocked(portion)) {
14+
return lockName;
1515
}
1616
}
17-
return false;
17+
return {};
1818
}
19-
virtual bool DoIsLocked(const TGranuleMeta& granule) const override {
19+
virtual std::optional<TString> DoIsLocked(const TGranuleMeta& granule) const override {
2020
for (auto&& i : Locks) {
21-
if (i->IsLocked(granule)) {
22-
return true;
21+
if (auto lockName = i->IsLocked(granule)) {
22+
return lockName;
2323
}
2424
}
25-
return false;
25+
return {};
2626
}
2727
bool DoIsEmpty() const override {
2828
return Locks.empty();
2929
}
3030
public:
31-
TCompositeLock(const std::vector<std::shared_ptr<ILock>>& locks, const bool readOnly = false)
32-
: TBase(readOnly)
31+
TCompositeLock(const TString& lockName, const std::vector<std::shared_ptr<ILock>>& locks, const bool readOnly = false)
32+
: TBase(lockName, readOnly)
3333
{
3434
for (auto&& l : locks) {
3535
if (!l || l->IsEmpty()) {
@@ -39,8 +39,8 @@ class TCompositeLock: public ILock {
3939
}
4040
}
4141

42-
TCompositeLock(std::initializer_list<std::shared_ptr<ILock>> locks, const bool readOnly = false)
43-
: TBase(readOnly)
42+
TCompositeLock(const TString& lockName, std::initializer_list<std::shared_ptr<ILock>> locks, const bool readOnly = false)
43+
: TBase(lockName, readOnly)
4444
{
4545
for (auto&& l : locks) {
4646
if (!l || l->IsEmpty()) {

ydb/core/tx/columnshard/data_locks/locks/list.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,42 @@ class TListPortionsLock: public ILock {
1111
THashSet<TPortionAddress> Portions;
1212
THashSet<TTabletId> Granules;
1313
protected:
14-
virtual bool DoIsLocked(const TPortionInfo& portion) const override {
15-
return Portions.contains(portion.GetAddress());
14+
virtual std::optional<TString> DoIsLocked(const TPortionInfo& portion) const override {
15+
if (Portions.contains(portion.GetAddress())) {
16+
return GetLockName();
17+
}
18+
return {};
1619
}
17-
virtual bool DoIsLocked(const TGranuleMeta& granule) const override {
18-
return Granules.contains((TTabletId)granule.GetPathId());
20+
virtual std::optional<TString> DoIsLocked(const TGranuleMeta& granule) const override {
21+
if (Granules.contains((TTabletId)granule.GetPathId())) {
22+
return GetLockName();
23+
}
24+
return {};
1925
}
2026
bool DoIsEmpty() const override {
2127
return Portions.empty();
2228
}
2329
public:
24-
TListPortionsLock(const std::vector<std::shared_ptr<TPortionInfo>>& portions, const bool readOnly = false)
25-
: TBase(readOnly)
30+
TListPortionsLock(const TString& lockName, const std::vector<std::shared_ptr<TPortionInfo>>& portions, const bool readOnly = false)
31+
: TBase(lockName, readOnly)
2632
{
2733
for (auto&& p : portions) {
2834
Portions.emplace(p->GetAddress());
2935
Granules.emplace((TTabletId)p->GetPathId());
3036
}
3137
}
3238

33-
TListPortionsLock(const std::vector<TPortionInfo>& portions, const bool readOnly = false)
34-
: TBase(readOnly) {
39+
TListPortionsLock(const TString& lockName, const std::vector<TPortionInfo>& portions, const bool readOnly = false)
40+
: TBase(lockName, readOnly) {
3541
for (auto&& p : portions) {
3642
Portions.emplace(p.GetAddress());
3743
Granules.emplace((TTabletId)p.GetPathId());
3844
}
3945
}
4046

4147
template <class T, class TGetter>
42-
TListPortionsLock(const std::vector<T>& portions, const TGetter& g, const bool readOnly = false)
43-
: TBase(readOnly) {
48+
TListPortionsLock(const TString& lockName, const std::vector<T>& portions, const TGetter& g, const bool readOnly = false)
49+
: TBase(lockName, readOnly) {
4450
for (auto&& p : portions) {
4551
const auto address = g(p);
4652
Portions.emplace(address);
@@ -49,8 +55,8 @@ class TListPortionsLock: public ILock {
4955
}
5056

5157
template <class T>
52-
TListPortionsLock(const THashMap<TPortionAddress, T>& portions, const bool readOnly = false)
53-
: TBase(readOnly) {
58+
TListPortionsLock(const TString& lockName, const THashMap<TPortionAddress, T>& portions, const bool readOnly = false)
59+
: TBase(lockName, readOnly) {
5460
for (auto&& p : portions) {
5561
const auto address = p.first;
5662
Portions.emplace(address);

ydb/core/tx/columnshard/data_locks/locks/snapshot.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ class TSnapshotLock: public ILock {
1111
const TSnapshot SnapshotBarrier;
1212
const THashSet<TTabletId> PathIds;
1313
protected:
14-
virtual bool DoIsLocked(const TPortionInfo& portion) const override {
15-
return PathIds.contains((TTabletId)portion.GetPathId()) && portion.RecordSnapshotMin() <= SnapshotBarrier;
14+
virtual std::optional<TString> DoIsLocked(const TPortionInfo& portion) const override {
15+
if (PathIds.contains((TTabletId)portion.GetPathId()) && portion.RecordSnapshotMin() <= SnapshotBarrier) {
16+
return GetLockName();
17+
}
18+
return {};
1619
}
17-
virtual bool DoIsLocked(const TGranuleMeta& granule) const override {
18-
return PathIds.contains((TTabletId)granule.GetPathId());
20+
virtual std::optional<TString> DoIsLocked(const TGranuleMeta& granule) const override {
21+
if (PathIds.contains((TTabletId)granule.GetPathId())) {
22+
return GetLockName();
23+
}
24+
return {};
1925
}
2026
public:
21-
TSnapshotLock(const TSnapshot& snapshotBarrier, const THashSet<TTabletId>& pathIds, const bool readOnly = false)
22-
: TBase(readOnly)
27+
TSnapshotLock(const TString& lockName, const TSnapshot& snapshotBarrier, const THashSet<TTabletId>& pathIds, const bool readOnly = false)
28+
: TBase(lockName, readOnly)
2329
, SnapshotBarrier(snapshotBarrier)
2430
, PathIds(pathIds)
2531
{

ydb/core/tx/columnshard/data_locks/manager/manager.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
namespace NKikimr::NOlap::NDataLocks {
55

6-
void TManager::RegisterLock(const TString& processId, const std::shared_ptr<ILock>& lock) {
7-
AFL_VERIFY(ProcessLocks.emplace(processId, lock).second)("process_id", processId);
6+
void TManager::RegisterLock(const std::shared_ptr<ILock>& lock) {
7+
AFL_VERIFY(lock);
8+
AFL_VERIFY(ProcessLocks.emplace(lock->GetLockName(), lock).second)("process_id", lock->GetLockName());
89
}
910

1011
void TManager::UnregisterLock(const TString& processId) {
@@ -13,17 +14,17 @@ void TManager::UnregisterLock(const TString& processId) {
1314

1415
std::optional<TString> TManager::IsLocked(const TPortionInfo& portion) const {
1516
for (auto&& i : ProcessLocks) {
16-
if (i.second->IsLocked(portion)) {
17-
return i.first;
17+
if (auto lockName = i.second->IsLocked(portion)) {
18+
return lockName;
1819
}
1920
}
2021
return {};
2122
}
2223

2324
std::optional<TString> TManager::IsLocked(const TGranuleMeta& granule) const {
2425
for (auto&& i : ProcessLocks) {
25-
if (i.second->IsLocked(granule)) {
26-
return i.first;
26+
if (auto lockName = i.second->IsLocked(granule)) {
27+
return lockName;
2728
}
2829
}
2930
return {};

ydb/core/tx/columnshard/data_locks/manager/manager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ class TManager {
1212
public:
1313
TManager() = default;
1414

15-
void RegisterLock(const TString& processId, const std::shared_ptr<ILock>& lock);
15+
void RegisterLock(const std::shared_ptr<ILock>& lock);
1616
template <class TLock, class ...Args>
17-
void RegisterLock(const TString& processId, Args&&... args) {
18-
RegisterLock(processId, std::make_shared<TLock>(args...));
17+
void RegisterLock(Args&&... args) {
18+
RegisterLock(std::make_shared<TLock>(args...));
1919
}
2020
void UnregisterLock(const TString& processId);
2121
std::optional<TString> IsLocked(const TPortionInfo& portion) const;

ydb/core/tx/columnshard/engines/changes/abstract/abstract.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void TColumnEngineChanges::Abort(NColumnShard::TColumnShard& self, TChangesFinis
7373
}
7474

7575
void TColumnEngineChanges::Start(NColumnShard::TColumnShard& self) {
76-
self.DataLocksManager->RegisterLock(TypeString() + "::" + GetTaskIdentifier(), BuildDataLock());
76+
self.DataLocksManager->RegisterLock(BuildDataLock());
7777
Y_ABORT_UNLESS(Stage == EStage::Created);
7878
DoStart(self);
7979
Stage = EStage::Started;

ydb/core/tx/columnshard/engines/changes/cleanup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TCleanupColumnEngineChanges: public TColumnEngineChanges {
2828
return 0;
2929
}
3030
virtual std::shared_ptr<NDataLocks::ILock> DoBuildDataLock() const override {
31-
return std::make_shared<NDataLocks::TListPortionsLock>(PortionsToDrop);
31+
return std::make_shared<NDataLocks::TListPortionsLock>(TypeString() + "::" + GetTaskIdentifier(), PortionsToDrop);
3232
}
3333

3434
public:

ydb/core/tx/columnshard/engines/changes/compaction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TCompactColumnEngineChanges: public TChangesWithAppend {
2525
NeedGranuleStatusProvide = false;
2626
}
2727
virtual std::shared_ptr<NDataLocks::ILock> DoBuildDataLockImpl() const override {
28-
return std::make_shared<NDataLocks::TListPortionsLock>(SwitchedPortions);
28+
return std::make_shared<NDataLocks::TListPortionsLock>(TypeString() + "::" + GetTaskIdentifier(), SwitchedPortions);
2929
}
3030

3131
public:

ydb/core/tx/columnshard/engines/changes/ttl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class TTTLColumnEngineChanges: public TChangesWithAppend {
6262
const auto pred = [](const TPortionForEviction& p) {
6363
return p.GetPortionInfo().GetAddress();
6464
};
65-
return std::make_shared<NDataLocks::TListPortionsLock>(PortionsToEvict, pred);
65+
return std::make_shared<NDataLocks::TListPortionsLock>(TypeString() + "::" + GetTaskIdentifier(), PortionsToEvict, pred);
6666
}
6767
public:
6868
class TMemoryPredictorSimplePolicy: public IMemoryPredictor {

0 commit comments

Comments
 (0)