Repository: influxdata/influxdb
File: influxdb3_wal/src/object_store.rs (Rust)

Code before:
    Path::from(format!(
        "{host_identifier_prefix}/wal/{:011}.wal",
        wal_file_number.0
    ))
}

impl<'a> TryFrom<&'a Path> for WalFileSequenceNumber {
    type Error = crate::Error;

    fn try_from(path: &'a Path) -> Result<Self, Self::Error> {
        let parts: Vec<PathPart<'_>> = path.parts().collect();
        if parts.len() != 3 {
            return Err(crate::Error::InvalidWalFilePath);
        }
        parts[2]
            .as_ref()
            .trim_end_matches(".wal")
            .parse()
            .map_err(|_| crate::Error::InvalidWalFilePath)
    }
}

#[derive(Debug)]
struct WalFileRemover {
    oldest_wal_file: Option<WalFileSequenceNumber>,
    last_wal_sequence_number: Option<WalFileSequenceNumber>,
}

impl WalFileRemover {
    fn get_current_state(&self) -> (u64, u64) {
        (
            self.oldest_wal_file.map(|num| num.as_u64()).unwrap_or(0),
            self.last_wal_sequence_number
                .map(|num| num.as_u64())
                .unwrap_or(0),
        )
    }

    fn update_last_wal_num(&mut self, last_wal: WalFileSequenceNumber) {
        self.last_wal_sequence_number.replace(last_wal);
    }

    fn update_state(&mut self, oldest: u64, last: u64) {
        self.oldest_wal_file = Some(WalFileSequenceNumber::new(oldest));
        self.last_wal_sequence_number = Some(WalFileSequenceNumber::new(last));
    }
}

#[cfg(test)]
mod tests {
    use super::*;

Review comment (suggestion):
rename to `last_snapshotted_wal_sequence_number` for clarity. The latest wal file number will always be >= this one.

Code after:
    type Error = crate::Error;

    fn try_from(path: &'a Path) -> Result<Self, Self::Error> {
        let parts: Vec<PathPart<'_>> = path.parts().collect();
        if parts.len() != 3 {
            return Err(crate::Error::InvalidWalFilePath);
        }
        parts[2]
            .as_ref()
            .trim_end_matches(".wal")
            .parse()
            .map_err(|_| crate::Error::InvalidWalFilePath)
    }
}

#[derive(Debug)]
struct WalFileRemover {
    oldest_wal_file: Option<WalFileSequenceNumber>,
    last_snapshotted_wal_sequence_number: Option<WalFileSequenceNumber>,
}

impl WalFileRemover {
    fn get_current_state(&self) -> (u64, u64) {
        (
            self.oldest_wal_file.map(|num| num.as_u64()).unwrap_or(0),
            self.last_snapshotted_wal_sequence_number
                .map(|num| num.as_u64())
                .unwrap_or(0),
        )
    }

    fn update_last_wal_num(&mut self, last_wal: WalFileSequenceNumber) {
        self.last_snapshotted_wal_sequence_number.replace(last_wal);
    }

    fn update_state(&mut self, oldest: u64, last: u64) {
        self.oldest_wal_file = Some(WalFileSequenceNumber::new(oldest));
        self.last_snapshotted_wal_sequence_number = Some(WalFileSequenceNumber::new(last));
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{
        create, Field, FieldData, Gen1Duration, Row, SnapshotSequenceNumber, TableChunk,
        TableChunks,
    };
    use async_trait::async_trait;
    use indexmap::IndexMap;
    use influxdb3_id::{ColumnId, DbId, TableId};