Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with prepared queries using sameness-groups. #19970

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/_7773.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
prepared-query: (Enterprise-only) Fix issue where sameness-group failover targets to peers would attempt to query data from the default partition, rather than the sameness-group's partition always.
```
128 changes: 64 additions & 64 deletions agent/consul/prepared_query_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3357,6 +3357,7 @@ type executeServers struct {

func createExecuteServers(t *testing.T) *executeServers {
es := newExecuteServers(t)
es.initPeering(t, "")
es.initWanFed(t)
es.exportPeeringServices(t)
es.initTokens(t)
Expand All @@ -3365,7 +3366,6 @@ func createExecuteServers(t *testing.T) *executeServers {
}

func newExecuteServers(t *testing.T) *executeServers {

// Setup server
dir1, s1 := testServerWithConfig(t, func(c *Config) {
c.PrimaryDatacenter = "dc1"
Expand Down Expand Up @@ -3416,67 +3416,6 @@ func newExecuteServers(t *testing.T) *executeServers {
testrpc.WaitForLeader(t, s1.RPC, "dc1", testrpc.WithToken("root"))
testrpc.WaitForLeader(t, s3.RPC, "dc3")

acceptingPeerName := "my-peer-accepting-server"
dialingPeerName := "my-peer-dialing-server"

// Set up peering between dc1 (dialing) and dc3 (accepting) and export the foo service
{
// Create a peering by generating a token.
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
t.Cleanup(cancel)

options := structs.QueryOptions{Token: "root"}
ctx, err := grpcexternal.ContextWithQueryOptions(ctx, options)
require.NoError(t, err)

conn, err := grpc.DialContext(ctx, s3.config.RPCAddr.String(),
grpc.WithContextDialer(newServerDialer(s3.config.RPCAddr.String())),
//nolint:staticcheck
grpc.WithInsecure(),
grpc.WithBlock())
require.NoError(t, err)
t.Cleanup(func() {
conn.Close()
})

peeringClient := pbpeering.NewPeeringServiceClient(conn)
req := pbpeering.GenerateTokenRequest{
PeerName: dialingPeerName,
}
resp, err := peeringClient.GenerateToken(ctx, &req)
require.NoError(t, err)

conn, err = grpc.DialContext(ctx, s1.config.RPCAddr.String(),
grpc.WithContextDialer(newServerDialer(s1.config.RPCAddr.String())),
//nolint:staticcheck
grpc.WithInsecure(),
grpc.WithBlock())
require.NoError(t, err)
t.Cleanup(func() {
conn.Close()
})

peeringClient = pbpeering.NewPeeringServiceClient(conn)
establishReq := pbpeering.EstablishRequest{
PeerName: acceptingPeerName,
PeeringToken: resp.PeeringToken,
}
establishResp, err := peeringClient.Establish(ctx, &establishReq)
require.NoError(t, err)
require.NotNil(t, establishResp)

readResp, err := peeringClient.PeeringRead(ctx, &pbpeering.PeeringReadRequest{Name: acceptingPeerName})
require.NoError(t, err)
require.NotNil(t, readResp)

// Wait for the stream to be connected.
retry.Run(t, func(r *retry.R) {
status, found := s1.peerStreamServer.StreamStatus(readResp.GetPeering().GetID())
require.True(r, found)
require.True(r, status.Connected)
})
}

es := executeServers{
server: &serverTestMetadata{
server: s1,
Expand All @@ -3487,8 +3426,8 @@ func newExecuteServers(t *testing.T) *executeServers {
server: s3,
codec: codec3,
datacenter: "dc3",
dialingPeerName: dialingPeerName,
acceptingPeerName: acceptingPeerName,
dialingPeerName: "my-peer-dialing-server",
acceptingPeerName: "my-peer-accepting-server",
},
}

Expand Down Expand Up @@ -3562,3 +3501,64 @@ func (es *executeServers) initWanFed(t *testing.T) {
datacenter: "dc2",
}
}

func (es *executeServers) initPeering(t *testing.T, localPartition string) {
// Create a peering by generating a token.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
t.Cleanup(cancel)

options := structs.QueryOptions{Token: "root"}
ctx, err := grpcexternal.ContextWithQueryOptions(ctx, options)
require.NoError(t, err)

conn, err := grpc.DialContext(ctx, es.peeringServer.server.config.RPCAddr.String(),
grpc.WithContextDialer(newServerDialer(es.peeringServer.server.config.RPCAddr.String())),
//nolint:staticcheck
grpc.WithInsecure(),
grpc.WithBlock())
require.NoError(t, err)
t.Cleanup(func() {
conn.Close()
})

peeringClient := pbpeering.NewPeeringServiceClient(conn)
req := pbpeering.GenerateTokenRequest{
PeerName: es.peeringServer.dialingPeerName,
}
resp, err := peeringClient.GenerateToken(ctx, &req)
require.NoError(t, err)

conn, err = grpc.DialContext(ctx, es.server.server.config.RPCAddr.String(),
grpc.WithContextDialer(newServerDialer(es.server.server.config.RPCAddr.String())),
//nolint:staticcheck
grpc.WithInsecure(),
grpc.WithBlock())
require.NoError(t, err)
t.Cleanup(func() {
conn.Close()
})

peeringClient = pbpeering.NewPeeringServiceClient(conn)
establishReq := pbpeering.EstablishRequest{
Partition: localPartition,
PeerName: es.peeringServer.acceptingPeerName,
PeeringToken: resp.PeeringToken,
}
establishResp, err := peeringClient.Establish(ctx, &establishReq)
require.NoError(t, err)
require.NotNil(t, establishResp)

readResp, err := peeringClient.PeeringRead(ctx, &pbpeering.PeeringReadRequest{
Partition: localPartition,
Name: es.peeringServer.acceptingPeerName,
})
require.NoError(t, err)
require.NotNil(t, readResp)

// Wait for the stream to be connected.
retry.Run(t, func(r *retry.R) {
status, found := es.server.server.peerStreamServer.StreamStatus(readResp.GetPeering().GetID())
require.True(r, found)
require.True(r, status.Connected)
})
}
Loading