Skip to content

Commit d45a506

Browse files
committed
cache: rename new prune/gc control fields
Naming that was chosen during review was reservedSpace, maxUsedSpace and minFreeSpace. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent a75b5eb commit d45a506

File tree

18 files changed

+605
-602
lines changed

18 files changed

+605
-602
lines changed

api/services/control/control.pb.go

Lines changed: 440 additions & 438 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/services/control/control.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ message PruneRequest {
2929
bool all = 2;
3030
int64 keepDuration = 3;
3131

32-
int64 minStorage = 4;
33-
int64 maxStorage = 5;
34-
int64 free = 6;
32+
int64 reservedSpace = 4;
33+
int64 maxUsedSpace = 5;
34+
int64 minFreeSpace = 6;
3535
}
3636

3737
message DiskUsageRequest {

api/types/worker.pb.go

Lines changed: 29 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/types/worker.proto

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ message GCPolicy {
1919
int64 keepDuration = 2;
2020
repeated string filters = 4;
2121

22-
// minStorage was renamed from freeBytes
23-
int64 minStorage = 3;
24-
int64 maxStorage = 5;
25-
int64 free = 6;
22+
// reservedSpace was renamed from freeBytes
23+
int64 reservedSpace = 3;
24+
int64 maxUsedSpace = 5;
25+
int64 minFreeSpace = 6;
2626
}
2727

2828
message BuildkitVersion {

cache/manager.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ func (cm *cacheManager) pruneOnce(ctx context.Context, ch chan client.UsageInfo,
10451045
}
10461046

10471047
totalSize := int64(0)
1048-
if opt.MaxStorage != 0 {
1048+
if opt.MaxUsedSpace != 0 {
10491049
du, err := cm.DiskUsage(ctx, client.DiskUsageInfo{})
10501050
if err != nil {
10511051
return err
@@ -1059,7 +1059,7 @@ func (cm *cacheManager) pruneOnce(ctx context.Context, ch chan client.UsageInfo,
10591059
}
10601060

10611061
var dstat disk.DiskStat
1062-
if opt.Free != 0 {
1062+
if opt.MinFreeSpace != 0 {
10631063
dstat, err = disk.GetDiskStat(cm.root)
10641064
if err != nil {
10651065
return err
@@ -1078,24 +1078,24 @@ func (cm *cacheManager) pruneOnce(ctx context.Context, ch chan client.UsageInfo,
10781078

10791079
func calculateKeepBytes(totalSize int64, dstat disk.DiskStat, opt client.PruneInfo) int64 {
10801080
// 0 values are special, and means we have no keep cap
1081-
if opt.MaxStorage == 0 && opt.MinStorage == 0 && opt.Free == 0 {
1081+
if opt.MaxUsedSpace == 0 && opt.ReservedSpace == 0 && opt.MinFreeSpace == 0 {
10821082
return 0
10831083
}
10841084

10851085
// try and keep as many bytes as we can
1086-
keepBytes := opt.MaxStorage
1086+
keepBytes := opt.MaxUsedSpace
10871087

10881088
// if we need to free up space, then decrease to that
1089-
if excess := opt.Free - dstat.Free; excess > 0 {
1089+
if excess := opt.MinFreeSpace - dstat.Free; excess > 0 {
10901090
if keepBytes == 0 {
10911091
keepBytes = totalSize - excess
10921092
} else {
10931093
keepBytes = min(keepBytes, totalSize-excess)
10941094
}
10951095
}
10961096

1097-
// but make sure we don't take the total below the minimum
1098-
keepBytes = max(keepBytes, opt.MinStorage)
1097+
// but make sure we don't take the total below the reserved space
1098+
keepBytes = max(keepBytes, opt.ReservedSpace)
10991099

11001100
return keepBytes
11011101
}

cache/manager_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,7 +2480,7 @@ func TestCalculateKeepBytes(t *testing.T) {
24802480
Free: 9000,
24812481
},
24822482
opt: client.PruneInfo{
2483-
MaxStorage: 2000, // 20% of the disk
2483+
MaxUsedSpace: 2000, // 20% of the disk
24842484
},
24852485
result: 2000,
24862486
},
@@ -2492,7 +2492,7 @@ func TestCalculateKeepBytes(t *testing.T) {
24922492
Free: 3000,
24932493
},
24942494
opt: client.PruneInfo{
2495-
Free: 5000, // 50% of the disk
2495+
MinFreeSpace: 5000, // 50% of the disk
24962496
},
24972497
result: 5000,
24982498
},
@@ -2504,8 +2504,8 @@ func TestCalculateKeepBytes(t *testing.T) {
25042504
Free: 3000,
25052505
},
25062506
opt: client.PruneInfo{
2507-
Free: 5000, // 50% of the disk
2508-
MinStorage: 6000, // 60% of the disk,
2507+
MinFreeSpace: 5000, // 50% of the disk
2508+
ReservedSpace: 6000, // 60% of the disk,
25092509
},
25102510
result: 6000,
25112511
},
@@ -2517,9 +2517,9 @@ func TestCalculateKeepBytes(t *testing.T) {
25172517
Free: 3000,
25182518
},
25192519
opt: client.PruneInfo{
2520-
Free: 5000, // 50% of the disk
2521-
MinStorage: 2000, // 20% of the disk
2522-
MaxStorage: 4000, // 40% of the disk
2520+
MinFreeSpace: 5000, // 50% of the disk
2521+
ReservedSpace: 2000, // 20% of the disk
2522+
MaxUsedSpace: 4000, // 40% of the disk
25232523
},
25242524
result: 4000,
25252525
},
@@ -2531,7 +2531,7 @@ func TestCalculateKeepBytes(t *testing.T) {
25312531
Free: 2000, // something else is using 4000
25322532
},
25332533
opt: client.PruneInfo{
2534-
MaxStorage: 2000, // 20% of the disk
2534+
MaxUsedSpace: 2000, // 20% of the disk
25352535
},
25362536
result: 2000,
25372537
},
@@ -2543,7 +2543,7 @@ func TestCalculateKeepBytes(t *testing.T) {
25432543
Free: 2000, // something else is using 4000
25442544
},
25452545
opt: client.PruneInfo{
2546-
Free: 5000, // 50% of the disk
2546+
MinFreeSpace: 5000, // 50% of the disk
25472547
},
25482548
result: 1000,
25492549
},
@@ -2555,8 +2555,8 @@ func TestCalculateKeepBytes(t *testing.T) {
25552555
Free: 2000, // something else is using 4000
25562556
},
25572557
opt: client.PruneInfo{
2558-
Free: 5000, // 50% of the disk
2559-
MinStorage: 2000, // 20% of the disk
2558+
MinFreeSpace: 5000, // 50% of the disk
2559+
ReservedSpace: 2000, // 20% of the disk
25602560
},
25612561
result: 2000,
25622562
},
@@ -2568,9 +2568,9 @@ func TestCalculateKeepBytes(t *testing.T) {
25682568
Free: 2000, // something else is using 4000
25692569
},
25702570
opt: client.PruneInfo{
2571-
Free: 5000, // 50% of the disk
2572-
MinStorage: 2000, // 20% of the disk
2573-
MaxStorage: 4000, // 40% of the disk
2571+
MinFreeSpace: 5000, // 50% of the disk
2572+
ReservedSpace: 2000, // 20% of the disk
2573+
MaxUsedSpace: 4000, // 40% of the disk
25742574
},
25752575
result: 2000,
25762576
},

client/prune.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ func (c *Client) Prune(ctx context.Context, ch chan UsageInfo, opts ...PruneOpti
1616
}
1717

1818
req := &controlapi.PruneRequest{
19-
Filter: info.Filter,
20-
KeepDuration: int64(info.KeepDuration),
21-
MinStorage: int64(info.MinStorage),
22-
MaxStorage: int64(info.MaxStorage),
23-
Free: int64(info.Free),
19+
Filter: info.Filter,
20+
KeepDuration: int64(info.KeepDuration),
21+
ReservedSpace: int64(info.ReservedSpace),
22+
MaxUsedSpace: int64(info.MaxUsedSpace),
23+
MinFreeSpace: int64(info.MinFreeSpace),
2424
}
2525
if info.All {
2626
req.All = true
@@ -71,9 +71,9 @@ type PruneInfo struct {
7171
Filter []string `json:"filter"`
7272
KeepDuration time.Duration `json:"keepDuration"`
7373

74-
MinStorage int64 `json:"minStorage"`
75-
MaxStorage int64 `json:"maxStorage"`
76-
Free int64 `json:"free"`
74+
ReservedSpace int64 `json:"reservedSpace"`
75+
MaxUsedSpace int64 `json:"maxUsedSpace"`
76+
MinFreeSpace int64 `json:"minFreeSpace"`
7777
}
7878

7979
type pruneOptionFunc func(*PruneInfo)
@@ -86,11 +86,11 @@ var PruneAll = pruneOptionFunc(func(pi *PruneInfo) {
8686
pi.All = true
8787
})
8888

89-
func WithKeepOpt(duration time.Duration, minStorage int64, maxStorage int64, free int64) PruneOption {
89+
func WithKeepOpt(duration time.Duration, reserved int64, max int64, free int64) PruneOption {
9090
return pruneOptionFunc(func(pi *PruneInfo) {
9191
pi.KeepDuration = duration
92-
pi.MinStorage = minStorage
93-
pi.MaxStorage = maxStorage
94-
pi.Free = free
92+
pi.ReservedSpace = reserved
93+
pi.MaxUsedSpace = max
94+
pi.MinFreeSpace = free
9595
})
9696
}

client/workers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ func fromAPIGCPolicy(in []*apitypes.GCPolicy) []PruneInfo {
6262
out := make([]PruneInfo, 0, len(in))
6363
for _, p := range in {
6464
out = append(out, PruneInfo{
65-
All: p.All,
66-
Filter: p.Filters,
67-
KeepDuration: time.Duration(p.KeepDuration),
68-
MinStorage: p.MinStorage,
69-
MaxStorage: p.MaxStorage,
70-
Free: p.Free,
65+
All: p.All,
66+
Filter: p.Filters,
67+
KeepDuration: time.Duration(p.KeepDuration),
68+
ReservedSpace: p.ReservedSpace,
69+
MaxUsedSpace: p.MaxUsedSpace,
70+
MinFreeSpace: p.MinFreeSpace,
7171
})
7272
}
7373
return out

cmd/buildctl/debug/workers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ func printWorkersVerbose(tw *tabwriter.Writer, winfo []*client.WorkerInfo) {
9191
if rule.KeepDuration > 0 {
9292
fmt.Fprintf(tw, "\tKeep duration:\t%v\n", rule.KeepDuration.String())
9393
}
94-
if rule.MinStorage > 0 {
95-
fmt.Fprintf(tw, "\tReserved storage:\t%g\n", units.Bytes(rule.MinStorage))
94+
if rule.ReservedSpace > 0 {
95+
fmt.Fprintf(tw, "\tReserved space:\t%g\n", units.Bytes(rule.ReservedSpace))
9696
}
97-
if rule.Free > 0 {
98-
fmt.Fprintf(tw, "\tMaintain free storage:\t%g\n", units.Bytes(rule.Free))
97+
if rule.MinFreeSpace > 0 {
98+
fmt.Fprintf(tw, "\tMinimum free space:\t%g\n", units.Bytes(rule.MinFreeSpace))
9999
}
100-
if rule.MaxStorage > 0 {
101-
fmt.Fprintf(tw, "\tMaximum storage:\t%g\n", units.Bytes(rule.MaxStorage))
100+
if rule.MaxUsedSpace > 0 {
101+
fmt.Fprintf(tw, "\tMaximum used space:\t%g\n", units.Bytes(rule.MaxUsedSpace))
102102
}
103103
}
104104
fmt.Fprintf(tw, "\n")

cmd/buildkitd/config/config.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ type OTELConfig struct {
7676

7777
type GCConfig struct {
7878
GC *bool `toml:"gc"`
79-
// Deprecated: use GCMinStorage instead
80-
GCKeepStorage DiskSpace `toml:"gckeepstorage"`
81-
GCMaxStorage DiskSpace `toml:"gcmaxstorage"`
82-
GCMinStorage DiskSpace `toml:"gcminstorage"`
83-
GCFreeStorage DiskSpace `toml:"gcfreestorage"`
84-
GCPolicy []GCPolicy `toml:"gcpolicy"`
79+
// Deprecated: use GCReservedSpace instead
80+
GCKeepStorage DiskSpace `toml:"gckeepstorage"`
81+
GCReservedSpace DiskSpace `toml:"reservedSpace"`
82+
GCMaxUsedSpace DiskSpace `toml:"maxUsedSpace"`
83+
GCMinFreeSpace DiskSpace `toml:"minFreeSpace"`
84+
GCPolicy []GCPolicy `toml:"gcpolicy"`
8585
}
8686

8787
type NetworkConfig struct {
@@ -167,20 +167,20 @@ type GCPolicy struct {
167167
// to consume. Any storage above this mark can be cleared during a gc
168168
// sweep.
169169
//
170-
// Deprecated: use MaxStorage instead
170+
// Deprecated: use ReservedSpace instead
171171
KeepBytes DiskSpace `toml:"keepBytes"`
172172

173-
// MinStorage is the minimum amount of storage this policy is always
174-
// allowed to consume. Any amount of storage below this mark will not be
175-
// cleared by this policy.
176-
MinStorage DiskSpace `toml:"minStorage"`
177-
// MaxStorage is the maximum amount of storage this policy is ever allowed
178-
// to consume. Any storage above this mark can be cleared during a gc
179-
// sweep.
180-
MaxStorage DiskSpace `toml:"maxStorage"`
181-
// Free is the amount of storage the gc will attempt to leave free on the
182-
// disk. However, it will never attempt to bring it below MinStorage.
183-
Free DiskSpace `toml:"free"`
173+
// ReservedSpace is the minimum amount of disk space this policy is guaranteed to retain.
174+
// Any usage below this threshold will not be reclaimed during garbage collection.
175+
ReservedSpace DiskSpace `toml:"reservedSpace"`
176+
177+
// MaxUsedSpace is the maximum amount of disk space this policy is allowed to use.
178+
// Any usage exceeding this limit will be cleaned up during a garbage collection sweep.
179+
MaxUsedSpace DiskSpace `toml:"maxUsedSpace"`
180+
181+
// MinFreeSpace is the target amount of free disk space the garbage collector will attempt to leave.
182+
// However, it will never let the available space fall below ReservedSpace.
183+
MinFreeSpace DiskSpace `toml:"minFreeSpace"`
184184
}
185185

186186
type DNSConfig struct {

0 commit comments

Comments
 (0)