From 01806db612a302e7e97476e719beefcca5821864 Mon Sep 17 00:00:00 2001 From: ZhangTao1596 Date: Wed, 28 Jul 2021 16:18:41 +0800 Subject: [PATCH] [#723] container/announcement/storage: Map announcements by epoch and container id Signed-off-by: ZhangTao1596 --- .../announcement/load/storage/storage.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/services/container/announcement/load/storage/storage.go b/pkg/services/container/announcement/load/storage/storage.go index f41af2360..569403ac4 100644 --- a/pkg/services/container/announcement/load/storage/storage.go +++ b/pkg/services/container/announcement/load/storage/storage.go @@ -14,6 +14,12 @@ type usedSpaceEstimations struct { sizes []uint64 } +type storageKey struct { + epoch uint64 + + cid string +} + // Storage represents in-memory storage of // UsedSpaceAnnouncement values. // @@ -34,7 +40,7 @@ type usedSpaceEstimations struct { type Storage struct { mtx sync.RWMutex - mItems map[uint64]*usedSpaceEstimations + mItems map[storageKey]*usedSpaceEstimations } // Prm groups the required parameters of the Storage's constructor. @@ -48,7 +54,7 @@ type Prm struct{} // initialization and is completely ready for work. func New(_ Prm) *Storage { return &Storage{ - mItems: make(map[uint64]*usedSpaceEstimations), + mItems: make(map[storageKey]*usedSpaceEstimations), } } @@ -60,7 +66,10 @@ func (s *Storage) Put(a container.UsedSpaceAnnouncement) error { s.mtx.Lock() { - key := a.Epoch() + key := storageKey{ + epoch: a.Epoch(), + cid: a.ContainerID().String(), + } estimations, ok := s.mItems[key] if !ok {