satellite/satellitedb: fix selection query with AOST
Union query for both reputable and new nodes didn't properly work. The top level query is required to have an `AS OF SYSTEM TIME` statement as well. Change-Id: I8ee6dd5b700c2b1ed2aa562962bfa72be7eec30a
This commit is contained in:
parent
4a146000cc
commit
51f488fc4b
@ -457,9 +457,11 @@ func TestNodeSelectionGracefulExit(t *testing.T) {
|
||||
} {
|
||||
t.Logf("#%2d. %+v", i, tt)
|
||||
|
||||
response, err := satellite.Overlay.Service.FindStorageNodesWithPreferences(ctx, overlay.FindStorageNodesRequest{
|
||||
RequestedCount: tt.RequestCount,
|
||||
}, &tt.Preferences)
|
||||
response, err := satellite.Overlay.Service.FindStorageNodesWithPreferences(ctx,
|
||||
overlay.FindStorageNodesRequest{
|
||||
RequestedCount: tt.RequestCount,
|
||||
AsOfSystemInterval: -time.Microsecond,
|
||||
}, &tt.Preferences)
|
||||
|
||||
t.Log(len(response), err)
|
||||
if tt.ShouldFailWith != nil {
|
||||
@ -688,9 +690,11 @@ func testDistinctIPs(t *testing.T, ctx *testcontext.Context, planet *testplanet.
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
response, err := service.FindStorageNodesWithPreferences(ctx, overlay.FindStorageNodesRequest{
|
||||
RequestedCount: tt.requestCount,
|
||||
}, &tt.preferences)
|
||||
response, err := service.FindStorageNodesWithPreferences(ctx,
|
||||
overlay.FindStorageNodesRequest{
|
||||
RequestedCount: tt.requestCount,
|
||||
AsOfSystemInterval: -time.Microsecond,
|
||||
}, &tt.preferences)
|
||||
if tt.shouldFailWith != nil {
|
||||
assert.Error(t, err)
|
||||
assert.True(t, tt.shouldFailWith.Has(err))
|
||||
|
@ -140,7 +140,7 @@ func (cache *overlaycache) selectStorageNodesOnce(ctx context.Context, reputable
|
||||
}
|
||||
}
|
||||
|
||||
query := unionAll(newNodeQuery, reputableNodeQuery)
|
||||
query := unionAll(asOf, newNodeQuery, reputableNodeQuery)
|
||||
|
||||
rows, err := cache.db.Query(ctx, cache.db.Rebind(query.query), query.args...)
|
||||
if err != nil {
|
||||
@ -282,7 +282,7 @@ func (partial partialQuery) asQuery() query {
|
||||
}
|
||||
|
||||
// unionAll combines multiple partial queries into a single query.
|
||||
func unionAll(partials ...partialQuery) query {
|
||||
func unionAll(asOf string, partials ...partialQuery) query {
|
||||
var queries []string
|
||||
var args []interface{}
|
||||
for _, partial := range partials {
|
||||
@ -302,8 +302,16 @@ func unionAll(partials ...partialQuery) query {
|
||||
return query{query: queries[0], args: args}
|
||||
}
|
||||
|
||||
union := "(" + strings.Join(queries, ") UNION ALL (") + ")"
|
||||
if asOf == "" {
|
||||
return query{
|
||||
query: union,
|
||||
args: args,
|
||||
}
|
||||
}
|
||||
|
||||
return query{
|
||||
query: "(" + strings.Join(queries, ") UNION ALL (") + ")",
|
||||
query: "SELECT * FROM (" + union + ") " + asOf,
|
||||
args: args,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user