pub struct DbCore { /* private fields */ }
Expand description
The main concurrent time-series database core struct.
Implementations§
Source§impl DbCore
impl DbCore
Sourcepub fn with_config(config: DbConfig) -> Result<Self, DbError>
pub fn with_config(config: DbConfig) -> Result<Self, DbError>
Creates a new DbCore
instance with the provided configuration.
This sets up the in-memory storage, write buffer, and (if enabled) persistence mechanisms such as the Write-Ahead Log (WAL) and snapshotting. It also spawns the background flush thread, which periodically flushes staged writes to storage and handles snapshot creation.
§Arguments
config
- The database configuration to use.
§Returns
Ok(DbCore)
if initialization succeeds.Err(DbError)
if any component fails to initialize (e.g., WAL or snapshotter).
§Errors
Returns an error if persistence components cannot be initialized.
Sourcepub fn new(flush_interval: Duration) -> Self
pub fn new(flush_interval: Duration) -> Self
Creates a new DbCore
instance with default configuration, but with a custom flush interval.
This is a convenience constructor for quickly creating a database with a specific flush interval. All other configuration options use their default values.
§Arguments
flush_interval
- The interval between automatic buffer flushes.
§Panics
Panics if the database cannot be initialized with the default configuration.
Sourcepub fn recover(&mut self) -> Result<(), DbError>
pub fn recover(&mut self) -> Result<(), DbError>
Recovers the database state from disk using the latest snapshot and any newer WAL entries.
This method should be called after constructing the database if you want to restore persisted data. It loads the most recent snapshot (if enabled), then applies any WAL entries that occurred after the snapshot.
§Returns
Ok(())
if recovery succeeds or if persistence is not enabled.Err(DbError)
if recovery fails.
§Errors
Returns an error if loading the snapshot or WAL fails.
Sourcepub fn insert(
&self,
series: &str,
timestamp: Timestamp,
value: Value,
tags: TagSet,
) -> Result<(), DbError>
pub fn insert( &self, series: &str, timestamp: Timestamp, value: Value, tags: TagSet, ) -> Result<(), DbError>
Inserts a data point into the specified time series.
This method is thread-safe and can be called concurrently from multiple threads.
The data point is first staged in the write buffer and will be flushed to storage
either automatically (by the background thread) or manually (via flush()
).
If WAL is enabled, the insert is also logged for durability.
§Arguments
series
- Name of the time series.timestamp
- Timestamp of the data point.value
- Value to insert.tags
- Associated tags for the data point.
§Returns
Ok(())
if the data point is staged successfully.Err(DbError)
if staging or logging fails.
§Errors
Returns an error if the WAL or write buffer cannot be accessed.
Sourcepub fn query(
&self,
series: &str,
time_range: Range<Timestamp>,
tag_filter: Option<&TagSet>,
) -> Result<Vec<(Timestamp, Value)>, DbError>
pub fn query( &self, series: &str, time_range: Range<Timestamp>, tag_filter: Option<&TagSet>, ) -> Result<Vec<(Timestamp, Value)>, DbError>
Queries data points from a specific time series within a given time range, optionally filtering by a set of tags.
This method is thread-safe and allows concurrent queries. It acquires a read lock on the storage and the relevant series chunk, then executes the query in parallel.
§Arguments
series
- The name of the time series to query.time_range
- The time range for the query (start inclusive, end exclusive).tag_filter
- An optional set of tags to filter by. Only points matching all tags are returned.
§Returns
Ok(Vec<(Timestamp, Value)>)
with all matching data points.Err(DbError)
if the series does not exist or a lock cannot be acquired.
§Errors
Returns an error if the series is not found or if a lock is poisoned.
Sourcepub fn flush(&self) -> Result<(), DbError>
pub fn flush(&self) -> Result<(), DbError>
Triggers an immediate flush of the write buffer to storage.
This sends a command to the background flush thread to flush all staged data points to the in-memory storage. Useful for testing or ensuring data is persisted before shutdown.
§Returns
Ok(())
if the flush command is sent successfully.Err(DbError)
if the command cannot be sent.
§Errors
Returns an error if the background thread cannot be reached.
Sourcepub fn snapshot(&self) -> Result<(), DbError>
pub fn snapshot(&self) -> Result<(), DbError>
Triggers an immediate snapshot of the current database state.
This sends a command to the background flush thread to create a snapshot of all in-memory data. Snapshots are only available if enabled in the configuration.
§Returns
Ok(())
if the snapshot command is sent successfully.Err(DbError)
if snapshots are not enabled or the command cannot be sent.
§Errors
Returns an error if snapshots are disabled or if the background thread cannot be reached.
Sourcepub fn get_config(&self) -> &DbConfig
pub fn get_config(&self) -> &DbConfig
Returns a reference to the current database configuration.
This allows inspection of the configuration used to initialize the database.
§Returns
- A reference to the
DbConfig
struct.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DbCore
impl !RefUnwindSafe for DbCore
impl Send for DbCore
impl Sync for DbCore
impl Unpin for DbCore
impl !UnwindSafe for DbCore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more