X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/0e6733b5009d22022c3b68bbd76b75ebdf5a12db..282d7a0c9d8279fa0a1293573e4313c8223be1b5:/services/keep-balance/balance.go diff --git a/services/keep-balance/balance.go b/services/keep-balance/balance.go index 33f3762b47..08a6c5881c 100644 --- a/services/keep-balance/balance.go +++ b/services/keep-balance/balance.go @@ -83,7 +83,13 @@ func (bal *Balancer) Run(config Config, runOptions RunOptions) (nextRunOptions R if err != nil { return } - defer os.Remove(tmpfn) + defer func() { + // Remove the tempfile only if we didn't get + // as far as successfully renaming it. + if lbFile != nil { + os.Remove(tmpfn) + } + }() bal.lostBlocks = lbFile } else { bal.lostBlocks = ioutil.Discard @@ -141,10 +147,7 @@ func (bal *Balancer) Run(config Config, runOptions RunOptions) (nextRunOptions R if err != nil { return } - err = lbFile.Close() - if err != nil { - return - } + lbFile = nil } if runOptions.CommitPulls { err = bal.CommitPulls(&config.Client) @@ -447,7 +450,13 @@ func (bal *Balancer) addCollection(coll arvados.Collection) error { repl = *coll.ReplicationDesired } debugf("%v: %d block x%d", coll.UUID, len(blkids), repl) - bal.BlockStateMap.IncreaseDesired(coll.StorageClassesDesired, repl, blkids) + // Pass pdh to IncreaseDesired only if LostBlocksFile is being + // written -- otherwise it's just a waste of memory. + pdh := "" + if bal.LostBlocksFile != "" { + pdh = coll.PortableDataHash + } + bal.BlockStateMap.IncreaseDesired(pdh, coll.StorageClassesDesired, repl, blkids) return nil } @@ -921,7 +930,11 @@ func (bal *Balancer) collectStatistics(results <-chan balanceResult) { s.lost.replicas -= surplus s.lost.blocks++ s.lost.bytes += bytes * int64(-surplus) - fmt.Fprintf(bal.lostBlocks, "%s\n", strings.SplitN(string(result.blkid), "+", 2)[0]) + fmt.Fprintf(bal.lostBlocks, "%s", strings.SplitN(string(result.blkid), "+", 2)[0]) + for pdh := range result.blk.Refs { + fmt.Fprintf(bal.lostBlocks, " %s", pdh) + } + fmt.Fprint(bal.lostBlocks, "\n") case surplus < 0: s.underrep.replicas -= surplus s.underrep.blocks++