Skip to content

Commit

Permalink
Fix table stats aggregation for OLAP tables (#8417)
Browse files Browse the repository at this point in the history
  • Loading branch information
swalrus1 authored Aug 29, 2024
1 parent 54b77f9 commit bf8c633
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 35 deletions.
5 changes: 3 additions & 2 deletions ydb/core/tx/schemeshard/olap/table/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ struct TColumnTableInfo {
Stats.UpdateShardStats(shardIdx, newStats);
}

void UpdateTableStats(const TPathId& pathId, const TPartitionStats& newStats) {
Stats.UpdateTableStats(pathId, newStats);
void UpdateTableStats(const TShardIdx shardIdx, const TPathId& pathId, const TPartitionStats& newStats) {
Stats.TableStats[pathId].Aggregated.PartCount = GetColumnShards().size();
Stats.UpdateTableStats(shardIdx, pathId, newStats);
}

TConclusion<std::shared_ptr<NOlap::NAlter::ISSEntity>> BuildEntity(const TPathId& pathId, const NOlap::NAlter::TEntityInitializationContext& iContext) const;
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/tx/schemeshard/schemeshard__table_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ bool TTxStoreTableStats::PersistSingleStats(const TPathId& pathId,
"add stats for exists table with pathId=" << tablePathId);

auto columnTable = Self->ColumnTables.TakeVerified(tablePathId);
columnTable->UpdateTableStats(tablePathId, newTableStats);
columnTable->UpdateTableStats(shardIdx, tablePathId, newTableStats);
} else {
LOG_WARN_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
"failed add stats for table with pathId=" << tablePathId);
Expand Down
33 changes: 5 additions & 28 deletions ydb/core/tx/schemeshard/schemeshard_info_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,7 @@ void TTableInfo::UpdateShardStats(TShardIdx datashardIdx, const TPartitionStats&
Stats.UpdateShardStats(datashardIdx, newStats);
}

void TAggregatedStats::UpdateShardStats(TShardIdx datashardIdx, const TPartitionStats& newStats) {
void TTableAggregatedStats::UpdateShardStats(TShardIdx datashardIdx, const TPartitionStats& newStats) {
// Ignore stats from unknown datashard (it could have been split)
if (!PartitionStats.contains(datashardIdx))
return;
Expand Down Expand Up @@ -1763,33 +1763,10 @@ void TAggregatedStats::UpdateShardStats(TShardIdx datashardIdx, const TPartition
}
}

void TAggregatedStats::UpdateTableStats(const TPathId& pathId, const TPartitionStats& newStats) {
if (!TableStats.contains(pathId)) {
TableStats[pathId] = newStats;
return;
}

TPartitionStats& oldStats = TableStats[pathId];

if (newStats.SeqNo <= oldStats.SeqNo) {
// Ignore outdated message
return;
}

if (newStats.SeqNo.Generation > oldStats.SeqNo.Generation) {
// Reset incremental counter baselines if tablet has restarted
oldStats.ImmediateTxCompleted = 0;
oldStats.PlannedTxCompleted = 0;
oldStats.TxRejectedByOverload = 0;
oldStats.TxRejectedBySpace = 0;
oldStats.RowUpdates = 0;
oldStats.RowDeletes = 0;
oldStats.RowReads = 0;
oldStats.RangeReads = 0;
oldStats.RangeReadRows = 0;
}
TableStats[pathId].RowCount += (newStats.RowCount - oldStats.RowCount);
TableStats[pathId].DataSize += (newStats.DataSize - oldStats.DataSize);
void TAggregatedStats::UpdateTableStats(TShardIdx shardIdx, const TPathId& pathId, const TPartitionStats& newStats) {
auto& tableStats = TableStats[pathId];
tableStats.PartitionStats[shardIdx]; // insert if none
tableStats.UpdateShardStats(shardIdx, newStats);
}

void TTableInfo::RegisterSplitMergeOp(TOperationId opId, const TTxState& txState) {
Expand Down
10 changes: 7 additions & 3 deletions ydb/core/tx/schemeshard/schemeshard_info_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,18 @@ struct TPartitionStats {
ui64 CPU = 0;
};

struct TAggregatedStats {
struct TTableAggregatedStats {
TPartitionStats Aggregated;
THashMap<TShardIdx, TPartitionStats> PartitionStats;
THashMap<TPathId, TPartitionStats> TableStats;
size_t PartitionStatsUpdated = 0;

void UpdateShardStats(TShardIdx datashardIdx, const TPartitionStats& newStats);
void UpdateTableStats(const TPathId& pathId, const TPartitionStats& newStats);
};

struct TAggregatedStats : public TTableAggregatedStats {
THashMap<TPathId, TTableAggregatedStats> TableStats;

void UpdateTableStats(TShardIdx datashardIdx, const TPathId& pathId, const TPartitionStats& newStats);
};

struct TSubDomainInfo;
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/tx/schemeshard/schemeshard_path_describer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ void TPathDescriber::DescribeColumnTable(TPathId pathId, TPathElement::TPtr path
description->MutableSchema()->SetVersion(description->GetSchema().GetVersion() + description->GetSchemaPresetVersionAdj());
}
if (tableInfo->GetStats().TableStats.contains(pathId)) {
FillTableStats(*pathDescription, tableInfo->GetStats().TableStats.at(pathId));
FillTableStats(*pathDescription, tableInfo->GetStats().TableStats.at(pathId).Aggregated);
} else {
FillTableStats(*pathDescription, TPartitionStats());
}
Expand Down

0 comments on commit bf8c633

Please sign in to comment.