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

Introducing logical collection pointers #393

Merged
merged 30 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cd15621
moved Branch, BranchPtr to branch.rs
Horusiath Feb 11, 2024
877499a
introduced RootRefs
Horusiath Feb 15, 2024
4ab1faf
exposed Root and Nested types
Horusiath Feb 16, 2024
73d2626
Working YArray on ywasm
Horusiath Feb 22, 2024
7afa7b9
ywasm: YDoc and YTransaction methods
Horusiath Feb 22, 2024
c1f1ce4
ywasm: working YArray
Horusiath Feb 24, 2024
fb8073c
ywasm: prepared UndoManager
Horusiath Feb 24, 2024
6c38c3d
ywasm: prepared WeakLink
Horusiath Feb 24, 2024
3e98907
ywasm: flattened YDoc
Horusiath Feb 24, 2024
d33f946
ywasm: make YDoc compilable through wasm-interpreter
Horusiath Feb 29, 2024
064444c
ywasm: support YWeakLink
Horusiath Feb 29, 2024
5d24059
ywasm: support YMap
Horusiath Feb 29, 2024
ddf8a8a
ywasm: support YText
Horusiath Feb 29, 2024
5b1f1d8
ywasm: support XML types
Horusiath Mar 2, 2024
d45b345
ywasm: support for snapshots and sticky indexes
Horusiath Mar 3, 2024
7d60a01
ywasm: first batch of fixes
Horusiath Mar 7, 2024
9054653
ywasm: second batch of fixes
Horusiath Mar 7, 2024
56c8963
ywasm: third batch of fixes
Horusiath Mar 8, 2024
7f137df
ywasm: fourth batch of fixes
Horusiath Mar 8, 2024
b07878e
ywasm: fixed remaining tests
Horusiath Mar 8, 2024
19cdcd8
exposed logical IDs in ywasm API
Horusiath Mar 8, 2024
9b70f79
added documentation
Horusiath Mar 8, 2024
e732534
fixed doc.rs example
Horusiath Mar 8, 2024
7d50569
updated yffi tests
Horusiath Mar 8, 2024
9ed4e5d
added BranchID to yffi
Horusiath Mar 8, 2024
80dbfba
yffi: fixed one test
Horusiath Mar 8, 2024
10e6f1c
yffi: fixed event target resolution
Horusiath Mar 8, 2024
a105298
wtf 1
Horusiath Mar 8, 2024
00f8e48
added test for logical branches
Horusiath Mar 9, 2024
10f3b6d
fixed c ffi tests
Horusiath Mar 9, 2024
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
Prev Previous commit
Next Next commit
added test for logical branches
  • Loading branch information
Horusiath committed Mar 9, 2024
commit 00f8e48bc05c95ef2ddd53c6f6a4ed66ed69a2ac
2 changes: 1 addition & 1 deletion tests-ffi/include/libyrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,7 @@ struct YBranchId ybranch_id(const Branch *branch);
* Returned pointer may still point to deleted collection. In such case a subsequent `ybranch_alive`
* function call is required.
*/
const Branch *ybranch_get(const struct YBranchId *branch_id, YTransaction *txn);
Branch *ybranch_get(const struct YBranchId *branch_id, YTransaction *txn);

/**
* Check if current branch is still alive (returns `Y_TRUE`, otherwise `Y_FALSE`).
Expand Down
51 changes: 51 additions & 0 deletions tests-ffi/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,57 @@ TEST_CASE("Weak link references") {

yweak_iter_destroy(iter);

ytransaction_commit(txn);
ydoc_destroy(doc);
}

TEST_CASE("Logical branch pointers") {
YDoc *doc = ydoc_new_with_id(1);
Branch *arr = yarray(doc, "array");
YTransaction *txn = ydoc_write_transaction(doc, 0, NULL);

// init doc -> 'array' = [{'key':'value'}]
char *key = "key";
YInput value = yinput_string("value");
YInput in = yinput_ymap(&key, &value, 1);
yarray_insert_range(arr, txn, 0, &in, 1);
YOutput *out = yarray_get(arr, txn, 0);
Branch *map = youtput_read_ymap(out);
youtput_destroy(out);

// get branch identifier
YBranchId map_id = ybranch_id(map);
YBranchId arr_id = ybranch_id(arr);

// remote changes
YDoc *doc2 = ydoc_new_with_id(2);
yarray(doc2, "array"); // roots needs to be pre-initialized
YTransaction *txn2 = ydoc_write_transaction(doc2, 0, NULL);

// synchronize the documents
uint32_t sv_len = 0;
char *sv = ytransaction_state_vector_v1(txn2, &sv_len);

uint32_t update_len = 0;
char *update = ytransaction_state_diff_v1(txn, sv, sv_len, &update_len);

ytransaction_apply(txn2, update, update_len);

ybinary_destroy(sv, sv_len);
ybinary_destroy(update, update_len);

// retrieve branch pointers on remote using logical IDs
Branch* arr2 = ybranch_get(&arr_id, txn2);
Branch* map2 = ybranch_get(&map_id, txn2);

REQUIRE_EQ(yarray_len(arr2), 1);
out = ymap_get(map2, txn2, key);
char* val = youtput_read_string(out);
REQUIRE(strcmp(val, "value") == 0);
youtput_destroy(out);

ytransaction_commit(txn2);
ydoc_destroy(doc2);
ytransaction_commit(txn);
ydoc_destroy(doc);
}
4 changes: 2 additions & 2 deletions yffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5247,7 +5247,7 @@ pub unsafe extern "C" fn ybranch_id(branch: *const Branch) -> YBranchId {
pub unsafe extern "C" fn ybranch_get(
branch_id: *const YBranchId,
txn: *mut Transaction,
) -> *const Branch {
) -> *mut Branch {
let txn = txn.as_ref().unwrap();
let branch_id = branch_id.as_ref().unwrap();
let client_or_len = branch_id.client_or_len;
Expand All @@ -5259,7 +5259,7 @@ pub unsafe extern "C" fn ybranch_get(
};

match ptr {
None => null(),
None => null_mut(),
Some(branch_ptr) => branch_ptr.into_raw_branch(),
}
}
Expand Down