Skip to content

Commit

Permalink
Add HDD and SSD limit_bytes counters (#4765)
Browse files Browse the repository at this point in the history
  • Loading branch information
jepett0 authored May 30, 2024
1 parent 4b1a4a2 commit 5a7ea75
Show file tree
Hide file tree
Showing 9 changed files with 380 additions and 92 deletions.
3 changes: 3 additions & 0 deletions ydb/core/protos/counters_schemeshard.proto
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ enum ESimpleCounters {
COUNTER_DISK_SPACE_TABLES_DATA_BYTES_ON_HDD = 168 [(CounterOpts) = {Name: "DiskSpaceTablesDataBytesOnHdd"}];
COUNTER_DISK_SPACE_TABLES_INDEX_BYTES_ON_HDD = 169 [(CounterOpts) = {Name: "DiskSpaceTablesIndexBytesOnHdd"}];
COUNTER_DISK_SPACE_TABLES_TOTAL_BYTES_ON_HDD = 170 [(CounterOpts) = {Name: "DiskSpaceTablesTotalBytesOnHdd"}];

COUNTER_DISK_SPACE_SOFT_QUOTA_BYTES_ON_SSD = 171 [(CounterOpts) = {Name: "DiskSpaceSoftQuotaBytesOnSsd"}];
COUNTER_DISK_SPACE_SOFT_QUOTA_BYTES_ON_HDD = 172 [(CounterOpts) = {Name: "DiskSpaceSoftQuotaBytesOnHdd"}];
}

enum ECumulativeCounters {
Expand Down
12 changes: 12 additions & 0 deletions ydb/core/tablet/tablet_counters_aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,8 @@ class TTabletMon {
TCounterPtr ResourcesStorageUsedBytesOnSsd;
TCounterPtr ResourcesStorageUsedBytesOnHdd;
TCounterPtr ResourcesStorageLimitBytes;
TCounterPtr ResourcesStorageLimitBytesOnSsd;
TCounterPtr ResourcesStorageLimitBytesOnHdd;
TCounterPtr ResourcesStorageTableUsedBytes;
TCounterPtr ResourcesStorageTableUsedBytesOnSsd;
TCounterPtr ResourcesStorageTableUsedBytesOnHdd;
Expand Down Expand Up @@ -814,6 +816,8 @@ class TTabletMon {
TCounterPtr DiskSpaceTablesTotalBytesOnHdd;
TCounterPtr DiskSpaceTopicsTotalBytes;
TCounterPtr DiskSpaceSoftQuotaBytes;
TCounterPtr DiskSpaceSoftQuotaBytesOnSsd;
TCounterPtr DiskSpaceSoftQuotaBytesOnHdd;

TCounterPtr StreamShardsCount;
TCounterPtr StreamShardsQuota;
Expand Down Expand Up @@ -872,6 +876,10 @@ class TTabletMon {
"resources.storage.used_bytes.hdd", false);
ResourcesStorageLimitBytes = ydbGroup->GetNamedCounter("name",
"resources.storage.limit_bytes", false);
ResourcesStorageLimitBytesOnSsd = ydbGroup->GetNamedCounter("name",
"resources.storage.limit_bytes.ssd", false);
ResourcesStorageLimitBytesOnHdd = ydbGroup->GetNamedCounter("name",
"resources.storage.limit_bytes.hdd", false);
ResourcesStorageTableUsedBytes = ydbGroup->GetNamedCounter("name",
"resources.storage.table.used_bytes", false);
ResourcesStorageTableUsedBytesOnSsd = ydbGroup->GetNamedCounter("name",
Expand Down Expand Up @@ -948,6 +956,8 @@ class TTabletMon {
DiskSpaceTablesTotalBytesOnHdd = appGroup->GetCounter("SUM(SchemeShard/DiskSpaceTablesTotalBytesOnHdd)");
DiskSpaceTopicsTotalBytes = appGroup->GetCounter("SUM(SchemeShard/DiskSpaceTopicsTotalBytes)");
DiskSpaceSoftQuotaBytes = appGroup->GetCounter("SUM(SchemeShard/DiskSpaceSoftQuotaBytes)");
DiskSpaceSoftQuotaBytesOnSsd = appGroup->GetCounter("SUM(SchemeShard/DiskSpaceSoftQuotaBytesOnSsd)");
DiskSpaceSoftQuotaBytesOnHdd = appGroup->GetCounter("SUM(SchemeShard/DiskSpaceSoftQuotaBytesOnHdd)");

StreamShardsCount = appGroup->GetCounter("SUM(SchemeShard/StreamShardsCount)");
StreamShardsQuota = appGroup->GetCounter("SUM(SchemeShard/StreamShardsQuota)");
Expand Down Expand Up @@ -988,6 +998,8 @@ class TTabletMon {

if (DiskSpaceTablesTotalBytes) {
ResourcesStorageLimitBytes->Set(DiskSpaceSoftQuotaBytes->Val());
ResourcesStorageLimitBytesOnSsd->Set(DiskSpaceSoftQuotaBytesOnSsd->Val());
ResourcesStorageLimitBytesOnHdd->Set(DiskSpaceSoftQuotaBytesOnHdd->Val());
ResourcesStorageTableUsedBytes->Set(DiskSpaceTablesTotalBytes->Val());
ResourcesStorageTableUsedBytesOnSsd->Set(DiskSpaceTablesTotalBytesOnSsd->Val());
ResourcesStorageTableUsedBytesOnHdd->Set(DiskSpaceTablesTotalBytesOnHdd->Val());
Expand Down
22 changes: 15 additions & 7 deletions ydb/core/tx/schemeshard/schemeshard_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7222,15 +7222,15 @@ void TSchemeShard::ChangeDiskSpaceTablesTotalBytes(i64 delta) {
TabletCounters->Simple()[COUNTER_DISK_SPACE_TABLES_TOTAL_BYTES].Add(delta);
}

void TSchemeShard::ChangeDiskSpaceTables(EUserFacingStorageType storageType, i64 dataDelta, i64 indexDelta) {
void TSchemeShard::AddDiskSpaceTables(EUserFacingStorageType storageType, ui64 data, ui64 index) {
if (storageType == EUserFacingStorageType::Ssd) {
TabletCounters->Simple()[COUNTER_DISK_SPACE_TABLES_DATA_BYTES_ON_SSD].Add(dataDelta);
TabletCounters->Simple()[COUNTER_DISK_SPACE_TABLES_INDEX_BYTES_ON_SSD].Add(indexDelta);
TabletCounters->Simple()[COUNTER_DISK_SPACE_TABLES_TOTAL_BYTES_ON_SSD].Add(dataDelta + indexDelta);
TabletCounters->Simple()[COUNTER_DISK_SPACE_TABLES_DATA_BYTES_ON_SSD].Add(data);
TabletCounters->Simple()[COUNTER_DISK_SPACE_TABLES_INDEX_BYTES_ON_SSD].Add(index);
TabletCounters->Simple()[COUNTER_DISK_SPACE_TABLES_TOTAL_BYTES_ON_SSD].Add(data + index);
} else if (storageType == EUserFacingStorageType::Hdd) {
TabletCounters->Simple()[COUNTER_DISK_SPACE_TABLES_DATA_BYTES_ON_HDD].Add(dataDelta);
TabletCounters->Simple()[COUNTER_DISK_SPACE_TABLES_INDEX_BYTES_ON_HDD].Add(indexDelta);
TabletCounters->Simple()[COUNTER_DISK_SPACE_TABLES_TOTAL_BYTES_ON_HDD].Add(dataDelta + indexDelta);
TabletCounters->Simple()[COUNTER_DISK_SPACE_TABLES_DATA_BYTES_ON_HDD].Add(data);
TabletCounters->Simple()[COUNTER_DISK_SPACE_TABLES_INDEX_BYTES_ON_HDD].Add(index);
TabletCounters->Simple()[COUNTER_DISK_SPACE_TABLES_TOTAL_BYTES_ON_HDD].Add(data + index);
}
}

Expand All @@ -7250,6 +7250,14 @@ void TSchemeShard::ChangeDiskSpaceSoftQuotaBytes(i64 delta) {
TabletCounters->Simple()[COUNTER_DISK_SPACE_SOFT_QUOTA_BYTES].Add(delta);
}

void TSchemeShard::AddDiskSpaceSoftQuotaBytes(EUserFacingStorageType storageType, ui64 addend) {
if (storageType == EUserFacingStorageType::Ssd) {
TabletCounters->Simple()[COUNTER_DISK_SPACE_SOFT_QUOTA_BYTES_ON_SSD].Add(addend);
} else if (storageType == EUserFacingStorageType::Hdd) {
TabletCounters->Simple()[COUNTER_DISK_SPACE_SOFT_QUOTA_BYTES_ON_HDD].Add(addend);
}
}

void TSchemeShard::Handle(TEvSchemeShard::TEvLogin::TPtr &ev, const TActorContext &ctx) {
Execute(CreateTxLogin(ev), ctx);
}
Expand Down
3 changes: 2 additions & 1 deletion ydb/core/tx/schemeshard/schemeshard_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1380,11 +1380,12 @@ class TSchemeShard
void ChangeDiskSpaceTablesDataBytes(i64 delta) override;
void ChangeDiskSpaceTablesIndexBytes(i64 delta) override;
void ChangeDiskSpaceTablesTotalBytes(i64 delta) override;
void ChangeDiskSpaceTables(EUserFacingStorageType storageType, i64 dataDelta, i64 indexDelta) override;
void AddDiskSpaceTables(EUserFacingStorageType storageType, ui64 data, ui64 index) override;
void ChangeDiskSpaceTopicsTotalBytes(ui64 value) override;
void ChangeDiskSpaceQuotaExceeded(i64 delta) override;
void ChangeDiskSpaceHardQuotaBytes(i64 delta) override;
void ChangeDiskSpaceSoftQuotaBytes(i64 delta) override;
void AddDiskSpaceSoftQuotaBytes(EUserFacingStorageType storageType, ui64 addend) override;

NLogin::TLoginProvider LoginProvider;

Expand Down
54 changes: 48 additions & 6 deletions ydb/core/tx/schemeshard/schemeshard_info_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,48 @@ bool TSubDomainInfo::CheckDiskSpaceQuotas(IQuotaCounters* counters) {
return false;
}

void TSubDomainInfo::CountDiskSpaceQuotas(IQuotaCounters* counters, const TDiskSpaceQuotas& quotas) {
if (quotas.HardQuota != 0) {
counters->ChangeDiskSpaceHardQuotaBytes(quotas.HardQuota);
}
if (quotas.SoftQuota != 0) {
counters->ChangeDiskSpaceSoftQuotaBytes(quotas.SoftQuota);
}
for (const auto& [poolKind, poolQuotas] : quotas.StoragePoolsQuotas) {
if (poolQuotas.SoftQuota != 0) {
counters->AddDiskSpaceSoftQuotaBytes(GetUserFacingStorageType(poolKind), poolQuotas.SoftQuota);
}
}
}

void TSubDomainInfo::CountDiskSpaceQuotas(IQuotaCounters* counters, const TDiskSpaceQuotas& prev, const TDiskSpaceQuotas& next) {
i64 hardDelta = next.HardQuota - prev.HardQuota;
if (hardDelta != 0) {
counters->ChangeDiskSpaceHardQuotaBytes(hardDelta);
}
i64 softDelta = next.SoftQuota - prev.SoftQuota;
if (softDelta != 0) {
counters->ChangeDiskSpaceSoftQuotaBytes(softDelta);
}
for (const auto& [poolKind, newPoolQuotas] : next.StoragePoolsQuotas) {
const auto* oldPoolQuotas = prev.StoragePoolsQuotas.FindPtr(poolKind);
ui64 addend = newPoolQuotas.SoftQuota - (oldPoolQuotas ? oldPoolQuotas->SoftQuota : 0u);
if (addend != 0u) {
counters->AddDiskSpaceSoftQuotaBytes(GetUserFacingStorageType(poolKind), addend);
}
}
for (const auto& [poolKind, oldPoolQuotas] : prev.StoragePoolsQuotas) {
if (const auto* newPoolQuotas = next.StoragePoolsQuotas.FindPtr(poolKind);
!newPoolQuotas
) {
ui64 addend = -oldPoolQuotas.SoftQuota;
if (addend != 0u) {
counters->AddDiskSpaceSoftQuotaBytes(GetUserFacingStorageType(poolKind), addend);
}
}
}
}

void TSubDomainInfo::AggrDiskSpaceUsage(IQuotaCounters* counters, const TPartitionStats& newAggr, const TPartitionStats& oldAggr) {
DiskSpaceUsage.Tables.DataSize += (newAggr.DataSize - oldAggr.DataSize);
counters->ChangeDiskSpaceTablesDataBytes(newAggr.DataSize - oldAggr.DataSize);
Expand All @@ -188,21 +230,21 @@ void TSubDomainInfo::AggrDiskSpaceUsage(IQuotaCounters* counters, const TPartiti

for (const auto& [poolKind, newStoragePoolStats] : newAggr.StoragePoolsStats) {
const auto* oldStats = oldAggr.StoragePoolsStats.FindPtr(poolKind);
const i64 dataSizeIncrement = newStoragePoolStats.DataSize - (oldStats ? oldStats->DataSize : 0u);
const i64 indexSizeIncrement = newStoragePoolStats.IndexSize - (oldStats ? oldStats->IndexSize : 0u);
const ui64 dataSizeIncrement = newStoragePoolStats.DataSize - (oldStats ? oldStats->DataSize : 0u);
const ui64 indexSizeIncrement = newStoragePoolStats.IndexSize - (oldStats ? oldStats->IndexSize : 0u);
auto& [dataSize, indexSize] = DiskSpaceUsage.StoragePoolsUsage[poolKind];
dataSize += dataSizeIncrement;
indexSize += indexSizeIncrement;
counters->ChangeDiskSpaceTables(GetUserFacingStorageType(poolKind), dataSizeIncrement, indexSizeIncrement);
counters->AddDiskSpaceTables(GetUserFacingStorageType(poolKind), dataSizeIncrement, indexSizeIncrement);
}
for (const auto& [poolKind, oldStoragePoolStats] : oldAggr.StoragePoolsStats) {
if (const auto* newStats = newAggr.StoragePoolsStats.FindPtr(poolKind); !newStats) {
const i64 dataSizeDecrement = oldStoragePoolStats.DataSize;
const i64 indexSizeDecrement = oldStoragePoolStats.IndexSize;
const ui64 dataSizeDecrement = oldStoragePoolStats.DataSize;
const ui64 indexSizeDecrement = oldStoragePoolStats.IndexSize;
auto& [dataSize, indexSize] = DiskSpaceUsage.StoragePoolsUsage[poolKind];
dataSize -= dataSizeDecrement;
indexSize -= indexSizeDecrement;
counters->ChangeDiskSpaceTables(GetUserFacingStorageType(poolKind), -dataSizeDecrement, -indexSizeDecrement);
counters->AddDiskSpaceTables(GetUserFacingStorageType(poolKind), -dataSizeDecrement, -indexSizeDecrement);
}
}
}
Expand Down
23 changes: 4 additions & 19 deletions ydb/core/tx/schemeshard/schemeshard_info_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1295,11 +1295,12 @@ struct IQuotaCounters {
virtual void ChangeDiskSpaceTablesDataBytes(i64 delta) = 0;
virtual void ChangeDiskSpaceTablesIndexBytes(i64 delta) = 0;
virtual void ChangeDiskSpaceTablesTotalBytes(i64 delta) = 0;
virtual void ChangeDiskSpaceTables(EUserFacingStorageType storageType, i64 dataDelta, i64 indexDelta) = 0;
virtual void AddDiskSpaceTables(EUserFacingStorageType storageType, ui64 data, ui64 index) = 0;
virtual void ChangeDiskSpaceTopicsTotalBytes(ui64 value) = 0;
virtual void ChangeDiskSpaceQuotaExceeded(i64 delta) = 0;
virtual void ChangeDiskSpaceHardQuotaBytes(i64 delta) = 0;
virtual void ChangeDiskSpaceSoftQuotaBytes(i64 delta) = 0;
virtual void AddDiskSpaceSoftQuotaBytes(EUserFacingStorageType storageType, ui64 addend) = 0;
};

struct TSubDomainInfo: TSimpleRefCount<TSubDomainInfo> {
Expand Down Expand Up @@ -1631,25 +1632,9 @@ struct TSubDomainInfo: TSimpleRefCount<TSubDomainInfo> {
return TDuration::Seconds(DatabaseQuotas->ttl_min_run_internal_seconds());
}

static void CountDiskSpaceQuotas(IQuotaCounters* counters, const TDiskSpaceQuotas& quotas) {
if (quotas.HardQuota != 0) {
counters->ChangeDiskSpaceHardQuotaBytes(quotas.HardQuota);
}
if (quotas.SoftQuota != 0) {
counters->ChangeDiskSpaceSoftQuotaBytes(quotas.SoftQuota);
}
}
static void CountDiskSpaceQuotas(IQuotaCounters* counters, const TDiskSpaceQuotas& quotas);

static void CountDiskSpaceQuotas(IQuotaCounters* counters, const TDiskSpaceQuotas& prev, const TDiskSpaceQuotas& next) {
i64 hardDelta = i64(next.HardQuota) - i64(prev.HardQuota);
if (hardDelta != 0) {
counters->ChangeDiskSpaceHardQuotaBytes(hardDelta);
}
i64 softDelta = i64(next.SoftQuota) - i64(prev.SoftQuota);
if (softDelta != 0) {
counters->ChangeDiskSpaceSoftQuotaBytes(softDelta);
}
}
static void CountDiskSpaceQuotas(IQuotaCounters* counters, const TDiskSpaceQuotas& prev, const TDiskSpaceQuotas& next);

static void CountStreamShardsQuota(IQuotaCounters* counters, const i64 delta) {
counters->ChangeStreamShardsQuota(delta);
Expand Down
Loading

0 comments on commit 5a7ea75

Please sign in to comment.