-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lock categories to control different lock-purposes (#12163)
- Loading branch information
1 parent
b458331
commit ad82e86
Showing
23 changed files
with
184 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,93 @@ | ||
#pragma once | ||
#include <ydb/library/accessor/accessor.h> | ||
|
||
#include <util/generic/string.h> | ||
#include <util/generic/hash_set.h> | ||
#include <util/generic/string.h> | ||
|
||
#include <optional> | ||
#include <memory> | ||
#include <optional> | ||
#include <set> | ||
#include <vector> | ||
|
||
namespace NKikimr::NOlap { | ||
class TPortionInfo; | ||
class TGranuleMeta; | ||
} | ||
} // namespace NKikimr::NOlap | ||
|
||
namespace NKikimr::NOlap::NDataLocks { | ||
|
||
enum class ELockCategory : ui32 { | ||
Compaction = 0, | ||
Cleanup, | ||
Sharing, | ||
Actualization, | ||
Tables, | ||
Any, | ||
MAX | ||
}; | ||
|
||
static const inline std::array<std::set<ELockCategory>, (ui32)ELockCategory::MAX> LockCategoriesInteraction = { | ||
//Compaction | ||
std::set<ELockCategory>({ ELockCategory::Compaction, ELockCategory::Actualization, ELockCategory::Tables, ELockCategory::Any}), | ||
//Cleanup | ||
std::set<ELockCategory>({ ELockCategory::Cleanup, ELockCategory::Sharing, ELockCategory::Tables, ELockCategory::Any }), | ||
//Sharing | ||
std::set<ELockCategory>({ ELockCategory::Sharing, ELockCategory::Cleanup, ELockCategory::Tables, ELockCategory::Any }), | ||
//Actualization | ||
std::set<ELockCategory>({ ELockCategory::Actualization, ELockCategory::Compaction, ELockCategory::Tables, ELockCategory::Any }), | ||
//Tables | ||
std::set<ELockCategory>({ ELockCategory::Cleanup, ELockCategory::Sharing, ELockCategory::Actualization, ELockCategory::Compaction, | ||
ELockCategory::Tables, ELockCategory::Any }), | ||
//Any | ||
std::set<ELockCategory>({ ELockCategory::Cleanup, ELockCategory::Sharing, ELockCategory::Actualization, ELockCategory::Compaction, | ||
ELockCategory::Tables, ELockCategory::Any }), | ||
}; | ||
|
||
class ILock { | ||
private: | ||
YDB_READONLY_DEF(TString, LockName); | ||
YDB_READONLY_FLAG(ReadOnly, false); | ||
const ELockCategory Category; | ||
|
||
protected: | ||
virtual std::optional<TString> DoIsLocked(const TPortionInfo& portion, const THashSet<TString>& excludedLocks = {}) const = 0; | ||
virtual std::optional<TString> DoIsLocked(const TGranuleMeta& granule, const THashSet<TString>& excludedLocks = {}) const = 0; | ||
virtual std::optional<TString> DoIsLocked( | ||
const TPortionInfo& portion, const ELockCategory category, const THashSet<TString>& excludedLocks = {}) const = 0; | ||
virtual std::optional<TString> DoIsLocked( | ||
const TGranuleMeta& granule, const ELockCategory category, const THashSet<TString>& excludedLocks = {}) const = 0; | ||
virtual bool DoIsEmpty() const = 0; | ||
|
||
public: | ||
ILock(const TString& lockName, const bool isReadOnly = false) | ||
ILock(const TString& lockName, const ELockCategory category, const bool isReadOnly = false) | ||
: LockName(lockName) | ||
, ReadOnlyFlag(isReadOnly) | ||
{ | ||
|
||
, Category(category) { | ||
} | ||
|
||
virtual ~ILock() = default; | ||
|
||
std::optional<TString> IsLocked(const TPortionInfo& portion, const THashSet<TString>& excludedLocks = {}, const bool readOnly = false) const { | ||
std::optional<TString> IsLocked(const TPortionInfo& portion, const ELockCategory portionForLock, const THashSet<TString>& excludedLocks = {}, | ||
const bool readOnly = false) const { | ||
if (IsReadOnly() && readOnly) { | ||
return {}; | ||
} | ||
return DoIsLocked(portion, excludedLocks); | ||
if (!LockCategoriesInteraction[(ui32)Category].contains(portionForLock)) { | ||
return {}; | ||
} | ||
return DoIsLocked(portion, portionForLock, excludedLocks); | ||
} | ||
std::optional<TString> IsLocked(const TGranuleMeta& g, const THashSet<TString>& excludedLocks = {}, const bool readOnly = false) const { | ||
std::optional<TString> IsLocked(const TGranuleMeta& g, const ELockCategory portionForLock, const THashSet<TString>& excludedLocks = {}, | ||
const bool readOnly = false) const { | ||
if (IsReadOnly() && readOnly) { | ||
return {}; | ||
} | ||
return DoIsLocked(g, excludedLocks); | ||
if (!LockCategoriesInteraction[(ui32)Category].contains(portionForLock)) { | ||
return {}; | ||
} | ||
return DoIsLocked(g, portionForLock, excludedLocks); | ||
} | ||
bool IsEmpty() const { | ||
return DoIsEmpty(); | ||
} | ||
}; | ||
|
||
} | ||
} // namespace NKikimr::NOlap::NDataLocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.