Skip to content
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
1 change: 0 additions & 1 deletion api/converter/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ func TestConverter(t *testing.T) {

pack, err := converter.FromChangePack(pbPack)
assert.NoError(t, err)
pack.MinSyncedTicket = time.MaxTicket

d2 := document.New("d1")
err = d2.ApplyChangePack(pack)
Expand Down
2 changes: 1 addition & 1 deletion api/converter/from_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func fromTextNode(
if err != nil {
return nil, err
}
textNode.Remove(removedAt, time.MaxTicket, time.MaxLamport)
textNode.Remove(removedAt, time.MaxLamport)
Comment thread
chacha912 marked this conversation as resolved.
}
return textNode, nil
}
Expand Down
64 changes: 6 additions & 58 deletions api/converter/from_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,13 @@ func FromChangePack(pbPack *api.ChangePack) (*change.Pack, error) {
return nil, err
}

minSyncedTicket, err := fromTimeTicket(pbPack.MinSyncedTicket)
if err != nil {
return nil, err
}

pack := &change.Pack{
DocumentKey: key.Key(pbPack.DocumentKey),
Checkpoint: fromCheckpoint(pbPack.Checkpoint),
Changes: changes,
Snapshot: pbPack.Snapshot,
IsRemoved: pbPack.IsRemoved,
VersionVector: versionVector,
MinSyncedTicket: minSyncedTicket,
DocumentKey: key.Key(pbPack.DocumentKey),
Checkpoint: fromCheckpoint(pbPack.Checkpoint),
Changes: changes,
Snapshot: pbPack.Snapshot,
IsRemoved: pbPack.IsRemoved,
VersionVector: versionVector,
}
Comment thread
chacha912 marked this conversation as resolved.

