feat: add ability to exclude a list of nodes when querying
This commit is contained in:
parent
82de843ad9
commit
e9f4a7b0b9
|
@ -26,6 +26,7 @@ type StorageLocationProviderImpl struct {
|
|||
isWaitingForUri bool
|
||||
mutex sync.Mutex
|
||||
logger *zap.Logger
|
||||
excludeNodes []*encoding.NodeId
|
||||
}
|
||||
|
||||
func (s *StorageLocationProviderImpl) Start() error {
|
||||
|
@ -43,6 +44,10 @@ func (s *StorageLocationProviderImpl) Start() error {
|
|||
continue
|
||||
}
|
||||
|
||||
if containsNode(s.excludeNodes, nodeId) {
|
||||
continue
|
||||
}
|
||||
|
||||
s.availableNodes = append(s.availableNodes, nodeId)
|
||||
}
|
||||
|
||||
|
@ -91,6 +96,9 @@ func (s *StorageLocationProviderImpl) Start() error {
|
|||
s.logger.Error("Error decoding node id", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
if containsNode(s.excludeNodes, nodeId) {
|
||||
continue
|
||||
}
|
||||
if !containsNode(s.availableNodes, nodeId) {
|
||||
s.availableNodes = append(s.availableNodes, nodeId)
|
||||
hasNewNode = true
|
||||
|
@ -180,6 +188,7 @@ func NewStorageLocationProvider(params StorageLocationProviderParams) *StorageLo
|
|||
timeoutDuration: 60 * time.Second,
|
||||
uris: make(map[string]storage.StorageLocation),
|
||||
logger: params.Logger,
|
||||
excludeNodes: params.ExcludeNodes,
|
||||
}
|
||||
}
|
||||
func containsNode(slice []*encoding.NodeId, item *encoding.NodeId) bool {
|
||||
|
@ -195,5 +204,6 @@ type StorageLocationProviderParams struct {
|
|||
Services service.Services
|
||||
Hash *encoding.Multihash
|
||||
LocationTypes []types.StorageLocationType
|
||||
ExcludeNodes []*encoding.NodeId
|
||||
service.ServiceParams
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue