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

libsql: rework sync v2 structure #1820

Closed
wants to merge 1 commit into from
Closed

Conversation

LucioFranco
Copy link
Contributor

@LucioFranco LucioFranco commented Nov 14, 2024

This refactors the new sync code to live in sync.rs. This also includes
support for writing metadata to disk to improve syncs on restarts.

This refactors the new sync code to live in sync.rs. This also includes
support for writing metadata to disk to improve syncs on restarts.
@LucioFranco LucioFranco force-pushed the lucio/rework-sync-ctx branch from 508d725 to bdb428e Compare November 15, 2024 20:41
Comment on lines +413 to +414
// TODO: figure out relation to durable_frame_num
// let max_frame_no = ctx.max_frame_no();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@penberg before we can merge this would be helpful to clairify the difference between durable_frame_ num and max_frame_no. What I understand is we want to write the durable_frame_num here (which I guess is the max_frame_no from the server) to disk to ensure we start at a more advanced wal frame than 0.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You always have two different max frame numbers: one on client, one on server. I tend to call the latter durable_frame_num.

self.set_max_frame_no(max_frame_no).await.unwrap();

return Ok(max_frame_no);
} else if res.status().is_server_error() || attempts < self.max_retries {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@penberg small change compared to what you had, I just retry on server failures rather than all failures like auth_token being invalid.

Comment on lines +327 to +330
pub async fn sync_until(
&self,
replication_index: FrameNo,
) -> Result<crate::database::Replicated> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid reformattings like that in PRs that are supposed to do something non-trivial.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really odd, my editor is auto formatting this but with cargo fmt which we use to check on CI so we avoid these changes its not formatting lines with #[cfg(feature = "")]. Gonna take a look into this, seems really odd that cargo fmt isn't picking this up.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't invest time into that. Just when you see stuff like this put it on a separate PR and even merge it without review.

let page_size = {
let rows = conn.query("PRAGMA page_size", crate::params::Params::None)?.unwrap();
let rows = conn
Copy link
Contributor

Choose a reason for hiding this comment

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

Again - please avoid noise like that in PRs

pub fn wal_get_frame(&self, frame_no: u32, page_size: u32) -> Result<BytesMut> {
let frame_size: usize = 24 + page_size as usize;

let mut buf = BytesMut::with_capacity(frame_size);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this better than just vec![0; frame_size]?

Comment on lines +111 to +143
pub(crate) async fn set_max_frame_no(&mut self, max_frame_no: u32) -> Result<()> {
// TODO: check if max_frame_no is larger than current known max_frame_no
self.max_frame_no = max_frame_no;

self.update_metadata().await?;

Ok(())
}

async fn update_metadata(&mut self) -> Result<()> {
let path = format!("{}-info", self.db_path);

let contents = serde_json::to_vec(&MetadataJson {
max_frame_no: self.max_frame_no,
})
.unwrap();

tokio::fs::write(path, contents).await.unwrap();

Ok(())
}

async fn read_and_update_metadata(&mut self) -> Result<()> {
let path = format!("{}-info", self.db_path);

let contents = tokio::fs::read(&path).await.unwrap();

let metadata = serde_json::from_slice::<MetadataJson>(&contents[..]).unwrap();

self.max_frame_no = metadata.max_frame_no;

Ok(())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What's all of this? Can we have one PR that just switches to hyper and all other changes in another PR please?

Copy link
Contributor

Choose a reason for hiding this comment

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

But also what's this?

@haaawk
Copy link
Contributor

haaawk commented Nov 18, 2024 via email

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