Skip to content

Commit

Permalink
[nspcc-dev#722] container/announcement/storage: Map announcements by …
Browse files Browse the repository at this point in the history
…epoch and container id

Signed-off-by: ZhangTao1596 <zhangtao@ngd.neo.org>
  • Loading branch information
ZhangTao1596 committed Jul 28, 2021
1 parent cf5f8a8 commit 5b70e17
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/services/container/announcement/load/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ type usedSpaceEstimations struct {
sizes []uint64
}

type storageKey struct {
epoch uint64

cid string
}

// Storage represents in-memory storage of
// UsedSpaceAnnouncement values.
//
Expand All @@ -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.
Expand All @@ -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),
}
}

Expand All @@ -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 {
Expand Down

0 comments on commit 5b70e17

Please sign in to comment.