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

feat: remove yrs #514

Merged
merged 60 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
1d188c6
feat: remove yrs
darkskygit Aug 17, 2023
f26f747
Merge remote-tracking branch 'origin/master' into darksky/switch_bind…
darkskygit Aug 21, 2023
4d4fe0f
chore: format codes
darkskygit Aug 21, 2023
b482de4
fix: dead lock in map
darkskygit Aug 21, 2023
dc47ab7
feat: keep storage thread alive
darkskygit Aug 21, 2023
61aa776
feat: merge update at startup
darkskygit Aug 21, 2023
5479def
feat: stop dispatch update at migrate
darkskygit Aug 21, 2023
2b3684b
feat: return changed update after apply
darkskygit Aug 21, 2023
a40e7ee
chore: disable remote temporarily
darkskygit Aug 21, 2023
1c94c52
chore: merge swift project
darkskygit Aug 21, 2023
c315b5f
feat: clearly update encode
darkskygit Aug 21, 2023
9969ff8
feat: make image minify feature optional
darkskygit Aug 21, 2023
d6c70de
chore: bump deps
darkskygit Aug 21, 2023
f39620d
chore: update headers
darkskygit Aug 21, 2023
c98cc52
feat: reorganize the structure of storage
darkskygit Aug 21, 2023
c97c623
chore: cleanup codes
darkskygit Aug 21, 2023
e9b0aab
Merge remote-tracking branch 'origin/master' into darksky/switch_bind…
darkskygit Aug 21, 2023
455a92c
Merge commit '083a37a707b2b1630d9b58eb974f00a4a9418f59' into darksky/…
darkskygit Aug 23, 2023
8d87a29
feat: keck core
darkskygit Aug 23, 2023
cdc7b29
Merge remote-tracking branch 'origin/master' into darksky/switch_bind…
darkskygit Aug 24, 2023
18489d9
fix: renew value in map
darkskygit Aug 24, 2023
592ab19
fix: sync protocol
darkskygit Aug 25, 2023
0ee6a9a
chore: cleanup subscribe
darkskygit Aug 26, 2023
4601ba2
feat: fix block apis
darkskygit Aug 26, 2023
8f00603
fix: collaboration test
darkskygit Aug 26, 2023
4a7ad67
Merge remote-tracking branch 'origin/master' into darksky/switch_bind…
darkskygit Aug 28, 2023
58356f4
fix: lint
darkskygit Aug 28, 2023
1313146
fix: merge error
darkskygit Aug 28, 2023
70caee9
fix: build warning
darkskygit Aug 28, 2023
37e914a
chore: merge keck-core
darkskygit Aug 28, 2023
600d539
chore: adjust debug config
darkskygit Aug 28, 2023
e80fdc5
fix: keck test
darkskygit Aug 28, 2023
e5d5c1b
chore: fix lint
darkskygit Aug 28, 2023
eafb42b
chore: merge jwst-rpc
darkskygit Aug 28, 2023
023342d
chore: merge jwst-storage
darkskygit Aug 28, 2023
e0e8940
fix: data storage in offline env
darkskygit Aug 28, 2023
3645a70
feat: move jni binding to jwst
darkskygit Aug 28, 2023
c262657
chore: cleanup demo & deps
darkskygit Aug 28, 2023
b7f3ff5
chore: bump deps
darkskygit Aug 28, 2023
53f96af
feat: bump jni version
darkskygit Aug 28, 2023
9a2fa5f
feat: raw history parsing
darkskygit Aug 28, 2023
fd4dcd7
Merge remote-tracking branch 'origin/master' into darksky/switch_bind…
darkskygit Aug 29, 2023
846fe33
Merge remote-tracking branch 'origin/master' into darksky/switch_bind…
darkskygit Aug 29, 2023
dc5ca87
chore: add gc for doc merger
darkskygit Aug 29, 2023
7d39205
Merge remote-tracking branch 'origin/master' into darksky/switch_bind…
darkskygit Aug 29, 2023
08b11c8
chore: add doc merge test
darkskygit Aug 29, 2023
ce693bf
Merge remote-tracking branch 'origin/master' into darksky/switch_bind…
darkskygit Aug 31, 2023
2584417
chore: improve workspace test case
darkskygit Aug 31, 2023
c0bd6d0
feat: improve doc merger
darkskygit Aug 31, 2023
878f318
Merge remote-tracking branch 'origin/master' into darksky/switch_bind…
darkskygit Sep 1, 2023
61eca90
chore: clippy fix
darkskygit Sep 1, 2023
5c74126
chore: add document for ancestor table
darkskygit Sep 1, 2023
ea3303e
chore: fix lint & loom test
darkskygit Sep 1, 2023
19a4b46
feat: remove cloud ci
darkskygit Sep 1, 2023
fe72633
Merge remote-tracking branch 'origin/master' into darksky/switch_bind…
darkskygit Sep 1, 2023
cedca13
chore: improve test
darkskygit Sep 1, 2023
b08c9cc
fix: lint
darkskygit Sep 1, 2023
5ab4509
chore: rename package & fix benchmark
darkskygit Sep 4, 2023
44d0985
chore: remove useless polyfill
darkskygit Sep 4, 2023
d76fce0
feat: bump jni version & enable large_refs for binding
darkskygit Sep 4, 2023
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,492 changes: 507 additions & 985 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
[workspace]

