Skip to content

Commit

Permalink
Fix the storage quota metric
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuyaoo committed Jan 8, 2025
1 parent 6b1ccc5 commit 07f482b
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public QuotaCheckerResponse isSegmentStorageWithinQuota(TableConfig tableConfig,
// when we are checking the quota for only existing segments (segmentSizeInBytes == 0)
// as in both cases quota is checked across existing segments estimated size alone
if (segmentSizeInBytes == 0 || tableSubtypeSize._missingSegments > 0) {
emitStorageQuotaUtilizationMetric(tableNameWithType, tableSubtypeSize, allowedStorageBytes);
if (tableSubtypeSize._estimatedSizeInBytes > allowedStorageBytes) {
return failure("Table " + tableNameWithType + " already over quota. Estimated size for all replicas is "
+ DataSizeUtils.fromBytes(tableSubtypeSize._estimatedSizeInBytes) + ". Configured size for " + numReplicas
Expand All @@ -147,14 +148,7 @@ public QuotaCheckerResponse isSegmentStorageWithinQuota(TableConfig tableConfig,
LOGGER.info("Table {}'s estimatedSizeInBytes is {}. ReportedSizeInBytes (actual reports from servers) is {}",
tableNameWithType, tableSubtypeSize._estimatedSizeInBytes, tableSubtypeSize._reportedSizeInBytes);

// Only emit the real percentage of storage quota usage by lead controller, otherwise emit 0L.
if (_leadControllerManager.isLeaderForTable(tableNameWithType)) {
long existingStorageQuotaUtilization = tableSubtypeSize._estimatedSizeInBytes * 100 / allowedStorageBytes;
_controllerMetrics.setValueOfTableGauge(tableNameWithType, ControllerGauge.TABLE_STORAGE_QUOTA_UTILIZATION,
existingStorageQuotaUtilization);
} else {
_controllerMetrics.setValueOfTableGauge(tableNameWithType, ControllerGauge.TABLE_STORAGE_QUOTA_UTILIZATION, 0L);
}
emitStorageQuotaUtilizationMetric(tableNameWithType, tableSubtypeSize, allowedStorageBytes);

// Note: incomingSegmentSizeBytes is uncompressed data size for just 1 replica,
// while estimatedFinalSizeBytes is for all replicas of all segments put together.
Expand Down Expand Up @@ -217,6 +211,18 @@ public QuotaCheckerResponse isSegmentStorageWithinQuota(TableConfig tableConfig,
}
}

private void emitStorageQuotaUtilizationMetric(String tableNameWithType, TableSizeReader.TableSubTypeSizeDetails
tableSubtypeSize, long allowedStorageBytes) {
// Only emit the real percentage of storage quota usage by lead controller, otherwise emit 0L.
if (_leadControllerManager.isLeaderForTable(tableNameWithType)) {
long existingStorageQuotaUtilization = tableSubtypeSize._estimatedSizeInBytes * 100 / allowedStorageBytes;
_controllerMetrics.setValueOfTableGauge(tableNameWithType, ControllerGauge.TABLE_STORAGE_QUOTA_UTILIZATION,
existingStorageQuotaUtilization);
} else {
_controllerMetrics.setValueOfTableGauge(tableNameWithType, ControllerGauge.TABLE_STORAGE_QUOTA_UTILIZATION, 0L);
}
}

/**
* Checks whether the table is within the storage quota.
* @return true if storage quota is exceeded by the table, else false.
Expand Down

0 comments on commit 07f482b

Please sign in to comment.