From f7d2e19ba443ab5ac5638a57e74d4989442e2f04 Mon Sep 17 00:00:00 2001 From: Youngteac Hong Date: Wed, 16 Oct 2024 16:49:16 +0900 Subject: [PATCH] Add gateway flag to server command --- api/docs/yorkie/v1/system.openapi.yaml | 24 ++-- api/yorkie/v1/system.pb.go | 104 +++++++++--------- api/yorkie/v1/system.proto | 6 +- api/yorkie/v1/v1connect/system.connect.go | 12 +- cmd/yorkie/server.go | 6 + pkg/document/internal_document.go | 12 ++ server/backend/config.go | 3 + .../backend/database/testcases/testcases.go | 50 --------- server/clients/clients.go | 25 +++-- server/clients/housekeeping.go | 12 +- server/config.go | 3 +- server/config.sample.yml | 3 + server/documents/documents.go | 8 +- server/packs/packs.go | 23 +++- server/packs/pushpull.go | 2 +- server/rpc/system_server.go | 14 +-- server/rpc/yorkie_server.go | 2 +- server/server.go | 2 +- system/client.go | 2 +- test/helper/helper.go | 1 + test/integration/housekeeping_test.go | 5 +- 21 files changed, 155 insertions(+), 164 deletions(-) diff --git a/api/docs/yorkie/v1/system.openapi.yaml b/api/docs/yorkie/v1/system.openapi.yaml index 6f3b92d2f..67c21694d 100644 --- a/api/docs/yorkie/v1/system.openapi.yaml +++ b/api/docs/yorkie/v1/system.openapi.yaml @@ -14,24 +14,24 @@ paths: post: description: "" requestBody: - $ref: '#/components/requestBodies/yorkie.v1.SystemService.DetachDocument.yorkie.v1.DetachDocumentRequestBySystem' + $ref: '#/components/requestBodies/yorkie.v1.SystemService.DetachDocument.yorkie.v1.SystemServiceDetachDocumentRequest' responses: "200": - $ref: '#/components/responses/yorkie.v1.SystemService.DetachDocument.yorkie.v1.DetachDocumentResponseBySystem' + $ref: '#/components/responses/yorkie.v1.SystemService.DetachDocument.yorkie.v1.SystemServiceDetachDocumentResponse' default: $ref: '#/components/responses/connect.error' tags: - yorkie.v1.SystemService components: requestBodies: - yorkie.v1.SystemService.DetachDocument.yorkie.v1.DetachDocumentRequestBySystem: + yorkie.v1.SystemService.DetachDocument.yorkie.v1.SystemServiceDetachDocumentRequest: content: application/json: schema: - $ref: '#/components/schemas/yorkie.v1.DetachDocumentRequestBySystem' + $ref: '#/components/schemas/yorkie.v1.SystemServiceDetachDocumentRequest' application/proto: schema: - $ref: '#/components/schemas/yorkie.v1.DetachDocumentRequestBySystem' + $ref: '#/components/schemas/yorkie.v1.SystemServiceDetachDocumentRequest' required: true responses: connect.error: @@ -43,14 +43,14 @@ components: schema: $ref: '#/components/schemas/connect.error' description: "" - yorkie.v1.SystemService.DetachDocument.yorkie.v1.DetachDocumentResponseBySystem: + yorkie.v1.SystemService.DetachDocument.yorkie.v1.SystemServiceDetachDocumentResponse: content: application/json: schema: - $ref: '#/components/schemas/yorkie.v1.DetachDocumentResponseBySystem' + $ref: '#/components/schemas/yorkie.v1.SystemServiceDetachDocumentResponse' application/proto: schema: - $ref: '#/components/schemas/yorkie.v1.DetachDocumentResponseBySystem' + $ref: '#/components/schemas/yorkie.v1.SystemServiceDetachDocumentResponse' description: "" schemas: connect.error: @@ -81,7 +81,7 @@ components: type: string title: Connect Error type: object - yorkie.v1.DetachDocumentRequestBySystem: + yorkie.v1.SystemServiceDetachDocumentRequest: additionalProperties: false description: "" properties: @@ -106,12 +106,12 @@ components: types.Client, types.DocumentSummary' title: project_id type: string - title: DetachDocumentRequestBySystem + title: SystemServiceDetachDocumentRequest type: object - yorkie.v1.DetachDocumentResponseBySystem: + yorkie.v1.SystemServiceDetachDocumentResponse: additionalProperties: false description: "" - title: DetachDocumentResponseBySystem + title: SystemServiceDetachDocumentResponse type: object securitySchemes: ApiKeyAuth: diff --git a/api/yorkie/v1/system.pb.go b/api/yorkie/v1/system.pb.go index a99485a94..6106f5200 100644 --- a/api/yorkie/v1/system.pb.go +++ b/api/yorkie/v1/system.pb.go @@ -35,7 +35,7 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -type DetachDocumentRequestBySystem struct { +type SystemServiceDetachDocumentRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -47,8 +47,8 @@ type DetachDocumentRequestBySystem struct { DocumentKey string `protobuf:"bytes,4,opt,name=document_key,json=documentKey,proto3" json:"document_key,omitempty"` } -func (x *DetachDocumentRequestBySystem) Reset() { - *x = DetachDocumentRequestBySystem{} +func (x *SystemServiceDetachDocumentRequest) Reset() { + *x = SystemServiceDetachDocumentRequest{} if protoimpl.UnsafeEnabled { mi := &file_yorkie_v1_system_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -56,13 +56,13 @@ func (x *DetachDocumentRequestBySystem) Reset() { } } -func (x *DetachDocumentRequestBySystem) String() string { +func (x *SystemServiceDetachDocumentRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*DetachDocumentRequestBySystem) ProtoMessage() {} +func (*SystemServiceDetachDocumentRequest) ProtoMessage() {} -func (x *DetachDocumentRequestBySystem) ProtoReflect() protoreflect.Message { +func (x *SystemServiceDetachDocumentRequest) ProtoReflect() protoreflect.Message { mi := &file_yorkie_v1_system_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -74,47 +74,47 @@ func (x *DetachDocumentRequestBySystem) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use DetachDocumentRequestBySystem.ProtoReflect.Descriptor instead. -func (*DetachDocumentRequestBySystem) Descriptor() ([]byte, []int) { +// Deprecated: Use SystemServiceDetachDocumentRequest.ProtoReflect.Descriptor instead. +func (*SystemServiceDetachDocumentRequest) Descriptor() ([]byte, []int) { return file_yorkie_v1_system_proto_rawDescGZIP(), []int{0} } -func (x *DetachDocumentRequestBySystem) GetProjectId() string { +func (x *SystemServiceDetachDocumentRequest) GetProjectId() string { if x != nil { return x.ProjectId } return "" } -func (x *DetachDocumentRequestBySystem) GetClientId() string { +func (x *SystemServiceDetachDocumentRequest) GetClientId() string { if x != nil { return x.ClientId } return "" } -func (x *DetachDocumentRequestBySystem) GetDocumentId() string { +func (x *SystemServiceDetachDocumentRequest) GetDocumentId() string { if x != nil { return x.DocumentId } return "" } -func (x *DetachDocumentRequestBySystem) GetDocumentKey() string { +func (x *SystemServiceDetachDocumentRequest) GetDocumentKey() string { if x != nil { return x.DocumentKey } return "" } -type DetachDocumentResponseBySystem struct { +type SystemServiceDetachDocumentResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields } -func (x *DetachDocumentResponseBySystem) Reset() { - *x = DetachDocumentResponseBySystem{} +func (x *SystemServiceDetachDocumentResponse) Reset() { + *x = SystemServiceDetachDocumentResponse{} if protoimpl.UnsafeEnabled { mi := &file_yorkie_v1_system_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -122,13 +122,13 @@ func (x *DetachDocumentResponseBySystem) Reset() { } } -func (x *DetachDocumentResponseBySystem) String() string { +func (x *SystemServiceDetachDocumentResponse) String() string { return protoimpl.X.MessageStringOf(x) } -func (*DetachDocumentResponseBySystem) ProtoMessage() {} +func (*SystemServiceDetachDocumentResponse) ProtoMessage() {} -func (x *DetachDocumentResponseBySystem) ProtoReflect() protoreflect.Message { +func (x *SystemServiceDetachDocumentResponse) ProtoReflect() protoreflect.Message { mi := &file_yorkie_v1_system_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -140,8 +140,8 @@ func (x *DetachDocumentResponseBySystem) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use DetachDocumentResponseBySystem.ProtoReflect.Descriptor instead. -func (*DetachDocumentResponseBySystem) Descriptor() ([]byte, []int) { +// Deprecated: Use SystemServiceDetachDocumentResponse.ProtoReflect.Descriptor instead. +func (*SystemServiceDetachDocumentResponse) Descriptor() ([]byte, []int) { return file_yorkie_v1_system_proto_rawDescGZIP(), []int{1} } @@ -150,31 +150,33 @@ var File_yorkie_v1_system_proto protoreflect.FileDescriptor var file_yorkie_v1_system_proto_rawDesc = []byte{ 0x0a, 0x16, 0x79, 0x6f, 0x72, 0x6b, 0x69, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x79, 0x6f, 0x72, 0x6b, 0x69, 0x65, - 0x2e, 0x76, 0x31, 0x22, 0x9f, 0x01, 0x0a, 0x1d, 0x44, 0x65, 0x74, 0x61, 0x63, 0x68, 0x44, 0x6f, - 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x42, 0x79, 0x53, - 0x79, 0x73, 0x74, 0x65, 0x6d, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, - 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x6a, 0x65, - 0x63, 0x74, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x69, - 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, - 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, - 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x6b, - 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, - 0x6e, 0x74, 0x4b, 0x65, 0x79, 0x22, 0x20, 0x0a, 0x1e, 0x44, 0x65, 0x74, 0x61, 0x63, 0x68, 0x44, - 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, - 0x79, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x32, 0x78, 0x0a, 0x0d, 0x53, 0x79, 0x73, 0x74, 0x65, - 0x6d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x67, 0x0a, 0x0e, 0x44, 0x65, 0x74, 0x61, - 0x63, 0x68, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x28, 0x2e, 0x79, 0x6f, 0x72, - 0x6b, 0x69, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x74, 0x61, 0x63, 0x68, 0x44, 0x6f, 0x63, - 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x42, 0x79, 0x53, 0x79, - 0x73, 0x74, 0x65, 0x6d, 0x1a, 0x29, 0x2e, 0x79, 0x6f, 0x72, 0x6b, 0x69, 0x65, 0x2e, 0x76, 0x31, - 0x2e, 0x44, 0x65, 0x74, 0x61, 0x63, 0x68, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x79, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x22, - 0x00, 0x42, 0x45, 0x0a, 0x11, 0x64, 0x65, 0x76, 0x2e, 0x79, 0x6f, 0x72, 0x6b, 0x69, 0x65, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x50, 0x01, 0x5a, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x79, 0x6f, 0x72, 0x6b, 0x69, 0x65, 0x2d, 0x74, 0x65, 0x61, 0x6d, - 0x2f, 0x79, 0x6f, 0x72, 0x6b, 0x69, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x79, 0x6f, 0x72, 0x6b, - 0x69, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x2e, 0x76, 0x31, 0x22, 0xa4, 0x01, 0x0a, 0x22, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x74, 0x61, 0x63, 0x68, 0x44, 0x6f, 0x63, 0x75, 0x6d, + 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x72, + 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, + 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x6c, 0x69, + 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x6c, + 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, + 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x64, 0x6f, 0x63, + 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, 0x64, 0x6f, 0x63, 0x75, 0x6d, + 0x65, 0x6e, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, + 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x4b, 0x65, 0x79, 0x22, 0x25, 0x0a, 0x23, 0x53, 0x79, + 0x73, 0x74, 0x65, 0x6d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x74, 0x61, 0x63, + 0x68, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x32, 0x82, 0x01, 0x0a, 0x0d, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x71, 0x0a, 0x0e, 0x44, 0x65, 0x74, 0x61, 0x63, 0x68, 0x44, 0x6f, 0x63, + 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x2d, 0x2e, 0x79, 0x6f, 0x72, 0x6b, 0x69, 0x65, 0x2e, 0x76, + 0x31, 0x2e, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, + 0x65, 0x74, 0x61, 0x63, 0x68, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2e, 0x2e, 0x79, 0x6f, 0x72, 0x6b, 0x69, 0x65, 0x2e, 0x76, 0x31, + 0x2e, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, + 0x74, 0x61, 0x63, 0x68, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x45, 0x0a, 0x11, 0x64, 0x65, 0x76, 0x2e, 0x79, 0x6f, + 0x72, 0x6b, 0x69, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x50, 0x01, 0x5a, 0x2e, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x79, 0x6f, 0x72, 0x6b, 0x69, 0x65, + 0x2d, 0x74, 0x65, 0x61, 0x6d, 0x2f, 0x79, 0x6f, 0x72, 0x6b, 0x69, 0x65, 0x2f, 0x61, 0x70, 0x69, + 0x2f, 0x79, 0x6f, 0x72, 0x6b, 0x69, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -191,12 +193,12 @@ func file_yorkie_v1_system_proto_rawDescGZIP() []byte { var file_yorkie_v1_system_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_yorkie_v1_system_proto_goTypes = []interface{}{ - (*DetachDocumentRequestBySystem)(nil), // 0: yorkie.v1.DetachDocumentRequestBySystem - (*DetachDocumentResponseBySystem)(nil), // 1: yorkie.v1.DetachDocumentResponseBySystem + (*SystemServiceDetachDocumentRequest)(nil), // 0: yorkie.v1.SystemServiceDetachDocumentRequest + (*SystemServiceDetachDocumentResponse)(nil), // 1: yorkie.v1.SystemServiceDetachDocumentResponse } var file_yorkie_v1_system_proto_depIdxs = []int32{ - 0, // 0: yorkie.v1.SystemService.DetachDocument:input_type -> yorkie.v1.DetachDocumentRequestBySystem - 1, // 1: yorkie.v1.SystemService.DetachDocument:output_type -> yorkie.v1.DetachDocumentResponseBySystem + 0, // 0: yorkie.v1.SystemService.DetachDocument:input_type -> yorkie.v1.SystemServiceDetachDocumentRequest + 1, // 1: yorkie.v1.SystemService.DetachDocument:output_type -> yorkie.v1.SystemServiceDetachDocumentResponse 1, // [1:2] is the sub-list for method output_type 0, // [0:1] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name @@ -211,7 +213,7 @@ func file_yorkie_v1_system_proto_init() { } if !protoimpl.UnsafeEnabled { file_yorkie_v1_system_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DetachDocumentRequestBySystem); i { + switch v := v.(*SystemServiceDetachDocumentRequest); i { case 0: return &v.state case 1: @@ -223,7 +225,7 @@ func file_yorkie_v1_system_proto_init() { } } file_yorkie_v1_system_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DetachDocumentResponseBySystem); i { + switch v := v.(*SystemServiceDetachDocumentResponse); i { case 0: return &v.state case 1: diff --git a/api/yorkie/v1/system.proto b/api/yorkie/v1/system.proto index c9cafc0ec..70ef8b989 100644 --- a/api/yorkie/v1/system.proto +++ b/api/yorkie/v1/system.proto @@ -24,10 +24,10 @@ option java_package = "dev.yorkie.api.v1"; // System is a service that provides an API for Cluster. service SystemService { - rpc DetachDocument (DetachDocumentRequestBySystem) returns (DetachDocumentResponseBySystem) {} + rpc DetachDocument (SystemServiceDetachDocumentRequest) returns (SystemServiceDetachDocumentResponse) {} } -message DetachDocumentRequestBySystem { +message SystemServiceDetachDocumentRequest { // TODO(hackerwins): Consider to replace this fields with types.Project, types.Client, types.DocumentSummary string project_id = 1; string client_id = 2; @@ -35,4 +35,4 @@ message DetachDocumentRequestBySystem { string document_key = 4; } -message DetachDocumentResponseBySystem {} \ No newline at end of file +message SystemServiceDetachDocumentResponse {} \ No newline at end of file diff --git a/api/yorkie/v1/v1connect/system.connect.go b/api/yorkie/v1/v1connect/system.connect.go index d633829f2..e8557036e 100644 --- a/api/yorkie/v1/v1connect/system.connect.go +++ b/api/yorkie/v1/v1connect/system.connect.go @@ -55,7 +55,7 @@ const ( // SystemServiceClient is a client for the yorkie.v1.SystemService service. type SystemServiceClient interface { - DetachDocument(context.Context, *connect.Request[v1.DetachDocumentRequestBySystem]) (*connect.Response[v1.DetachDocumentResponseBySystem], error) + DetachDocument(context.Context, *connect.Request[v1.SystemServiceDetachDocumentRequest]) (*connect.Response[v1.SystemServiceDetachDocumentResponse], error) } // NewSystemServiceClient constructs a client for the yorkie.v1.SystemService service. By default, @@ -68,7 +68,7 @@ type SystemServiceClient interface { func NewSystemServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) SystemServiceClient { baseURL = strings.TrimRight(baseURL, "/") return &systemServiceClient{ - detachDocument: connect.NewClient[v1.DetachDocumentRequestBySystem, v1.DetachDocumentResponseBySystem]( + detachDocument: connect.NewClient[v1.SystemServiceDetachDocumentRequest, v1.SystemServiceDetachDocumentResponse]( httpClient, baseURL+SystemServiceDetachDocumentProcedure, opts..., @@ -78,17 +78,17 @@ func NewSystemServiceClient(httpClient connect.HTTPClient, baseURL string, opts // systemServiceClient implements SystemServiceClient. type systemServiceClient struct { - detachDocument *connect.Client[v1.DetachDocumentRequestBySystem, v1.DetachDocumentResponseBySystem] + detachDocument *connect.Client[v1.SystemServiceDetachDocumentRequest, v1.SystemServiceDetachDocumentResponse] } // DetachDocument calls yorkie.v1.SystemService.DetachDocument. -func (c *systemServiceClient) DetachDocument(ctx context.Context, req *connect.Request[v1.DetachDocumentRequestBySystem]) (*connect.Response[v1.DetachDocumentResponseBySystem], error) { +func (c *systemServiceClient) DetachDocument(ctx context.Context, req *connect.Request[v1.SystemServiceDetachDocumentRequest]) (*connect.Response[v1.SystemServiceDetachDocumentResponse], error) { return c.detachDocument.CallUnary(ctx, req) } // SystemServiceHandler is an implementation of the yorkie.v1.SystemService service. type SystemServiceHandler interface { - DetachDocument(context.Context, *connect.Request[v1.DetachDocumentRequestBySystem]) (*connect.Response[v1.DetachDocumentResponseBySystem], error) + DetachDocument(context.Context, *connect.Request[v1.SystemServiceDetachDocumentRequest]) (*connect.Response[v1.SystemServiceDetachDocumentResponse], error) } // NewSystemServiceHandler builds an HTTP handler from the service implementation. It returns the @@ -115,6 +115,6 @@ func NewSystemServiceHandler(svc SystemServiceHandler, opts ...connect.HandlerOp // UnimplementedSystemServiceHandler returns CodeUnimplemented from all methods. type UnimplementedSystemServiceHandler struct{} -func (UnimplementedSystemServiceHandler) DetachDocument(context.Context, *connect.Request[v1.DetachDocumentRequestBySystem]) (*connect.Response[v1.DetachDocumentResponseBySystem], error) { +func (UnimplementedSystemServiceHandler) DetachDocument(context.Context, *connect.Request[v1.SystemServiceDetachDocumentRequest]) (*connect.Response[v1.SystemServiceDetachDocumentResponse], error) { return nil, connect.NewError(connect.CodeUnimplemented, errors.New("yorkie.v1.SystemService.DetachDocument is not implemented")) } diff --git a/cmd/yorkie/server.go b/cmd/yorkie/server.go index cca3b91d5..54ea63094 100644 --- a/cmd/yorkie/server.go +++ b/cmd/yorkie/server.go @@ -345,6 +345,12 @@ func init() { server.DefaultHostname, "Yorkie Server Hostname", ) + cmd.Flags().StringVar( + &conf.Backend.GatewayAddr, + "backend-gateway-addr", + server.DefaultGatewayAddr, + "Gateway address", + ) rootCmd.AddCommand(cmd) } diff --git a/pkg/document/internal_document.go b/pkg/document/internal_document.go index 66f4cdca1..296b5e642 100644 --- a/pkg/document/internal_document.go +++ b/pkg/document/internal_document.go @@ -136,6 +136,18 @@ func (d *InternalDocument) Checkpoint() change.Checkpoint { return d.checkpoint } +// SyncCheckpoint syncs the checkpoint and the changeID with the given serverSeq +// and clientSeq. +func (d *InternalDocument) SyncCheckpoint(serverSeq int64, clientSeq uint32) { + d.changeID = change.NewID( + clientSeq, + serverSeq, + d.changeID.Lamport(), + d.changeID.ActorID(), + ) + d.checkpoint = d.checkpoint.SyncClientSeq(clientSeq) +} + // HasLocalChanges returns whether this document has local changes or not. func (d *InternalDocument) HasLocalChanges() bool { return len(d.localChanges) > 0 diff --git a/server/backend/config.go b/server/backend/config.go index 38d87b2d3..8b5cbc511 100644 --- a/server/backend/config.go +++ b/server/backend/config.go @@ -81,6 +81,9 @@ type Config struct { // Hostname is yorkie server hostname. hostname is used by metrics. Hostname string `yaml:"Hostname"` + + // GatewayAddr is the address of the gateway server. + GatewayAddr string `yaml:"GatewayAddr"` } // Validate validates this config. diff --git a/server/backend/database/testcases/testcases.go b/server/backend/database/testcases/testcases.go index 2108f8c83..839bbc43f 100644 --- a/server/backend/database/testcases/testcases.go +++ b/server/backend/database/testcases/testcases.go @@ -676,56 +676,6 @@ func RunActivateClientDeactivateClientTest(t *testing.T, db database.Database, p assert.Equal(t, t.Name(), clientInfo.Key) assert.Equal(t, database.ClientDeactivated, clientInfo.Status) }) - - t.Run("ensure document detached when deactivate client test", func(t *testing.T) { - ctx := context.Background() - - // 01. Create a client - clientInfo, err := db.ActivateClient(ctx, projectID, t.Name()) - assert.NoError(t, err) - assert.Equal(t, t.Name(), clientInfo.Key) - assert.Equal(t, database.ClientActivated, clientInfo.Status) - - // 02. Create documents and attach them to the client - for i := 0; i < 3; i++ { - docInfo, _ := db.FindDocInfoByKeyAndOwner(ctx, clientInfo.RefKey(), helper.TestDocKey(t, i), true) - assert.NoError(t, clientInfo.AttachDocument(docInfo.ID, false)) - clientInfo.Documents[docInfo.ID].ServerSeq = 1 - clientInfo.Documents[docInfo.ID].ClientSeq = 1 - assert.NoError(t, db.UpdateClientInfoAfterPushPull(ctx, clientInfo, docInfo)) - - result, err := db.FindClientInfoByRefKey(ctx, clientInfo.RefKey()) - assert.Equal(t, result.Documents[docInfo.ID].Status, database.DocumentAttached) - assert.Equal(t, result.Documents[docInfo.ID].ServerSeq, int64(1)) - assert.Equal(t, result.Documents[docInfo.ID].ClientSeq, uint32(1)) - assert.NoError(t, err) - } - - // 03. Remove one document - docInfo, err := db.FindDocInfoByKeyAndOwner(ctx, clientInfo.RefKey(), helper.TestDocKey(t, 2), true) - assert.NoError(t, err) - assert.NoError(t, clientInfo.RemoveDocument(docInfo.ID)) - assert.NoError(t, db.UpdateClientInfoAfterPushPull(ctx, clientInfo, docInfo)) - - // 04. Deactivate the client - result, err := db.DeactivateClient(ctx, types.ClientRefKey{ - ProjectID: projectID, - ClientID: clientInfo.ID, - }) - assert.NoError(t, err) - - // 05. Check whether doc.Status is reflected properly. - // If it was `DocumentAttached`, it should be changed to `DocumentDetached`. - for i := 0; i < 2; i++ { - docInfo, err := db.FindDocInfoByKeyAndOwner(ctx, clientInfo.RefKey(), helper.TestDocKey(t, i), true) - assert.NoError(t, err) - assert.Equal(t, result.Documents[docInfo.ID].Status, database.DocumentDetached) - } - // If it was `DocumentRemoved`, it should be remained `DocumentRemoved`. - docInfo, err = db.FindDocInfoByKeyAndOwner(ctx, clientInfo.RefKey(), helper.TestDocKey(t, 2), true) - assert.NoError(t, err) - assert.Equal(t, result.Documents[docInfo.ID].Status, database.DocumentRemoved) - }) } // RunUpdateProjectInfoTest runs the UpdateProjectInfo tests for the given db. diff --git a/server/clients/clients.go b/server/clients/clients.go index 0721c4e9c..045a7a21a 100644 --- a/server/clients/clients.go +++ b/server/clients/clients.go @@ -14,7 +14,7 @@ * limitations under the License. */ -// Package clients provides the client related business logic. +// Package clients provides the Client related business logic. package clients import ( @@ -22,19 +22,20 @@ import ( "errors" "github.com/yorkie-team/yorkie/api/types" + "github.com/yorkie-team/yorkie/server/backend" "github.com/yorkie-team/yorkie/server/backend/database" "github.com/yorkie-team/yorkie/system" ) var ( // ErrInvalidClientKey is returned when the given Key is not valid ClientKey. - ErrInvalidClientKey = errors.New("invalid client key") + ErrInvalidClientKey = errors.New("invalid Client key") // ErrInvalidClientID is returned when the given Key is not valid ClientID. - ErrInvalidClientID = errors.New("invalid client id") + ErrInvalidClientID = errors.New("invalid Client id") ) -// Activate activates the given client. +// Activate activates the given Client. func Activate( ctx context.Context, db database.Database, @@ -44,23 +45,23 @@ func Activate( return db.ActivateClient(ctx, project.ID, clientKey) } -// Deactivate deactivates the given client. +// Deactivate deactivates the given Client. func Deactivate( ctx context.Context, - db database.Database, + be *backend.Backend, project *types.Project, refKey types.ClientRefKey, ) (*database.ClientInfo, error) { - info, err := FindActiveClientInfo(ctx, db, refKey) + info, err := FindActiveClientInfo(ctx, be.DB, refKey) if err != nil { return nil, err } - // TODO(hackerwins): Inject gatewayAddr - systemClient, err := system.Dial("localhost:8080") + systemClient, err := system.Dial(be.Config.GatewayAddr, system.WithInsecure(true)) if err != nil { return nil, err } + defer systemClient.Close() for docID, clientDocInfo := range info.Documents { // TODO(hackerwins): Solve N+1 @@ -68,7 +69,7 @@ func Deactivate( continue } - docInfo, err := db.FindDocInfoByRefKey(ctx, types.DocRefKey{ + docInfo, err := be.DB.FindDocInfoByRefKey(ctx, types.DocRefKey{ ProjectID: project.ID, DocID: docID, }) @@ -86,7 +87,7 @@ func Deactivate( } } - info, err = db.DeactivateClient(ctx, refKey) + info, err = be.DB.DeactivateClient(ctx, refKey) if err != nil { return nil, err } @@ -94,7 +95,7 @@ func Deactivate( return info, err } -// FindActiveClientInfo find the active client info by the given ref key. +// FindActiveClientInfo find the active Client info by the given ref key. func FindActiveClientInfo( ctx context.Context, db database.Database, diff --git a/server/clients/housekeeping.go b/server/clients/housekeeping.go index ed1b00254..57a632ec7 100644 --- a/server/clients/housekeeping.go +++ b/server/clients/housekeeping.go @@ -69,7 +69,7 @@ func DeactivateInactives( deactivatedCount := 0 for _, pair := range candidates { - if _, err := Deactivate(ctx, be.DB, pair.project.ToProject(), pair.client.RefKey()); err != nil { + if _, err := Deactivate(ctx, be, pair.Project.ToProject(), pair.Client.RefKey()); err != nil { return database.DefaultProjectID, err } @@ -88,10 +88,10 @@ func DeactivateInactives( return lastProjectID, nil } -// CandidatePair represents a pair of project and client. +// CandidatePair represents a pair of Project and Client. type CandidatePair struct { - project *database.ProjectInfo - client *database.ClientInfo + Project *database.ProjectInfo + Client *database.ClientInfo } // FindDeactivateCandidates finds candidates to deactivate from the database. @@ -116,8 +116,8 @@ func FindDeactivateCandidates( for _, info := range infos { candidates = append(candidates, CandidatePair{ - project: projectInfo, - client: info, + Project: projectInfo, + Client: info, }) } } diff --git a/server/config.go b/server/config.go index eea4f3a25..118f63ea2 100644 --- a/server/config.go +++ b/server/config.go @@ -68,7 +68,8 @@ const ( DefaultProjectInfoCacheSize = 256 DefaultProjectInfoCacheTTL = 10 * time.Minute - DefaultHostname = "" + DefaultHostname = "" + DefaultGatewayAddr = "localhost:8080" ) // Config is the configuration for creating a Yorkie instance. diff --git a/server/config.sample.yml b/server/config.sample.yml index d5c72edbb..31497b197 100644 --- a/server/config.sample.yml +++ b/server/config.sample.yml @@ -87,6 +87,9 @@ Backend: # determined automatically by the OS (Optional, default: os.Hostname()). Hostname: "" + # GatewayAddr is the address of the gateway server. + GatewayAddr: "" + # Mongo is the MongoDB configuration (Optional). Mongo: # ConnectionTimeout is the timeout for connecting to MongoDB. diff --git a/server/documents/documents.go b/server/documents/documents.go index e73167e34..d10abe72a 100644 --- a/server/documents/documents.go +++ b/server/documents/documents.go @@ -71,7 +71,7 @@ func ListDocumentSummaries( } if includeSnapshot { - doc, err := packs.BuildDocumentForServerSeq(ctx, be, docInfo, docInfo.ServerSeq) + doc, err := packs.BuildInternalDocForServerSeq(ctx, be, docInfo, docInfo.ServerSeq) if err != nil { return nil, err } @@ -102,7 +102,7 @@ func GetDocumentSummary( return nil, err } - doc, err := packs.BuildDocumentForServerSeq(ctx, be, docInfo, docInfo.ServerSeq) + doc, err := packs.BuildInternalDocForServerSeq(ctx, be, docInfo, docInfo.ServerSeq) if err != nil { return nil, err } @@ -135,7 +135,7 @@ func GetDocumentSummaries( snapshot := "" if includeSnapshot { // TODO(hackerwins, kokodak): Resolve the N+1 problem. - doc, err := packs.BuildDocumentForServerSeq(ctx, be, docInfo, docInfo.ServerSeq) + doc, err := packs.BuildInternalDocForServerSeq(ctx, be, docInfo, docInfo.ServerSeq) if err != nil { return nil, err } @@ -179,7 +179,7 @@ func GetDocumentByServerSeq( return nil, err } - doc, err := packs.BuildDocumentForServerSeq(ctx, be, docInfo, serverSeq) + doc, err := packs.BuildInternalDocForServerSeq(ctx, be, docInfo, serverSeq) if err != nil { return nil, err } diff --git a/server/packs/packs.go b/server/packs/packs.go index 79425e572..de10a7d6a 100644 --- a/server/packs/packs.go +++ b/server/packs/packs.go @@ -30,6 +30,7 @@ import ( "github.com/yorkie-team/yorkie/pkg/document" "github.com/yorkie-team/yorkie/pkg/document/change" "github.com/yorkie-team/yorkie/pkg/document/key" + "github.com/yorkie-team/yorkie/pkg/document/time" "github.com/yorkie-team/yorkie/pkg/units" "github.com/yorkie-team/yorkie/server/backend" "github.com/yorkie-team/yorkie/server/backend/database" @@ -211,8 +212,26 @@ func PushPull( return respPack, nil } -// BuildDocumentForServerSeq returns a new document for the given serverSeq. -func BuildDocumentForServerSeq( +// BuildDocForCheckpoint returns a new document for the given checkpoint. +func BuildDocForCheckpoint( + ctx context.Context, + be *backend.Backend, + docInfo *database.DocInfo, + cp change.Checkpoint, + actorID *time.ActorID, +) (*document.Document, error) { + internalDoc, err := BuildInternalDocForServerSeq(ctx, be, docInfo, cp.ServerSeq) + if err != nil { + return nil, err + } + + internalDoc.SetActor(actorID) + internalDoc.SyncCheckpoint(cp.ServerSeq, cp.ClientSeq) + return internalDoc.ToDocument(), nil +} + +// BuildInternalDocForServerSeq returns a new document for the given serverSeq. +func BuildInternalDocForServerSeq( ctx context.Context, be *backend.Backend, docInfo *database.DocInfo, diff --git a/server/packs/pushpull.go b/server/packs/pushpull.go index 20303689a..ebc2000d6 100644 --- a/server/packs/pushpull.go +++ b/server/packs/pushpull.go @@ -139,7 +139,7 @@ func pullSnapshot( initialServerSeq int64, ) (*ServerPack, error) { // Build document from DB if the size of changes for the response is greater than the snapshot threshold. - doc, err := BuildDocumentForServerSeq(ctx, be, docInfo, initialServerSeq) + doc, err := BuildInternalDocForServerSeq(ctx, be, docInfo, initialServerSeq) if err != nil { return nil, err } diff --git a/server/rpc/system_server.go b/server/rpc/system_server.go index e209542b9..f6ebddfa9 100644 --- a/server/rpc/system_server.go +++ b/server/rpc/system_server.go @@ -50,8 +50,8 @@ func newSystemServer(backend *backend.Backend) *systemServer { // DetachDocument detaches the given document from the given client. func (s *systemServer) DetachDocument( ctx context.Context, - req *connect.Request[api.DetachDocumentRequestBySystem], -) (*connect.Response[api.DetachDocumentResponseBySystem], error) { + req *connect.Request[api.SystemServiceDetachDocumentRequest], +) (*connect.Response[api.SystemServiceDetachDocumentResponse], error) { actorID, err := time.ActorIDFromHex(req.Msg.ClientId) if err != nil { return nil, err @@ -100,17 +100,11 @@ func (s *systemServer) DetachDocument( return nil, err } - serverSeq, err := clientInfo.ServerSeq(docID) + doc, err := packs.BuildDocForCheckpoint(ctx, s.backend, docInfo, clientInfo.Checkpoint(docID), actorID) if err != nil { return nil, err } - internalDoc, err := packs.BuildDocumentForServerSeq(ctx, s.backend, docInfo, serverSeq) - if err != nil { - return nil, err - } - - doc := internalDoc.ToDocument() if err := doc.Update(func(root *json.Object, p *presence.Presence) error { p.Clear() return nil @@ -133,5 +127,5 @@ func (s *systemServer) DetachDocument( return nil, err } - return connect.NewResponse(&api.DetachDocumentResponseBySystem{}), nil + return connect.NewResponse(&api.SystemServiceDetachDocumentResponse{}), nil } diff --git a/server/rpc/yorkie_server.go b/server/rpc/yorkie_server.go index 71eddb794..88a469448 100644 --- a/server/rpc/yorkie_server.go +++ b/server/rpc/yorkie_server.go @@ -94,7 +94,7 @@ func (s *yorkieServer) DeactivateClient( } project := projects.From(ctx) - _, err = clients.Deactivate(ctx, s.backend.DB, project, types.ClientRefKey{ + _, err = clients.Deactivate(ctx, s.backend, project, types.ClientRefKey{ ProjectID: project.ID, ClientID: types.IDFromActorID(actorID), }) diff --git a/server/server.go b/server/server.go index 5475a26c0..fd14db3bf 100644 --- a/server/server.go +++ b/server/server.go @@ -150,7 +150,7 @@ func (r *Yorkie) DeactivateClient(ctx context.Context, c1 *client.Client) error return err } - _, err = clients.Deactivate(ctx, r.backend.DB, project, types.ClientRefKey{ + _, err = clients.Deactivate(ctx, r.backend, project, types.ClientRefKey{ ProjectID: project.ID, ClientID: types.IDFromActorID(c1.ID()), }) diff --git a/system/client.go b/system/client.go index 22e25e82a..3d9ddb7f1 100644 --- a/system/client.go +++ b/system/client.go @@ -137,7 +137,7 @@ func (c *Client) DetachDocument( ) error { _, err := c.client.DetachDocument( ctx, - withShardKey(connect.NewRequest(&api.DetachDocumentRequestBySystem{ + withShardKey(connect.NewRequest(&api.SystemServiceDetachDocumentRequest{ ProjectId: projectID.String(), ClientId: clientID.String(), DocumentId: docID.String(), diff --git a/test/helper/helper.go b/test/helper/helper.go index 346074c52..5fb74fe4d 100644 --- a/test/helper/helper.go +++ b/test/helper/helper.go @@ -256,6 +256,7 @@ func TestConfig() *server.Config { AuthWebhookCacheUnauthTTL: AuthWebhookCacheUnauthTTL.String(), ProjectInfoCacheSize: ProjectInfoCacheSize, ProjectInfoCacheTTL: ProjectInfoCacheTTL.String(), + GatewayAddr: fmt.Sprintf("localhost:%d", RPCPort+portOffset), }, Mongo: &mongo.Config{ ConnectionURI: MongoConnectionURI, diff --git a/test/integration/housekeeping_test.go b/test/integration/housekeeping_test.go index add1a9a93..a6991d1e8 100644 --- a/test/integration/housekeeping_test.go +++ b/test/integration/housekeeping_test.go @@ -136,9 +136,8 @@ func TestHousekeeping(t *testing.T) { assert.NoError(t, err) assert.Len(t, candidates, 2) - assert.Equal(t, candidates[0].ID, clientA.ID) - assert.Equal(t, candidates[1].ID, clientB.ID) - assert.NotContains(t, candidates, clientC) + assert.Equal(t, candidates[0].Client.ID, clientA.ID) + assert.Equal(t, candidates[1].Client.ID, clientB.ID) }) }