Repository: libsql/libsql
File: libsql/src/replication/mod.rs (Rust)

Code before:
    /// libsql write ahead log.
    pub fn frames_synced(&self) -> usize {
        self.frames_synced
    }
}

/// A set of rames to be injected via `sync_frames`.
pub enum Frames {
    /// A set of frames, in increasing frame_no.
    Vec(Vec<Frame>),
    /// A stream of snapshot frames. The frames must be in reverse frame_no, and the pages
    /// deduplicated. The snapshot is expected to be a single commit unit.
    Snapshot(SnapshotFile),
}

/// Detailed logs about bytes synced with primary
#[derive(Debug)]
pub struct SyncUsageStats {
    pub prefetched_bytes: u64,
    pub prefetched_bytes_discarded_due_to_new_session: u64,
    pub prefetched_bytes_discarded_due_to_consecutive_handshake: u64,
    pub prefetched_bytes_discarded_due_to_invalid_frame_header: u64,
    pub synced_bytes_discarded_due_to_invalid_frame_header: u64,
    pub prefetched_bytes_used: u64,
    pub synced_bytes_used: u64,
    pub snapshot_bytes: u64,
}

#[derive(Clone)]
pub(crate) struct Writer {
    pub(crate) client: client::Client,
    pub(crate) replicator: Option<EmbeddedReplicator>,
}

impl Writer {
    pub(crate) async fn execute_program(
        &self,
        steps: Vec<Statement>,
        params: impl Into<Params>,
    ) -> anyhow::Result<ExecuteResults> {
        let mut params = Some(params.into());

        let steps = steps
            .into_iter()
            .map(|stmt| Step {
                query: Some(Query {
                    stmt: stmt.stmt,
                    // TODO(lucio): Pass params
                    params: Some(
                        params
                            .take()

Review comment (suggestion):
We should convert these to getters rather than public fields on a struct. More so for public structs that we expose to users and we should follow the style in the rest of the crate for that. If these are pub for internal reasons then they should be `pub(crate)` etc.

Code after:
    /// libsql write ahead log.
    pub fn frames_synced(&self) -> usize {
        self.frames_synced
    }
}

/// A set of rames to be injected via `sync_frames`.
pub enum Frames {
    /// A set of frames, in increasing frame_no.
    Vec(Vec<Frame>),
    /// A stream of snapshot frames. The frames must be in reverse frame_no, and the pages
    /// deduplicated. The snapshot is expected to be a single commit unit.
    Snapshot(SnapshotFile),
}

/// Detailed logs about bytes synced with primary
pub struct SyncUsageStats {
    prefetched_bytes: u64,
    prefetched_bytes_discarded_due_to_new_session: u64,
    prefetched_bytes_discarded_due_to_consecutive_handshake: u64,
    prefetched_bytes_discarded_due_to_invalid_frame_header: u64,
    synced_bytes_discarded_due_to_invalid_frame_header: u64,
    prefetched_bytes_used: u64,
    synced_bytes_used: u64,
    snapshot_bytes: u64,
}

impl SyncUsageStats {
    /// Number of bytes prefetched while doing handshake
    pub fn prefetched_bytes(&self) -> u64 {
        self.prefetched_bytes
    }

    /// Number of bytes prefetched and discarded due to the change of the client session
    pub fn prefetched_bytes_discarded_due_to_new_session(&self) -> u64 {
        self.prefetched_bytes_discarded_due_to_new_session
    }

    /// Number of bytes prefetched and discarded due to consecutive handshake with new prefetch
    pub fn prefetched_bytes_discarded_due_to_consecutive_handshake(&self) -> u64 {
        self.prefetched_bytes_discarded_due_to_consecutive_handshake
    }

    /// Number of bytes prefetched and discarded due to invalid frame header in received frames
    pub fn prefetched_bytes_discarded_due_to_invalid_frame_header(&self) -> u64 {
        self.prefetched_bytes_discarded_due_to_invalid_frame_header
    }

    /// Number of bytes synced and discarded due to invalid frame header in received frames
    pub fn synced_bytes_discarded_due_to_invalid_frame_header(&self) -> u64 {
        self.synced_bytes_discarded_due_to_invalid_frame_header