Skip to content

Commit bf8c633

Browse files
authored
Fix table stats aggregation for OLAP tables (#8417)
1 parent 54b77f9 commit bf8c633

File tree

5 files changed

+17
-35
lines changed

5 files changed

+17
-35
lines changed

ydb/core/tx/schemeshard/olap/table/table.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ struct TColumnTableInfo {
9999
Stats.UpdateShardStats(shardIdx, newStats);
100100
}
101101

102-
void UpdateTableStats(const TPathId& pathId, const TPartitionStats& newStats) {
103-
Stats.UpdateTableStats(pathId, newStats);
102+
void UpdateTableStats(const TShardIdx shardIdx, const TPathId& pathId, const TPartitionStats& newStats) {
103+
Stats.TableStats[pathId].Aggregated.PartCount = GetColumnShards().size();
104+
Stats.UpdateTableStats(shardIdx, pathId, newStats);
104105
}
105106

106107
TConclusion<std::shared_ptr<NOlap::NAlter::ISSEntity>> BuildEntity(const TPathId& pathId, const NOlap::NAlter::TEntityInitializationContext& iContext) const;

ydb/core/tx/schemeshard/schemeshard__table_stats.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ bool TTxStoreTableStats::PersistSingleStats(const TPathId& pathId,
327327
"add stats for exists table with pathId=" << tablePathId);
328328

329329
auto columnTable = Self->ColumnTables.TakeVerified(tablePathId);
330-
columnTable->UpdateTableStats(tablePathId, newTableStats);
330+
columnTable->UpdateTableStats(shardIdx, tablePathId, newTableStats);
331331
} else {
332332
LOG_WARN_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
333333
"failed add stats for table with pathId=" << tablePathId);

ydb/core/tx/schemeshard/schemeshard_info_types.cpp

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ void TTableInfo::UpdateShardStats(TShardIdx datashardIdx, const TPartitionStats&
16731673
Stats.UpdateShardStats(datashardIdx, newStats);
16741674
}
16751675

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

1766-
void TAggregatedStats::UpdateTableStats(const TPathId& pathId, const TPartitionStats& newStats) {
1767-
if (!TableStats.contains(pathId)) {
1768-
TableStats[pathId] = newStats;
1769-
return;
1770-
}
1771-
1772-
TPartitionStats& oldStats = TableStats[pathId];
1773-
1774-
if (newStats.SeqNo <= oldStats.SeqNo) {
1775-
// Ignore outdated message
1776-
return;
1777-
}
1778-
1779-
if (newStats.SeqNo.Generation > oldStats.SeqNo.Generation) {
1780-
// Reset incremental counter baselines if tablet has restarted
1781-
oldStats.ImmediateTxCompleted = 0;
1782-
oldStats.PlannedTxCompleted = 0;
1783-
oldStats.TxRejectedByOverload = 0;
1784-
oldStats.TxRejectedBySpace = 0;
1785-
oldStats.RowUpdates = 0;
1786-
oldStats.RowDeletes = 0;
1787-
oldStats.RowReads = 0;
1788-
oldStats.RangeReads = 0;
1789-
oldStats.RangeReadRows = 0;
1790-
}
1791-
TableStats[pathId].RowCount += (newStats.RowCount - oldStats.RowCount);
1792-
TableStats[pathId].DataSize += (newStats.DataSize - oldStats.DataSize);
1766+
void TAggregatedStats::UpdateTableStats(TShardIdx shardIdx, const TPathId& pathId, const TPartitionStats& newStats) {
1767+
auto& tableStats = TableStats[pathId];
1768+
tableStats.PartitionStats[shardIdx]; // insert if none
1769+
tableStats.UpdateShardStats(shardIdx, newStats);
17931770
}
17941771

17951772
void TTableInfo::RegisterSplitMergeOp(TOperationId opId, const TTxState& txState) {

ydb/core/tx/schemeshard/schemeshard_info_types.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,18 @@ struct TPartitionStats {
321321
ui64 CPU = 0;
322322
};
323323

324-
struct TAggregatedStats {
324+
struct TTableAggregatedStats {
325325
TPartitionStats Aggregated;
326326
THashMap<TShardIdx, TPartitionStats> PartitionStats;
327-
THashMap<TPathId, TPartitionStats> TableStats;
328327
size_t PartitionStatsUpdated = 0;
329328

330329
void UpdateShardStats(TShardIdx datashardIdx, const TPartitionStats& newStats);
331-
void UpdateTableStats(const TPathId& pathId, const TPartitionStats& newStats);
330+
};
331+
332+
struct TAggregatedStats : public TTableAggregatedStats {
333+
THashMap<TPathId, TTableAggregatedStats> TableStats;
334+
335+
void UpdateTableStats(TShardIdx datashardIdx, const TPathId& pathId, const TPartitionStats& newStats);
332336
};
333337

334338
struct TSubDomainInfo;

ydb/core/tx/schemeshard/schemeshard_path_describer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ void TPathDescriber::DescribeColumnTable(TPathId pathId, TPathElement::TPtr path
570570
description->MutableSchema()->SetVersion(description->GetSchema().GetVersion() + description->GetSchemaPresetVersionAdj());
571571
}
572572
if (tableInfo->GetStats().TableStats.contains(pathId)) {
573-
FillTableStats(*pathDescription, tableInfo->GetStats().TableStats.at(pathId));
573+
FillTableStats(*pathDescription, tableInfo->GetStats().TableStats.at(pathId).Aggregated);
574574
} else {
575575
FillTableStats(*pathDescription, TPartitionStats());
576576
}

0 commit comments

Comments
 (0)