pub trait Engine: Send + Sync {
Show 27 methods
// Required methods
fn open(&mut self) -> Result<()>;
fn close(&mut self) -> Result<()>;
fn begin_transaction(&self) -> Result<Box<dyn Transaction>>;
fn begin_transaction_with_level(
&self,
level: IsolationLevel,
) -> Result<Box<dyn Transaction>>;
fn path(&self) -> Option<&str>;
fn table_exists(&self, table_name: &str) -> Result<bool>;
fn index_exists(&self, index_name: &str, table_name: &str) -> Result<bool>;
fn get_index(
&self,
table_name: &str,
index_name: &str,
) -> Result<Box<dyn Index>>;
fn get_table_schema(&self, table_name: &str) -> Result<CompactArc<Schema>>;
fn schema_epoch(&self) -> u64;
fn list_table_indexes(
&self,
table_name: &str,
) -> Result<FxHashMap<String, String>>;
fn get_all_indexes(&self, table_name: &str) -> Result<Vec<Arc<dyn Index>>>;
fn get_isolation_level(&self) -> IsolationLevel;
fn set_isolation_level(&mut self, level: IsolationLevel) -> Result<()>;
fn get_config(&self) -> Config;
fn update_config(&mut self, config: Config) -> Result<()>;
fn create_snapshot(&self) -> Result<()>;
// Provided methods
fn record_create_index(
&self,
table_name: &str,
index_name: &str,
column_names: &[String],
is_unique: bool,
index_type: IndexType,
) { ... }
fn record_drop_index(&self, table_name: &str, index_name: &str) { ... }
fn record_alter_table_add_column(
&self,
table_name: &str,
column_name: &str,
data_type: DataType,
nullable: bool,
default_expr: Option<&str>,
) { ... }
fn record_alter_table_drop_column(
&self,
table_name: &str,
column_name: &str,
) { ... }
fn record_alter_table_rename_column(
&self,
table_name: &str,
old_column_name: &str,
new_column_name: &str,
) { ... }
fn record_alter_table_modify_column(
&self,
table_name: &str,
column_name: &str,
data_type: DataType,
nullable: bool,
) { ... }
fn record_alter_table_rename(
&self,
old_table_name: &str,
new_table_name: &str,
) { ... }
fn fetch_rows_by_ids(
&self,
table_name: &str,
row_ids: &[i64],
) -> Result<RowVec> { ... }
fn get_row_fetcher(
&self,
table_name: &str,
) -> Result<Box<dyn Fn(&[i64]) -> RowVec + Send + Sync>> { ... }
fn get_row_counter(
&self,
table_name: &str,
) -> Result<Box<dyn Fn(&[i64]) -> usize + Send + Sync>> { ... }
}Expand description
Engine represents the storage engine
This is the main entry point for interacting with the database. It manages transactions, tables, indexes, and persistence.
§Example
let config = Config::with_path("/tmp/mydb");
let mut engine = MvccEngine::new(config);
engine.open()?;
let tx = engine.begin_transaction()?;
// ... perform operations ...
tx.commit()?;
engine.close()?;Required Methods§
Sourcefn open(&mut self) -> Result<()>
fn open(&mut self) -> Result<()>
Opens the storage engine
This initializes the engine, opens the database path (if any), recovers from WAL, and loads existing data.
Sourcefn close(&mut self) -> Result<()>
fn close(&mut self) -> Result<()>
Closes the storage engine
This flushes pending writes, creates a final snapshot if needed, and releases all resources.
Sourcefn begin_transaction(&self) -> Result<Box<dyn Transaction>>
fn begin_transaction(&self) -> Result<Box<dyn Transaction>>
Begins a new transaction
The transaction will use the engine’s default isolation level.
Sourcefn begin_transaction_with_level(
&self,
level: IsolationLevel,
) -> Result<Box<dyn Transaction>>
fn begin_transaction_with_level( &self, level: IsolationLevel, ) -> Result<Box<dyn Transaction>>
Begins a new transaction with a specific isolation level
§Arguments
level- The isolation level for the transaction
Sourcefn path(&self) -> Option<&str>
fn path(&self) -> Option<&str>
Returns the path to the database directory
Returns None if operating in memory-only mode.
Sourcefn table_exists(&self, table_name: &str) -> Result<bool>
fn table_exists(&self, table_name: &str) -> Result<bool>
Checks if a table exists
Sourcefn index_exists(&self, index_name: &str, table_name: &str) -> Result<bool>
fn index_exists(&self, index_name: &str, table_name: &str) -> Result<bool>
Checks if an index exists
Sourcefn get_index(
&self,
table_name: &str,
index_name: &str,
) -> Result<Box<dyn Index>>
fn get_index( &self, table_name: &str, index_name: &str, ) -> Result<Box<dyn Index>>
Gets an index by name
Sourcefn get_table_schema(&self, table_name: &str) -> Result<CompactArc<Schema>>
fn get_table_schema(&self, table_name: &str) -> Result<CompactArc<Schema>>
Gets the schema for a table
Returns an Arc to avoid cloning the schema on every access. This is a critical optimization for hot paths like PK lookups.
Sourcefn schema_epoch(&self) -> u64
fn schema_epoch(&self) -> u64
Gets the current schema epoch
This is a monotonically increasing counter that increments on any CREATE TABLE, ALTER TABLE, or DROP TABLE operation. Used for fast cache invalidation without HashMap lookup (~1ns vs ~7ns).
Sourcefn list_table_indexes(
&self,
table_name: &str,
) -> Result<FxHashMap<String, String>>
fn list_table_indexes( &self, table_name: &str, ) -> Result<FxHashMap<String, String>>
Lists all indexes for a table
Returns a map from index name to index type string.
Sourcefn get_all_indexes(&self, table_name: &str) -> Result<Vec<Arc<dyn Index>>>
fn get_all_indexes(&self, table_name: &str) -> Result<Vec<Arc<dyn Index>>>
Gets all index objects for a table
Sourcefn get_isolation_level(&self) -> IsolationLevel
fn get_isolation_level(&self) -> IsolationLevel
Gets the current default isolation level
Sourcefn set_isolation_level(&mut self, level: IsolationLevel) -> Result<()>
fn set_isolation_level(&mut self, level: IsolationLevel) -> Result<()>
Sets the default isolation level for new transactions
Sourcefn get_config(&self) -> Config
fn get_config(&self) -> Config
Gets the current engine configuration
Returns a clone of the configuration to avoid lifetime issues with internal locks.
Sourcefn update_config(&mut self, config: Config) -> Result<()>
fn update_config(&mut self, config: Config) -> Result<()>
Updates the engine configuration
Note: Some configuration changes may require a restart to take effect.
Sourcefn create_snapshot(&self) -> Result<()>
fn create_snapshot(&self) -> Result<()>
Manually triggers snapshot creation for all tables
This is useful for creating a consistent backup point.
Provided Methods§
Sourcefn record_create_index(
&self,
table_name: &str,
index_name: &str,
column_names: &[String],
is_unique: bool,
index_type: IndexType,
)
fn record_create_index( &self, table_name: &str, index_name: &str, column_names: &[String], is_unique: bool, index_type: IndexType, )
Record an index creation operation to WAL for persistence
This should be called by the executor after creating an index to ensure the index is recreated on recovery.
Sourcefn record_drop_index(&self, table_name: &str, index_name: &str)
fn record_drop_index(&self, table_name: &str, index_name: &str)
Record an index drop operation to WAL for persistence
Sourcefn record_alter_table_add_column(
&self,
table_name: &str,
column_name: &str,
data_type: DataType,
nullable: bool,
default_expr: Option<&str>,
)
fn record_alter_table_add_column( &self, table_name: &str, column_name: &str, data_type: DataType, nullable: bool, default_expr: Option<&str>, )
Record ALTER TABLE ADD COLUMN operation to WAL for persistence
Sourcefn record_alter_table_drop_column(&self, table_name: &str, column_name: &str)
fn record_alter_table_drop_column(&self, table_name: &str, column_name: &str)
Record ALTER TABLE DROP COLUMN operation to WAL for persistence
Sourcefn record_alter_table_rename_column(
&self,
table_name: &str,
old_column_name: &str,
new_column_name: &str,
)
fn record_alter_table_rename_column( &self, table_name: &str, old_column_name: &str, new_column_name: &str, )
Record ALTER TABLE RENAME COLUMN operation to WAL for persistence
Sourcefn record_alter_table_modify_column(
&self,
table_name: &str,
column_name: &str,
data_type: DataType,
nullable: bool,
)
fn record_alter_table_modify_column( &self, table_name: &str, column_name: &str, data_type: DataType, nullable: bool, )
Record ALTER TABLE MODIFY COLUMN operation to WAL for persistence
Sourcefn record_alter_table_rename(&self, old_table_name: &str, new_table_name: &str)
fn record_alter_table_rename(&self, old_table_name: &str, new_table_name: &str)
Record ALTER TABLE RENAME TO operation to WAL for persistence
Sourcefn fetch_rows_by_ids(&self, table_name: &str, row_ids: &[i64]) -> Result<RowVec>
fn fetch_rows_by_ids(&self, table_name: &str, row_ids: &[i64]) -> Result<RowVec>
Fetch rows by IDs directly from storage without creating a full transaction.
This is an optimization for EXISTS subquery evaluation where we only need to check if rows exist and evaluate predicates. It avoids the ~2-5μs overhead of creating a new transaction per EXISTS probe.
The returned rows represent the latest committed state visible to any reader.
Sourcefn get_row_fetcher(
&self,
table_name: &str,
) -> Result<Box<dyn Fn(&[i64]) -> RowVec + Send + Sync>>
fn get_row_fetcher( &self, table_name: &str, ) -> Result<Box<dyn Fn(&[i64]) -> RowVec + Send + Sync>>
Get a cached row fetcher for a table.
This returns a function that can be called repeatedly to fetch rows without the overhead of looking up the table each time. This is useful for EXISTS subquery evaluation where we probe the same table many times.