return pack, nil
Expand Down Expand Up @@ -187,7 +181,6 @@ func fromChangeID(id *api.ChangeID) (change.ID, error) {
// FromVersionVector converts the given Protobuf formats to model format.
func FromVersionVector(pbVersionVector *api.VersionVector) (time.VersionVector, error) {
versionVector := make(time.VersionVector)
// TODO(hackerwins): Old clients do not send VersionVector. We should remove this later.
if pbVersionVector == nil {
return versionVector, nil
}
Expand Down Expand Up @@ -422,12 +415,6 @@ func fromEdit(pbEdit *api.Operation_Edit) (*operations.Edit, error) {
if err != nil {
return nil, err
}
createdAtMapByActor, err := fromCreatedAtMapByActor(
pbEdit.CreatedAtMapByActor,
)
if err != nil {
return nil, err
}
executedAt, err := fromTimeTicket(pbEdit.ExecutedAt)
if err != nil {
return nil, err
Expand All @@ -436,7 +423,6 @@ func fromEdit(pbEdit *api.Operation_Edit) (*operations.Edit, error) {
parentCreatedAt,
from,
to,
createdAtMapByActor,
pbEdit.Content,
pbEdit.Attributes,
executedAt,
Expand All @@ -456,12 +442,6 @@ func fromStyle(pbStyle *api.Operation_Style) (*operations.Style, error) {
if err != nil {
return nil, err
}
createdAtMapByActor, err := fromCreatedAtMapByActor(
pbStyle.CreatedAtMapByActor,
)
if err != nil {
return nil, err
}
executedAt, err := fromTimeTicket(pbStyle.ExecutedAt)
if err != nil {
return nil, err
Expand All @@ -470,7 +450,6 @@ func fromStyle(pbStyle *api.Operation_Style) (*operations.Style, error) {
parentCreatedAt,
from,
to,
createdAtMapByActor,
pbStyle.Attributes,
executedAt,
), nil
Expand Down Expand Up @@ -517,13 +496,6 @@ func fromTreeEdit(pbTreeEdit *api.Operation_TreeEdit) (*operations.TreeEdit, err
return nil, err
}

createdAtMapByActor, err := fromCreatedAtMapByActor(
pbTreeEdit.CreatedAtMapByActor,
)
if err != nil {
return nil, err
}

nodes, err := FromTreeNodesWhenEdit(pbTreeEdit.Contents)
if err != nil {
return nil, err
Expand All @@ -535,7 +507,6 @@ func fromTreeEdit(pbTreeEdit *api.Operation_TreeEdit) (*operations.TreeEdit, err
to,
nodes,
int(pbTreeEdit.SplitLevel),
createdAtMapByActor,
executedAt,
), nil
}
Expand All @@ -561,19 +532,11 @@ func fromTreeStyle(pbTreeStyle *api.Operation_TreeStyle) (*operations.TreeStyle,
return nil, err
}

createdAtMapByActor, err := fromCreatedAtMapByActor(
pbTreeStyle.CreatedAtMapByActor,
)
if err != nil {
return nil, err
}

if len(pbTreeStyle.AttributesToRemove) > 0 {
return operations.NewTreeStyleRemove(
parentCreatedAt,
from,
to,
createdAtMapByActor,
pbTreeStyle.AttributesToRemove,
executedAt,
), nil
Expand All @@ -583,7 +546,6 @@ func fromTreeStyle(pbTreeStyle *api.Operation_TreeStyle) (*operations.TreeStyle,
parentCreatedAt,
from,
to,
createdAtMapByActor,
pbTreeStyle.Attributes,
executedAt,
), nil
Expand Down Expand Up @@ -614,20 +576,6 @@ func fromArraySet(pbSetByIndex *api.Operation_ArraySet) (*operations.ArraySet, e
), nil
}

func fromCreatedAtMapByActor(
pbCreatedAtMapByActor map[string]*api.TimeTicket,
) (map[string]*time.Ticket, error) {
createdAtMapByActor := make(map[string]*time.Ticket)
for actor, pbTicket := range pbCreatedAtMapByActor {
ticket, err := fromTimeTicket(pbTicket)
if err != nil {
return nil, err
}
createdAtMapByActor[actor] = ticket
}
return createdAtMapByActor, nil
}

func fromTextNodePos(
pbPos *api.TextNodePos,
) (*crdt.RGATreeSplitNodePos, error) {
Expand Down
73 changes: 29 additions & 44 deletions api/converter/to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,12 @@ func ToChangePack(pack *change.Pack) (*api.ChangePack, error) {
}

return &api.ChangePack{
DocumentKey: pack.DocumentKey.String(),
Checkpoint: ToCheckpoint(pack.Checkpoint),
Changes: pbChanges,
Snapshot: pack.Snapshot,
MinSyncedTicket: ToTimeTicket(pack.MinSyncedTicket),
VersionVector: pbVersionVector,
IsRemoved: pack.IsRemoved,
DocumentKey: pack.DocumentKey.String(),
Checkpoint: ToCheckpoint(pack.Checkpoint),
Changes: pbChanges,
Snapshot: pack.Snapshot,
VersionVector: pbVersionVector,
IsRemoved: pack.IsRemoved,
}, nil
}

Expand Down Expand Up @@ -379,26 +378,24 @@ func toRemove(remove *operations.Remove) (*api.Operation_Remove_, error) {
func toEdit(e *operations.Edit) (*api.Operation_Edit_, error) {
return &api.Operation_Edit_{
Edit: &api.Operation_Edit{
ParentCreatedAt: ToTimeTicket(e.ParentCreatedAt()),
From: toTextNodePos(e.From()),
To: toTextNodePos(e.To()),
CreatedAtMapByActor: toCreatedAtMapByActor(e.MaxCreatedAtMapByActor()),
Content: e.Content(),
Attributes: e.Attributes(),
ExecutedAt: ToTimeTicket(e.ExecutedAt()),
ParentCreatedAt: ToTimeTicket(e.ParentCreatedAt()),
From: toTextNodePos(e.From()),
To: toTextNodePos(e.To()),
Content: e.Content(),
Attributes: e.Attributes(),
ExecutedAt: ToTimeTicket(e.ExecutedAt()),
},
}, nil
}

func toStyle(style *operations.Style) (*api.Operation_Style_, error) {
return &api.Operation_Style_{
Style: &api.Operation_Style{
ParentCreatedAt: ToTimeTicket(style.ParentCreatedAt()),
From: toTextNodePos(style.From()),
To: toTextNodePos(style.To()),
CreatedAtMapByActor: toCreatedAtMapByActor(style.MaxCreatedAtMapByActor()),
Attributes: style.Attributes(),
ExecutedAt: ToTimeTicket(style.ExecutedAt()),
ParentCreatedAt: ToTimeTicket(style.ParentCreatedAt()),
From: toTextNodePos(style.From()),
To: toTextNodePos(style.To()),
Attributes: style.Attributes(),
ExecutedAt: ToTimeTicket(style.ExecutedAt()),
},
}, nil
}
Expand All @@ -421,27 +418,25 @@ func toIncrease(increase *operations.Increase) (*api.Operation_Increase_, error)
func toTreeEdit(e *operations.TreeEdit) (*api.Operation_TreeEdit_, error) {
return &api.Operation_TreeEdit_{
TreeEdit: &api.Operation_TreeEdit{
ParentCreatedAt: ToTimeTicket(e.ParentCreatedAt()),
From: toTreePos(e.FromPos()),
To: toTreePos(e.ToPos()),
Contents: ToTreeNodesWhenEdit(e.Contents()),
SplitLevel: int32(e.SplitLevel()),
CreatedAtMapByActor: toCreatedAtMapByActor(e.MaxCreatedAtMapByActor()),
ExecutedAt: ToTimeTicket(e.ExecutedAt()),
ParentCreatedAt: ToTimeTicket(e.ParentCreatedAt()),
From: toTreePos(e.FromPos()),
To: toTreePos(e.ToPos()),
Contents: ToTreeNodesWhenEdit(e.Contents()),
SplitLevel: int32(e.SplitLevel()),
ExecutedAt: ToTimeTicket(e.ExecutedAt()),
},
}, nil
}

func toTreeStyle(style *operations.TreeStyle) (*api.Operation_TreeStyle_, error) {
return &api.Operation_TreeStyle_{
TreeStyle: &api.Operation_TreeStyle{
ParentCreatedAt: ToTimeTicket(style.ParentCreatedAt()),
From: toTreePos(style.FromPos()),
To: toTreePos(style.ToPos()),
Attributes: style.Attributes(),
ExecutedAt: ToTimeTicket(style.ExecutedAt()),
AttributesToRemove: style.AttributesToRemove(),
CreatedAtMapByActor: toCreatedAtMapByActor(style.MaxCreatedAtMapByActor()),
ParentCreatedAt: ToTimeTicket(style.ParentCreatedAt()),
From: toTreePos(style.FromPos()),
To: toTreePos(style.ToPos()),
Attributes: style.Attributes(),
ExecutedAt: ToTimeTicket(style.ExecutedAt()),
AttributesToRemove: style.AttributesToRemove(),
},
}, nil
}
Expand Down Expand Up @@ -537,16 +532,6 @@ func toTextNodePos(pos *crdt.RGATreeSplitNodePos) *api.TextNodePos {
}
}

func toCreatedAtMapByActor(
createdAtMapByActor map[string]*time.Ticket,
) map[string]*api.TimeTicket {
pbCreatedAtMapByActor := make(map[string]*api.TimeTicket)
for actor, createdAt := range createdAtMapByActor {
pbCreatedAtMapByActor[actor] = ToTimeTicket(createdAt)
}
return pbCreatedAtMapByActor
}

func toValueType(valueType crdt.ValueType) (api.ValueType, error) {
switch valueType {
case crdt.Null:
Expand Down
10 changes: 5 additions & 5 deletions api/yorkie/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ message ChangePack {
Checkpoint checkpoint = 2;
bytes snapshot = 3;
repeated Change changes = 4;
TimeTicket min_synced_ticket = 5;
TimeTicket min_synced_ticket = 5; // deprecated
bool is_removed = 6;
VersionVector version_vector = 7;
}
Expand Down Expand Up @@ -96,7 +96,7 @@ message Operation {
TimeTicket parent_created_at = 1;
TextNodePos from = 2;
TextNodePos to = 3;
map<string, TimeTicket> created_at_map_by_actor = 4;
map<string, TimeTicket> created_at_map_by_actor = 4; // deprecated
string content = 5;
TimeTicket executed_at = 6;
map<string, string> attributes = 7;
Expand All @@ -117,7 +117,7 @@ message Operation {
TextNodePos to = 3;
map<string, string> attributes = 4;
TimeTicket executed_at = 5;
map<string, TimeTicket> created_at_map_by_actor = 6;
map<string, TimeTicket> created_at_map_by_actor = 6; // deprecated
}
message Increase {
TimeTicket parent_created_at = 1;
Expand All @@ -128,7 +128,7 @@ message Operation {
TimeTicket parent_created_at = 1;
TreePos from = 2;
TreePos to = 3;
map<string, TimeTicket> created_at_map_by_actor = 4;
map<string, TimeTicket> created_at_map_by_actor = 4; // deprecated
repeated TreeNodes contents = 5;
int32 split_level = 7;
TimeTicket executed_at = 6;
Expand All @@ -140,7 +140,7 @@ message Operation {
map<string, string> attributes = 4;
TimeTicket executed_at = 5;
repeated string attributes_to_remove = 6;
map<string, TimeTicket> created_at_map_by_actor = 7;
map<string, TimeTicket> created_at_map_by_actor = 7; // deprecated
}
message ArraySet {
TimeTicket parent_created_at = 1;
Expand Down
5 changes: 0 additions & 5 deletions build/charts/yorkie-cluster/charts/yorkie-mongodb/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ sharded:
- name: doc_id
method: "1"
unique: false
- collectionName: syncedseqs
shardKeys:
- name: doc_id
method: "1"
unique: false
- collectionName: versionvectors
shardKeys:
- name: doc_id
Expand Down
2 changes: 0 additions & 2 deletions build/docker/sharding/scripts/init-mongos1.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ sh.shardCollection(mongoClientDB + ".clients", { project_id: 1 });
sh.shardCollection(mongoClientDB + ".documents", { project_id: 1 });
sh.shardCollection(mongoClientDB + ".changes", { doc_id: 1 });
sh.shardCollection(mongoClientDB + ".snapshots", { doc_id: 1 });
sh.shardCollection(mongoClientDB + ".syncedseqs", { doc_id: 1 });
sh.shardCollection(mongoClientDB + ".versionvectors", { doc_id: 1 });

// Split the inital range at `splitPoint` to allow doc_ids duplicate in different shards.
Expand All @@ -42,5 +41,4 @@ sh.shardCollection(serverDB + ".clients", { project_id: 1 });
sh.shardCollection(serverDB + ".documents", { project_id: 1 });
sh.shardCollection(serverDB + ".changes", { doc_id: 1 });
sh.shardCollection(serverDB + ".snapshots", { doc_id: 1 });
sh.shardCollection(serverDB + ".syncedseqs", { doc_id: 1 });
sh.shardCollection(serverDB + ".versionvectors", { doc_id: 1 });
11 changes: 4 additions & 7 deletions design/mongodb-sharding.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This document will only explain the core concepts of the selected sharding strat

1. Cluster-wide: `users`, `projects`
2. Project-wide: `documents`, `clients`
3. Document-wide: `changes`, `snapshots`, `syncedseqs`, `versionvectors`
3. Document-wide: `changes`, `snapshots`, `versionvectors`

<img src="media/mongodb-sharding-prev-relation.png">

Expand All @@ -47,8 +47,7 @@ Shard Project-wide and Document-wide collections due to the large number of data
2. `Clients`: `(project_id, key)`
3. `Changes`: `(doc_id, server_seq)`
4. `Snapshots`: `(doc_id, server_seq)`
5. `Syncedseqs`: `(doc_id, client_id)`
6. `Versionvectors`: `(doc_id, client_id)`
5. `Versionvectors`: `(doc_id, client_id)`

**Main Query Patterns**

Expand Down Expand Up @@ -133,8 +132,7 @@ Every unique constraint can be satisfied because each has the shard key as a pre
2. `Clients`: `(project_id, key)`
3. `Changes`: `(doc_id, server_seq)`
4. `Snapshots`: `(doc_id, server_seq)`
5. `Syncedseqs`: `(doc_id, client_id)`
6. `Versionvectors`: `(doc_id, client_id)`
5. `Versionvectors`: `(doc_id, client_id)`

**Changes of Reference Keys**

Expand All @@ -144,8 +142,7 @@ Since the uniqueness of `_id` isn't guaranteed across shards, reference keys to
2. `Clients`: `_id` -> `(project_id, _id)`
3. `Changes`: `_id` -> `(project_id, doc_id, server_seq)`
4. `Snapshots`: `_id` -> `(project_id, doc_id, server_seq)`
5. `Syncedseqs`: `_id` -> `(project_id, doc_id, client_id)`
6. `Versionvectors`: `_id` -> `(project_id, doc_id, client_id)`
5. `Versionvectors`: `_id` -> `(project_id, doc_id, client_id)`

Considering that MongoDB ensures the uniqueness of `_id` per shard, `Documents` and `Clients` can be identified with the combination of `project_id` and `_id`. Note that the reference keys of document-wide collections are also subsequently changed.

Expand Down
Loading
Loading