From 525a2c71dd0b85392facdb512466a36707b496f6 Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 6 Jul 2021 01:27:56 +0300 Subject: [PATCH] use hashes as keys in weight map to avoid duplicate work otherwise the root object will be raw, but internal references will be dag; duplicate work. --- blockstore/splitstore/splitstore.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/blockstore/splitstore/splitstore.go b/blockstore/splitstore/splitstore.go index f58f318be..cc455419a 100644 --- a/blockstore/splitstore/splitstore.go +++ b/blockstore/splitstore/splitstore.go @@ -1323,7 +1323,7 @@ func (s *SplitStore) moveColdBlocks(cold []cid.Cid) error { } func (s *SplitStore) sortObjects(cids []cid.Cid) error { - weight := make(map[cid.Cid]int) + weight := make(map[string]int) for _, c := range cids { switch c.Prefix().Codec { case cid.DagCBOR, cid.Raw: @@ -1334,7 +1334,7 @@ func (s *SplitStore) sortObjects(cids []cid.Cid) error { w := 0 err := s.walkObjectRaw(c, cid.NewSet(), func(c cid.Cid) error { - wc, ok := weight[c] + wc, ok := weight[string(c.Hash())] if ok { w += wc return errStopWalk @@ -1348,12 +1348,12 @@ func (s *SplitStore) sortObjects(cids []cid.Cid) error { return xerrors.Errorf("error determining cold object weight: %w", err) } - weight[c] = w + weight[string(c.Hash())] = w } sort.Slice(cids, func(i, j int) bool { - wi := weight[cids[i]] - wj := weight[cids[j]] + wi := weight[string(cids[i].Hash())] + wj := weight[string(cids[j].Hash())] if wi == wj { return bytes.Compare(cids[i].Hash(), cids[j].Hash()) > 0 }