satellite/metainfo/piecedeletion: use nodes cache

Piece deletion service was using KnownReliable method from
overlaycache to get nodes addresses to send delete request.
KnownReliable was always hitting DB because this method was
not using cache. This change is using new DownloadSelectionCache
to avoid direct DB calls.

Change is not perfect because DownloadSelectionCache is not as
precise as KnownReliable method and can select few more nodes
to which we will send delete request but difference should be
small and we can improve it later.

Updates https://github.com/storj/storj/issues/4959

Change-Id: I4c3d91089a18ac35ebcb469a56536c33f76e44ea
This commit is contained in:
Michał Niewrzał 2022-07-19 23:04:12 +02:00 committed by Storj Robot
parent ba009b846f
commit d72f9525d4
3 changed files with 10 additions and 9 deletions

View File

@ -419,7 +419,8 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB,
peer.Metainfo.PieceDeletion, err = piecedeletion.NewService(
peer.Log.Named("metainfo:piecedeletion"),
peer.Dialer,
peer.Overlay.Service,
// TODO use cache designed for deletion
peer.Overlay.Service.DownloadSelectionCache,
config.Metainfo.PieceDeletion,
)
if err != nil {

View File

@ -11,10 +11,10 @@ import (
"go.uber.org/zap"
"golang.org/x/sync/semaphore"
"storj.io/common/pb"
"storj.io/common/rpc"
"storj.io/common/storj"
"storj.io/common/sync2"
"storj.io/storj/satellite/overlay"
)
// Config defines configuration options for Service.
@ -64,7 +64,7 @@ func (config *Config) Verify() errs.Group {
// Nodes stores reliable nodes information.
type Nodes interface {
KnownReliable(ctx context.Context, nodeIDs storj.NodeIDList) ([]*pb.Node, error)
GetNodes(ctx context.Context, nodes []storj.NodeID) (_ map[storj.NodeID]*overlay.SelectedNode, err error)
}
// Service handles combining piece deletion requests.
@ -190,18 +190,18 @@ func (service *Service) Delete(ctx context.Context, requests []Request, successT
}
if len(nodeIDs) > 0 {
nodes, err := service.nodesDB.KnownReliable(ctx, nodeIDs)
nodes, err := service.nodesDB.GetNodes(ctx, nodeIDs)
if err != nil {
// Pieces will be collected by garbage collector
return Error.Wrap(err)
}
for _, node := range nodes {
req := nodesReqs[node.Id]
req := nodesReqs[node.ID]
nodesReqs[node.Id] = Request{
nodesReqs[node.ID] = Request{
Node: storj.NodeURL{
ID: node.Id,
ID: node.ID,
Address: node.Address.Address,
},
Pieces: req.Pieces,

View File

@ -14,7 +14,6 @@ import (
"go.uber.org/zap/zaptest"
"storj.io/common/memory"
"storj.io/common/pb"
"storj.io/common/rpc"
"storj.io/common/storj"
"storj.io/common/testcontext"
@ -23,6 +22,7 @@ import (
"storj.io/storj/private/testplanet"
"storj.io/storj/satellite"
"storj.io/storj/satellite/metainfo/piecedeletion"
"storj.io/storj/satellite/overlay"
"storj.io/storj/storagenode"
"storj.io/storj/storagenode/pieces"
)
@ -412,6 +412,6 @@ func TestService_DeletePieces_Timeout(t *testing.T) {
type nodesDB struct{}
func (n *nodesDB) KnownReliable(ctx context.Context, nodesID storj.NodeIDList) ([]*pb.Node, error) {
func (n *nodesDB) GetNodes(ctx context.Context, nodes []storj.NodeID) (_ map[storj.NodeID]*overlay.SelectedNode, err error) {
return nil, nil
}