[#723] container/announcement/storage: Map announcements by epoch and container id

Signed-off-by: ZhangTao1596 <zhangtao@ngd.neo.org>
This commit is contained in:
ZhangTao1596 2021-07-28 16:18:41 +08:00 committed by Alex Vanin
parent 2290109849
commit 01806db612

View file

@ -14,6 +14,12 @@ type usedSpaceEstimations struct {
sizes []uint64 sizes []uint64
} }
type storageKey struct {
epoch uint64
cid string
}
// Storage represents in-memory storage of // Storage represents in-memory storage of
// UsedSpaceAnnouncement values. // UsedSpaceAnnouncement values.
// //
@ -34,7 +40,7 @@ type usedSpaceEstimations struct {
type Storage struct { type Storage struct {
mtx sync.RWMutex mtx sync.RWMutex
mItems map[uint64]*usedSpaceEstimations mItems map[storageKey]*usedSpaceEstimations
} }
// Prm groups the required parameters of the Storage's constructor. // Prm groups the required parameters of the Storage's constructor.
@ -48,7 +54,7 @@ type Prm struct{}
// initialization and is completely ready for work. // initialization and is completely ready for work.
func New(_ Prm) *Storage { func New(_ Prm) *Storage {
return &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() s.mtx.Lock()
{ {
key := a.Epoch() key := storageKey{
epoch: a.Epoch(),
cid: a.ContainerID().String(),
}
estimations, ok := s.mItems[key] estimations, ok := s.mItems[key]
if !ok { if !ok {