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

Respond to AcknowledgeBackfill with the tickets that were assigned #1382

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
12 changes: 11 additions & 1 deletion api/frontend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ message AcknowledgeBackfillRequest {
Assignment assignment = 2;
}

// BETA FEATURE WARNING: This Request message is not finalized and still subject
// to possible change or removal.
message AcknowledgeBackfillResponse {
// The Backfill that was acknowledged.
Backfill backfill = 1;

// All of the Tickets that were successfully assigned
repeated Ticket tickets = 2;
}

// BETA FEATURE WARNING: This Request message is not finalized and still subject
// to possible change or removal.
message CreateBackfillRequest {
Expand Down Expand Up @@ -163,7 +173,7 @@ service FrontendService {
// This triggers an assignment process.
// BETA FEATURE WARNING: This call and the associated Request and Response
// messages are not finalized and still subject to possible change or removal.
rpc AcknowledgeBackfill(AcknowledgeBackfillRequest) returns (Backfill) {
rpc AcknowledgeBackfill(AcknowledgeBackfillRequest) returns (AcknowledgeBackfillResponse) {
option (google.api.http) = {
post: "/v1/frontendservice/backfills/{backfill_id}/acknowledge"
body: "*"
Expand Down
19 changes: 18 additions & 1 deletion api/frontend.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/openmatchBackfill"
"$ref": "#/definitions/openmatchAcknowledgeBackfillResponse"
}
},
"404": {
Expand Down Expand Up @@ -410,6 +410,23 @@
},
"description": "BETA FEATURE WARNING: This Request message is not finalized and still subject\nto possible change or removal."
},
"openmatchAcknowledgeBackfillResponse": {
"type": "object",
"properties": {
"backfill": {
"$ref": "#/definitions/openmatchBackfill",
"description": "The Backfill that was acknowledged."
},
"tickets": {
"type": "array",
"items": {
"$ref": "#/definitions/openmatchTicket"
},
"title": "All of the Tickets that were successfully assigned"
}
},
"description": "BETA FEATURE WARNING: This Request message is not finalized and still subject\nto possible change or removal."
},
"openmatchAssignment": {
"type": "object",
"properties": {
Expand Down
15 changes: 11 additions & 4 deletions internal/app/frontend/frontend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func doWatchAssignments(ctx context.Context, id string, sender func(*pb.Assignme

// AcknowledgeBackfill is used to notify OpenMatch about GameServer connection info.
// This triggers an assignment process.
func (s *frontendService) AcknowledgeBackfill(ctx context.Context, req *pb.AcknowledgeBackfillRequest) (*pb.Backfill, error) {
func (s *frontendService) AcknowledgeBackfill(ctx context.Context, req *pb.AcknowledgeBackfillRequest) (*pb.AcknowledgeBackfillResponse, error) {
if req.GetBackfillId() == "" {
return nil, status.Errorf(codes.InvalidArgument, ".BackfillId is required")
}
Expand Down Expand Up @@ -347,16 +347,23 @@ func (s *frontendService) AcknowledgeBackfill(ctx context.Context, req *pb.Ackno
return nil, err
}

resp := &pb.AcknowledgeBackfillResponse{
Backfill: bf,
Tickets: make([]*pb.Ticket, 0),
}

if len(associatedTickets) != 0 {
resp, _, err := s.store.UpdateAssignments(ctx, &pb.AssignTicketsRequest{
setResp, tickets, err := s.store.UpdateAssignments(ctx, &pb.AssignTicketsRequest{
Assignments: []*pb.AssignmentGroup{{TicketIds: associatedTickets, Assignment: req.GetAssignment()}},
})
if err != nil {
return nil, err
}

resp.Tickets = tickets

// log errors returned from UpdateAssignments to track tickets with NotFound errors
for _, f := range resp.Failures {
for _, f := range setResp.Failures {
logger.Errorf("failed to assign ticket %s, cause %d", f.TicketId, f.Cause)
}
for _, id := range associatedTickets {
Expand All @@ -374,7 +381,7 @@ func (s *frontendService) AcknowledgeBackfill(ctx context.Context, req *pb.Ackno
}
}

return bf, nil
return resp, nil
}

// GetBackfill fetches a Backfill object by its ID.
Expand Down
14 changes: 8 additions & 6 deletions internal/app/frontend/frontend_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,23 +401,25 @@ func TestAcknowledgeBackfill(t *testing.T) {
require.NoError(t, err)
fs := frontendService{cfg, store}

bf, err := fs.AcknowledgeBackfill(ctx, &pb.AcknowledgeBackfillRequest{BackfillId: fakeBackfill.Id, Assignment: &pb.Assignment{Connection: "10.0.0.1"}})
resp, err := fs.AcknowledgeBackfill(ctx, &pb.AcknowledgeBackfillRequest{BackfillId: fakeBackfill.Id, Assignment: &pb.Assignment{Connection: "10.0.0.1"}})
require.NoError(t, err)
require.NotNil(t, bf)
require.NotNil(t, resp)
require.NotNil(t, resp.Backfill)
require.NotNil(t, resp.Tickets)

// Use wrong BackfillID, error is returned
bf, err = fs.AcknowledgeBackfill(ctx, &pb.AcknowledgeBackfillRequest{BackfillId: "42", Assignment: &pb.Assignment{Connection: "10.0.0.1"}})
resp, err = fs.AcknowledgeBackfill(ctx, &pb.AcknowledgeBackfillRequest{BackfillId: "42", Assignment: &pb.Assignment{Connection: "10.0.0.1"}})
require.Error(t, err)
require.Nil(t, bf)
require.Nil(t, resp)
require.Equal(t, "Backfill id: 42 not found", status.Convert(err).Message())

time.Sleep(cfg.GetDuration("pendingReleaseTimeout"))
ids, err := store.GetExpiredBackfillIDs(ctx)
require.NoError(t, err)
require.Len(t, ids, 1)

bf, err = fs.AcknowledgeBackfill(ctx, &pb.AcknowledgeBackfillRequest{BackfillId: fakeBackfill.Id, Assignment: &pb.Assignment{Connection: "10.0.0.1"}})
require.Nil(t, bf)
resp, err = fs.AcknowledgeBackfill(ctx, &pb.AcknowledgeBackfillRequest{BackfillId: fakeBackfill.Id, Assignment: &pb.Assignment{Connection: "10.0.0.1"}})
require.Nil(t, resp)
require.Error(t, err)
require.Equal(t, codes.Unavailable.String(), status.Convert(err).Code().String())
require.Contains(t, status.Convert(err).Message(), "can not acknowledge an expired backfill, id: 1")
Expand Down
20 changes: 16 additions & 4 deletions internal/testing/e2e/backfill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestAcknowledgeBackfill(t *testing.T) {
ticketIDs := createMatchWithBackfill(ctx, om, createdBf, t)

conn := "127.0.0.1:4242"
getBF, err := om.Frontend().AcknowledgeBackfill(ctx, &pb.AcknowledgeBackfillRequest{
getResp, err := om.Frontend().AcknowledgeBackfill(ctx, &pb.AcknowledgeBackfillRequest{
BackfillId: createdBf.Id,
Assignment: &pb.Assignment{
Connection: conn,
Expand All @@ -161,12 +161,22 @@ func TestAcknowledgeBackfill(t *testing.T) {
},
},
})
require.NotNil(t, getBF)
require.NotNil(t, getResp)
require.NotNil(t, getResp.Backfill)
require.NotNil(t, getResp.Tickets)
require.Equal(t, len(ticketIDs), len(getResp.Tickets))
require.NoError(t, err)

respTicketIds := make([]string, len(getResp.Tickets))

for _, rt := range getResp.Tickets {
respTicketIds = append(respTicketIds, rt.Id)
}

for _, v := range ticketIDs {
ticket, err := om.Frontend().GetTicket(ctx, &pb.GetTicketRequest{TicketId: v})
require.NoError(t, err)
require.Contains(t, respTicketIds, ticket.Id)
require.NotNil(t, ticket.Assignment)
require.Equal(t, conn, ticket.Assignment.Connection)
}
Expand All @@ -193,12 +203,14 @@ func TestAcknowledgeBackfillDeletedTicket(t *testing.T) {
// Delete 1st ticket
om.Frontend().DeleteTicket(ctx, &pb.DeleteTicketRequest{TicketId: ticketIDs[0]})
conn := "127.0.0.1:4242"
getBF, err := om.Frontend().AcknowledgeBackfill(ctx, &pb.AcknowledgeBackfillRequest{BackfillId: createdBf.Id, Assignment: &pb.Assignment{Connection: conn, Extensions: map[string]*any.Any{
getResp, err := om.Frontend().AcknowledgeBackfill(ctx, &pb.AcknowledgeBackfillRequest{BackfillId: createdBf.Id, Assignment: &pb.Assignment{Connection: conn, Extensions: map[string]*any.Any{
"evaluation_input": mustAny(&pb.DefaultEvaluationCriteria{
Score: 10,
}),
}}})
require.NotNil(t, getBF)
require.NotNil(t, getResp)
require.NotNil(t, getResp.Backfill)
require.NotNil(t, getResp.Tickets)
require.NoError(t, err)

// Check that an error on 1st ticket assignment does not change 2nd ticket assignment
Expand Down
2 changes: 1 addition & 1 deletion internal/testing/fake_frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *FakeFrontend) WatchAssignments(req *pb.WatchAssignmentsRequest, stream

// AcknowledgeBackfill is used to notify OpenMatch about GameServer connection info.
// This triggers an assignment process.
func (s *FakeFrontend) AcknowledgeBackfill(ctx context.Context, req *pb.AcknowledgeBackfillRequest) (*pb.Backfill, error) {
func (s *FakeFrontend) AcknowledgeBackfill(ctx context.Context, req *pb.AcknowledgeBackfillRequest) (*pb.AcknowledgeBackfillResponse, error) {
return nil, status.Error(codes.Unimplemented, "not implemented")
}

Expand Down
Loading