Skip to content

Commit 7799148

Browse files
authored
chore: wrap transaction with retry (#424)
* chore: wrap transaction with retry * chore: bump jni * ci: bump to [email protected]
1 parent f14e0ee commit 7799148

File tree

8 files changed

+17
-25
lines changed

8 files changed

+17
-25
lines changed

.github/workflows/jwst-android.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
target: aarch64-linux-android
3333
- run: cargo install cargo-ndk
3434
- name: Publish package
35-
uses: gradle/gradle-build-action@v2
35+
uses: gradle/gradle-build-action@v2.4.2
3636
with:
3737
arguments: :jwst:publishReleasePublicationToGitHubPackagesRepository
3838
build-root-directory: apps/android

apps/cloud/src/api/workspace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ pub async fn get_public_doc(
475475
async fn get_workspace_doc(ctx: Arc<Context>, workspace_id: String) -> Response {
476476
match ctx.storage.get_workspace(workspace_id).await {
477477
Ok(workspace) => {
478-
if let Ok(update) = workspace.sync_migration(50) {
478+
if let Ok(update) = workspace.sync_migration() {
479479
update.into_response()
480480
} else {
481481
ErrorStatus::NotFound.into_response()

libs/jwst-binding/jwst-jni/android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ publishing {
117117
release(MavenPublication) {
118118
groupId = 'com.toeverything'
119119
artifactId = 'octobase'
120-
version = '0.1.18'
120+
version = '0.1.19'
121121

122122
afterEvaluate {
123123
from components.release

libs/jwst-storage/src/storage/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl JwstStorage {
146146
};
147147
Some(update)
148148
} else {
149-
workspace.sync_migration(50).ok()
149+
workspace.sync_migration().ok()
150150
};
151151

152152
let Some(update) = update else {

libs/jwst/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub use workspace::{MapSubscription, Workspace, WorkspaceMetadata, WorkspaceTran
2222
#[cfg(feature = "workspace-search")]
2323
pub use workspace::{SearchResult, SearchResults};
2424

25+
const RETRY_NUM: i32 = 200;
26+
2527
#[inline]
2628
pub fn print_versions(pkg_name: &str, pkg_version: &str) {
2729
use convert_case::{Case, Casing};

libs/jwst/src/space/convert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,6 @@ impl Space {
162162
Ok::<_, JwstError>(())
163163
})?;
164164

165-
ws.sync_migration(10)
165+
ws.sync_migration()
166166
}
167167
}

libs/jwst/src/workspace/sync.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::*;
2+
use crate::RETRY_NUM;
23
use jwst_codec::{write_sync_message, DocMessage, SyncMessage, SyncMessageScanner};
34
use std::{
45
panic::{catch_unwind, AssertUnwindSafe},
@@ -11,7 +12,8 @@ use yrs::{
1112
};
1213

1314
impl Workspace {
14-
pub fn sync_migration(&self, mut retry: i32) -> JwstResult<Vec<u8>> {
15+
pub fn sync_migration(&self) -> JwstResult<Vec<u8>> {
16+
let mut retry = RETRY_NUM;
1517
let trx = loop {
1618
match self.doc.try_transact() {
1719
Ok(trx) => break trx,
@@ -30,7 +32,7 @@ impl Workspace {
3032

3133
pub async fn sync_init_message(&self) -> JwstResult<Vec<u8>> {
3234
let (sv, awareness_update) = {
33-
let mut retry = 50;
35+
let mut retry = RETRY_NUM;
3436
let trx = loop {
3537
if let Ok(trx) = self.doc.try_transact() {
3638
break trx;
@@ -87,7 +89,7 @@ impl Workspace {
8789
if !content_msg.is_empty() {
8890
let doc = self.doc();
8991
if let Err(e) = catch_unwind(AssertUnwindSafe(|| {
90-
let mut retry = 30;
92+
let mut retry = RETRY_NUM;
9193
let mut trx = loop {
9294
if let Ok(trx) = doc.try_transact_mut() {
9395
break trx;

libs/jwst/src/workspace/transaction.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::{thread::sleep, time::Duration};
2+
use std::cmp::max;
23

34
use crate::utils::JS_INT_RANGE;
45

56
use super::*;
7+
use crate::RETRY_NUM;
68
use lib0::any::Any;
79
use yrs::{Map, ReadTxn, Transact, TransactionMut};
810

@@ -99,33 +101,19 @@ impl WorkspaceTransaction<'_> {
99101

100102
impl Workspace {
101103
pub fn with_trx<T>(&self, f: impl FnOnce(WorkspaceTransaction) -> T) -> T {
102-
let doc = self.doc();
103-
let trx = WorkspaceTransaction {
104-
trx: doc.transact_mut(),
105-
ws: self,
106-
};
107-
108-
f(trx)
104+
self.retry_with_trx(f, RETRY_NUM).unwrap()
109105
}
110106

111107
pub fn try_with_trx<T>(&self, f: impl FnOnce(WorkspaceTransaction) -> T) -> Option<T> {
112-
match self.doc().try_transact_mut() {
113-
Ok(trx) => {
114-
let trx = WorkspaceTransaction { trx, ws: self };
115-
Some(f(trx))
116-
}
117-
Err(e) => {
118-
info!("try_with_trx error: {}", e);
119-
None
120-
}
121-
}
108+
self.retry_with_trx(f, RETRY_NUM).ok()
122109
}
123110

124111
pub fn retry_with_trx<T>(
125112
&self,
126113
f: impl FnOnce(WorkspaceTransaction) -> T,
127114
mut retry: i32,
128115
) -> JwstResult<T> {
116+
retry = max(RETRY_NUM, retry);
129117
let trx = loop {
130118
match self.doc.try_transact_mut() {
131119
Ok(trx) => break trx,

0 commit comments

Comments
 (0)