Skip to content

Commit 1fcd6f2

Browse files
authored
Fix usage of storage until alter the topic (#21515)
1 parent b492fde commit 1fcd6f2

File tree

4 files changed

+89
-4
lines changed

4 files changed

+89
-4
lines changed

ydb/core/tx/schemeshard/schemeshard__operation_alter_pq.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,11 +792,13 @@ class TAlterPQ: public TSubOperation {
792792
return result;
793793
}
794794

795+
const auto& stats = topic->Stats;
795796
const PQGroupReserve reserve(newTabletConfig, alterData->ActivePartitionCount);
796797
const PQGroupReserve reserveForCheckLimit(newTabletConfig, alterData->ActivePartitionCount + involvedPartitions.size());
797798
const PQGroupReserve oldReserve(tabletConfig, topic->ActivePartitionCount);
799+
const PQGroupReserve oldReserveForCheckLimit(tabletConfig, topic->ActivePartitionCount, stats.DataSize);
798800

799-
const ui64 storageToReserve = reserveForCheckLimit.Storage > oldReserve.Storage ? reserveForCheckLimit.Storage - oldReserve.Storage : 0;
801+
const ui64 storageToReserve = reserveForCheckLimit.Storage > oldReserveForCheckLimit.Storage ? reserveForCheckLimit.Storage - oldReserveForCheckLimit.Storage : 0;
800802

801803
{
802804
TPath::TChecker checks = path.Check();

ydb/core/tx/schemeshard/schemeshard_utils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
namespace NKikimr {
99
namespace NSchemeShard {
1010

11-
PQGroupReserve::PQGroupReserve(const ::NKikimrPQ::TPQTabletConfig& tabletConfig, ui64 partitions) {
12-
Storage = partitions * NPQ::TopicPartitionReserveSize(tabletConfig);
11+
PQGroupReserve::PQGroupReserve(const ::NKikimrPQ::TPQTabletConfig& tabletConfig, ui64 partitions, ui64 currentStorageUsage) {
12+
Storage = NKikimrPQ::TPQTabletConfig::METERING_MODE_REQUEST_UNITS == tabletConfig.GetMeteringMode()
13+
? currentStorageUsage : partitions * NPQ::TopicPartitionReserveSize(tabletConfig);
1314
Throughput = partitions * NPQ::TopicPartitionReserveThroughput(tabletConfig);
1415
}
1516

ydb/core/tx/schemeshard/schemeshard_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ inline NKikimrSchemeOp::TModifyScheme TransactionTemplate(const TString& working
3838

3939
class PQGroupReserve {
4040
public:
41-
PQGroupReserve(const ::NKikimrPQ::TPQTabletConfig& tabletConfig, ui64 partitions);
41+
PQGroupReserve(const ::NKikimrPQ::TPQTabletConfig& tabletConfig, ui64 partitions, ui64 currentStorageUsage = 0);
4242

4343
ui64 Storage;
4444
ui64 Throughput;

ydb/core/tx/schemeshard/ut_base/ut_base.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11595,6 +11595,88 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) {
1159511595
env.TestWaitNotification(runtime, txId);
1159611596
}
1159711597

11598+
Y_UNIT_TEST(AlterTopicOverDiskSpaceQuotas) {
11599+
TTestBasicRuntime runtime;
11600+
11601+
TTestEnvOptions opts;
11602+
opts.DisableStatsBatching(true);
11603+
opts.EnablePersistentPartitionStats(true);
11604+
opts.EnableTopicDiskSubDomainQuota(true);
11605+
11606+
TTestEnv env(runtime, opts);
11607+
11608+
ui64 txId = 100;
11609+
11610+
// Subdomain with a 1-byte data size quota
11611+
TestCreateSubDomain(runtime, ++txId, "/MyRoot", R"(
11612+
Name: "USER_1"
11613+
PlanResolution: 50
11614+
Coordinators: 1
11615+
Mediators: 1
11616+
TimeCastBucketsPerMediator: 2
11617+
StoragePools {
11618+
Name: "name_USER_0_kind_hdd-1"
11619+
Kind: "hdd-1"
11620+
}
11621+
StoragePools {
11622+
Name: "name_USER_0_kind_hdd-2"
11623+
Kind: "hdd-2"
11624+
}
11625+
DatabaseQuotas {
11626+
data_size_hard_quota: 100
11627+
}
11628+
)");
11629+
env.TestWaitNotification(runtime, txId);
11630+
11631+
TestCreatePQGroup(runtime, ++txId, "/MyRoot/USER_1", R"(
11632+
Name: "Topic1"
11633+
TotalGroupCount: 1
11634+
PartitionPerTablet: 1
11635+
PQTabletConfig {
11636+
PartitionConfig {
11637+
LifetimeSeconds: 1
11638+
WriteSpeedInBytesPerSecond : 100
11639+
}
11640+
MeteringMode: METERING_MODE_REQUEST_UNITS
11641+
}
11642+
)");
11643+
env.TestWaitNotification(runtime, txId);
11644+
11645+
ui64 topicId = DescribePath(runtime, "/MyRoot/USER_1/Topic1").GetPathDescription().GetSelf().GetPathId();
11646+
11647+
ui64 generation = 1;
11648+
ui64 round = 1;
11649+
11650+
// Now topic use 50 bytes of the storage
11651+
SendTEvPeriodicTopicStats(runtime, topicId, generation, ++round, 50, 0);
11652+
11653+
// Now we reserve 150 bytes but limit 100 bytes
11654+
TestAlterPQGroup(runtime, ++txId, "/MyRoot/USER_1", R"(
11655+
Name: "Topic1"
11656+
PQTabletConfig {
11657+
PartitionConfig {
11658+
LifetimeSeconds: 1
11659+
WriteSpeedInBytesPerSecond : 150
11660+
}
11661+
MeteringMode: METERING_MODE_RESERVED_CAPACITY
11662+
}
11663+
)", {{TEvSchemeShard::EStatus::StatusResourceExhausted, "database size limit exceeded"}});
11664+
env.TestWaitNotification(runtime, txId);
11665+
11666+
// Now we reserve 100 bytes and limit 100 bytes
11667+
TestAlterPQGroup(runtime, ++txId, "/MyRoot/USER_1", R"(
11668+
Name: "Topic1"
11669+
PQTabletConfig {
11670+
PartitionConfig {
11671+
LifetimeSeconds: 1
11672+
WriteSpeedInBytesPerSecond : 100
11673+
}
11674+
MeteringMode: METERING_MODE_RESERVED_CAPACITY
11675+
}
11676+
)");
11677+
env.TestWaitNotification(runtime, txId);
11678+
}
11679+
1159811680
Y_UNIT_TEST(CreateSystemColumn) {
1159911681
TTestBasicRuntime runtime;
1160011682
TTestEnv env(runtime);

0 commit comments

Comments
 (0)