Skip to content

Commit 8f66eea

Browse files
committed
fix: drop request deduper, sqlite dulicated write, add more tracing::debug
1 parent 77ccda1 commit 8f66eea

File tree

13 files changed

+240
-169
lines changed

13 files changed

+240
-169
lines changed

core/src/db/postgres/comment_attachment_repo.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ impl PostgresCommentAttachmentRepository {
3333
mime: row.get("mime"),
3434
size: row.get("size"),
3535
created_at,
36-
created_by: row
37-
.get::<Option<String>, _>("created_by")
38-
.map(UserId::from),
36+
created_by: row.get::<Option<String>, _>("created_by").map(UserId::from),
3937
}
4038
}
4139
}

core/src/db/rocks/doc_role_backend.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,11 @@ impl DocRoleBackend for RocksDocRoleBackend {
182182

183183
let mut batch = WriteBatch::default();
184184
for role in roles {
185-
let key =
186-
Self::role_key(role.workspace_id.as_str(), role.doc_id.as_str(), role.user_id.as_str());
185+
let key = Self::role_key(
186+
role.workspace_id.as_str(),
187+
role.doc_id.as_str(),
188+
role.user_id.as_str(),
189+
);
187190
let value = Self::encode_record(role)?;
188191
batch.put_cf(self.store.doc_roles_cf(), key.as_bytes(), &value);
189192
}

core/src/db/sqlite/comment_attachment_repo.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ impl SqliteCommentAttachmentRepository {
3333
mime: row.get("mime"),
3434
size: row.get("size"),
3535
created_at,
36-
created_by: row
37-
.get::<Option<String>, _>("created_by")
38-
.map(UserId::from),
36+
created_by: row.get::<Option<String>, _>("created_by").map(UserId::from),
3937
}
4038
}
4139
}

core/src/db/sqlite/doc_update_log_store.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,27 @@ impl SqliteDocUpdateLogStore {
4343
}
4444

4545
pub fn uses_external_storage(&self) -> bool {
46-
self.payloads.uses_external_storage()
46+
// NOTE:
47+
// For the SQLite backend we always store doc update payloads inline in the
48+
// `doc_updates.update_blob` column, even if a `DocDataBackend` is configured.
49+
//
50+
// When `DocDataBackend::Sqlite` is used, the doc-data store shares the same
51+
// underlying SQLite database and connection pool as the main repositories.
52+
// Treating it as an "external" log store would cause `insert_updates` to:
53+
//
54+
// 1. Insert a row into `doc_updates` inside a transaction, then
55+
// 2. Call `payloads.put_external`, which issues another `UPDATE doc_updates`
56+
// through the pool on a separate connection while the first transaction
57+
// still holds a write lock.
58+
//
59+
// This easily leads to `SQLITE_BUSY` / "database is locked" errors and surfaces
60+
// as `failed to store doc update log payload for key log:<id>` during
61+
// `space:push-doc-update`.
62+
//
63+
// Only the Rocks-backed `DocDataBackend` should be used for truly external
64+
// log payload storage. For SQLite we disable external payloads here so that
65+
// doc updates are kept inline and written once per row.
66+
false
4767
}
4868

4969
pub async fn insert_updates(

core/src/search.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ mod tests {
6767
fn builder_api() {
6868
let query = SearchQuery::new("affine").with_workspace(WorkspaceId::from("workspace"));
6969
assert_eq!(query.term, "affine");
70-
assert_eq!(
71-
query.workspace_ids,
72-
&[WorkspaceId::from("workspace")]
73-
);
70+
assert_eq!(query.workspace_ids, &[WorkspaceId::from("workspace")]);
7471
}
7572
}

server/src/comment/notifications.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ pub async fn notify_comment_reply(
4545
let mut notify_ids =
4646
collect_workspace_owner_target(state, actor_id, comment, &mention_ids).await?;
4747

48-
if comment.author_id.as_str() != actor_id
49-
&& !mention_ids.contains(comment.author_id.as_str())
50-
{
48+
if comment.author_id.as_str() != actor_id && !mention_ids.contains(comment.author_id.as_str()) {
5149
notify_ids.insert(comment.author_id.clone());
5250
}
5351

server/src/doc/cache.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,14 @@ impl DocCache {
576576
space_id: &str,
577577
doc_id: &str,
578578
) -> DocCacheResult<(Vec<u8>, i64)> {
579+
debug!(
580+
space_type = ?space_type,
581+
space_id,
582+
doc_id,
583+
mode = ?self.mode,
584+
"doc cache snapshot requested"
585+
);
586+
579587
if let DocCacheMode::Bypass = self.mode {
580588
return match space_type {
581589
SpaceType::Workspace => {

server/src/doc/sync.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ pub async fn apply_doc_updates<S>(
144144
where
145145
S: DocUpdateState,
146146
{
147+
tracing::debug!(
148+
?space_type,
149+
workspace_id = workspace_id,
150+
doc_id = doc_id,
151+
update_count = updates.len(),
152+
has_editor = context.editor_id.is_some(),
153+
"apply_doc_updates starting"
154+
);
155+
147156
let cache_result = state
148157
.doc_cache()
149158
.apply_updates(
@@ -156,6 +165,14 @@ where
156165
.await
157166
.map_err(AppError::from_anyhow)?;
158167

168+
tracing::debug!(
169+
?space_type,
170+
workspace_id = workspace_id,
171+
doc_id = doc_id,
172+
timestamp = cache_result.timestamp,
173+
"apply_doc_updates cache apply complete"
174+
);
175+
159176
let channel_key = doc_channel_key(workspace_id, doc_id);
160177
let meta = SocketBroadcastMeta::new(
161178
space_type,

server/src/graphql/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ mod tests {
285285
testing::{insert_document, seed_workspace, setup_state},
286286
};
287287
use async_graphql::{Request as GraphQLRequest, Value as GraphQLValue};
288-
use barffine_core::{ids::UserId, notification::NotificationRecord};
288+
use barffine_core::{ids::UserId, notification::NotificationRecord};
289289
use chrono::{Duration, Utc};
290290
use serde_json::json;
291291
use uuid::Uuid;

server/src/socket/auth.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ use crate::{
1919
state::{AppState, SocketRuntimeState},
2020
};
2121

22-
pub(crate) fn build_socket(
23-
runtime: Arc<SocketRuntimeState>,
24-
) -> (SocketIoLayer, SocketIo) {
22+
pub(crate) fn build_socket(runtime: Arc<SocketRuntimeState>) -> (SocketIoLayer, SocketIo) {
2523
SocketIo::builder()
2624
.with_state(runtime.clone())
2725
.max_payload(100_000_000)

0 commit comments

Comments
 (0)