-
Notifications
You must be signed in to change notification settings - Fork 699
Statistics: Two force traversal collections in local DB #7765
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
Merged
azevaykin
merged 3 commits into
ydb-platform:main
from
azevaykin:TwoForceTraversalTables
Aug 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -443,8 +443,8 @@ void TStatisticsAggregator::Handle(TEvStatistics::TEvAnalyzeStatus::TPtr& ev) { | |
if (ForceTraversalOperationId == operationId) { | ||
outRecord.SetStatus(NKikimrStat::TEvAnalyzeStatusResponse::STATUS_IN_PROGRESS); | ||
} else { | ||
if (std::any_of(ForceTraversals.begin(), ForceTraversals.end(), | ||
[&operationId](const TForceTraversal& elem) { return elem.OperationId == operationId;})) { | ||
auto forceTraversalOperation = ForceTraversalOperation(operationId); | ||
if (forceTraversalOperation) { | ||
outRecord.SetStatus(NKikimrStat::TEvAnalyzeStatusResponse::STATUS_ENQUEUED); | ||
} else { | ||
outRecord.SetStatus(NKikimrStat::TEvAnalyzeStatusResponse::STATUS_NO_OPERATION); | ||
|
@@ -580,22 +580,36 @@ void TStatisticsAggregator::ScheduleNextTraversal(NIceDb::TNiceDb& db) { | |
|
||
TPathId pathId; | ||
|
||
if (!ForceTraversals.empty() && !LastTraversalWasForce) { | ||
if (!LastTraversalWasForce) { | ||
LastTraversalWasForce = true; | ||
|
||
TForceTraversal& operation = ForceTraversals.front(); | ||
pathId = operation.PathId; | ||
for (TForceTraversalOperation& operation : ForceTraversals) { | ||
for (TForceTraversalTable& operationTable : operation.Tables) { | ||
if (operationTable.Status == TForceTraversalTable::EStatus::None) { | ||
operationTable.Status = TForceTraversalTable::EStatus::RequestSent; | ||
// TODO delete it later, after EStatus::ResponseReceived. Only update status in local db | ||
// db.Table<Schema::ForceTraversalTables>().Key(operation.OperationId, operationTable.PathId.OwnerId, operationTable.PathId.LocalPathId) | ||
// .Update(NIceDb::TUpdate<Schema::ForceTraversalTables::Status>((ui64)operationTable.Status)); | ||
db.Table<Schema::ForceTraversalTables>().Key(operation.OperationId, operationTable.PathId.OwnerId, operationTable.PathId.LocalPathId).Delete(); | ||
|
||
pathId = operationTable.PathId; | ||
azevaykin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
if (!pathId) { | ||
SA_LOG_D("[" << TabletID() << "] All the force traversal tables sent the requests. OperationId=" << operation.OperationId); | ||
continue; | ||
} | ||
|
||
ForceTraversalOperationId = operation.OperationId; | ||
ForceTraversalColumnTags = operation.ColumnTags; | ||
ForceTraversalTypes = operation.Types; | ||
ForceTraversalReplyToActorId = operation.ReplyToActorId; | ||
ForceTraversalOperationId = operation.OperationId; | ||
} | ||
|
||
PersistForceTraversal(db); | ||
if (!pathId) { | ||
SA_LOG_D("[" << TabletID() << "] All the force traversal operations sent the requests."); | ||
} | ||
} | ||
|
||
// db.Table<Schema::ForceTraversals>().Key(operation.OperationId, operation.PathId.OwnerId, operation.PathId.LocalPathId).Delete(); | ||
ForceTraversals.pop_front(); | ||
} else if (!ScheduleTraversalsByTime.Empty()){ | ||
if (!pathId && !ScheduleTraversalsByTime.Empty()){ | ||
LastTraversalWasForce = false; | ||
|
||
auto* oldestTable = ScheduleTraversalsByTime.Top(); | ||
|
@@ -606,8 +620,10 @@ void TStatisticsAggregator::ScheduleNextTraversal(NIceDb::TNiceDb& db) { | |
} | ||
|
||
pathId = oldestTable->PathId; | ||
} else { | ||
SA_LOG_E("[" << TabletID() << "] No schedule traversal from schemeshard."); | ||
} | ||
|
||
if (!pathId) { | ||
SA_LOG_E("[" << TabletID() << "] No traversal from schemeshard."); | ||
return; | ||
} | ||
|
||
|
@@ -653,13 +669,60 @@ void TStatisticsAggregator::FinishTraversal(NIceDb::TNiceDb& db) { | |
} | ||
} | ||
|
||
auto forceTraversalOperation = CurrentForceTraversalOperation(); | ||
if (forceTraversalOperation) { | ||
bool tablesRemained = std::any_of(forceTraversalOperation->Tables.begin(), forceTraversalOperation->Tables.end(), | ||
[](const TForceTraversalTable& elem) { return elem.Status == TForceTraversalTable::EStatus::None;}); | ||
azevaykin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!tablesRemained) { | ||
DeleteForceTraversalOperation(ForceTraversalOperationId); | ||
db.Table<Schema::ForceTraversalOperations>().Key(ForceTraversalOperationId).Delete(); | ||
} | ||
} | ||
|
||
ResetTraversalState(db); | ||
} | ||
|
||
TString TStatisticsAggregator::LastTraversalWasForceString() const { | ||
return LastTraversalWasForce ? "force" : "schedule"; | ||
} | ||
|
||
TStatisticsAggregator::TForceTraversalOperation* TStatisticsAggregator::CurrentForceTraversalOperation() { | ||
return ForceTraversalOperation(ForceTraversalOperationId); | ||
} | ||
|
||
TStatisticsAggregator::TForceTraversalOperation* TStatisticsAggregator::ForceTraversalOperation(const TString& operationId) { | ||
auto forceTraversalOperation = std::find_if(ForceTraversals.begin(), ForceTraversals.end(), | ||
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. В будущем было бы неплохо сделать хеш-таблицу чтобы не делать линейный поиск. |
||
[operationId](const TForceTraversalOperation& elem) { return elem.OperationId == operationId;}); | ||
|
||
if (forceTraversalOperation == ForceTraversals.end()) { | ||
return nullptr; | ||
} else { | ||
return &*forceTraversalOperation; | ||
} | ||
} | ||
|
||
void TStatisticsAggregator::DeleteForceTraversalOperation(const TString& operationId) { | ||
ForceTraversals.remove_if([operationId](const TForceTraversalOperation& elem) { return elem.OperationId == operationId;}); | ||
} | ||
|
||
TStatisticsAggregator::TForceTraversalTable* TStatisticsAggregator::ForceTraversalTable(const TString& operationId, const TPathId& pathId) { | ||
for (TForceTraversalOperation& operation : ForceTraversals) { | ||
if (operation.OperationId == operationId) { | ||
for (TForceTraversalTable& operationTable : operation.Tables) { | ||
if (operationTable.PathId == pathId) { | ||
return &operationTable; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
TStatisticsAggregator::TForceTraversalTable* TStatisticsAggregator::CurrentForceTraversalTable() { | ||
return ForceTraversalTable(ForceTraversalOperationId, TraversalTableId.PathId); | ||
} | ||
|
||
void TStatisticsAggregator::PersistSysParam(NIceDb::TNiceDb& db, ui64 id, const TString& value) { | ||
db.Table<Schema::SysParams>().Key(id).Update( | ||
NIceDb::TUpdate<Schema::SysParams::Value>(value)); | ||
|
@@ -676,30 +739,19 @@ void TStatisticsAggregator::PersistStartKey(NIceDb::TNiceDb& db) { | |
PersistSysParam(db, Schema::SysParam_TraversalStartKey, TraversalStartKey.GetBuffer()); | ||
} | ||
|
||
void TStatisticsAggregator::PersistForceTraversal(NIceDb::TNiceDb& db) { | ||
PersistSysParam(db, Schema::SysParam_ForceTraversalOperationId, ToString(ForceTraversalOperationId)); | ||
PersistSysParam(db, Schema::SysParam_ForceTraversalCookie, ForceTraversalOperationId); | ||
PersistSysParam(db, Schema::SysParam_ForceTraversalColumnTags, ToString(ForceTraversalColumnTags)); | ||
PersistSysParam(db, Schema::SysParam_ForceTraversalTypes, ToString(ForceTraversalTypes)); | ||
} | ||
|
||
void TStatisticsAggregator::PersistGlobalTraversalRound(NIceDb::TNiceDb& db) { | ||
PersistSysParam(db, Schema::SysParam_GlobalTraversalRound, ToString(GlobalTraversalRound)); | ||
} | ||
|
||
void TStatisticsAggregator::ResetTraversalState(NIceDb::TNiceDb& db) { | ||
ForceTraversalOperationId.clear(); | ||
TraversalTableId.PathId = TPathId(); | ||
ForceTraversalColumnTags.clear(); | ||
ForceTraversalTypes.clear(); | ||
TraversalStartTime = TInstant::MicroSeconds(0); | ||
PersistTraversal(db); | ||
|
||
TraversalStartKey = TSerializedCellVec(); | ||
PersistStartKey(db); | ||
|
||
ForceTraversalReplyToActorId = {}; | ||
|
||
for (auto& [tag, _] : CountMinSketches) { | ||
db.Table<Schema::ColumnStatistics>().Key(tag).Delete(); | ||
} | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.