Skip to content

Commit 585a708

Browse files
authored
schemeshard: fix stats processing op1, part 3 (#29813)
Fix disk space aggregation for column tables. Make subdomain and storage pool kind aggregation levels separation more robust. Add tests on subdomain level aggregation.
1 parent 89e7c47 commit 585a708

File tree

6 files changed

+557
-40
lines changed

6 files changed

+557
-40
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ struct TColumnTableInfo {
109109
Stats.UpdateShardStats(diskSpaceUsageDelta, shardIdx, newStats, now);
110110
}
111111

112-
void UpdateTableStats(TDiskSpaceUsageDelta* diskSpaceUsageDelta, const TShardIdx shardIdx, const TPathId& pathId, const TPartitionStats& newStats, TInstant now) {
112+
void UpdateTableStats(const TShardIdx shardIdx, const TPathId& pathId, const TPartitionStats& newStats, TInstant now) {
113113
Stats.TableStats[pathId].Aggregated.PartCount = GetColumnShards().size();
114-
Stats.UpdateTableStats(diskSpaceUsageDelta, shardIdx, pathId, newStats, now);
114+
Stats.UpdateTableStats(shardIdx, pathId, newStats, now);
115115
}
116116

117117
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
@@ -459,7 +459,7 @@ bool TTxStoreTableStats::PersistSingleStats(const TPathId& pathId,
459459
LOG_TRACE_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
460460
"add stats for exists table with pathId=" << tablePathId);
461461

462-
Self->ColumnTables.GetVerifiedPtr(tablePathId)->UpdateTableStats(&diskSpaceUsageDelta, shardIdx, tablePathId, newTableStats, now);
462+
Self->ColumnTables.GetVerifiedPtr(tablePathId)->UpdateTableStats(shardIdx, tablePathId, newTableStats, now);
463463
} else {
464464
LOG_WARN_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
465465
"failed add stats for table with pathId=" << tablePathId);

ydb/core/tx/schemeshard/schemeshard_info_types.cpp

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -279,27 +279,33 @@ void TSubDomainInfo::AggrDiskSpaceUsage(IQuotaCounters* counters, const TPartiti
279279
}
280280

281281
void TSubDomainInfo::AggrDiskSpaceUsage(IQuotaCounters* counters, const TDiskSpaceUsageDelta& diskSpaceUsageDelta) {
282+
// just (in)sanity check, diskSpaceUsageDelta should have at least 1 element
283+
if (diskSpaceUsageDelta.empty()) {
284+
return;
285+
}
282286
// see filling of diskSpaceUsageDelta in UpdateShardStats()
283-
for (const auto& [poolKind, delta] : diskSpaceUsageDelta) {
284-
if (poolKind.empty()) {
285-
// total space
286-
DiskSpaceUsage.Tables.DataSize += delta.DataSize;
287-
counters->ChangeDiskSpaceTablesDataBytes(delta.DataSize);
288-
289-
DiskSpaceUsage.Tables.IndexSize += delta.IndexSize;
290-
counters->ChangeDiskSpaceTablesIndexBytes(delta.IndexSize);
291-
292-
i64 oldTotalBytes = DiskSpaceUsage.Tables.TotalSize;
293-
DiskSpaceUsage.Tables.TotalSize = DiskSpaceUsage.Tables.DataSize + DiskSpaceUsage.Tables.IndexSize;
294-
i64 newTotalBytes = DiskSpaceUsage.Tables.TotalSize;
295-
counters->ChangeDiskSpaceTablesTotalBytes(newTotalBytes - oldTotalBytes);
296-
} else {
297-
// space separated by storage pool kinds
298-
auto& r = DiskSpaceUsage.StoragePoolsUsage[poolKind];
299-
r.DataSize += delta.DataSize;
300-
r.IndexSize += delta.IndexSize;
301-
counters->AddDiskSpaceTables(GetUserFacingStorageType(poolKind), delta.DataSize, delta.IndexSize);
302-
}
287+
// total space usage, index 0
288+
{
289+
const auto& [poolKind, delta] = diskSpaceUsageDelta[0];
290+
291+
DiskSpaceUsage.Tables.DataSize += delta.DataSize;
292+
counters->ChangeDiskSpaceTablesDataBytes(delta.DataSize);
293+
294+
DiskSpaceUsage.Tables.IndexSize += delta.IndexSize;
295+
counters->ChangeDiskSpaceTablesIndexBytes(delta.IndexSize);
296+
297+
i64 oldTotalBytes = DiskSpaceUsage.Tables.TotalSize;
298+
DiskSpaceUsage.Tables.TotalSize = DiskSpaceUsage.Tables.DataSize + DiskSpaceUsage.Tables.IndexSize;
299+
i64 newTotalBytes = DiskSpaceUsage.Tables.TotalSize;
300+
counters->ChangeDiskSpaceTablesTotalBytes(newTotalBytes - oldTotalBytes);
301+
}
302+
// space usage by storage pool kinds, from index 1 onwards
303+
for (size_t i = 1; i < diskSpaceUsageDelta.size(); ++i) {
304+
const auto& [poolKind, delta] = diskSpaceUsageDelta[i];
305+
auto& r = DiskSpaceUsage.StoragePoolsUsage[poolKind];
306+
r.DataSize += delta.DataSize;
307+
r.IndexSize += delta.IndexSize;
308+
counters->AddDiskSpaceTables(GetUserFacingStorageType(poolKind), delta.DataSize, delta.IndexSize);
303309
}
304310
}
305311

@@ -1853,10 +1859,9 @@ void TTableAggregatedStats::UpdateShardStats(TDiskSpaceUsageDelta* diskSpaceUsag
18531859
diskSpaceUsageDelta->emplace_back(poolKind, delta);
18541860
}
18551861
}
1856-
for (const auto& [poolKind, delta] : *diskSpaceUsageDelta) {
1857-
if (poolKind.empty()) {
1858-
continue;
1859-
}
1862+
// from index 1 onwards (as index 0 holds total space delta)
1863+
for (size_t i = 1; i < diskSpaceUsageDelta->size(); ++i) {
1864+
const auto& [poolKind, delta] = (*diskSpaceUsageDelta)[i];
18601865
auto& r = Aggregated.StoragePoolsStats[poolKind];
18611866
r.DataSize += delta.DataSize;
18621867
r.IndexSize += delta.IndexSize;
@@ -1961,10 +1966,11 @@ void TTableAggregatedStats::UpdateShardStatsForFollower(
19611966
oldStats.TopCpuUsage.Update(newStats.TopCpuUsage); // The left is new stats now!
19621967
}
19631968

1964-
void TAggregatedStats::UpdateTableStats(TDiskSpaceUsageDelta* diskSpaceUsageDelta, TShardIdx shardIdx, const TPathId& pathId, const TPartitionStats& newStats, TInstant now) {
1969+
void TAggregatedStats::UpdateTableStats(TShardIdx shardIdx, const TPathId& pathId, const TPartitionStats& newStats, TInstant now) {
19651970
auto& tableStats = TableStats[pathId];
19661971
tableStats.PartitionStats[shardIdx]; // insert if none
1967-
tableStats.UpdateShardStats(diskSpaceUsageDelta, shardIdx, newStats, now);
1972+
TDiskSpaceUsageDelta unused;
1973+
tableStats.UpdateShardStats(&unused, shardIdx, newStats, now);
19681974
}
19691975

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

ydb/core/tx/schemeshard/schemeshard_info_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ struct TTableAggregatedStats {
483483
struct TAggregatedStats : public TTableAggregatedStats {
484484
THashMap<TPathId, TTableAggregatedStats> TableStats;
485485

486-
void UpdateTableStats(TDiskSpaceUsageDelta* diskSpaceUsageDelta, TShardIdx datashardIdx, const TPathId& pathId, const TPartitionStats& newStats, TInstant now);
486+
void UpdateTableStats(TShardIdx datashardIdx, const TPathId& pathId, const TPartitionStats& newStats, TInstant now);
487487
};
488488

489489
struct TSubDomainInfo;

0 commit comments

Comments
 (0)