aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortesseract <tesseract@yandex-team.com>2023-03-16 15:47:20 +0300
committertesseract <tesseract@yandex-team.com>2023-03-16 15:47:20 +0300
commit4220e061c4f48d46e8d82210c313e154c9e5f7b8 (patch)
treecf9972f73f165e7ccf1ef2a77874162f7901f7ff
parent15058e189776d010764409f87717212d7c1d88c7 (diff)
downloadydb-4220e061c4f48d46e8d82210c313e154c9e5f7b8.tar.gz
Не давать превышать дисковую квоту БД при создании топика
-rw-r--r--ydb/core/tx/schemeshard/schemeshard_info_types.h16
-rw-r--r--ydb/core/tx/schemeshard/schemeshard_path.cpp8
-rw-r--r--ydb/core/tx/schemeshard/ut_base.cpp49
3 files changed, 72 insertions, 1 deletions
diff --git a/ydb/core/tx/schemeshard/schemeshard_info_types.h b/ydb/core/tx/schemeshard/schemeshard_info_types.h
index 1fd8f1ba22e..37e03495783 100644
--- a/ydb/core/tx/schemeshard/schemeshard_info_types.h
+++ b/ydb/core/tx/schemeshard/schemeshard_info_types.h
@@ -1692,7 +1692,7 @@ struct TSubDomainInfo: TSimpleRefCount<TSubDomainInfo> {
return false;
}
- ui64 totalUsage = DiskSpaceUsage.Tables.TotalSize + (AppData()->FeatureFlags.GetEnableTopicDiskSubDomainQuota() ? GetPQAccountStorage() : 0);
+ ui64 totalUsage = TotalDiskSpaceUsage();
if (totalUsage > quotas.HardQuota) {
if (!DiskQuotaExceeded) {
counters->ChangeDiskSpaceQuotaExceeded(+1);
@@ -1716,6 +1716,20 @@ struct TSubDomainInfo: TSimpleRefCount<TSubDomainInfo> {
return false;
}
+ ui64 TotalDiskSpaceUsage() {
+ return DiskSpaceUsage.Tables.TotalSize + (AppData()->FeatureFlags.GetEnableTopicDiskSubDomainQuota() ? GetPQAccountStorage() : 0);
+ }
+
+ ui64 DiskSpaceQuotasAvailable() {
+ auto quotas = GetDiskSpaceQuotas();
+ if (!quotas) {
+ return Max<ui64>();
+ }
+
+ auto usage = TotalDiskSpaceUsage();
+ return usage < quotas.HardQuota ? quotas.HardQuota - usage : 0;
+ }
+
const TStoragePools& GetStoragePools() const {
return StoragePools ;
}
diff --git a/ydb/core/tx/schemeshard/schemeshard_path.cpp b/ydb/core/tx/schemeshard/schemeshard_path.cpp
index 28beabc6d32..755308f0a28 100644
--- a/ydb/core/tx/schemeshard/schemeshard_path.cpp
+++ b/ydb/core/tx/schemeshard/schemeshard_path.cpp
@@ -739,6 +739,14 @@ const TPath::TChecker& TPath::TChecker::PQReservedStorageLimit(ui64 delta, EStat
}
}
+ ui64 quotasAvailable = domainInfo->DiskSpaceQuotasAvailable();
+ if (quotasAvailable < delta && AppData()->FeatureFlags.GetEnableTopicDiskSubDomainQuota()) {
+ return Fail(status, TStringBuilder() << "database size limit exceeded"
+ << ", limit: " << domainInfo->GetDiskSpaceQuotas().HardQuota << " bytes"
+ << ", available: " << quotasAvailable << " bytes"
+ << ", delta: " << delta << " bytes");
+ }
+
return *this;
}
diff --git a/ydb/core/tx/schemeshard/ut_base.cpp b/ydb/core/tx/schemeshard/ut_base.cpp
index 3dcd2da7095..e81a0c5bf14 100644
--- a/ydb/core/tx/schemeshard/ut_base.cpp
+++ b/ydb/core/tx/schemeshard/ut_base.cpp
@@ -10884,4 +10884,53 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) {
UNIT_ASSERT_VALUES_EQUAL(subDomainPathId, event->LocalPathId);
}
+
+ Y_UNIT_TEST(CreateTopicOverDiskSpaceQuotas) {
+ TTestBasicRuntime runtime;
+
+ TTestEnvOptions opts;
+ opts.DisableStatsBatching(true);
+ opts.EnablePersistentPartitionStats(true);
+ opts.EnableTopicDiskSubDomainQuota(true);
+
+ TTestEnv env(runtime, opts);
+
+ ui64 txId = 100;
+
+ // Subdomain with a 1-byte data size quota
+ TestCreateSubDomain(runtime, ++txId, "/MyRoot", R"(
+ Name: "USER_1"
+ PlanResolution: 50
+ Coordinators: 1
+ Mediators: 1
+ TimeCastBucketsPerMediator: 2
+ StoragePools {
+ Name: "name_USER_0_kind_hdd-1"
+ Kind: "hdd-1"
+ }
+ StoragePools {
+ Name: "name_USER_0_kind_hdd-2"
+ Kind: "hdd-2"
+ }
+ DatabaseQuotas {
+ data_size_hard_quota: 1
+ }
+ )");
+ env.TestWaitNotification(runtime, txId);
+
+ TestCreatePQGroup(runtime, ++txId, "/MyRoot/USER_1", R"(
+ Name: "Topic1"
+ TotalGroupCount: 3
+ PartitionPerTablet: 7
+ PQTabletConfig {
+ PartitionConfig {
+ LifetimeSeconds: 1
+ WriteSpeedInBytesPerSecond : 121
+ }
+ MeteringMode: METERING_MODE_RESERVED_CAPACITY
+ }
+ )", {{TEvSchemeShard::EStatus::StatusResourceExhausted, "database size limit exceeded"}});
+ env.TestWaitNotification(runtime, txId);
+ }
+
}