From 017b15af6a20c8d45cc3ec6f723a00cca71bd338 Mon Sep 17 00:00:00 2001 From: "yihao.dai" Date: Fri, 28 Apr 2023 11:10:35 +0800 Subject: [PATCH] Fix disk quota when there's no binlog file (#23776) Signed-off-by: bigsheeper --- internal/rootcoord/quota_center.go | 2 +- internal/rootcoord/quota_center_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/rootcoord/quota_center.go b/internal/rootcoord/quota_center.go index c8619e6e51..07a4bf38f6 100644 --- a/internal/rootcoord/quota_center.go +++ b/internal/rootcoord/quota_center.go @@ -708,7 +708,7 @@ func (q *QuotaCenter) diskAllowance(collection UniqueID) float64 { } totalDiskQuota := Params.QuotaConfig.DiskQuota.GetAsFloat() colDiskQuota := Params.QuotaConfig.DiskQuotaPerCollection.GetAsFloat() - allowance := float64(math.MaxInt64) + allowance := math.Min(totalDiskQuota, colDiskQuota) if binlogSize, ok := q.dataCoordMetrics.CollectionBinlogSize[collection]; ok { allowance = math.Min(allowance, colDiskQuota-float64(binlogSize)) } diff --git a/internal/rootcoord/quota_center_test.go b/internal/rootcoord/quota_center_test.go index 32209c5f88..243eada7cf 100644 --- a/internal/rootcoord/quota_center_test.go +++ b/internal/rootcoord/quota_center_test.go @@ -420,11 +420,11 @@ func TestQuotaCenter(t *testing.T) { name string totalDiskQuota string collDiskQuota string - totalDiskUsage int64 // in MB - collDiskUsage int64 // in MB - expectAllowance int64 // in bytes + totalDiskUsage int64 // in MB + collDiskUsage int64 // in MB + expectAllowance float64 // in bytes }{ - {"test max", "-1", "-1", 100, 100, math.MaxInt64}, + {"test max", "-1", "-1", 100, 100, math.MaxFloat64}, {"test total quota exceeded", "100", "-1", 100, 100, 0}, {"test coll quota exceeded", "-1", "20", 100, 20, 0}, {"test not exceeded", "100", "20", 80, 10, 10 * 1024 * 1024}, @@ -444,7 +444,7 @@ func TestQuotaCenter(t *testing.T) { quotaCenter.totalBinlogSize = test.totalDiskUsage * 1024 * 1024 quotaCenter.diskMu.Unlock() allowance := quotaCenter.diskAllowance(collection) - assert.Equal(t, float64(test.expectAllowance), allowance) + assert.Equal(t, test.expectAllowance, allowance) paramtable.Get().Save(Params.QuotaConfig.DiskQuota.Key, quotaBackup.GetValue()) paramtable.Get().Save(Params.QuotaConfig.DiskQuotaPerCollection.Key, colQuotaBackup.GetValue()) })