members = [
"apps/cloud",
"apps/doc_merger",
"apps/keck",
"libs/cloud-database",
"libs/cloud-database/migration",
"libs/cloud-infra",
"libs/jwst",
# "libs/jwst-binding/jwst-ffi",
"libs/jwst-binding/jwst-jni",
Expand All @@ -16,7 +12,6 @@ members = [
# "libs/jwst-binding/jwst-wasm",
"libs/jwst-codec",
"libs/jwst-codec-util",
#"libs/jwst-codec/fuzz",
"libs/jwst-core",
"libs/jwst-logger",
"libs/jwst-rpc",
Expand Down Expand Up @@ -47,9 +42,6 @@ lto = false
inherits = "fast-release"
debug = true

# [profile.release.package.jwst-codec-fuzz]
# debug = 1

[profile.dev.package.image]
opt-level = 3

Expand Down
1 change: 1 addition & 0 deletions apps/android/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion apps/android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

167 changes: 88 additions & 79 deletions apps/android/app/src/main/java/com/example/jwst_demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import android.os.Bundle
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import com.toeverything.jwst.Block
import com.toeverything.jwst.Storage
import java.io.File
import java.util.*
import com.toeverything.jwst.JwstVecOfStrings
import com.toeverything.jwst.Workspace
import kotlin.jvm.optionals.getOrNull

fun <T> Optional<T>.unwrap(): T? = orElse(null)

Expand All @@ -21,112 +23,119 @@ class MainActivity : AppCompatActivity() {

val database = File(filesDir, "jwst.db")
val storage = Storage(database.absolutePath, "ws://10.0.2.2:3000/collaboration", "debug")
storage.getWorkspace("test").unwrap()?.let { workspace ->
workspace.setCallback { block_ids -> Log.i("jwst", "change: $block_ids") }
workspace.withTrx { trx -> workspace.get(trx, "a").unwrap() }?.let { block ->
// load the existing block on the second startup program.
val content = workspace.withTrx { trx -> block.get(trx, "a key") }?.get()
this.title = (content as String) + " exists"
workspace.withTrx { trx -> workspace.get(trx, "root").get().children(trx) }
?.joinToString { it }
?.let { Log.i("jwst", it) }
workspace.withTrx { trx ->
Thread.sleep(1000)
trx.create("child11", "child");
}
} ?: run {
// create a new block on the first startup program.
workspace.withTrx { trx ->
val block = trx.create("a", "b")
block.set(trx, "a key", "a value")
}

val content = workspace.withTrx { trx ->
val block = workspace.get(trx, "a").get()
block.get(trx, "a key").get()
}
this.title = content as String

// new lot of block and insert into children
workspace.withTrx { trx ->
val block1 = trx.create("root", "root")
val block2 = trx.create("child1", "child")
val block3 = trx.create("child2", "child")
val block4 = trx.create("child3", "child")
val block5 = trx.create("child4", "child")
val block6 = trx.create("child5", "child")
val block7 = trx.create("child6", "child")
val block8 = trx.create("child7", "child")
val block9 = trx.create("child8", "child")
val block10 = trx.create("child9", "child")
val block11 = trx.create("child10", "child")

block1.insertChildrenAt(trx, block2, 0)
block1.insertChildrenAt(trx, block3, 1)
block1.insertChildrenAt(trx, block4, 2)
block1.insertChildrenAt(trx, block5, 3)
block1.insertChildrenAt(trx, block6, 4)
block1.insertChildrenAt(trx, block7, 5)
block1.insertChildrenAt(trx, block8, 6)
block1.insertChildrenAt(trx, block9, 7)
block1.insertChildrenAt(trx, block10, 8)
block1.insertChildrenAt(trx, block11, 9)
}
}

Log.i("jwst", "getSyncState " + storage.getSyncState())
Log.i("jwst", "isOffline " + storage.isOffline())
Log.i("jwst", "isConnected " + storage.isConnected())
Log.i("jwst", "isFinished " + storage.isFinished())
Log.i("jwst", "isError " + storage.isError())

storage.getWorkspace("test").unwrap()?.let { workspace ->
setupWorkspace(workspace)

workspace.withTrx { trx ->
trx.create("test", "list")
trx.create("test2", "list")
}
workspace.create("test", "list")
workspace.create("test2", "list")

val blocks = workspace.getBlocksByFlavour("list")
Log.i("jwst", "getBlocksByFlavour: $blocks")

// search demo
Log.i("jwst", "search demo")
workspace.withTrx { trx ->
val block = trx.create("search_test", "search_test_flavour")
block.set(trx, "title", "introduction")
block.set(trx, "text", "hello every one")
block.set(trx, "index", "this is index")
}

val block = workspace.create("search_test", "search_test_flavour")
block.set("title", "introduction")
block.set("text", "hello every one")
block.set("index", "this is index")

var indexFields = arrayOf("title", "text")
workspace.setSearchIndex(indexFields)
Log.i("jwst", "search index: " + workspace.getSearchIndex().joinToString(" "))
Log.i("jwst", "search index: " + workspace.getSearchIndex().joinToString(" "))

val searchResult1 = "search result1: " + workspace.search("duc")
Log.i("jwst", searchResult1)
Log.i("jwst", searchResult1)

val searchResult2 = "search result2: " + workspace.search("this")
Log.i("jwst", searchResult2)

var indexFields2 = arrayOf("index")
workspace.setSearchIndex(indexFields2)

Log.i("jwst", "search index: " + workspace.getSearchIndex().joinToString(" "))
Log.i("jwst", "search index: " + workspace.getSearchIndex().joinToString(" "))

val searchResult3 = "search result3: " + workspace.search("this")
Log.i("jwst", searchResult3)

while (true) {
workspace.withTrx { trx ->
Log.i("jwst", " getting root")
workspace.get(trx, "root").unwrap()?.let { block ->
block.get(trx, "test").ifPresent { value ->
Log.i("jwst", "test: $value")
}

Log.i("jwst", " getting root")
workspace.get("root").unwrap()?.let { block ->
block.get("test").ifPresent { value ->
Log.i("jwst", "test: $value")
}
}

Thread.sleep(1000)
}
}
}
}

private fun setupWorkspace(workspace: Workspace) {
workspace.setCallback { blockIds ->
Log.i("jwst", "change: $blockIds")
}

val existingBlock = workspace.get("a").getOrNull()

if (existingBlock != null) {
handleExistingBlock(existingBlock, workspace)
} else {
handleNewBlock(workspace)
}

while (true) {
Log.i("jwst", " getting root")
workspace.get("root").unwrap()?.let { block ->
block.get("test").ifPresent { value ->
Log.i("jwst", "test: $value")
}
}
Thread.sleep(1000)
}
}


private fun handleExistingBlock(block: Block, workspace: Workspace) {
val content = block.get("a key").get()
this.title = "$content exists"

val children = workspace.get("root").get().children().joinToString { it.toString() }
Log.i("jwst", children)

Thread.sleep(1000)
workspace.create("child11", "child")
}

private fun handleNewBlock(workspace: Workspace) {
val block = workspace.create("a", "b")
block.set("a key", "a value")

val content = workspace.get("a").get().get("a key").get()
this.title = content as String

// Create and insert blocks into children
createAndInsertChildren(workspace)
}

private fun createAndInsertChildren(workspace: Workspace) {
val root = workspace.create("root", "root")
val children = (1..10).map { i ->
workspace.create("child$i", "child")
}

children.forEachIndexed { index, child ->
root.insertChildrenAt(child, index.toLong())
}
}

private fun logWorkspaceStatus(storage: Storage) {
Log.i("jwst", "getSyncState ${storage.getSyncState()}")
Log.i("jwst", "isOffline ${storage.isOffline()}")
Log.i("jwst", "isConnected ${storage.isConnected()}")
Log.i("jwst", "isFinished ${storage.isFinished()}")
Log.i("jwst", "isError ${storage.isError()}")
}
}
1 change: 1 addition & 0 deletions apps/doc_merger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ license = "AGPL-3.0-only"
[dependencies]
clap = { version = "4.3.19", features = ["derive"] }
jwst-codec = { workspace = true }
serde_json = "1.0.105"
yrs = "0.16.5"
69 changes: 51 additions & 18 deletions apps/doc_merger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,56 @@

fn main() {
let args = Args::parse();
jwst_merge(&args);
yrs_merge(&args);
jwst_merge(
&args.path,
&args.output.clone().unwrap_or_else(|| format!("{}.jwst", args.path)),
);
std::io::stdin().read_line(&mut String::new()).unwrap();
yrs_merge(
&args.path,
&args.output.clone().unwrap_or_else(|| format!("{}.yrs", args.path)),
);
}

fn jwst_merge(args: &Args) {
let updates = load_path(&args.path).unwrap();
fn jwst_merge(path: &str, output: &str) {
let updates = load_path(path).unwrap();

let mut doc = Doc::default();
for (i, update) in updates.iter().enumerate() {
println!("apply update{i} {} bytes", update.len());
doc.apply_update_from_binary(update.clone()).unwrap();
}
let binary = doc.encode_update_v1().unwrap();
println!("merged {} bytes", binary.len());
write(
args.output.clone().unwrap_or_else(|| format!("{}.jwst", args.path)),
binary,
)
.unwrap();
doc.gc().unwrap();

let binary = {
// let json =
// serde_json::to_string_pretty(&doc.get_map("space:blocks").unwrap()).unwrap();
// println!("json {} bytes", json.len());
let binary = doc.encode_update_v1().unwrap();
drop(doc);
println!("merged {} bytes", binary.len());
std::io::stdin().read_line(&mut String::new()).unwrap();
binary
};

{
let mut doc = Doc::default();
doc.apply_update_from_binary(binary.clone()).unwrap();
let new_binary = doc.encode_update_v1().unwrap();
let new_json = serde_json::to_string_pretty(&doc.get_map("space:blocks").unwrap()).unwrap();

println!(
"re-encoded {} bytes, new json {} bytes",
new_binary.len(),
new_json.len()
);
std::io::stdin().read_line(&mut String::new()).unwrap();
}
write(output, binary).unwrap();
}

fn yrs_merge(args: &Args) {
let updates = load_path(&args.path).unwrap();
fn yrs_merge(path: &str, output: &str) {
let updates = load_path(&path).unwrap();
Fixed Show fixed Hide fixed

let doc = yrs::Doc::new();
for (i, update) in updates.iter().enumerate() {
Expand All @@ -86,9 +113,15 @@
.encode_state_as_update_v1(&StateVector::default())
.unwrap();
println!("merged {} bytes", binary.len());
write(
args.output.clone().unwrap_or_else(|| format!("{}.yrs", args.path)),
binary,
)
.unwrap();
write(output, binary).unwrap();
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_gc() {
jwst_merge("/Users/ds/Downloads/out", "/Users/ds/Downloads/out.jwst");
}
}
19 changes: 8 additions & 11 deletions apps/keck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ schema = ["utoipa-swagger-ui"]

[dependencies]
anyhow = "1.0.70"
axum = { version = "0.6.16", features = ["headers", "ws"] }
axum = { version = "0.6.20", features = ["headers", "ws"] }
cfg-if = "1.0.0"
futures = "0.3.28"
lib0 = { version = "0.16.5", features = ["lib0-serde"] }
log = { version = "0.4.17", features = [
"max_level_trace",
"release_max_level_info",
Expand All @@ -43,27 +42,25 @@ tower = "0.4.13"
tower-http = { version = "0.4.0", features = ["cors"] }
thiserror = "1.0.40"
time = "0.3.20"
tokio = { version = "1.27.0", features = [
tokio = { version = "=1.28.0", features = [
"macros",
"rt-multi-thread",
"signal",
] }
utoipa = { version = "3.3.0", features = ["axum_extras"], optional = true }
utoipa-swagger-ui = { version = "3.1.3", features = ["axum"], optional = true }
yrs = "0.16.5"
libc = "0.2.141"
utoipa = { version = "3.5.0", features = ["axum_extras"], optional = true }
utoipa-swagger-ui = { version = "3.1.5", optional = true }
libc = "0.2.147"
rand = "0.8.5"
reqwest = { version = "0.11.14", default-features = false, features = [
reqwest = { version = "0.11.19", default-features = false, features = [
"json",
"rustls-tls",
] }

# ======= workspace dependencies =======
cloud-infra = { path = "../../libs/cloud-infra" }
jwst = { workspace = true, features = ["workspace-auto-subscribe"] }
jwst-core = { workspace = true }
jwst-logger = { workspace = true }
jwst-rpc = { workspace = true }
jwst-storage = { workspace = true }

[dev-dependencies]
axum-test-helper = "0.2.0"
axum-test-helper = "0.3.0"
Loading
Loading