Skip to content

Commit e27a9da

Browse files
authored
Include layers with refs when --all is passed as they are going to referenced by the build solver (#29)
1 parent 6ce0c19 commit e27a9da

1 file changed

Lines changed: 40 additions & 45 deletions

File tree

‎cache/manager.go‎

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,67 +1145,62 @@ func (cm *cacheManager) pruneOnce(ctx context.Context, ch chan client.UsageInfo,
11451145
continue
11461146
}
11471147

1148-
if len(cr.refs) > 0 {
1149-
_, lu := cr.getLastUsed()
1150-
bklog.G(ctx).Infof("%.2fMB prune skip refs=%d id=%s lastUsed=%v",
1151-
float64(cr.getSize())/(1024*1024), len(cr.refs), cr.ID(), lu)
1148+
if len(cr.refs) > 0 && (!opt.all || opt.keepBytes == 0) {
1149+
cr.mu.Unlock()
1150+
continue
11521151
}
11531152

1154-
if len(cr.refs) == 0 {
1155-
recordType := cr.GetRecordType()
1156-
if recordType == "" {
1157-
recordType = client.UsageRecordTypeRegular
1158-
}
1153+
recordType := cr.GetRecordType()
1154+
if recordType == "" {
1155+
recordType = client.UsageRecordTypeRegular
1156+
}
11591157

1160-
shared := false
1161-
if opt.checkShared != nil {
1162-
shared = opt.checkShared.Exists(cr.ID(), cr.layerDigestChain())
1163-
}
1158+
shared := false
1159+
if opt.checkShared != nil {
1160+
shared = opt.checkShared.Exists(cr.ID(), cr.layerDigestChain())
1161+
}
11641162

1165-
if !opt.all {
1166-
if recordType == client.UsageRecordTypeInternal || recordType == client.UsageRecordTypeFrontend || shared {
1167-
cr.mu.Unlock()
1168-
continue
1169-
}
1163+
if !opt.all {
1164+
if recordType == client.UsageRecordTypeInternal || recordType == client.UsageRecordTypeFrontend || shared {
1165+
cr.mu.Unlock()
1166+
continue
11701167
}
1168+
}
11711169

1172-
c := &client.UsageInfo{
1173-
ID: cr.ID(),
1174-
Mutable: cr.mutable,
1175-
RecordType: recordType,
1176-
Shared: shared,
1177-
Description: cr.GetDescription(),
1178-
}
1170+
c := &client.UsageInfo{
1171+
ID: cr.ID(),
1172+
Mutable: cr.mutable,
1173+
RecordType: recordType,
1174+
Shared: shared,
1175+
Description: cr.GetDescription(),
1176+
}
11791177

1180-
usageCount, lastUsedAt := cr.getLastUsed()
1181-
c.LastUsedAt = lastUsedAt
1182-
c.UsageCount = usageCount
1178+
usageCount, lastUsedAt := cr.getLastUsed()
1179+
c.LastUsedAt = lastUsedAt
1180+
c.UsageCount = usageCount
11831181

1184-
if opt.keepDuration != 0 {
1185-
if lastUsedAt != nil && lastUsedAt.After(cutOff) {
1186-
cr.mu.Unlock()
1187-
continue
1188-
}
1182+
if opt.keepDuration != 0 {
1183+
if lastUsedAt != nil && lastUsedAt.After(cutOff) {
1184+
cr.mu.Unlock()
1185+
continue
11891186
}
1187+
}
11901188

1191-
if opt.filter.Match(adaptUsageInfo(c)) {
1192-
toDelete = append(toDelete, &deleteRecord{
1193-
cacheRecord: cr,
1194-
lastUsedAt: c.LastUsedAt,
1195-
usageCount: c.UsageCount,
1196-
})
1197-
locked[cr.mu] = struct{}{}
1198-
continue // leave the record locked
1199-
}
1189+
if opt.filter.Match(adaptUsageInfo(c)) {
1190+
toDelete = append(toDelete, &deleteRecord{
1191+
cacheRecord: cr,
1192+
lastUsedAt: c.LastUsedAt,
1193+
usageCount: c.UsageCount,
1194+
})
1195+
locked[cr.mu] = struct{}{}
1196+
continue // leave the record locked
12001197
}
1198+
12011199
cr.mu.Unlock()
12021200
}
12031201

12041202
if len(toDelete) > 0 {
12051203
sortDeleteRecords(toDelete)
1206-
bklog.G(ctx).Infof("prune candidates=%d, deleting=%s lastUsed=%v size=%.2fMB",
1207-
len(toDelete),
1208-
toDelete[0].ID(), toDelete[0].lastUsedAt, float64(toDelete[0].getSize())/(1024*1024))
12091204
}
12101205
batchSize := len(toDelete)
12111206
if gcMode && batchSize > 0 {

0 commit comments

Comments
 (0)