Skip to main content

timeseries_table_format/storage/
layout.rs

1//! On-disk layout helpers for a table root.
2//!
3//! This module centralizes all *relative* path conventions under a table root:
4//! - transaction log directory / commit file naming (`_timeseries_log/`)
5//! - coverage sidecar directories (`_coverage/`)
6//! - conventional data directory (`data/`)
7//!
8//! The functions here return relative [`std::path::PathBuf`] values. Callers are
9//! expected to join these with a table root (for example, a
10//! [`crate::storage::TableLocation`] / backend root) before doing IO.
11
12use std::path::PathBuf;
13
14// Coverage layout lives under `coverage/` but is re-exported here for convenience
15// and to keep older imports compiling.
16pub use crate::coverage::layout::{
17    COVERAGE_EXT, COVERAGE_ROOT_DIR, CoverageLayoutError, SEGMENT_COVERAGE_DIR, TABLE_SNAPSHOT_DIR,
18    segment_coverage_id_v2, segment_coverage_key, table_coverage_id_v2, table_snapshot_key,
19    validate_coverage_id,
20};
21
22// ====================
23// Data layout
24// ====================
25
26/// Conventional directory where segment files are stored (v0.1 default).
27pub const DATA_DIR_NAME: &str = "data";
28
29/// Relative path: `data/`
30pub fn data_rel_dir() -> PathBuf {
31    PathBuf::from(DATA_DIR_NAME)
32}
33
34// ====================
35// Transaction log layout
36// ====================
37
38/// Name of the subdirectory containing the commit log.
39pub const LOG_DIR_NAME: &str = "_timeseries_log";
40
41/// Name of the file that stores the current version pointer.
42pub const CURRENT_FILE_NAME: &str = "CURRENT";
43
44/// Number of digits used in zero-padded commit file names.
45pub const COMMIT_FILENAME_DIGITS: usize = 10;
46
47/// Relative path: `_timeseries_log/`
48pub fn log_rel_dir() -> PathBuf {
49    PathBuf::from(LOG_DIR_NAME)
50}
51
52/// Relative path: `_timeseries_log/CURRENT`
53pub fn current_rel_path() -> PathBuf {
54    log_rel_dir().join(CURRENT_FILE_NAME)
55}
56
57/// Relative path: `_timeseries_log/<zero-padded>.json`
58pub fn commit_rel_path(version: u64) -> PathBuf {
59    let file_name = format!("{:0width$}.json", version, width = COMMIT_FILENAME_DIGITS);
60    log_rel_dir().join(file_name)
61}