Skip to content

Commit ee5f289

Browse files
committed
Persist storage pool usage stats in table partition stats
1 parent e33a32b commit ee5f289

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

ydb/core/tx/schemeshard/schemeshard__init.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,6 +2259,22 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> {
22592259
stats.RowCount = rowSet.GetValue<Schema::TablePartitionStats::RowCount>();
22602260
stats.DataSize = rowSet.GetValue<Schema::TablePartitionStats::DataSize>();
22612261
stats.IndexSize = rowSet.GetValue<Schema::TablePartitionStats::IndexSize>();
2262+
if (rowSet.HaveValue<Schema::TablePartitionStats::StoragePoolsStats>()) {
2263+
NKikimrTableStats::TStoragePoolsStats protobufRepresentation;
2264+
Y_ABORT_UNLESS(ParseFromStringNoSizeLimit(
2265+
protobufRepresentation,
2266+
rowSet.GetValue<Schema::TablePartitionStats::StoragePoolsStats>()
2267+
)
2268+
);
2269+
for (const auto& poolUsage : protobufRepresentation.GetPoolsUsage()) {
2270+
stats.StoragePoolsStats.emplace(
2271+
poolUsage.GetPoolKind(),
2272+
TPartitionStats::TStoragePoolStats{poolUsage.GetDataSize(),
2273+
poolUsage.GetIndexSize()
2274+
}
2275+
);
2276+
}
2277+
}
22622278

22632279
stats.LastAccessTime = TInstant::FromValue(rowSet.GetValue<Schema::TablePartitionStats::LastAccessTime>());
22642280
stats.LastUpdateTime = TInstant::FromValue(rowSet.GetValue<Schema::TablePartitionStats::LastUpdateTime>());

ydb/core/tx/schemeshard/schemeshard_impl.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2411,7 +2411,8 @@ void TSchemeShard::PersistTablePartitionStats(NIceDb::TNiceDb& db, const TPathId
24112411
return;
24122412
}
24132413

2414-
db.Table<Schema::TablePartitionStats>().Key(tableId.OwnerId, tableId.LocalPathId, partitionId).Update(
2414+
auto persistedStats = db.Table<Schema::TablePartitionStats>().Key(tableId.OwnerId, tableId.LocalPathId, partitionId);
2415+
persistedStats.Update(
24152416
NIceDb::TUpdate<Schema::TablePartitionStats::SeqNoGeneration>(stats.SeqNo.Generation),
24162417
NIceDb::TUpdate<Schema::TablePartitionStats::SeqNoRound>(stats.SeqNo.Round),
24172418

@@ -2448,6 +2449,21 @@ void TSchemeShard::PersistTablePartitionStats(NIceDb::TNiceDb& db, const TPathId
24482449
NIceDb::TUpdate<Schema::TablePartitionStats::FullCompactionTs>(stats.FullCompactionTs),
24492450
NIceDb::TUpdate<Schema::TablePartitionStats::MemDataSize>(stats.MemDataSize)
24502451
);
2452+
2453+
if (!stats.StoragePoolsStats.empty()) {
2454+
NKikimrTableStats::TStoragePoolsStats protobufRepresentation;
2455+
for (const auto& [poolKind, storagePoolStats] : stats.StoragePoolsStats) {
2456+
auto* poolUsage = protobufRepresentation.MutablePoolsUsage()->Add();
2457+
poolUsage->SetPoolKind(poolKind);
2458+
poolUsage->SetDataSize(storagePoolStats.DataSize);
2459+
poolUsage->SetIndexSize(storagePoolStats.IndexSize);
2460+
}
2461+
TString serializedStoragePoolsStats;
2462+
Y_ABORT_UNLESS(protobufRepresentation.SerializeToString(&serializedStoragePoolsStats));
2463+
persistedStats.Update(NIceDb::TUpdate<Schema::TablePartitionStats::StoragePoolsStats>(serializedStoragePoolsStats));
2464+
} else {
2465+
persistedStats.Update(NIceDb::TNull<Schema::TablePartitionStats::StoragePoolsStats>());
2466+
}
24512467
}
24522468

24532469
void TSchemeShard::PersistTablePartitionStats(NIceDb::TNiceDb& db, const TPathId& tableId, const TShardIdx& shardIdx, const TTableInfo::TPtr tableInfo) {

ydb/core/tx/schemeshard/schemeshard_schema.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ struct Schema : NIceDb::Schema {
368368

369369
// PartCount, PartOwners & ShardState are volatile data
370370

371+
// Represented by NKikimrTableStats::TStoragePoolsStats.
372+
struct StoragePoolsStats : Column<33, NScheme::NTypeIds::String> { using Type = TString; };
373+
371374
using TKey = TableKey<TableOwnerId, TableLocalId, PartitionId>;
372375
using TColumns = TableColumns<
373376
TableOwnerId,
@@ -401,7 +404,8 @@ struct Schema : NIceDb::Schema {
401404
WriteIops,
402405
SearchHeight,
403406
FullCompactionTs,
404-
MemDataSize
407+
MemDataSize,
408+
StoragePoolsStats
405409
>;
406410
};
407411

ydb/tests/functional/scheme_tests/canondata/tablet_scheme_tests.TestTabletSchemes.test_tablet_schemes_flat_schemeshard_/flat_schemeshard.schema

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6787,6 +6787,11 @@
67876787
"ColumnId": 32,
67886788
"ColumnName": "MemDataSize",
67896789
"ColumnType": "Uint64"
6790+
},
6791+
{
6792+
"ColumnId": 33,
6793+
"ColumnName": "StoragePoolsStats",
6794+
"ColumnType": "String"
67906795
}
67916796
],
67926797
"ColumnsDropped": [],
@@ -6824,7 +6829,8 @@
68246829
29,
68256830
30,
68266831
31,
6827-
32
6832+
32,
6833+
33
68286834
],
68296835
"RoomID": 0,
68306836
"Codec": 0,

0 commit comments

Comments
 (0)