1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
8 "github.com/sirupsen/logrus"
11 type putProgress struct {
12 classNeeded map[string]bool
13 classTodo map[string]bool
14 mountUsed map[*mount]bool
16 classDone map[string]int
19 func (pr *putProgress) Add(mnt *mount) {
20 if pr.mountUsed[mnt] {
21 logrus.Warnf("BUG? superfluous extra write to mount %s", mnt.UUID)
24 pr.mountUsed[mnt] = true
25 pr.totalReplication += mnt.Replication
26 for class := range mnt.StorageClasses {
27 pr.classDone[class] += mnt.Replication
28 delete(pr.classTodo, class)
32 func (pr *putProgress) Sub(mnt *mount) {
33 if !pr.mountUsed[mnt] {
34 logrus.Warnf("BUG? Sub called with no prior matching Add: %s", mnt.UUID)
37 pr.mountUsed[mnt] = false
38 pr.totalReplication -= mnt.Replication
39 for class := range mnt.StorageClasses {
40 pr.classDone[class] -= mnt.Replication
41 if pr.classNeeded[class] {
42 pr.classTodo[class] = true
47 func (pr *putProgress) Done() bool {
48 return len(pr.classTodo) == 0 && pr.totalReplication > 0
51 func (pr *putProgress) Want(mnt *mount) bool {
52 if pr.Done() || pr.mountUsed[mnt] {
55 if len(pr.classTodo) == 0 {
56 // none specified == "any"
59 for class := range mnt.StorageClasses {
60 if pr.classTodo[class] {
67 func (pr *putProgress) Copy() *putProgress {
69 classNeeded: pr.classNeeded,
70 classTodo: make(map[string]bool, len(pr.classTodo)),
71 classDone: make(map[string]int, len(pr.classDone)),
72 mountUsed: make(map[*mount]bool, len(pr.mountUsed)),
73 totalReplication: pr.totalReplication,
75 for k, v := range pr.classTodo {
78 for k, v := range pr.classDone {
81 for k, v := range pr.mountUsed {
87 func newPutProgress(classes []string) putProgress {
89 classNeeded: make(map[string]bool, len(classes)),
90 classTodo: make(map[string]bool, len(classes)),
91 classDone: map[string]int{},
92 mountUsed: map[*mount]bool{},
94 for _, c := range classes {
96 pr.classNeeded[c] = true
97 pr.classTodo[c] = true