diff --git a/api/openmatch/frontend.proto b/api/openmatch/frontend.proto index acf79d8..43cc2e0 100644 --- a/api/openmatch/frontend.proto +++ b/api/openmatch/frontend.proto @@ -51,6 +51,13 @@ message UpdateBackfillRequest { Backfill backfill = 1; } +message DeindexTicketRequest { + string ticket_id = 1; +} + +message DeindexTicketResponse { +} + service FrontendService { rpc CreateTicket(CreateTicketRequest) returns (Ticket); rpc DeleteTicket(DeleteTicketRequest) returns (google.protobuf.Empty); @@ -61,4 +68,9 @@ service FrontendService { rpc DeleteBackfill(DeleteBackfillRequest) returns (google.protobuf.Empty); rpc GetBackfill(GetBackfillRequest) returns (Backfill); rpc UpdateBackfill(UpdateBackfillRequest) returns (Backfill); + + // DeindexTickets removes the ticket from the matching candidates. + // unlike DeleteTicket, it does not delete the ticket body; + // you can still get the Assignment with GetTicket after Deindex. + rpc DeindexTicket(DeindexTicketRequest) returns (DeindexTicketResponse); } diff --git a/docs/differences.md b/docs/differences.md index 0942d90..4f23fb6 100644 --- a/docs/differences.md +++ b/docs/differences.md @@ -43,3 +43,15 @@ minimatch stores Ticket and Assignment in separate keys. If the Ticket ID is `abc`, the Ticket key is `abc` and the Assignement key is `assign:abc`. See also [Scalable minimatch](./scalable.md) for how to store each in a different Redis instance. + +## DeindexTicket API + +The minimatch Frontend has a DeindexTicket API that the Open Match Frontend does not have. + +DeindexTickets removes the ticket from the matching candidates. +unlike DeleteTicket, it does not delete the ticket body; +you can still get the Assignment with GetTicket after Deindex. + +To use the Frontend API added by minimatch, +you need to use [connect-go](https://github.com/connectrpc/connect-go) and `github.com/castaneai/minimatch/gen/openmatch` instead of package `open-match.dev/open-match`. +Please see [examples/frontendclient](../examples/frontendclient/frontendclient.go). diff --git a/examples/frontendclient/frontendclient.go b/examples/frontendclient/frontendclient.go new file mode 100644 index 0000000..241deb4 --- /dev/null +++ b/examples/frontendclient/frontendclient.go @@ -0,0 +1,34 @@ +package main + +import ( + "context" + "log" + "net/http" + "os/signal" + "syscall" + + "connectrpc.com/connect" + + pb "github.com/castaneai/minimatch/gen/openmatch" + "github.com/castaneai/minimatch/gen/openmatch/openmatchconnect" +) + +func main() { + ctx, shutdown := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + defer shutdown() + + client := openmatchconnect.NewFrontendServiceClient(http.DefaultClient, "http://localhost:50504", connect.WithGRPC()) + resp, err := client.CreateTicket(ctx, connect.NewRequest(&pb.CreateTicketRequest{Ticket: &pb.Ticket{}})) + if err != nil { + log.Printf("failed to create ticket: %+v", err) + return + } + ticket := resp.Msg + log.Printf("ticket created: %s", ticket.Id) + + if _, err := client.DeindexTicket(ctx, connect.NewRequest(&pb.DeindexTicketRequest{TicketId: ticket.Id})); err != nil { + log.Printf("failed to deindex ticket: %+v", err) + return + } + log.Printf("ticket deindexed: %s", ticket.Id) +} diff --git a/frontend.go b/frontend.go index 1b0c40f..8ce6b00 100644 --- a/frontend.go +++ b/frontend.go @@ -173,6 +173,16 @@ func (s *FrontendService) UpdateBackfill(ctx context.Context, request *connect.R return nil, connect.NewError(connect.CodeUnimplemented, errors.New("not implemented")) } +func (s *FrontendService) DeindexTicket(ctx context.Context, req *connect.Request[pb.DeindexTicketRequest]) (*connect.Response[pb.DeindexTicketResponse], error) { + if req.Msg.TicketId == "" { + return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("invalid ticket_id")) + } + if err := s.store.DeindexTicket(ctx, req.Msg.TicketId); err != nil { + return nil, err + } + return connect.NewResponse(&pb.DeindexTicketResponse{}), nil +} + func newWatchAssignmentBackoff() retry.Backoff { return retry.NewConstant(watchAssignmentInterval) } diff --git a/gen/openmatch/frontend.pb.go b/gen/openmatch/frontend.pb.go index 0e4af96..8a5100a 100644 --- a/gen/openmatch/frontend.pb.go +++ b/gen/openmatch/frontend.pb.go @@ -554,6 +554,91 @@ func (x *UpdateBackfillRequest) GetBackfill() *Backfill { return nil } +type DeindexTicketRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TicketId string `protobuf:"bytes,1,opt,name=ticket_id,json=ticketId,proto3" json:"ticket_id,omitempty"` +} + +func (x *DeindexTicketRequest) Reset() { + *x = DeindexTicketRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_openmatch_frontend_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DeindexTicketRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeindexTicketRequest) ProtoMessage() {} + +func (x *DeindexTicketRequest) ProtoReflect() protoreflect.Message { + mi := &file_openmatch_frontend_proto_msgTypes[11] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DeindexTicketRequest.ProtoReflect.Descriptor instead. +func (*DeindexTicketRequest) Descriptor() ([]byte, []int) { + return file_openmatch_frontend_proto_rawDescGZIP(), []int{11} +} + +func (x *DeindexTicketRequest) GetTicketId() string { + if x != nil { + return x.TicketId + } + return "" +} + +type DeindexTicketResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *DeindexTicketResponse) Reset() { + *x = DeindexTicketResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_openmatch_frontend_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DeindexTicketResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeindexTicketResponse) ProtoMessage() {} + +func (x *DeindexTicketResponse) ProtoReflect() protoreflect.Message { + mi := &file_openmatch_frontend_proto_msgTypes[12] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DeindexTicketResponse.ProtoReflect.Descriptor instead. +func (*DeindexTicketResponse) Descriptor() ([]byte, []int) { + return file_openmatch_frontend_proto_rawDescGZIP(), []int{12} +} + var File_openmatch_frontend_proto protoreflect.FileDescriptor var file_openmatch_frontend_proto_rawDesc = []byte{ @@ -613,61 +698,71 @@ var file_openmatch_frontend_proto_rawDesc = []byte{ 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2f, 0x0a, 0x08, 0x62, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x52, 0x08, 0x62, 0x61, - 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x32, 0xbf, 0x05, 0x0a, 0x0f, 0x46, 0x72, 0x6f, 0x6e, 0x74, - 0x65, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x41, 0x0a, 0x0c, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x1e, 0x2e, 0x6f, 0x70, 0x65, - 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x63, - 0x6b, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x6f, 0x70, 0x65, - 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x46, 0x0a, - 0x0c, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x1e, 0x2e, - 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, - 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x3b, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x54, 0x69, 0x63, 0x6b, - 0x65, 0x74, 0x12, 0x1b, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x47, - 0x65, 0x74, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x11, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x54, 0x69, 0x63, 0x6b, - 0x65, 0x74, 0x12, 0x5d, 0x0a, 0x10, 0x57, 0x61, 0x74, 0x63, 0x68, 0x41, 0x73, 0x73, 0x69, 0x67, - 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x22, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, - 0x63, 0x68, 0x2e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, - 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x6f, 0x70, 0x65, - 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x41, 0x73, 0x73, 0x69, - 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, - 0x01, 0x12, 0x64, 0x0a, 0x13, 0x41, 0x63, 0x6b, 0x6e, 0x6f, 0x77, 0x6c, 0x65, 0x64, 0x67, 0x65, - 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x12, 0x25, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, - 0x61, 0x74, 0x63, 0x68, 0x2e, 0x41, 0x63, 0x6b, 0x6e, 0x6f, 0x77, 0x6c, 0x65, 0x64, 0x67, 0x65, - 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x26, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x41, 0x63, 0x6b, 0x6e, - 0x6f, 0x77, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x47, 0x0a, 0x0e, 0x43, 0x72, 0x65, 0x61, 0x74, - 0x65, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x12, 0x20, 0x2e, 0x6f, 0x70, 0x65, 0x6e, - 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x42, 0x61, 0x63, 0x6b, - 0x66, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x6f, 0x70, - 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, - 0x12, 0x4a, 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, - 0x6c, 0x6c, 0x12, 0x20, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x44, - 0x65, 0x6c, 0x65, 0x74, 0x65, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x41, 0x0a, 0x0b, - 0x47, 0x65, 0x74, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x12, 0x1d, 0x2e, 0x6f, 0x70, - 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x63, 0x6b, 0x66, - 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x6f, 0x70, 0x65, - 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x12, - 0x47, 0x0a, 0x0e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, - 0x6c, 0x12, 0x20, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x55, 0x70, - 0x64, 0x61, 0x74, 0x65, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, - 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x42, 0x90, 0x01, 0x0a, 0x0d, 0x63, 0x6f, 0x6d, - 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x42, 0x0d, 0x46, 0x72, 0x6f, 0x6e, - 0x74, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2c, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x61, 0x73, 0x74, 0x61, 0x6e, 0x65, 0x61, - 0x69, 0x2f, 0x6d, 0x69, 0x6e, 0x69, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2f, 0x67, 0x65, 0x6e, 0x2f, - 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0xa2, 0x02, 0x03, 0x4f, 0x58, 0x58, 0xaa, - 0x02, 0x09, 0x4f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0xca, 0x02, 0x09, 0x4f, 0x70, - 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0xe2, 0x02, 0x15, 0x4f, 0x70, 0x65, 0x6e, 0x6d, 0x61, - 0x74, 0x63, 0x68, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, - 0x02, 0x09, 0x4f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x22, 0x33, 0x0a, 0x14, 0x44, 0x65, 0x69, 0x6e, 0x64, 0x65, + 0x78, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, + 0x0a, 0x09, 0x74, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x74, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x49, 0x64, 0x22, 0x17, 0x0a, 0x15, 0x44, + 0x65, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x93, 0x06, 0x0a, 0x0f, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, + 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x41, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x1e, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x63, 0x6b, 0x65, + 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x2e, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x46, 0x0a, 0x0c, 0x44, + 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x1e, 0x2e, 0x6f, 0x70, + 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x69, + 0x63, 0x6b, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, + 0x70, 0x74, 0x79, 0x12, 0x3b, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, + 0x12, 0x1b, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x47, 0x65, 0x74, + 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, + 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, + 0x12, 0x5d, 0x0a, 0x10, 0x57, 0x61, 0x74, 0x63, 0x68, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, + 0x65, 0x6e, 0x74, 0x73, 0x12, 0x22, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x2e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, + 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x2e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, + 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, + 0x64, 0x0a, 0x13, 0x41, 0x63, 0x6b, 0x6e, 0x6f, 0x77, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x42, 0x61, + 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x12, 0x25, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x2e, 0x41, 0x63, 0x6b, 0x6e, 0x6f, 0x77, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x42, 0x61, + 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x26, 0x2e, + 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x41, 0x63, 0x6b, 0x6e, 0x6f, 0x77, + 0x6c, 0x65, 0x64, 0x67, 0x65, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x47, 0x0a, 0x0e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x42, + 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x12, 0x20, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, + 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x6f, 0x70, 0x65, 0x6e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x12, 0x4a, + 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, + 0x12, 0x20, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x44, 0x65, 0x6c, + 0x65, 0x74, 0x65, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x41, 0x0a, 0x0b, 0x47, 0x65, + 0x74, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x12, 0x1d, 0x2e, 0x6f, 0x70, 0x65, 0x6e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, + 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x12, 0x47, 0x0a, + 0x0e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x12, + 0x20, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x42, 0x61, 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x13, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2e, 0x42, 0x61, + 0x63, 0x6b, 0x66, 0x69, 0x6c, 0x6c, 0x12, 0x52, 0x0a, 0x0d, 0x44, 0x65, 0x69, 0x6e, 0x64, 0x65, + 0x78, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x1f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x2e, 0x44, 0x65, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x54, 0x69, 0x63, 0x6b, 0x65, + 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x2e, 0x44, 0x65, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x54, 0x69, 0x63, 0x6b, + 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x90, 0x01, 0x0a, 0x0d, 0x63, + 0x6f, 0x6d, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x42, 0x0d, 0x46, 0x72, + 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2c, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x61, 0x73, 0x74, 0x61, 0x6e, + 0x65, 0x61, 0x69, 0x2f, 0x6d, 0x69, 0x6e, 0x69, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x2f, 0x67, 0x65, + 0x6e, 0x2f, 0x6f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0xa2, 0x02, 0x03, 0x4f, 0x58, + 0x58, 0xaa, 0x02, 0x09, 0x4f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0xca, 0x02, 0x09, + 0x4f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0xe2, 0x02, 0x15, 0x4f, 0x70, 0x65, 0x6e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, + 0x61, 0xea, 0x02, 0x09, 0x4f, 0x70, 0x65, 0x6e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -682,7 +777,7 @@ func file_openmatch_frontend_proto_rawDescGZIP() []byte { return file_openmatch_frontend_proto_rawDescData } -var file_openmatch_frontend_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_openmatch_frontend_proto_msgTypes = make([]protoimpl.MessageInfo, 13) var file_openmatch_frontend_proto_goTypes = []any{ (*CreateTicketRequest)(nil), // 0: openmatch.CreateTicketRequest (*DeleteTicketRequest)(nil), // 1: openmatch.DeleteTicketRequest @@ -695,19 +790,21 @@ var file_openmatch_frontend_proto_goTypes = []any{ (*DeleteBackfillRequest)(nil), // 8: openmatch.DeleteBackfillRequest (*GetBackfillRequest)(nil), // 9: openmatch.GetBackfillRequest (*UpdateBackfillRequest)(nil), // 10: openmatch.UpdateBackfillRequest - (*Ticket)(nil), // 11: openmatch.Ticket - (*Assignment)(nil), // 12: openmatch.Assignment - (*Backfill)(nil), // 13: openmatch.Backfill - (*emptypb.Empty)(nil), // 14: google.protobuf.Empty + (*DeindexTicketRequest)(nil), // 11: openmatch.DeindexTicketRequest + (*DeindexTicketResponse)(nil), // 12: openmatch.DeindexTicketResponse + (*Ticket)(nil), // 13: openmatch.Ticket + (*Assignment)(nil), // 14: openmatch.Assignment + (*Backfill)(nil), // 15: openmatch.Backfill + (*emptypb.Empty)(nil), // 16: google.protobuf.Empty } var file_openmatch_frontend_proto_depIdxs = []int32{ - 11, // 0: openmatch.CreateTicketRequest.ticket:type_name -> openmatch.Ticket - 12, // 1: openmatch.WatchAssignmentsResponse.assignment:type_name -> openmatch.Assignment - 12, // 2: openmatch.AcknowledgeBackfillRequest.assignment:type_name -> openmatch.Assignment - 13, // 3: openmatch.AcknowledgeBackfillResponse.backfill:type_name -> openmatch.Backfill - 11, // 4: openmatch.AcknowledgeBackfillResponse.tickets:type_name -> openmatch.Ticket - 13, // 5: openmatch.CreateBackfillRequest.backfill:type_name -> openmatch.Backfill - 13, // 6: openmatch.UpdateBackfillRequest.backfill:type_name -> openmatch.Backfill + 13, // 0: openmatch.CreateTicketRequest.ticket:type_name -> openmatch.Ticket + 14, // 1: openmatch.WatchAssignmentsResponse.assignment:type_name -> openmatch.Assignment + 14, // 2: openmatch.AcknowledgeBackfillRequest.assignment:type_name -> openmatch.Assignment + 15, // 3: openmatch.AcknowledgeBackfillResponse.backfill:type_name -> openmatch.Backfill + 13, // 4: openmatch.AcknowledgeBackfillResponse.tickets:type_name -> openmatch.Ticket + 15, // 5: openmatch.CreateBackfillRequest.backfill:type_name -> openmatch.Backfill + 15, // 6: openmatch.UpdateBackfillRequest.backfill:type_name -> openmatch.Backfill 0, // 7: openmatch.FrontendService.CreateTicket:input_type -> openmatch.CreateTicketRequest 1, // 8: openmatch.FrontendService.DeleteTicket:input_type -> openmatch.DeleteTicketRequest 2, // 9: openmatch.FrontendService.GetTicket:input_type -> openmatch.GetTicketRequest @@ -717,17 +814,19 @@ var file_openmatch_frontend_proto_depIdxs = []int32{ 8, // 13: openmatch.FrontendService.DeleteBackfill:input_type -> openmatch.DeleteBackfillRequest 9, // 14: openmatch.FrontendService.GetBackfill:input_type -> openmatch.GetBackfillRequest 10, // 15: openmatch.FrontendService.UpdateBackfill:input_type -> openmatch.UpdateBackfillRequest - 11, // 16: openmatch.FrontendService.CreateTicket:output_type -> openmatch.Ticket - 14, // 17: openmatch.FrontendService.DeleteTicket:output_type -> google.protobuf.Empty - 11, // 18: openmatch.FrontendService.GetTicket:output_type -> openmatch.Ticket - 4, // 19: openmatch.FrontendService.WatchAssignments:output_type -> openmatch.WatchAssignmentsResponse - 6, // 20: openmatch.FrontendService.AcknowledgeBackfill:output_type -> openmatch.AcknowledgeBackfillResponse - 13, // 21: openmatch.FrontendService.CreateBackfill:output_type -> openmatch.Backfill - 14, // 22: openmatch.FrontendService.DeleteBackfill:output_type -> google.protobuf.Empty - 13, // 23: openmatch.FrontendService.GetBackfill:output_type -> openmatch.Backfill - 13, // 24: openmatch.FrontendService.UpdateBackfill:output_type -> openmatch.Backfill - 16, // [16:25] is the sub-list for method output_type - 7, // [7:16] is the sub-list for method input_type + 11, // 16: openmatch.FrontendService.DeindexTicket:input_type -> openmatch.DeindexTicketRequest + 13, // 17: openmatch.FrontendService.CreateTicket:output_type -> openmatch.Ticket + 16, // 18: openmatch.FrontendService.DeleteTicket:output_type -> google.protobuf.Empty + 13, // 19: openmatch.FrontendService.GetTicket:output_type -> openmatch.Ticket + 4, // 20: openmatch.FrontendService.WatchAssignments:output_type -> openmatch.WatchAssignmentsResponse + 6, // 21: openmatch.FrontendService.AcknowledgeBackfill:output_type -> openmatch.AcknowledgeBackfillResponse + 15, // 22: openmatch.FrontendService.CreateBackfill:output_type -> openmatch.Backfill + 16, // 23: openmatch.FrontendService.DeleteBackfill:output_type -> google.protobuf.Empty + 15, // 24: openmatch.FrontendService.GetBackfill:output_type -> openmatch.Backfill + 15, // 25: openmatch.FrontendService.UpdateBackfill:output_type -> openmatch.Backfill + 12, // 26: openmatch.FrontendService.DeindexTicket:output_type -> openmatch.DeindexTicketResponse + 17, // [17:27] is the sub-list for method output_type + 7, // [7:17] is the sub-list for method input_type 7, // [7:7] is the sub-list for extension type_name 7, // [7:7] is the sub-list for extension extendee 0, // [0:7] is the sub-list for field type_name @@ -872,6 +971,30 @@ func file_openmatch_frontend_proto_init() { return nil } } + file_openmatch_frontend_proto_msgTypes[11].Exporter = func(v any, i int) any { + switch v := v.(*DeindexTicketRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_openmatch_frontend_proto_msgTypes[12].Exporter = func(v any, i int) any { + switch v := v.(*DeindexTicketResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -879,7 +1002,7 @@ func file_openmatch_frontend_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_openmatch_frontend_proto_rawDesc, NumEnums: 0, - NumMessages: 11, + NumMessages: 13, NumExtensions: 0, NumServices: 1, }, diff --git a/gen/openmatch/openmatchconnect/frontend.connect.go b/gen/openmatch/openmatchconnect/frontend.connect.go index 38cec06..f207a19 100644 --- a/gen/openmatch/openmatchconnect/frontend.connect.go +++ b/gen/openmatch/openmatchconnect/frontend.connect.go @@ -61,6 +61,9 @@ const ( // FrontendServiceUpdateBackfillProcedure is the fully-qualified name of the FrontendService's // UpdateBackfill RPC. FrontendServiceUpdateBackfillProcedure = "/openmatch.FrontendService/UpdateBackfill" + // FrontendServiceDeindexTicketProcedure is the fully-qualified name of the FrontendService's + // DeindexTicket RPC. + FrontendServiceDeindexTicketProcedure = "/openmatch.FrontendService/DeindexTicket" ) // These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. @@ -75,6 +78,7 @@ var ( frontendServiceDeleteBackfillMethodDescriptor = frontendServiceServiceDescriptor.Methods().ByName("DeleteBackfill") frontendServiceGetBackfillMethodDescriptor = frontendServiceServiceDescriptor.Methods().ByName("GetBackfill") frontendServiceUpdateBackfillMethodDescriptor = frontendServiceServiceDescriptor.Methods().ByName("UpdateBackfill") + frontendServiceDeindexTicketMethodDescriptor = frontendServiceServiceDescriptor.Methods().ByName("DeindexTicket") ) // FrontendServiceClient is a client for the openmatch.FrontendService service. @@ -88,6 +92,10 @@ type FrontendServiceClient interface { DeleteBackfill(context.Context, *connect.Request[openmatch.DeleteBackfillRequest]) (*connect.Response[emptypb.Empty], error) GetBackfill(context.Context, *connect.Request[openmatch.GetBackfillRequest]) (*connect.Response[openmatch.Backfill], error) UpdateBackfill(context.Context, *connect.Request[openmatch.UpdateBackfillRequest]) (*connect.Response[openmatch.Backfill], error) + // DeindexTickets removes the ticket from the matching candidates; + // unlike DeleteTicket, it does not delete the ticket body; + // you can still get the Assignment with GetTicket after Deindex. + DeindexTicket(context.Context, *connect.Request[openmatch.DeindexTicketRequest]) (*connect.Response[openmatch.DeindexTicketResponse], error) } // NewFrontendServiceClient constructs a client for the openmatch.FrontendService service. By @@ -154,6 +162,12 @@ func NewFrontendServiceClient(httpClient connect.HTTPClient, baseURL string, opt connect.WithSchema(frontendServiceUpdateBackfillMethodDescriptor), connect.WithClientOptions(opts...), ), + deindexTicket: connect.NewClient[openmatch.DeindexTicketRequest, openmatch.DeindexTicketResponse]( + httpClient, + baseURL+FrontendServiceDeindexTicketProcedure, + connect.WithSchema(frontendServiceDeindexTicketMethodDescriptor), + connect.WithClientOptions(opts...), + ), } } @@ -168,6 +182,7 @@ type frontendServiceClient struct { deleteBackfill *connect.Client[openmatch.DeleteBackfillRequest, emptypb.Empty] getBackfill *connect.Client[openmatch.GetBackfillRequest, openmatch.Backfill] updateBackfill *connect.Client[openmatch.UpdateBackfillRequest, openmatch.Backfill] + deindexTicket *connect.Client[openmatch.DeindexTicketRequest, openmatch.DeindexTicketResponse] } // CreateTicket calls openmatch.FrontendService.CreateTicket. @@ -215,6 +230,11 @@ func (c *frontendServiceClient) UpdateBackfill(ctx context.Context, req *connect return c.updateBackfill.CallUnary(ctx, req) } +// DeindexTicket calls openmatch.FrontendService.DeindexTicket. +func (c *frontendServiceClient) DeindexTicket(ctx context.Context, req *connect.Request[openmatch.DeindexTicketRequest]) (*connect.Response[openmatch.DeindexTicketResponse], error) { + return c.deindexTicket.CallUnary(ctx, req) +} + // FrontendServiceHandler is an implementation of the openmatch.FrontendService service. type FrontendServiceHandler interface { CreateTicket(context.Context, *connect.Request[openmatch.CreateTicketRequest]) (*connect.Response[openmatch.Ticket], error) @@ -226,6 +246,10 @@ type FrontendServiceHandler interface { DeleteBackfill(context.Context, *connect.Request[openmatch.DeleteBackfillRequest]) (*connect.Response[emptypb.Empty], error) GetBackfill(context.Context, *connect.Request[openmatch.GetBackfillRequest]) (*connect.Response[openmatch.Backfill], error) UpdateBackfill(context.Context, *connect.Request[openmatch.UpdateBackfillRequest]) (*connect.Response[openmatch.Backfill], error) + // DeindexTickets removes the ticket from the matching candidates; + // unlike DeleteTicket, it does not delete the ticket body; + // you can still get the Assignment with GetTicket after Deindex. + DeindexTicket(context.Context, *connect.Request[openmatch.DeindexTicketRequest]) (*connect.Response[openmatch.DeindexTicketResponse], error) } // NewFrontendServiceHandler builds an HTTP handler from the service implementation. It returns the @@ -288,6 +312,12 @@ func NewFrontendServiceHandler(svc FrontendServiceHandler, opts ...connect.Handl connect.WithSchema(frontendServiceUpdateBackfillMethodDescriptor), connect.WithHandlerOptions(opts...), ) + frontendServiceDeindexTicketHandler := connect.NewUnaryHandler( + FrontendServiceDeindexTicketProcedure, + svc.DeindexTicket, + connect.WithSchema(frontendServiceDeindexTicketMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) return "/openmatch.FrontendService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { case FrontendServiceCreateTicketProcedure: @@ -308,6 +338,8 @@ func NewFrontendServiceHandler(svc FrontendServiceHandler, opts ...connect.Handl frontendServiceGetBackfillHandler.ServeHTTP(w, r) case FrontendServiceUpdateBackfillProcedure: frontendServiceUpdateBackfillHandler.ServeHTTP(w, r) + case FrontendServiceDeindexTicketProcedure: + frontendServiceDeindexTicketHandler.ServeHTTP(w, r) default: http.NotFound(w, r) } @@ -352,3 +384,7 @@ func (UnimplementedFrontendServiceHandler) GetBackfill(context.Context, *connect func (UnimplementedFrontendServiceHandler) UpdateBackfill(context.Context, *connect.Request[openmatch.UpdateBackfillRequest]) (*connect.Response[openmatch.Backfill], error) { return nil, connect.NewError(connect.CodeUnimplemented, errors.New("openmatch.FrontendService.UpdateBackfill is not implemented")) } + +func (UnimplementedFrontendServiceHandler) DeindexTicket(context.Context, *connect.Request[openmatch.DeindexTicketRequest]) (*connect.Response[openmatch.DeindexTicketResponse], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("openmatch.FrontendService.DeindexTicket is not implemented")) +} diff --git a/pkg/statestore/frontend.go b/pkg/statestore/frontend.go index fccb194..010eec4 100644 --- a/pkg/statestore/frontend.go +++ b/pkg/statestore/frontend.go @@ -12,4 +12,5 @@ type FrontendStore interface { DeleteTicket(ctx context.Context, ticketID string) error GetTicket(ctx context.Context, ticketID string) (*pb.Ticket, error) GetAssignment(ctx context.Context, ticketID string) (*pb.Assignment, error) + DeindexTicket(ctx context.Context, ticketID string) error } diff --git a/pkg/statestore/redis.go b/pkg/statestore/redis.go index 6543f2a..404feb1 100644 --- a/pkg/statestore/redis.go +++ b/pkg/statestore/redis.go @@ -325,6 +325,10 @@ func (s *RedisStore) GetTicketCount(ctx context.Context) (int64, error) { return count, nil } +func (s *RedisStore) DeindexTicket(ctx context.Context, ticketID string) error { + return s.deIndexTickets(ctx, []string{ticketID}) +} + func (s *RedisStore) getTicket(ctx context.Context, client rueidis.Client, ticketID string) (*pb.Ticket, error) { resp := client.Do(ctx, client.B().Get().Key(redisKeyTicketData(s.opts.keyPrefix, ticketID)).Build()) if err := resp.Error(); err != nil { diff --git a/pkg/statestore/redis_test.go b/pkg/statestore/redis_test.go index e7a256c..72358af 100644 --- a/pkg/statestore/redis_test.go +++ b/pkg/statestore/redis_test.go @@ -306,6 +306,60 @@ func TestReadReplica(t *testing.T) { require.Equal(t, "replica", t2.SearchFields.Tags[0]) } +func TestDeindexTicket(t *testing.T) { + mr := miniredis.RunT(t) + ticketTTL := 5 * time.Second + store := newTestRedisStore(t, mr.Addr()) + ctx := context.Background() + + mustCreateTicket := func(id string) { + require.NoError(t, store.CreateTicket(ctx, &pb.Ticket{Id: id}, ticketTTL)) + ticket, err := store.GetTicket(ctx, id) + require.NoError(t, err) + require.Equal(t, id, ticket.Id) + } + + mustCreateTicket("t1") + mustCreateTicket("t2") + + activeTicketIDs, err := store.GetActiveTicketIDs(ctx, defaultGetTicketLimit) + require.NoError(t, err) + require.ElementsMatch(t, []string{"t1", "t2"}, activeTicketIDs) + + t1, err := store.GetTicket(ctx, "t1") + require.NoError(t, err) + require.Equal(t, "t1", t1.Id) + t2, err := store.GetTicket(ctx, "t2") + require.NoError(t, err) + require.Equal(t, "t2", t2.Id) + + err = store.ReleaseTickets(ctx, activeTicketIDs) + require.NoError(t, err) + + err = store.DeindexTicket(ctx, "t1") + require.NoError(t, err) + + activeTicketIDs, err = store.GetActiveTicketIDs(ctx, defaultGetTicketLimit) + require.NoError(t, err) + require.ElementsMatch(t, []string{"t2"}, activeTicketIDs) + + t1, err = store.GetTicket(ctx, "t1") + require.NoError(t, err) + require.Equal(t, "t1", t1.Id) + t2, err = store.GetTicket(ctx, "t2") + require.NoError(t, err) + require.Equal(t, "t2", t2.Id) + + err = store.ReleaseTickets(ctx, activeTicketIDs) + require.NoError(t, err) + + err = store.DeleteTicket(ctx, "t1") + require.NoError(t, err) + + _, err = store.GetTicket(ctx, "t1") + require.ErrorIs(t, err, ErrTicketNotFound) +} + // https://stackoverflow.com/a/72408490 func chunkBy[T any](items []T, chunkSize int) (chunks [][]T) { for chunkSize < len(items) { diff --git a/pkg/statestore/ticketcache.go b/pkg/statestore/ticketcache.go index c8328e5..6b54611 100644 --- a/pkg/statestore/ticketcache.go +++ b/pkg/statestore/ticketcache.go @@ -81,6 +81,10 @@ func (s *FrontendStoreWithTicketCache) GetAssignment(ctx context.Context, ticket return s.origin.GetAssignment(ctx, ticketID) } +func (s *FrontendStoreWithTicketCache) DeindexTicket(ctx context.Context, ticketID string) error { + return s.origin.DeindexTicket(ctx, ticketID) +} + // BackendStoreWithTicketCache caches GetTickets results in-memory with TTL type BackendStoreWithTicketCache struct { origin BackendStore