pub const PROTOCOL_VERSION: u64 = 1;
pub const KNOWN_READER_FEATURES: &[&str] = &[];
pub const KNOWN_WRITER_FEATURES: &[&str] = &[];
pub const ENGINE_NAME: &str = "chdb";
pub const BACKUP_FORMAT_BASELINE: u64 = 1;
pub const MAX_SQL_BYTES: u64 = 64 * 1024 * 1024;
pub const MAX_WAL_SEGMENT_BYTES: u64 = 128 * 1024 * 1024;
pub const MAX_HEAD_BYTES: u64 = 1024 * 1024;
pub const MAX_SAFE_INTEGER: u64 = (1u64 << 53) - 1;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct Protocol {
pub version: u64,
pub reader_features: Vec<String>,
pub writer_features: Vec<String>,
}
impl Default for Protocol {
fn default() -> Self {
Self {
version: PROTOCOL_VERSION,
reader_features: Vec::new(),
writer_features: Vec::new(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct EngineIdentity {
pub name: String,
pub version: String,
pub backup_format: u64,
pub min_reader: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ObjectRef {
pub key: String,
pub size: u64,
pub sha256: String,
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct Lease {
pub generation: u64,
pub owner: Option<String>,
pub instance: Option<String>,
pub expires_at: Option<f64>,
}
impl Lease {
pub(crate) fn released(generation: u64) -> Self {
Self {
generation,
owner: None,
instance: None,
expires_at: None,
}
}
pub(crate) fn is_held(&self) -> bool {
self.owner.is_some()
}
pub(crate) fn instance_is(&self, instance: &str) -> bool {
self.instance.as_deref() == Some(instance)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct Manifest {
pub db: String,
pub base: Option<ObjectRef>,
pub wal: Vec<ObjectRef>,
pub seq: u64,
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct Head {
pub protocol: Protocol,
pub engine: EngineIdentity,
pub lease: Lease,
pub manifest: Manifest,
}
impl Head {
pub(crate) fn cold(db: &str, engine_version: &str, backup_format: u64) -> Self {
Self {
protocol: Protocol::default(),
engine: EngineIdentity {
name: ENGINE_NAME.to_string(),
version: engine_version.to_string(),
backup_format,
min_reader: engine_version.to_string(),
},
lease: Lease::released(1),
manifest: Manifest {
db: db.to_string(),
base: None,
wal: Vec::new(),
seq: 0,
},
}
}
}