262
var buildIdsToRemove []string
263
for setIdx, set := range versioningData.GetVersionSets() {
264
>
// Note that setActive counts build ids that may have associated workflows, i.e. not
scavenger.go
265
>
// just all with STATE_ACTIVE. Also note that we always examine the default build ID
266
>
// for a set last, so setActive will be 1 + the number of active non-default build ids.
267
>
setActive := len(set.BuildIds)
268
>
for buildIdIdx, buildId := range set.BuildIds {
269
>
if buildId.State == persistencespb.STATE_DELETED {
270
setActive--
271
continue
272
}
273
>
buildIdIsSetDefault := buildIdIdx == len(set.BuildIds)-1
scavenger.go
274
>
setIsQueueDefault := setIdx == len(versioningData.VersionSets)-1
275
>
// Don't remove if build ID is the queue default or there's another active build ID in
276
>
// this set, since we might need to dispatch new tasks to this set. But if no build ids
277
>
// are active for the whole set, we can remove them all.
278
>
if buildIdIsSetDefault && (setIsQueueDefault || setActive > 1) {
279
>
continue
280
}
281
>
if hlc.Since(buildId.BecameDefaultTimestamp) < removableBuildIdDurationSinceDefault {
scavenger.go
282
continue
283
}
284
>
if !input.IgnoreRetentionTime && hlc.Since(buildId.StateUpdateTimestamp) < retention {
scavenger.go
285
continue
286
}
287
288
>
if err := rateLimiter.Wait(ctx); err != nil {
scavenger.go
289
return nil, context.DeadlineExceeded
290
}
291
>
exists, err := worker_versioning.WorkflowsExistForBuildId(ctx, a.visibilityManager, ns, entry.TaskQueue, buildId.Id)
scavenger.go
292
>
if err != nil {
293
return nil, err
294
}
296
>
if !exists {
297
>
a.logger.Info("Found build ID to remove",
298
>
tag.WorkflowNamespace(ns.Name().String()),
299
>
tag.WorkflowTaskQueueName(entry.TaskQueue),
300
>
tag.BuildId(buildId.Id),
301
>
)
302
>
buildIdsToRemove = append(buildIdsToRemove, buildId.Id)
303
>
setActive--
304
>
}
305
}
306
}