Skip to content

Commit

Permalink
satellite/metainfo: fix GetLocationFromPlacement after YAML based pla…
Browse files Browse the repository at this point in the history
…cements

we tried to be backward compatible, and placement.GetAnnotation("location") can return with the name from the YAML based , but code was not prepared for placement.NodeFilter.GetAnnotation("location")

Easy fix is using the new placement struct instead.

Change-Id: I10f814b46a3564207d01628796d205f676847dbe
  • Loading branch information
elek committed Feb 20, 2024
1 parent 9606442 commit af5d446
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 2 additions & 3 deletions satellite/metainfo/endpoint_bucket_test.go
Expand Up @@ -308,8 +308,7 @@ func TestGetBucketLocation(t *testing.T) {
Reconfigure: testplanet.Reconfigure{
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
config.Placement = nodeselection.ConfigurablePlacementRule{
PlacementRules: fmt.Sprintf(`40:annotated(annotated(country("PL"),annotation("%s","Poland")),annotation("%s","%s"))`,
nodeselection.Location, nodeselection.AutoExcludeSubnet, nodeselection.AutoExcludeSubnetOFF),
PlacementRules: "endpoint_bucket_test_placement.yaml",
}
},
},
Expand Down Expand Up @@ -355,7 +354,7 @@ func TestGetBucketLocation(t *testing.T) {
Name: []byte("test-bucket"),
})
require.NoError(t, err)
require.Equal(t, []byte("Poland"), response.Location)
require.Equal(t, "Poland", string(response.Location))
})
}

Expand Down
3 changes: 3 additions & 0 deletions satellite/metainfo/endpoint_bucket_test_placement.yaml
@@ -0,0 +1,3 @@
placements:
- id: 40
name: Poland
10 changes: 5 additions & 5 deletions satellite/overlay/service.go
Expand Up @@ -305,7 +305,7 @@ type Service struct {
UploadSelectionCache *UploadSelectionCache
DownloadSelectionCache *DownloadSelectionCache
LastNetFunc LastNetFunc
placementRules nodeselection.PlacementRules
placementDefinitions nodeselection.PlacementDefinitions
}

// LastNetFunc is the type of a function that will be used to derive a network from an ip and port.
Expand Down Expand Up @@ -373,7 +373,7 @@ func NewService(log *zap.Logger, db DB, nodeEvents nodeevents.DB, placements nod
DownloadSelectionCache: downloadSelectionCache,
LastNetFunc: MaskOffLastNet,

placementRules: placements.CreateFilters,
placementDefinitions: placements,
}, nil
}

Expand Down Expand Up @@ -734,10 +734,10 @@ func (service *Service) GetNodeTags(ctx context.Context, id storj.NodeID) (nodes
return service.db.GetNodeTags(ctx, id)
}

// GetLocationFromPlacement returns the value for `nodeselection.Location` that
// placement is currently annotated with.
// GetLocationFromPlacement returns the location identifier of the bucket.
// It comes from the name of the placement (or `nodeselection.Location` in case of legacy config).
func (service *Service) GetLocationFromPlacement(placement storj.PlacementConstraint) string {
return nodeselection.GetAnnotation(service.placementRules(placement), nodeselection.Location)
return service.placementDefinitions[placement].Name
}

// ResolveIPAndNetwork resolves the target address and determines its IP and appropriate last_net, as indicated.
Expand Down

0 comments on commit af5d446

Please sign in to comment.