From: Tom Clegg Date: Tue, 3 Aug 2021 20:42:04 +0000 (-0400) Subject: 17574: Confirm storage classes as [] when replication is 0. X-Git-Tag: 2.3.0~118^2~1 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/de030f2c3f7a0c57904def9662d4d7a979b90497 17574: Confirm storage classes as [] when replication is 0. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- diff --git a/services/keep-balance/collection.go b/services/keep-balance/collection.go index 1da3ec4415..1e1e51abe7 100644 --- a/services/keep-balance/collection.go +++ b/services/keep-balance/collection.go @@ -199,10 +199,13 @@ func (bal *Balancer) updateCollections(ctx context.Context, c *arvados.Client, c // temporarily. repl = desired } - classes, err := json.Marshal(coll.StorageClassesDesired) - if err != nil { - bal.logf("BUG? json.Marshal(%v) failed: %s", classes, err) - continue + classes := emptyJSONArray + if repl > 0 { + classes, err = json.Marshal(coll.StorageClassesDesired) + if err != nil { + bal.logf("BUG? json.Marshal(%v) failed: %s", classes, err) + continue + } } needUpdate := coll.ReplicationConfirmed == nil || *coll.ReplicationConfirmed != repl || len(coll.StorageClassesConfirmed) != len(coll.StorageClassesDesired) for i := range coll.StorageClassesDesired { @@ -259,3 +262,5 @@ func goSendErr(errs chan<- error, f func() error) { } }() } + +var emptyJSONArray = []byte("[]") diff --git a/services/keep-balance/integration_test.go b/services/keep-balance/integration_test.go index 3ddcb159d8..52e6149158 100644 --- a/services/keep-balance/integration_test.go +++ b/services/keep-balance/integration_test.go @@ -118,10 +118,10 @@ func (s *integrationSuite) TestBalanceAPIFixtures(c *check.C) { repl int classes []string }{ - {arvadostest.EmptyCollectionUUID, 0, []string{"default"}}, + {arvadostest.EmptyCollectionUUID, 0, []string{}}, {arvadostest.FooCollection, 2, []string{"default"}}, // "foo" blk {arvadostest.StorageClassesDesiredDefaultConfirmedDefault, 2, []string{"default"}}, // "bar" blk - {arvadostest.StorageClassesDesiredArchiveConfirmedDefault, 0, []string{"archive"}}, // "bar" blk + {arvadostest.StorageClassesDesiredArchiveConfirmedDefault, 0, []string{}}, // "bar" blk } { c.Logf("%#v", trial) var coll arvados.Collection