Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrent case handling for Yorkie.tree #131

Merged
merged 13 commits into from
Aug 28, 2023
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ jobs:
ram-size: 4096M
emulator-boot-timeout: 12000
disable-animations: true
script: ./gradlew yorkie:connectedCheck --no-build-cache --no-daemon --stacktrace
script: |
./gradlew yorkie:connectedCheck -Pandroid.testInstrumentationRunnerArguments.notAnnotation=androidx.test.filters.LargeTest --no-build-cache --no-daemon --stacktrace
./gradlew yorkie:connectedCheck -Pandroid.testInstrumentationRunnerArguments.annotation=androidx.test.filters.LargeTest --no-build-cache --no-daemon --stacktrace
- if: ${{ matrix.api-level == 30 }}
run: ./gradlew yorkie:jacocoDebugTestReport
- if: ${{ matrix.api-level == 30 }}
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
depends_on:
- yorkie
yorkie:
image: 'yorkieteam/yorkie:0.4.5'
image: 'yorkieteam/yorkie:0.4.6'
container_name: 'yorkie'
command: [
'server',
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
extra_hosts:
- "host.docker.internal:host-gateway"
yorkie:
image: 'yorkieteam/yorkie:0.4.5'
image: 'yorkieteam/yorkie:0.4.6'
container_name: 'yorkie'
command: [
'server',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ class EditorViewModel(private val client: Client) : ViewModel(), YorkieEditText.
private val _content = MutableSharedFlow<String>()
val content = _content.asSharedFlow()

private val _textOpInfos = MutableSharedFlow<Pair<ActorID, OperationInfo.TextOpInfo>>()
val textOpInfos = _textOpInfos.asSharedFlow()
private val _textOperationInfos =
MutableSharedFlow<Pair<ActorID, OperationInfo.TextOperationInfo>>()
val textOpInfos = _textOperationInfos.asSharedFlow()

val removedPeers = document.events.filterIsInstance<PresenceChange.Others.Unwatched>()
.map { it.unwatched.actorID }
Expand Down Expand Up @@ -73,7 +74,7 @@ class EditorViewModel(private val client: Client) : ViewModel(), YorkieEditText.
private suspend fun emitEditOpInfos(changeInfo: Document.Event.ChangeInfo) {
changeInfo.operations.filterIsInstance<OperationInfo.EditOpInfo>()
.forEach { opInfo ->
_textOpInfos.emit(changeInfo.actorID to opInfo)
_textOperationInfos.emit(changeInfo.actorID to opInfo)
}
}

Expand All @@ -85,7 +86,7 @@ class EditorViewModel(private val client: Client) : ViewModel(), YorkieEditText.
gson.fromJson(jsonArray.getString(1), TextPosStructure::class.java) ?: return
val (from, to) = document.getRoot().getAs<JsonText>(TEXT_KEY)
.posRangeToIndexRange(fromPos to toPos)
_textOpInfos.emit(actorID to OperationInfo.SelectOpInfo(from, to))
_textOperationInfos.emit(actorID to OperationInfo.SelectOpInfo(from, to))
}

fun syncText() {
Expand Down
33 changes: 22 additions & 11 deletions yorkie/proto/src/main/proto/yorkie/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ message Operation {
TimeTicket executed_at = 6;
map<string, string> attributes = 7;
}
// NOTE(hackerwins): Select Operation is not used in the current version.
// In the previous version, it was used to represent selection of Text.
// However, it has been replaced by Presence now. It is retained for backward
// compatibility purposes.
message Select {
TimeTicket parent_created_at = 1;
TextNodePos from = 2;
Expand All @@ -117,8 +121,9 @@ message Operation {
TimeTicket parent_created_at = 1;
TreePos from = 2;
TreePos to = 3;
repeated TreeNodes contents = 4;
TimeTicket executed_at = 5;
map<string, TimeTicket> created_at_map_by_actor = 4;
repeated TreeNodes contents = 5;
TimeTicket executed_at = 6;
}
message TreeStyle {
TimeTicket parent_created_at = 1;
Expand Down Expand Up @@ -233,24 +238,30 @@ message TextNodeID {
}

message TreeNode {
TreePos pos = 1;
TreeNodeID id = 1;
string type = 2;
string value = 3;
TimeTicket removed_at = 4;
TreePos ins_prev_pos = 5;
int32 depth = 6;
map<string, NodeAttr> attributes = 7;
TreeNodeID ins_prev_id = 5;
TreeNodeID ins_next_id = 6;
int32 depth = 7;
map<string, NodeAttr> attributes = 8;
}

message TreeNodes {
repeated TreeNode content = 1;
}

message TreePos {
message TreeNodeID {
TimeTicket created_at = 1;
int32 offset = 2;
}

message TreePos {
TreeNodeID parent_id = 1;
TreeNodeID left_sibling_id = 2;
}

/////////////////////////////////////////
// Messages for Common //
/////////////////////////////////////////
Expand Down Expand Up @@ -343,12 +354,12 @@ enum ValueType {
}

enum DocEventType {
DOC_EVENT_TYPE_DOCUMENTS_CHANGED = 0;
DOC_EVENT_TYPE_DOCUMENTS_WATCHED = 1;
DOC_EVENT_TYPE_DOCUMENTS_UNWATCHED = 2;
DOC_EVENT_TYPE_DOCUMENT_CHANGED = 0;
DOC_EVENT_TYPE_DOCUMENT_WATCHED = 1;
DOC_EVENT_TYPE_DOCUMENT_UNWATCHED = 2;
}

message DocEvent {
DocEventType type = 1;
bytes publisher = 2;
string publisher = 2;
}
30 changes: 12 additions & 18 deletions yorkie/proto/src/main/proto/yorkie/v1/yorkie.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,49 +42,45 @@ message ActivateClientRequest {
}

message ActivateClientResponse {
string client_key = 1;
bytes client_id = 2;
string client_id = 1;
}

message DeactivateClientRequest {
bytes client_id = 1;
string client_id = 1;
}

message DeactivateClientResponse {
bytes client_id = 1;
}

message AttachDocumentRequest {
bytes client_id = 1;
string client_id = 1;
ChangePack change_pack = 2;
}

message AttachDocumentResponse {
bytes client_id = 1;
string document_id = 2;
ChangePack change_pack = 3;
string document_id = 1;
ChangePack change_pack = 2;
}

message DetachDocumentRequest {
bytes client_id = 1;
string client_id = 1;
string document_id = 2;
ChangePack change_pack = 3;
bool remove_if_not_attached = 4;
}

message DetachDocumentResponse {
string client_key = 1;
ChangePack change_pack = 2;
}

message WatchDocumentRequest {
bytes client_id = 1;
string client_id = 1;
string document_id = 2;
}

message WatchDocumentResponse {
message Initialization {
repeated bytes client_ids = 1;
repeated string client_ids = 1;
}

oneof body {
Expand All @@ -94,24 +90,22 @@ message WatchDocumentResponse {
}

message RemoveDocumentRequest {
bytes client_id = 1;
string client_id = 1;
string document_id = 2;
ChangePack change_pack = 3;
}

message RemoveDocumentResponse {
string client_key = 1;
ChangePack change_pack = 2;
ChangePack change_pack = 1;
}

message PushPullChangesRequest {
bytes client_id = 1;
string client_id = 1;
string document_id = 2;
ChangePack change_pack = 3;
bool push_only = 4;
}

message PushPullChangesResponse {
bytes client_id = 1;
ChangePack change_pack = 2;
ChangePack change_pack = 1;
}
20 changes: 12 additions & 8 deletions yorkie/src/androidTest/kotlin/dev/yorkie/core/ClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package dev.yorkie.core
import androidx.test.ext.junit.runners.AndroidJUnit4
import dev.yorkie.assertJsonContentEquals
import dev.yorkie.core.Client.DocumentSyncResult
import dev.yorkie.core.Client.Event.DocumentChanged
import dev.yorkie.core.Client.Event.DocumentSynced
import dev.yorkie.core.Client.Event.DocumentsChanged
import dev.yorkie.core.Client.StreamConnectionStatus
import dev.yorkie.document.Document
import dev.yorkie.document.Document.Event.LocalChange
Expand Down Expand Up @@ -89,8 +89,8 @@ class ClientTest {
delay(50)
}
}
val changeEvent = assertIs<DocumentsChanged>(
client2Events.first { it is DocumentsChanged },
val changeEvent = assertIs<DocumentChanged>(
client2Events.first { it is DocumentChanged },
)
assertContentEquals(listOf(documentKey), changeEvent.documentKeys)
var syncEvent = assertIs<DocumentSynced>(client2Events.first { it is DocumentSynced })
Expand Down Expand Up @@ -121,11 +121,15 @@ class ClientTest {
root.remove("k1")
}.await()

while (client1Events.none { it is DocumentSynced }) {
delay(50)
withTimeout(GENERAL_TIMEOUT) {
while (client1Events.none { it is DocumentSynced }) {
delay(50)
}
}
while (client2Events.isEmpty()) {
delay(50)
withTimeout(GENERAL_TIMEOUT) {
while (client2Events.isEmpty()) {
delay(50)
}
}
syncEvent = assertIs(client2Events.first { it is DocumentSynced })
assertIs<DocumentSyncResult.Synced>(syncEvent.result)
Expand Down Expand Up @@ -191,7 +195,7 @@ class ClientTest {
root["version"] = "v2"
}.await()
client1.syncAsync().await()
withTimeout(5_000) {
withTimeout(GENERAL_TIMEOUT) {
while (client2Events.size < 2) {
delay(50)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ class DocumentTest {
assertEquals(document1.toJson(), document2.toJson())

client1.removeAsync(document1).await()
client2.detachAsync(document2).await()
if (document2.status != DocumentStatus.Removed) {
client2.detachAsync(document2).await()
}
assertEquals(DocumentStatus.Removed, document1.status)
assertEquals(DocumentStatus.Removed, document2.status)
}
Expand Down
Loading
Loading