[#132] Add cleanup table in netmap processor

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-29 18:57:55 +03:00 committed by Alex Vanin
parent 9b97e95f82
commit 0c42db2c3c
3 changed files with 16 additions and 12 deletions

View file

@ -4,7 +4,7 @@ import (
"encoding/hex" "encoding/hex"
"sync" "sync"
"github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
) )
type ( type (

View file

@ -4,20 +4,20 @@ import (
"encoding/hex" "encoding/hex"
"testing" "testing"
"github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
crypto "github.com/nspcc-dev/neofs-crypto" crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/util/test" "github.com/nspcc-dev/neofs-node/pkg/util/test"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestCleanupTable(t *testing.T) { func TestCleanupTable(t *testing.T) {
var infos = []netmap.NodeInfo{ infos := []netmap.NodeInfo{
{PublicKey: crypto.MarshalPublicKey(&test.DecodeKey(1).PublicKey)}, {PublicKey: crypto.MarshalPublicKey(&test.DecodeKey(1).PublicKey)},
{PublicKey: crypto.MarshalPublicKey(&test.DecodeKey(2).PublicKey)}, {PublicKey: crypto.MarshalPublicKey(&test.DecodeKey(2).PublicKey)},
{PublicKey: crypto.MarshalPublicKey(&test.DecodeKey(3).PublicKey)}, {PublicKey: crypto.MarshalPublicKey(&test.DecodeKey(3).PublicKey)},
} }
var mapInfos = map[string]struct{}{ mapInfos := map[string]struct{}{
hex.EncodeToString(infos[0].PublicKey): {}, hex.EncodeToString(infos[0].PublicKey): {},
hex.EncodeToString(infos[1].PublicKey): {}, hex.EncodeToString(infos[1].PublicKey): {},
hex.EncodeToString(infos[2].PublicKey): {}, hex.EncodeToString(infos[2].PublicKey): {},
@ -110,6 +110,5 @@ func TestCleanupTable(t *testing.T) {
})) }))
require.EqualValues(t, len(infos)-1, cnt) require.EqualValues(t, len(infos)-1, cnt)
}) })
}) })
} }

View file

@ -38,6 +38,8 @@ type (
epochState EpochState epochState EpochState
activeState ActiveState activeState ActiveState
morphClient *client.Client morphClient *client.Client
netmapSnapshot cleanupTable
} }
// Params of the processor constructor. // Params of the processor constructor.
@ -49,6 +51,8 @@ type (
MorphClient *client.Client MorphClient *client.Client
EpochState EpochState EpochState EpochState
ActiveState ActiveState ActiveState ActiveState
CleanupEnabled bool
CleanupThreshold uint64 // in epochs
} }
) )
@ -88,6 +92,7 @@ func New(p *Params) (*Processor, error) {
epochState: p.EpochState, epochState: p.EpochState,
activeState: p.ActiveState, activeState: p.ActiveState,
morphClient: p.MorphClient, morphClient: p.MorphClient,
netmapSnapshot: newCleanupTable(p.CleanupEnabled, p.CleanupThreshold),
}, nil }, nil
} }