-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maintan schema versions reference count and remove unused from local database and memory #9134
base: main
Are you sure you want to change the base?
Changes from all commits
c361ddd
edc66e1
42fcd94
1d76717
ffc16cb
dc8a1ee
1e08bfb
81a5da5
890af11
5e35b86
59c183c
0591e59
2802c1b
dfeeebb
f1a7ac8
f2e6baf
4adeaf7
f2dda73
7d9b831
47efee4
2aeba59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
#include "columnshard_private_events.h" | ||
#include "tables_manager.h" | ||
|
||
#include "common/log.h" | ||
|
||
#include "blobs_action/events/delete_blobs.h" | ||
#include "bg_tasks/events/local.h" | ||
#include "transactions/tx_controller.h" | ||
|
@@ -45,6 +47,8 @@ | |
#include <ydb/services/metadata/service.h> | ||
#include <ydb/services/metadata/abstract/common.h> | ||
|
||
#include <util/generic/string.h> | ||
|
||
namespace NKikimr::NOlap { | ||
class TCleanupPortionsColumnEngineChanges; | ||
class TCleanupTablesColumnEngineChanges; | ||
|
@@ -53,6 +57,8 @@ class TChangesWithAppend; | |
class TCompactColumnEngineChanges; | ||
class TInsertColumnEngineChanges; | ||
class TStoragesManager; | ||
class TDbWrapper; | ||
class TColumnEngineForLogs; | ||
|
||
namespace NReader { | ||
class TTxScan; | ||
|
@@ -136,6 +142,94 @@ using ITransaction = NTabletFlatExecutor::ITransaction; | |
template <typename T> | ||
using TTransactionBase = NTabletFlatExecutor::TTransactionBase<T>; | ||
|
||
class TInsertKey { | ||
public: | ||
ui64 PlanStep; | ||
ui64 TxId; | ||
ui64 PathId; | ||
TString DedupId; | ||
ui8 RecType; | ||
|
||
public: | ||
TInsertKey() = default; | ||
|
||
TInsertKey(ui64 planStep, ui64 txId, ui64 pathId, const TString& dedupId, ui8 recType) | ||
: PlanStep(planStep) | ||
, TxId(txId) | ||
, PathId(pathId) | ||
, DedupId(dedupId) | ||
, RecType(recType) | ||
{ | ||
} | ||
|
||
bool operator==(const TInsertKey& other) const { | ||
return (PlanStep == other.PlanStep) && (TxId == other.TxId) && (PathId == other.PathId) && (DedupId == other.DedupId) && (RecType == other.RecType); | ||
} | ||
|
||
ui64 Hash() const { | ||
return CombineHashes(PlanStep, CombineHashes(TxId, CombineHashes(PathId, CombineHashes(hash<TString>()(DedupId), (ui64)RecType)))); | ||
} | ||
}; | ||
|
||
class TVersionCounts { | ||
private: | ||
struct Hasher { | ||
inline size_t operator()(const TInsertKey& key) const noexcept { | ||
return key.Hash(); | ||
} | ||
}; | ||
|
||
private: | ||
THashMap<TInsertKey, ui64, Hasher> InsertVersions; | ||
THashMap<std::pair<ui64, ui64>, ui64> PortionVersions; | ||
THashMap<ui64, ui32> VersionCounts; | ||
|
||
public: | ||
template<class Key, class Versions> | ||
void VersionAddRef(Versions& versions, const Key& portion, ui64 version) { | ||
ui64& curVer = versions[portion]; | ||
if (curVer != 0) {// Portion is already in the local database, no need to increase ref count | ||
TEMPLOG("Schema version is already written"); | ||
AFL_VERIFY(version == curVer); | ||
return; | ||
} | ||
curVer = version; | ||
ui32& refCount = VersionCounts[version]; | ||
refCount++; | ||
TEMPLOG("Ref count of schema version " << version << " changed from " << refCount - 1 << " to " << refCount << " this " << (ui64)this); | ||
} | ||
|
||
template<class Key, class Versions> | ||
ui32 VersionRemoveRef(Versions& versions, const Key& portion, ui64 version) { | ||
auto iter = versions.find(portion); | ||
if (iter == versions.end()) { //Portion is already removed from local databae, no need to decrease ref count | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А когда VersionRemoveRef может позваться дважды для одной порции? Почему возникает необходимость проверять, что порция не посчитана ранее? То же самое для VersionAddRef. |
||
return (ui32)-1; | ||
} | ||
versions.erase(iter); | ||
ui32& refCount = VersionCounts[version]; | ||
AFL_VERIFY(refCount > 0); | ||
TEMPLOG("Ref count of schema version " << version << " changed from " << refCount << " to " << refCount - 1 << " this " << (ui64)this); | ||
return --refCount; | ||
} | ||
|
||
void VersionAddRef(ui64 portion, ui64 pathId, ui64 version) { | ||
VersionAddRef(PortionVersions, std::pair<ui64, ui64>(portion, pathId), version); | ||
} | ||
|
||
ui32 VersionRemoveRef(ui64 portion, ui64 pathId, ui64 version) { | ||
return VersionRemoveRef(PortionVersions, std::pair<ui64, ui64>(portion, pathId), version); | ||
} | ||
|
||
void VersionAddRef(const TInsertKey& key, ui64 version) { | ||
VersionAddRef(InsertVersions, key, version); | ||
} | ||
|
||
ui32 VersionRemoveRef(const TInsertKey& key, ui64 version) { | ||
return VersionRemoveRef(InsertVersions, key, version); | ||
} | ||
|
||
}; | ||
|
||
class TColumnShard | ||
: public TActor<TColumnShard> | ||
, public NTabletFlatExecutor::TTabletExecutedFlat | ||
|
@@ -186,6 +280,9 @@ class TColumnShard | |
friend class NOlap::NReader::TTxInternalScan; | ||
friend class NOlap::NReader::NPlain::TIndexScannerConstructor; | ||
|
||
friend class NOlap::TDbWrapper; | ||
friend class NOlap::TColumnEngineForLogs; | ||
|
||
class TStoragesManager; | ||
friend class TTxController; | ||
|
||
|
@@ -620,6 +717,29 @@ class TColumnShard | |
} | ||
|
||
TColumnShard(TTabletStorageInfo* info, const TActorId& tablet); | ||
|
||
void VersionAddRef(ui64 portion, ui64 pathId, ui64 version) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Счётчики стоит инкапсулировать в класс, чтобы не передавать CS везде, где нужен доступ к ним. Как будто можно убрать эти методы и передавать VersionCounts везде. |
||
VersionCounts.VersionAddRef(portion, pathId, version); | ||
} | ||
|
||
ui32 VersionRemoveRef(ui64 portion, ui64 pathId, ui64 version) { | ||
return VersionCounts.VersionRemoveRef(portion, pathId, version); | ||
} | ||
|
||
void VersionAddRef(ui64 planStep, ui64 txId, ui64 pathId, const TString& dedupId, ui8 recType, ui64 version) { | ||
VersionCounts.VersionAddRef(TInsertKey(planStep, txId, pathId, dedupId, recType), version); | ||
} | ||
|
||
ui32 VersionRemoveRef(ui64 planStep, ui64 txId, ui64 pathId, const TString& dedupId, ui8 recType, ui64 version) { | ||
return VersionCounts.VersionRemoveRef(TInsertKey(planStep, txId, pathId, dedupId, recType), version); | ||
} | ||
|
||
void RemoveUnusedSchemaVersion(NTable::TDatabase* database, ui64 version) { | ||
TablesManager.RemoveUnusedSchemaVersion(database, version); | ||
} | ||
|
||
private: | ||
TVersionCounts VersionCounts; | ||
}; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
#if 0 | ||
#define TEMPLOG(x) LOG_S_CRIT(x) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Для выборочной записи логов можно использовать AFL_DEBUG|TRACE|... Как будто они решают ту же задачу -- зачем ещё один механизм? |
||
#else | ||
#define TEMPLOG(x) | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем таблет в контексте транзакции?
Почему нельзя прокинуть CS, не нагружая им TTransactionContext? Но лучше даже не передавать CS, а передавать только счётчики туда, где они используются.