Skip to content

Fix large sync sessions by reusing the same session#2036

Merged
penberg merged 2 commits intotursodatabase:mainfrom
avinassh:baton
Apr 22, 2025
Merged

Fix large sync sessions by reusing the same session#2036
penberg merged 2 commits intotursodatabase:mainfrom
avinassh:baton

Conversation

@avinassh
Copy link
Copy Markdown
Member

Currently, we have a bug where each push request creates a new sync session in the server. Each push request can send up to 128 frames.
However, if a transaction spans more than 128 frames, then it needs to reuse the same sync session. Otherwise, the first push will succeed, but the rest of the pushes will fail due to the write lock held by the previous session.

This patch reuses the sync session. The way we do this is by using batons. If the server sends a baton, then we pass it back. Reusing the same baton ensures that we are using the same sync session.

Currently, we have a bug where each `push` request creates
a new sync session in the server. Each push request can send
up to 128 frames.
However, if a transaction spans more than 128 frames, then it
needs to reuse the same sync session. Otherwise, the first
push will succeed, but the rest of the pushes will fail due
to the write lock held by the previous session.

This patch reuses the sync session. The way we do this is
by using batons. If the server sends a baton, then we pass it
back. Reusing the same baton ensures that we are using
the same sync session.
@avinassh avinassh changed the title Reuse the same sync session bugfix: Reuse the same sync session Apr 19, 2025
@avinassh avinassh changed the title bugfix: Reuse the same sync session bugfix: reuse the same sync session Apr 19, 2025
@avinassh avinassh requested a review from Copilot April 20, 2025 19:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug by reusing the same sync session during consecutive push requests through the introduction of baton handling. The key changes include:

  • Updated the push_frames API to accept an optional baton parameter and return a PushFramesResult struct.
  • Adjusted test cases in libsql/src/sync/test.rs to align with the new return type.
  • Modified the sync session logic in libsql/src/sync.rs to reuse the baton for subsequent push requests.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
libsql/src/sync/test.rs Updated tests to provide the baton parameter and assert on max_frame_no.
libsql/src/sync.rs Revised the push_frames API and related logic to support baton reuse.
Comments suppressed due to low confidence (2)

libsql/src/sync/test.rs:33

  • Consider adding tests that simulate scenarios where the server returns a defined baton to ensure that baton reuse works correctly.
assert_eq!(durable_frame.max_frame_no, 0); // First frame should return max_frame_no = 0

libsql/src/sync.rs:200

  • Consider adding an inline comment explaining the purpose of appending the baton to the URI, which reinforces the session reuse mechanism.
if let Some(ref baton) = baton { uri.push_str(&format!("/{}", baton)); }

@penberg penberg changed the title bugfix: reuse the same sync session Fix large sync sessions by reusing the same session Apr 22, 2025
@penberg
Copy link
Copy Markdown
Collaborator

penberg commented Apr 22, 2025

@avinassh This is similar to #2014, no? I am happy to use your variant, just wanted to make sure you're fixing the same issue?

@avinassh
Copy link
Copy Markdown
Member Author

@penberg indeed it is same, I wasn't aware that you had a patch already

@penberg penberg added this pull request to the merge queue Apr 22, 2025
Merged via the queue into tursodatabase:main with commit 3d149d6 Apr 22, 2025
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants