Skip to content

Commit

Permalink
Reflect interface changes of server DB sharding (#726)
Browse files Browse the repository at this point in the history
This commit reflects passing sharding keys to the SDK in advance
before releasing the server with MongoDB sharding applied.
  • Loading branch information
sejongk authored Jan 19, 2024
1 parent 383abd9 commit 363229b
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/api/yorkie/v1/yorkie.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ message ActivateClientResponse {
}

message DeactivateClientRequest {
string client_key = 2;
string client_id = 1;
}

message DeactivateClientResponse {
}

message AttachDocumentRequest {
string client_key = 3;
string client_id = 1;
ChangePack change_pack = 2;
}
Expand All @@ -65,6 +67,7 @@ message AttachDocumentResponse {
}

message DetachDocumentRequest {
string client_key = 5;
string client_id = 1;
string document_id = 2;
ChangePack change_pack = 3;
Expand All @@ -76,7 +79,9 @@ message DetachDocumentResponse {
}

message WatchDocumentRequest {
string client_key = 4;
string client_id = 1;
string document_key = 3;
string document_id = 2;
}

Expand All @@ -92,6 +97,7 @@ message WatchDocumentResponse {
}

message RemoveDocumentRequest {
string client_key = 4;
string client_id = 1;
string document_id = 2;
ChangePack change_pack = 3;
Expand All @@ -102,6 +108,7 @@ message RemoveDocumentResponse {
}

message PushPullChangesRequest {
string client_key = 5;
string client_id = 1;
string document_id = 2;
ChangePack change_pack = 3;
Expand All @@ -113,7 +120,9 @@ message PushPullChangesResponse {
}

message BroadcastRequest {
string client_key = 6;
string client_id = 1;
string document_key = 5;
string document_id = 2;
string topic = 3;
bytes payload = 4;
Expand Down
45 changes: 45 additions & 0 deletions src/api/yorkie/v1/yorkie_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export declare class ActivateClientResponse extends Message<ActivateClientRespon
* @generated from message yorkie.v1.DeactivateClientRequest
*/
export declare class DeactivateClientRequest extends Message<DeactivateClientRequest> {
/**
* @generated from field: string client_key = 2;
*/
clientKey: string;

/**
* @generated from field: string client_id = 1;
*/
Expand Down Expand Up @@ -117,6 +122,11 @@ export declare class DeactivateClientResponse extends Message<DeactivateClientRe
* @generated from message yorkie.v1.AttachDocumentRequest
*/
export declare class AttachDocumentRequest extends Message<AttachDocumentRequest> {
/**
* @generated from field: string client_key = 3;
*/
clientKey: string;

/**
* @generated from field: string client_id = 1;
*/
Expand Down Expand Up @@ -175,6 +185,11 @@ export declare class AttachDocumentResponse extends Message<AttachDocumentRespon
* @generated from message yorkie.v1.DetachDocumentRequest
*/
export declare class DetachDocumentRequest extends Message<DetachDocumentRequest> {
/**
* @generated from field: string client_key = 5;
*/
clientKey: string;

/**
* @generated from field: string client_id = 1;
*/
Expand Down Expand Up @@ -238,11 +253,21 @@ export declare class DetachDocumentResponse extends Message<DetachDocumentRespon
* @generated from message yorkie.v1.WatchDocumentRequest
*/
export declare class WatchDocumentRequest extends Message<WatchDocumentRequest> {
/**
* @generated from field: string client_key = 4;
*/
clientKey: string;

/**
* @generated from field: string client_id = 1;
*/
clientId: string;

/**
* @generated from field: string document_key = 3;
*/
documentKey: string;

/**
* @generated from field: string document_id = 2;
*/
Expand Down Expand Up @@ -327,6 +352,11 @@ export declare class WatchDocumentResponse_Initialization extends Message<WatchD
* @generated from message yorkie.v1.RemoveDocumentRequest
*/
export declare class RemoveDocumentRequest extends Message<RemoveDocumentRequest> {
/**
* @generated from field: string client_key = 4;
*/
clientKey: string;

/**
* @generated from field: string client_id = 1;
*/
Expand Down Expand Up @@ -385,6 +415,11 @@ export declare class RemoveDocumentResponse extends Message<RemoveDocumentRespon
* @generated from message yorkie.v1.PushPullChangesRequest
*/
export declare class PushPullChangesRequest extends Message<PushPullChangesRequest> {
/**
* @generated from field: string client_key = 5;
*/
clientKey: string;

/**
* @generated from field: string client_id = 1;
*/
Expand Down Expand Up @@ -448,11 +483,21 @@ export declare class PushPullChangesResponse extends Message<PushPullChangesResp
* @generated from message yorkie.v1.BroadcastRequest
*/
export declare class BroadcastRequest extends Message<BroadcastRequest> {
/**
* @generated from field: string client_key = 6;
*/
clientKey: string;

/**
* @generated from field: string client_id = 1;
*/
clientId: string;

/**
* @generated from field: string document_key = 5;
*/
documentKey: string;

/**
* @generated from field: string document_id = 2;
*/
Expand Down
9 changes: 9 additions & 0 deletions src/api/yorkie/v1/yorkie_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const ActivateClientResponse = proto3.makeMessageType(
const DeactivateClientRequest = proto3.makeMessageType(
"yorkie.v1.DeactivateClientRequest",
() => [
{ no: 2, name: "client_key", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 1, name: "client_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
],
);
Expand All @@ -68,6 +69,7 @@ const DeactivateClientResponse = proto3.makeMessageType(
const AttachDocumentRequest = proto3.makeMessageType(
"yorkie.v1.AttachDocumentRequest",
() => [
{ no: 3, name: "client_key", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 1, name: "client_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "change_pack", kind: "message", T: ChangePack },
],
Expand All @@ -90,6 +92,7 @@ const AttachDocumentResponse = proto3.makeMessageType(
const DetachDocumentRequest = proto3.makeMessageType(
"yorkie.v1.DetachDocumentRequest",
() => [
{ no: 5, name: "client_key", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 1, name: "client_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "document_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 3, name: "change_pack", kind: "message", T: ChangePack },
Expand All @@ -113,7 +116,9 @@ const DetachDocumentResponse = proto3.makeMessageType(
const WatchDocumentRequest = proto3.makeMessageType(
"yorkie.v1.WatchDocumentRequest",
() => [
{ no: 4, name: "client_key", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 1, name: "client_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 3, name: "document_key", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "document_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
],
);
Expand Down Expand Up @@ -146,6 +151,7 @@ const WatchDocumentResponse_Initialization = proto3.makeMessageType(
const RemoveDocumentRequest = proto3.makeMessageType(
"yorkie.v1.RemoveDocumentRequest",
() => [
{ no: 4, name: "client_key", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 1, name: "client_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "document_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 3, name: "change_pack", kind: "message", T: ChangePack },
Expand All @@ -168,6 +174,7 @@ const RemoveDocumentResponse = proto3.makeMessageType(
const PushPullChangesRequest = proto3.makeMessageType(
"yorkie.v1.PushPullChangesRequest",
() => [
{ no: 5, name: "client_key", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 1, name: "client_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "document_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 3, name: "change_pack", kind: "message", T: ChangePack },
Expand All @@ -191,7 +198,9 @@ const PushPullChangesResponse = proto3.makeMessageType(
const BroadcastRequest = proto3.makeMessageType(
"yorkie.v1.BroadcastRequest",
() => [
{ no: 6, name: "client_key", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 1, name: "client_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 5, name: "document_key", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "document_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 3, name: "topic", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 4, name: "payload", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
Expand Down
7 changes: 7 additions & 0 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ export class Client implements Observable<ClientEvent> {
return this.rpcClient
.deactivateClient(
{
clientKey: this.key!,
clientId: this.id!,
},
{ headers: { 'x-shard-key': this.apiKey } },
Expand Down Expand Up @@ -435,6 +436,7 @@ export class Client implements Observable<ClientEvent> {
return this.rpcClient
.attachDocument(
{
clientKey: this.key!,
clientId: this.id!,
changePack: converter.toChangePack(doc.createChangePack()),
},
Expand Down Expand Up @@ -502,6 +504,7 @@ export class Client implements Observable<ClientEvent> {
return this.rpcClient
.detachDocument(
{
clientKey: this.key!,
clientId: this.id!,
documentId: attachment.docID,
changePack: converter.toChangePack(doc.createChangePack()),
Expand Down Expand Up @@ -691,6 +694,7 @@ export class Client implements Observable<ClientEvent> {
return this.rpcClient
.removeDocument(
{
clientKey: this.key!,
clientId: this.id!,
documentId: attachment.docID,
changePack: pbChangePack,
Expand Down Expand Up @@ -806,7 +810,9 @@ export class Client implements Observable<ClientEvent> {
const ac = new AbortController();
const stream = this.rpcClient.watchDocument(
{
clientKey: this.key!,
clientId: this.id!,
documentKey: docKey,
documentId: attachment.docID,
},
{
Expand Down Expand Up @@ -942,6 +948,7 @@ export class Client implements Observable<ClientEvent> {
return this.rpcClient
.pushPullChanges(
{
clientKey: this.key!,
clientId: this.id!,
documentId: docID,
changePack: converter.toChangePack(reqPack),
Expand Down
15 changes: 11 additions & 4 deletions test/integration/document_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,19 +629,22 @@ describe('Document', function () {
d1.update((root) => {
root['k1'] = [1, 2];
}, 'set array');
await c1.attach(d1);
await c1.attach(d1, { isRealtimeSync: false });
assert.equal(d1.toSortedJSON(), '{"k1":[1,2]}');

const c2 = new yorkie.Client(testRPCAddr);
await c2.activate();
const d2 = new yorkie.Document<TestDoc>(docKey);
await c2.attach(d2);
await c2.attach(d2, { isRealtimeSync: false });
assert.equal(d2.toSortedJSON(), '{"k1":[1,2]}');

// 02. c1 removes d1 and c2 detaches d2.
await c1.remove(d1);
await c2.detach(d2);

await c1.sync();
await c2.sync();

assert.equal(d1.getStatus(), DocumentStatus.Removed);
assert.equal(d2.getStatus(), DocumentStatus.Removed);

Expand All @@ -660,18 +663,22 @@ describe('Document', function () {
d1.update((root) => {
root['k1'] = [1, 2];
}, 'set array');
await c1.attach(d1);
await c1.attach(d1, { isRealtimeSync: false });
assert.equal(d1.toSortedJSON(), '{"k1":[1,2]}');

const c2 = new yorkie.Client(testRPCAddr);
await c2.activate();
const d2 = new yorkie.Document<TestDoc>(docKey);
await c2.attach(d2);
await c2.attach(d2, { isRealtimeSync: false });
assert.equal(d2.toSortedJSON(), '{"k1":[1,2]}');

// 02. c1 removes d1 and c2 removes d2.
await c1.remove(d1);
await c2.remove(d2);

await c1.sync();
await c2.sync();

assert.equal(d1.getStatus(), DocumentStatus.Removed);
assert.equal(d2.getStatus(), DocumentStatus.Removed);

Expand Down

0 comments on commit 363229b

Please sign in to comment.