### Method: install Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Installs an operation onto the thread pool, returning a result. The operation and its return type must be sendable. ```rust pub fn install(self: &Self, op: OP) -> R where OP: FnOnce(fn(IN) -> RR) -> R + Send, IN: FnOnce(&mut HashMap>) -> RR, R: Send { /* ... */ } ``` -------------------------------- ### Install and Run SierraDB with Cargo Source: https://github.com/sierra-db/sierradb/blob/main/README.md Install the SierraDB server using Cargo and run it with specified data directory and client address. ```bash cargo install sierradb-server sierradb --dir ./data --client-address 0.0.0.0:9090 ``` -------------------------------- ### DatabaseBuilder: new() Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Creates a new instance of the DatabaseBuilder. This is the starting point for configuring a database. ```rust pub fn new() -> Self { /* ... */ } ``` -------------------------------- ### Start SierraDB with Docker Source: https://github.com/sierra-db/sierradb/blob/main/README.md Run SierraDB using Docker. This command exposes the default port 9090. ```bash # Start SierraDB docker run -p 9090:9090 tqwewe/sierradb ``` -------------------------------- ### Get Database Directory Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Returns a reference to the `PathBuf` representing the database directory. ```rust pub fn dir(self: &Self) -> &PathBuf { /* ... */ } ``` -------------------------------- ### Set Up SierraDB Cluster Nodes Source: https://github.com/sierra-db/sierradb/blob/main/README.md Commands to start three SierraDB nodes for a distributed deployment. Ensure each node has a unique directory and client address. ```bash # Node 1 sierradb --dir ./data1 --node-index 0 --node-count 3 --client-address 0.0.0.0:9090 # Node 2 sierradb --dir ./data2 --node-index 1 --node-count 3 --client-address 0.0.0.0:9091 # Node 3 sierradb --dir ./data3 --node-index 2 --node-count 3 --client-address 0.0.0.0:9092 ``` -------------------------------- ### Bootstrap Kameo System Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Initializes the Kameo system and registers a default actor. This is the primary entry point for starting the actor system. ```rust #[tokio::main] async fn main() -> Result<(), Box> { // One line to get started! remote::bootstrap()?; // Now use remote actors normally let actor_ref = MyActor::spawn_default(); actor_ref.register("my_actor").await?; Ok(()) } ``` -------------------------------- ### Example Debugging Output for Model Inconsistency Source: https://github.com/sierra-db/sierradb/blob/main/debug_fuzzer.md This is an example of the output seen when a model inconsistency is detected during a fuzz test, showing error details, initialization arguments, current command, and model state. ```text === DEBUGGING MODEL INCONSISTENCY === Error: Model has version 0 for stream '\u{8d0d0}' in partition 416 but database returned none Init args: InitArgs { segment_size: 8192, total_buckets: 32, ... } Current command 2: GetStreamVersion { partition_id: Some(416), stream_id: Some(...) } Model state: - Partitions: [416, 123, 456] - Streams: {(416, StreamId("test")): 0, ...} - Total buckets: 32 Saved failing input to: fuzz_failure_12345.json ``` -------------------------------- ### Basic Seglog Write and Read Example Source: https://github.com/sierra-db/sierradb/blob/main/crates/seglog/README.md Demonstrates creating a segment file, appending records, flushing to disk, and reading records concurrently using seglog's Writer and Reader APIs. ```rust use seglog::write::Writer; use seglog::read::{Reader, ReadHint}; // Create a 1MB segment let mut writer = Writer::create("segment.log", 1024 * 1024, 0)?; // Append records let (offset, _) = writer.append(b"event data")?; writer.sync()?; // Flush to disk // Read concurrently let flushed = writer.flushed_offset(); let mut reader = Reader::open("segment.log", Some(flushed))?; let data = reader.read_record(offset, ReadHint::Random)?; assert_eq!(&*data, b"event data"); ``` -------------------------------- ### Custom Remote Actor System Configuration Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Example of setting up a custom libp2p swarm with full control over transports, discovery, and protocol composition for production deployments. ```rust use kameo::remote; use libp2p::swarm::NetworkBehaviour; #[derive(NetworkBehaviour)] struct MyBehaviour { kameo: remote::Behaviour, // Add other libp2p behaviors as needed } // Create custom libp2p swarm with full control over // transports, discovery, and protocol composition ``` -------------------------------- ### Import Kameo Prelude Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Import all common types and functions from the Kameo prelude with a single use statement. This is the most common way to start using Kameo. ```rust use kameo::prelude::*; ``` -------------------------------- ### Bootstrap Remote Actor System (Quick Start) Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Quickly bootstrap a distributed actor system for prototyping and development. This function returns the peer ID of the bootstrapped system. ```rust use kameo::remote; #[tokio::main] async fn main() -> Result<(), Box> { // One line to bootstrap a distributed actor system let peer_id = remote::bootstrap()?; // Now use actors normally // actor_ref.register("my_actor").await?; Ok(()) } ``` -------------------------------- ### Bootstrap with Specific Listen Address Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Starts the Kameo system and listens on a specified network address. Use this when you need to control the network interface the system binds to. ```rust pub fn bootstrap_on(addr: &str) -> Result> { /* ... */ } ``` -------------------------------- ### Get Coordinator Order by Startup Timestamp Source: https://github.com/sierra-db/sierradb/blob/main/docs/Coordinator Ordering and Recovery Design.md Sorts replicas for a partition based on startup timestamp (ascending) and then peer ID (ascending) to determine coordinator order. Older nodes are preferred. ```rust fn get_coordinator_order(&self, partition_id: PartitionId) -> Vec> { let mut replicas = self.get_replicas_for_partition(partition_id); replicas.sort_by(|a, b| { let a_info = self.get_node_info(a.peer_id()); let b_info = self.get_node_info(b.peer_id()); match a_info.startup_timestamp.cmp(&b_info.startup_timestamp) { Ordering::Equal => a_info.peer_id.cmp(&b_info.peer_id), other => other, // Earlier timestamp wins } }); replicas } ``` -------------------------------- ### Subscribe to Partition Events Source: https://github.com/sierra-db/sierradb/blob/main/README.md Subscribes to real-time event delivery from one or more partitions. Supports various starting positions and window sizes. ```shell EPSUB * # All partitions, latest ``` ```shell EPSUB * WINDOW 100 # All partitions, latest, window 100 ``` ```shell EPSUB * FROM 1000 WINDOW 100 # All partitions, from seq 1000 ``` ```shell EPSUB 5 FROM 100 WINDOW 50 # Partition 5, from seq 100 ``` ```shell EPSUB 1,2,3 FROM MAP 1=100 2=200 DEFAULT 0 WINDOW 500 ``` -------------------------------- ### ReaderThreadPool::install Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Installs an operation into the thread pool that returns a value. This method allows for operations that produce a result after execution. ```APIDOC ## ReaderThreadPool::install ### Description Installs an operation into the thread pool that returns a value. This method allows for operations that produce a result after execution. ### Method Instance Method ### Signature ```rust pub fn install(self: &Self, op: OP) -> R where OP: FnOnce(fn(IN) -> RR) -> R + Send, IN: FnOnce(&mut HashMap>) -> RR, R: Send ``` ### Parameters - **op** (OP) - A closure that takes a function `fn(IN) -> RR` and returns a value `R`. It must be `Send`. - **IN** - A type that implements `FnOnce` to be passed to the operation, returning `RR`. - **RR** - The return type of the inner function `IN`. - **R** - The return type of the `install` method, must be `Send`. ``` -------------------------------- ### EPSUB - Subscribe to Partition Events Source: https://github.com/sierra-db/sierradb/blob/main/README.md Subscribes to real-time event delivery from one or more partitions. Supports various starting positions and optional windowing. ```APIDOC ## EPSUB - Subscribe to Partition Events ### Description Subscribes to events from one or more partitions with real-time delivery. ### Method Not applicable (CLI command) ### Endpoint Not applicable (CLI command) ### Parameters #### Path Parameters Not applicable #### Query Parameters Not applicable #### Request Body Not applicable ### Parameters - `partition_id` - Partition identifier(s) (* for all, comma-separated list for multiple) - `FROM` (optional) - Starting position (LATEST, sequence number, or MAP for per-partition positions) - `WINDOW` (optional) - Maximum number of unacknowledged events ### Request Example ``` EPSUB * # All partitions, latest EPSUB * WINDOW 100 # All partitions, latest, window 100 EPSUB * FROM 1000 WINDOW 100 # All partitions, from seq 1000 EPSUB 5 FROM 100 WINDOW 50 # Partition 5, from seq 100 EPSUB 1,2,3 FROM MAP 1=100 2=200 DEFAULT 0 WINDOW 500 ``` ### Response #### Success Response Establishes a persistent connection for real-time event delivery. #### Response Example Not applicable (persistent connection). ``` -------------------------------- ### Actor with Derive Macro Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Implement an actor using the derive macro for simplified setup. This is the recommended approach for most use cases. ```rust use kameo::{Actor, RemoteActor}; #[derive(Actor, RemoteActor)] pub struct MyActor; ``` -------------------------------- ### Implement next Method for CurrentVersion Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Provides a method to get the next version from the CurrentVersion enum. This is a placeholder implementation. ```rust pub fn next(self: &Self) -> u64 { /* ... */ } ``` -------------------------------- ### Install Custom Actor Error Hook in Kameo Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Use this to define and install a custom function that will be called when an actor panics. The hook is global and replaces any existing hook. ```rust use kameo::error::{set_actor_error_hook, PanicError}; // Define a custom error hook fn my_custom_hook(err: &PanicError) { // log the error or something... } // Install the custom hook set_actor_error_hook(my_custom_hook); ``` -------------------------------- ### OpenPartitionIndex: Get Method Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Retrieves a reference to a PartitionIndexRecord for a given partition ID, if it exists. ```rust pub fn get(self: &Self, partition_id: PartitionId) -> Option<&PartitionIndexRecord> { /* ... */ } ``` -------------------------------- ### Get Coordinator for Partition (Rust) Source: https://github.com/sierra-db/sierradb/blob/main/docs/Distributed Write Protocol Specification.md Selects the oldest healthy replica as the coordinator for a given partition. Relies on startup timestamp and peer ID for deterministic selection and failover. ```rust fn get_coordinator_for_partition(partition_id: PartitionId) -> NodeId { let replicas = get_replicas_for_partition(partition_id); let healthy_replicas = replicas.filter(|node| node.is_healthy()); // Sort by startup timestamp (ascending), then by peer_id as tiebreaker healthy_replicas.sort_by_key(|node| (node.startup_timestamp, node.peer_id)); healthy_replicas.first().unwrap() } ``` -------------------------------- ### Create New Registry Behaviour Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Initializes a new registry behaviour with a local peer ID. This is the starting point for registry operations. ```rust pub fn new(local_peer_id: PeerId) -> Self { /* ... */ } ``` -------------------------------- ### Subscribe to New Events Source: https://github.com/sierra-db/sierradb/blob/main/README.md Subscribe to the 'user-123' stream to receive new events in real-time, starting from the latest event. ```bash # Subscribe to new events (will stream in real-time) ESUB user-123 FROM LATEST ``` -------------------------------- ### Actor::spawn Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Spawns a new actor instance in a Tokio task with a default bounded mailbox. This is the standard way to start an actor. ```APIDOC ## Actor::spawn ### Description Spawns the actor in a Tokio task, running asynchronously with a default bounded mailbox. ### Method ```rust fn spawn(args: ::Args) -> ActorRef ``` ``` -------------------------------- ### Spawn Actor with Default Mailbox Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Spawns an actor in a Tokio task with a default bounded mailbox. This is the standard way to start an actor. ```rust fn spawn(args: ::Args) -> ActorRef { /* ... */ } ``` -------------------------------- ### Re-export PreparedActor Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Re-exports 'PreparedActor' from the 'actor' module. This type is used in actor setup. ```rust pub use crate::actor::PreparedActor; ``` -------------------------------- ### Embed SierraDB in a Rust Application Source: https://github.com/sierra-db/sierradb/blob/main/README.md Example of opening a local SierraDB instance and appending a new event transactionally within a Rust application. Requires the `sierradb` and `uuid` crates. ```rust use std::time::{SystemTime, UNIX_EPOCH}; use sierradb::{Database, Transaction, NewEvent, StreamId}; use sierradb::id::{NAMESPACE_PARTITION_KEY, uuid_to_partition_hash, uuid_v7_with_partition_hash}; use sierradb_protocol::ExpectedVersion; use uuid::Uuid; #[tokio::main] async fn main() -> Result<(), Box> { // Open database directly let db = Database::open("./data")?; // Create and append events let stream_id = StreamId::new("user-123")?; let partition_key = Uuid::new_v5(&NAMESPACE_PARTITION_KEY, stream_id.as_bytes()); let partition_hash = uuid_to_partition_hash(partition_key); let partition_id = uuid_v7_with_partition_hash(partition_hash); let timestamp = SystemTime::now()? .duration_since(UNIX_EPOCH)? .as_nanos() as u64; let transaction = Transaction::new( partition_key, partition_id, vec![NewEvent { event_id: Uuid::new_v4(), stream_id, stream_version: ExpectedVersion::Empty, event_name: "UserCreated".into(), timestamp, payload: br#"{"name":"john"}"#.to_vec(), metadata: vec![], }] )?; let result = db.append_events(transaction).await?; println!("Event appended with sequence: {}", result.first_partition_sequence); Ok(()) } ``` -------------------------------- ### Define Actor with Derive Macro Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Use the `#[derive(Actor)]` macro for a concise way to define a Kameo actor. No additional setup is required. ```rust use kameo::Actor; #[derive(Actor)] struct MyActor; ``` -------------------------------- ### Deriving Reply Trait Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Example of deriving the Reply trait for a custom struct. ```rust use kameo::Reply; #[derive(Reply)] pub struct Foo { } ``` -------------------------------- ### Database::read_partition Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Reads events from a partition starting from a specified sequence number. ```APIDOC ## Database::read_partition ### Description Reads events from a partition starting from a specified sequence number. ### Method `Database::read_partition` ### Parameters - `self`: `&Self` - An immutable reference to the `Database` instance. - `partition_id`: `PartitionId` - The ID of the partition. - `from_sequence`: `u64` - The sequence number to start reading from. ### Returns - `Result` - Returns a `PartitionEventIter` iterator on success or a `PartitionIndexError` on failure. ``` -------------------------------- ### Subscribe to Stream Events Source: https://github.com/sierra-db/sierradb/blob/main/README.md Establishes a persistent connection to receive real-time events from one or more streams. Supports specifying a starting position and a window size for unacknowledged events. ```resp3 ESUB user-123 ``` ```resp3 ESUB user-123 WINDOW 100 ``` ```resp3 ESUB user-123 FROM 50 WINDOW 100 ``` ```resp3 ESUB user-1 user-2 user-3 FROM MAP user-1=10 user-2=20 user-3=30 WINDOW 50 ``` -------------------------------- ### Get Channel Length Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Returns the current number of messages waiting in the channel. ```rust pub fn len(self: &Self) -> usize { /* ... */ } ``` -------------------------------- ### Get Transaction ID Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Returns the unique transaction identifier, represented as a `Uuid`. ```rust pub fn transaction_id(self: &Self) -> Uuid { /* ... */ } ``` -------------------------------- ### DatabaseBuilder: open() Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Opens a database instance at the specified directory. Requires a path that can be converted into a PathBuf. ```rust pub fn open: Into>(self: &Self, dir: impl Into) -> Result { /* ... */ } ``` -------------------------------- ### ESUB - Subscribe to Stream Events Source: https://github.com/sierra-db/sierradb/blob/main/README.md Establishes a persistent connection to subscribe to real-time event delivery from one or more streams. Supports specifying a starting position and a window size for unacknowledged events. ```APIDOC ## ESUB - Subscribe to Stream Events ### Description Subscribe to events from one or more streams with real-time delivery. ### Method RESP3 Command ### Endpoint N/A (Command-line/Client Interface) ### Parameters #### Required Parameters - **stream_id** (string) - Stream identifier(s) to subscribe to #### Optional Parameters - **partition_key** (string) - UUID for specific partition - **FROM** (string) - Starting position (LATEST, version number, or MAP for per-stream positions) - **WINDOW** (integer) - Maximum number of unacknowledged events ### Request Example ``` # Single stream ESUB user-123 ESUB user-123 WINDOW 100 ESUB user-123 FROM 50 WINDOW 100 # Multiple streams ESUB user-1 user-2 user-3 FROM MAP user-1=10 user-2=20 user-3=30 WINDOW 50 ``` ``` -------------------------------- ### Get Current Stream Version Source: https://github.com/sierra-db/sierradb/blob/main/README.md Retrieve the current version of the 'user-123' stream. ```bash # Get the current version of the stream ESVER user-123 ``` -------------------------------- ### OpenPartitionIndex: Create Method Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Creates a new OpenPartitionIndex. Requires a bucket segment ID and a path. ```rust pub fn create: AsRef>(id: BucketSegmentId, path: impl AsRef) -> Result { /* ... */ } ``` -------------------------------- ### EPSEQ - Get Partition Sequence Source: https://github.com/sierra-db/sierradb/blob/main/README.md Retrieves the current sequence number for a given partition. ```APIDOC ## EPSEQ - Get Partition Sequence ### Description Gets the current sequence number for a partition. ### Method Not applicable (CLI command) ### Endpoint Not applicable (CLI command) ### Parameters #### Path Parameters Not applicable #### Query Parameters Not applicable #### Request Body Not applicable ### Parameters - `partition` - Partition selector (partition ID 0-65535 or UUID key) ### Request Example ``` EPSEQ 42 EPSEQ 550e8400-e29b-41d4-a716-446655440000 ``` ### Response #### Success Response The current sequence number for the partition. #### Response Example Not explicitly defined, but would be a sequence number. ``` -------------------------------- ### Method: new Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Spawns threads to process read requests in a thread pool. Use this to initialize the thread pool. ```rust pub fn new(num_workers: usize) -> Self { /* ... */ } ``` -------------------------------- ### Get Event by ID Source: https://github.com/sierra-db/sierradb/blob/main/README.md Retrieves a specific event using its unique event identifier. ```resp3 EGET 550e8400-e29b-41d4-a716-446655440000 ``` -------------------------------- ### Basic Bootstrap Function Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Provides a basic function to bootstrap the system. This is a simplified version of the main entry point. ```rust pub fn bootstrap() -> Result> { /* ... */ } ``` -------------------------------- ### HELLO - Protocol Handshake Source: https://github.com/sierra-db/sierradb/blob/main/README.md Initiates a protocol handshake with the server to retrieve essential server information. ```APIDOC ## HELLO - Protocol Handshake ### Description Perform protocol handshake and retrieve server information. ### Method Not applicable (CLI command) ### Endpoint Not applicable (CLI command) ### Parameters #### Path Parameters Not applicable #### Query Parameters Not applicable #### Request Body Not applicable ### Parameters - `version` - Protocol version (currently only 3 is supported) ### Request Example ``` HELLO 3 ``` ### Response #### Success Response - `server` (string) - Server name ("sierradb") - `version` (string) - Server version - `peer_id` (string) - Cluster peer ID - `num_partitions` (integer) - Number of partitions #### Response Example ```json { "server": "sierradb", "version": "1.0.0", "peer_id": "some-uuid", "num_partitions": 16 } ``` ``` -------------------------------- ### Get Sender Weak Count Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Returns the number of active weak references to the sender half of the channel. ```rust pub fn sender_weak_count(self: &Self) -> usize { /* ... */ } ``` -------------------------------- ### OpenPartitionIndex: Open Method Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Opens an existing OpenPartitionIndex. Requires a bucket segment ID and a path. ```rust pub fn open: AsRef>(id: BucketSegmentId, path: impl AsRef) -> Result { /* ... */ } ``` -------------------------------- ### Get Sender Strong Count Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Returns the number of active strong references to the sender half of the channel. ```rust pub fn sender_strong_count(self: &Self) -> usize { /* ... */ } ``` -------------------------------- ### Use SierraDB Rust Client for Event Operations Source: https://github.com/sierra-db/sierradb/blob/main/README.md Demonstrates using the native Rust client to append events, scan streams, and subscribe to real-time events. Requires the `sierradb-client` crate. ```rust use sierradb_client::{SierraClient, SierraAsyncClientExt, SierraMessage}; #[tokio::main] async fn main() -> Result<(), Box> { let client = SierraClient::connect("redis://localhost:9090").await?; // Append an event with type safety let options = EAppendOptions::new() .payload(br#"{"name":"john"}"#) .metadata(br#"{"source":"api"}"#); let result = client.eappend("user-123", "UserCreated", options)?; // Scan events from stream let events = client.escan("user-123", "-", None, Some(50)) .execute() .await?; // Subscribe to real-time events let mut manager = client.subscription_manager().await?; let mut subscription = manager .subscribe_to_stream_from_version("user-123", 0) .await?; while let Some(msg) = subscription.next_message().await? { println!("Received event: {msg:?}"); } Ok(()) } ``` -------------------------------- ### Get Partition Key Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Retrieves the partition key associated with the current instance. The key is of type `Uuid`. ```rust pub fn partition_key(self: &Self) -> Uuid { /* ... */ } ``` -------------------------------- ### EGET - Get Event by ID Source: https://github.com/sierra-db/sierradb/blob/main/README.md Retrieves a specific event from the database using its unique event identifier. ```APIDOC ## EGET - Get Event by ID ### Description Retrieve an event by its unique identifier. ### Method RESP3 Command ### Endpoint N/A (Command-line/Client Interface) ### Parameters #### Required Parameters - **event_id** (string) - UUID of the event to retrieve ### Request Example ``` EGET 550e8400-e29b-41d4-a716-446655440000 ``` ``` -------------------------------- ### Open Database Connection Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Opens a new database connection at the specified directory. Requires a type that can be converted into `PathBuf`. ```rust pub fn open: Into>(dir: impl Into) -> Result { /* ... */ } ``` -------------------------------- ### Actor Name Method Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Provides a static method to get the actor's name, useful for logging and debugging. ```rust fn name() -> &''static str { /* ... */ } ``` -------------------------------- ### Database::open Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Opens or creates a new SierraDB database at the specified directory path. ```APIDOC ## Database::open ### Description Opens or creates a new SierraDB database at the specified directory path. ### Method `Database::open` ### Parameters - `dir`: `impl Into` - The directory path where the database will be located. ### Returns - `Result` - Returns a `Database` instance on success or a `DatabaseError` on failure. ``` -------------------------------- ### Get Offsets from Key in ClosedStreamIndex Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Retrieves stream offsets from a given key. Returns a `Result` with `StreamOffsets` or a `StreamIndexError`. ```rust pub fn get_from_key(self: &Self, key: StreamIndexRecord) -> Result { /* ... */ } ``` -------------------------------- ### Startup Timestamp Generation Source: https://github.com/sierra-db/sierradb/blob/main/docs/Coordinator Ordering and Recovery Design.md Generates a Unix timestamp representing the node's startup time. This timestamp is crucial for the coordinator ordering mechanism. ```rust let startup_timestamp = SystemTime::now() .duration_since(UNIX_EPOCH)? .as_secs(); ``` -------------------------------- ### Get Stream Version Source: https://github.com/sierra-db/sierradb/blob/main/README.md Retrieves the current version number of a specified stream. Can optionally target a specific partition. ```resp3 ESVER my-stream ``` ```resp3 ESVER my-stream PARTITION_KEY 550e8400-e29b-41d4-a716-446655440000 ``` -------------------------------- ### Implement From for PartitionOffsets (to Self) Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Provides a From implementation for PartitionOffsets, allowing conversion from another type into Self. This is used for creating a PartitionOffsets instance from a given value. ```rust fn from(offsets: PartitionOffsets) -> Self { /* ... */ } ``` -------------------------------- ### Read Partition Events Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Iterates over events in a partition starting from a specified sequence number. Returns `Result`. ```rust pub async fn read_partition(self: &Self, partition_id: PartitionId, from_sequence: u64) -> Result { /* ... */ } ``` -------------------------------- ### Get Stream Offsets from ClosedStreamIndex Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Retrieves stream offsets for a given stream ID. Returns an `Option` of `StreamOffsets` or a `StreamIndexError`. ```rust pub fn get(self: &mut Self, stream_id: &str) -> Result, StreamIndexError> { /* ... */ } ``` -------------------------------- ### Actor::prepare Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Creates a prepared actor instance, allowing access to its ActorRef before it is spawned. This is useful for setting up actor references in advance. ```APIDOC ## Actor::prepare ### Description Creates a new prepared actor, allowing access to its [`ActorRef`] before spawning. ### Method ```rust fn prepare() -> PreparedActor ``` ``` -------------------------------- ### ESVER - Get Stream Version Source: https://github.com/sierra-db/sierradb/blob/main/README.md Retrieves the current version number of a specified stream. Can optionally filter by partition key. ```APIDOC ## ESVER - Get Stream Version ### Description Get the current version number for a stream. ### Method RESP3 Command ### Endpoint N/A (Command-line/Client Interface) ### Parameters #### Required Parameters - **stream_id** (string) - Stream identifier to get version for #### Optional Parameters - **partition_key** (string) - UUID to check specific partition ### Request Example ``` ESVER my-stream ESVER my-stream PARTITION_KEY 550e8400-e29b-41d4-a716-446655440000 ``` ``` -------------------------------- ### Prepare Actor Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Creates a new prepared actor, allowing access to its ActorRef before spawning. Useful for setting up actor references. ```rust fn prepare() -> PreparedActor { /* ... */ } ``` -------------------------------- ### from Implementation for TryFrom Trait (AddProviderError) Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Implementation of the from method for the TryFrom trait, converting libp2p::kad::AddProviderError into RegistryError. ```rust fn from(err: libp2p::kad::AddProviderError) -> Self { /* ... */ } ``` -------------------------------- ### Initialize SierraDB WriterThreadPool Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Constructs a new SierraDB WriterThreadPool instance. Requires specifying directory, segment size, bucket IDs, thread count, flush intervals, and thread pools. ```rust pub fn new: Into>(dir: impl Into, segment_size: usize, bucket_ids: Arc<[BucketId]>, num_threads: u16, flush_interval_duration: Duration, flush_interval_events: u32, reader_pool: &ReaderThreadPool, thread_pool: &Arc) -> Result { /* ... */ } ``` -------------------------------- ### Add Kameo Dependency via Command Line Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Add Kameo as a dependency to your project using the cargo add command. ```bash cargo add kameo ``` -------------------------------- ### Seglog Writer with Custom Header Size Source: https://github.com/sierra-db/sierradb/blob/main/crates/seglog/README.md Shows how to create a segment file with a pre-allocated header space for application-specific data. Records are appended after the header. ```rust const HEADER_SIZE: u64 = 64; let mut writer = Writer::create("segment.log", 1024 * 1024, HEADER_SIZE)?; // Write header data writer.file().write_all_at(b"MAGIC", 0)?; // Records automatically start after header writer.append(b"data")?; ``` -------------------------------- ### Basic Event Operations with redis-cli Source: https://github.com/sierra-db/sierradb/blob/main/README.md Perform basic event operations like appending, reading, and subscribing to streams using the redis-cli. ```bash # Connect with any Redis client redis-cli -p 9090 # Append events to streams EAPPEND order-456 OrderCreated EXPECTED_VERSION empty PAYLOAD '{"total":99.99,"items":["laptop"]}' # Read events back ESCAN orders - + COUNT 100 # Subscribe to real-time events ESUB orders FROM LATEST ``` -------------------------------- ### Get Weak Count of MailboxSender Handles Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Returns the number of `WeakMailboxSender` handles associated with this sender. This indicates the number of weak references. ```rust pub fn weak_count(self: &Self) -> usize { /* ... */ } ``` -------------------------------- ### Prepare Actor with Custom Mailbox Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Creates a new prepared actor with a specific mailbox configuration. Allows for pre-spawning configuration of mailboxes. ```rust fn prepare_with_mailbox((mailbox_tx, mailbox_rx): (MailboxSender, MailboxReceiver)) -> PreparedActor { /* ... */ } ``` -------------------------------- ### Get Flag from UUID Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Retrieves the boolean value of a specific flag from a UUID. Use this to check the status of a flag within a UUID. ```rust pub fn get_uuid_flag(uuid: &uuid::Uuid) -> bool { /* ... */ } ``` -------------------------------- ### Get Stream Version Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Retrieves the latest version of a specific stream within a partition. Returns `Result, StreamIndexError>`. ```rust pub async fn get_stream_version(self: &Self, partition_id: PartitionId, stream_id: &Arc) -> Result, StreamIndexError> { /* ... */ } ``` -------------------------------- ### Implement From for PartitionOffsets (identity) Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Provides an identity From implementation for PartitionOffsets, where `T` is converted from `T` unchanged. This is a simple conversion that returns the argument. ```rust fn from(t: T) -> T { /* ... */ } Returns the argument unchanged. ``` -------------------------------- ### Get Latest Partition Sequence Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Retrieves the sequence number of the latest event in a partition. Returns `Result, PartitionIndexError>`. ```rust pub async fn get_partition_sequence(self: &Self, partition_id: PartitionId) -> Result, PartitionIndexError> { /* ... */ } ``` -------------------------------- ### from Implementation for TryFrom Trait (Store Error) Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Implementation of the from method for the TryFrom trait, converting libp2p::kad::store::Error into RegistryError. ```rust fn from(err: libp2p::kad::store::Error) -> Self { /* ... */ } ``` -------------------------------- ### Get Key from ClosedStreamIndex Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Retrieves a stream index record using a stream ID. Returns an `Option` of `StreamIndexRecord` or a `StreamIndexError`. ```rust pub fn get_key(self: &mut Self, stream_id: &str) -> Result>, StreamIndexError> { /* ... */ } ``` -------------------------------- ### Actor::prepare_with_mailbox Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Creates a prepared actor with a specific mailbox configuration. This allows for pre-configuration of the actor's message handling before it is spawned. ```APIDOC ## Actor::prepare_with_mailbox ### Description Creates a new prepared actor with a specific mailbox configuration, allowing access to its [`ActorRef`] before spawning. ### Method ```rust fn prepare_with_mailbox((mailbox_tx, mailbox_rx): (MailboxSender, MailboxReceiver)) -> PreparedActor ``` ``` -------------------------------- ### Create OpenStreamIndex Instance Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Creates a new OpenStreamIndex instance. Requires a bucket segment ID, a path, and a segment size. ```rust pub fn create: AsRef>(id: BucketSegmentId, path: impl AsRef, segment_size: usize) -> Result { /* ... */ } ``` -------------------------------- ### Get Stream Index Record Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Retrieves a stream index record by its stream ID. Returns None if the stream ID is not found. ```rust pub fn get(self: &Self, stream_id: &str) -> Option<&StreamIndexRecord> { /* ... */ } ``` -------------------------------- ### Interact with SierraDB using redis-cli Source: https://github.com/sierra-db/sierradb/blob/main/README.md Connect to a running SierraDB instance using redis-cli and execute event store commands. ```bash # In another terminal, use redis-cli to interact with SierraDB redis-cli -p 9090 ``` -------------------------------- ### Get Offsets from Key in ClosedPartitionIndex Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Retrieves partition offsets based on a provided `PartitionIndexRecord`. This method operates on an immutable reference to `ClosedPartitionIndex`. ```rust pub fn get_from_key(self: &Self, key: PartitionIndexRecord) -> Result { /* ... */ } ``` -------------------------------- ### Define StreamMessage Enum Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Defines the StreamMessage enum with variants for Next, Started, and Finished stream events. Typically used with ActorRef::attach_stream. ```rust pub enum StreamMessage { Next(T), Started(S), Finished(F), } ``` -------------------------------- ### Pointable::init Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Initializes a Pointable object. This is an unsafe method and requires careful handling. ```APIDOC ## Pointable::init ### Description Initializes a Pointable object. This is an unsafe method and requires careful handling. ### Method Trait Method (Pointable) ### Signature ```rust unsafe fn init(init: ::Init) -> usize ``` ### Parameters - **init** (::Init) - The initialization data for the Pointable object. ``` -------------------------------- ### Get Strong Count of MailboxSender Handles Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Returns the number of active `MailboxSender` handles. This indicates how many strong references exist to the sender. ```rust pub fn strong_count(self: &Self) -> usize { /* ... */ } ``` -------------------------------- ### Run SierraDB with Docker Source: https://github.com/sierra-db/sierradb/blob/main/README.md Run SierraDB using Docker with persistent data storage mounted to a local directory. ```bash # Run with persistent data docker run -p 9090:9090 -v ./data:/app/data tqwewe/sierradb ``` -------------------------------- ### Get SierraDB Indexes Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Retrieves the indexes for all buckets within the SierraDB instance. This provides access to atomic counters and live index data. ```rust pub fn indexes(self: &Self) -> &Arc, LiveIndexes)>> { /* ... */ } ``` -------------------------------- ### from Implementation for TryFrom Trait (GetProvidersError) Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Implementation of the from method for the TryFrom trait, converting libp2p::kad::GetProvidersError into RegistryError. ```rust fn from(err: libp2p::kad::GetProvidersError) -> Self { /* ... */ } ``` -------------------------------- ### Get Key from ClosedPartitionIndex Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Retrieves the index record for a given partition ID from a mutable reference to `ClosedPartitionIndex`. Returns an `Option` of the record or a `PartitionIndexError`. ```rust pub fn get_key(self: &mut Self, partition_id: PartitionId) -> Result>, PartitionIndexError> { /* ... */ } ``` -------------------------------- ### WriterThreadPool::new Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Constructs a new WriterThreadPool. ```APIDOC ## WriterThreadPool::new ### Description Constructs a new WriterThreadPool. ### Method ```rust pub fn new: Into>(dir: impl Into, segment_size: usize, bucket_ids: Arc<[BucketId]>, num_threads: u16, flush_interval_duration: Duration, flush_interval_events: u32, reader_pool: &ReaderThreadPool, thread_pool: &Arc) -> Result ``` ``` -------------------------------- ### Method: get EventIndex Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Retrieves the offset for a given event ID from the event index. Returns an Option representing the offset if found. ```rust pub fn get(self: &Self, event_id: &Uuid) -> Option { /* ... */ } ``` -------------------------------- ### Get Current Sequence Number for a Partition Source: https://github.com/sierra-db/sierradb/blob/main/README.md Retrieves the current sequence number for a given partition. Supports partition IDs or UUID keys. ```shell EPSEQ 42 ``` ```shell EPSEQ 550e8400-e29b-41d4-a716-446655440000 ``` -------------------------------- ### Create and Push Git Tag Source: https://github.com/sierra-db/sierradb/blob/main/RELEASING.md Create a Git tag for the new version and push it to the remote repository, along with all other local branches. This action triggers the release workflow. ```bash git tag vX.Y.Z git push && git push --tags ``` -------------------------------- ### OpenPartitionIndex: Insert External Bucket Method Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Inserts an external bucket reference for a given partition ID. ```rust pub fn insert_external_bucket(self: &mut Self, partition_id: PartitionId) -> Result<(), PartitionIndexError> { /* ... */ } ``` -------------------------------- ### Get Actor Reference in Rust Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Retrieves the current actor's reference, enabling messages to be sent to itself. This method takes an immutable reference to self. ```rust pub fn actor_ref(self: &Self) -> ActorRef { /* ... */ } ``` -------------------------------- ### SegmentKind Get Path Method Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Constructs the full file path for a specific segment file given a base directory and bucket segment ID. ```rust pub fn get_path(self: &Self, base_dir: &Path, bucket_segment_id: BucketSegmentId) -> PathBuf { /* ... */ } ``` -------------------------------- ### Implement PartialEq for PartitionOffsets Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Defines the equality comparison for PartitionOffsets. This allows checking if two PartitionOffsets instances are equal. ```rust fn eq(self: &Self, other: &PartitionOffsets) -> bool { /* ... */ } ``` -------------------------------- ### from Implementation for TryFrom Trait (PutRecordError) Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Implementation of the from method for the TryFrom trait, converting libp2p::kad::PutRecordError into RegistryError. ```rust fn from(err: libp2p::kad::PutRecordError) -> Self { /* ... */ } ``` -------------------------------- ### Create New Event Instance Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Constructs a new `NewEvent` instance with a specified partition hash and a small collection of events. Returns a `Result` which can be an `EventValidationError`. ```rust pub fn new(partition_hash: PartitionHash, events: SmallVec<[NewEvent; 4]>) -> Result { /* ... */ } ``` -------------------------------- ### OpenStreamIndex::create Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Creates a new stream index at the specified path. This is a constructor method for initializing a stream index. ```APIDOC ## OpenStreamIndex::create ### Description Creates a new stream index at the specified path. This is a constructor method for initializing a stream index. ### Method ```rust pub fn create: AsRef>(id: BucketSegmentId, path: impl AsRef, segment_size: usize) -> Result ``` ### Parameters - **id**: `BucketSegmentId` - Identifier for the bucket segment. - **path**: `impl AsRef` - The file system path where the index will be created. - **segment_size**: `usize` - The size of the segments for the index. ### Returns - `Result` - Ok containing the new `OpenStreamIndex` on success, or a `StreamIndexError` on failure. ``` -------------------------------- ### Get Partition Offsets by ID Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Retrieves partition offsets for a specific partition ID using a mutable reference to `ClosedPartitionIndex`. Returns an `Option` of `PartitionOffsets` or a `PartitionIndexError`. ```rust pub fn get(self: &mut Self, partition_id: PartitionId) -> Result, PartitionIndexError> { /* ... */ } ``` -------------------------------- ### Open Existing OpenStreamIndex Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Opens an existing OpenStreamIndex instance. Requires a bucket segment ID, a path, and a segment size. ```rust pub fn open: AsRef>(id: BucketSegmentId, path: impl AsRef, segment_size: usize) -> Result { /* ... */ } ``` -------------------------------- ### Method: open EventIndex Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Opens an existing event index from the specified path. Requires a bucket segment ID and a path that can be referenced as a path. ```rust pub fn open: AsRef>(id: BucketSegmentId, path: impl AsRef) -> Result { /* ... */ } ``` -------------------------------- ### Perform Protocol Handshake Source: https://github.com/sierra-db/sierradb/blob/main/README.md Initiates a protocol handshake with the server using a specified protocol version. Retrieves server information upon success. ```shell HELLO 3 ``` -------------------------------- ### Implement Downcast for References Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Provides methods to get references to the underlying `Any` trait object from a `WithoutRequestTimeout` instance. This allows for runtime type inspection without consuming the value. ```rust fn as_any(self: &Self) -> &dyn Any + ''static { /* ... */ } ``` ```rust fn as_any_mut(self: &mut Self) -> &mut dyn Any + ''static { /* ... */ } ``` -------------------------------- ### Combine Debugging Options for Fuzz Test Source: https://github.com/sierra-db/sierradb/blob/main/debug_fuzzer.md Combine `FUZZ_DEBUG=1` and `FUZZ_PANIC_ON_MODEL_ERROR=1` for maximum debugging insight, enabling detailed input logging and panicking on model errors. ```bash FUZZ_DEBUG=1 FUZZ_PANIC_ON_MODEL_ERROR=1 cargo fuzz run commands ``` -------------------------------- ### Create Bounded Mailbox Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Creates a bounded mailbox for actor communication with backpressure. Based on tokio's mpsc::channel. ```rust pub fn bounded(buffer: usize) -> (MailboxSender, MailboxReceiver) { /* ... */ } ``` -------------------------------- ### Upgrade MailboxSender Source: https://github.com/sierra-db/sierradb/blob/main/docs/Kameo Docs.md Tries to convert a WeakMailboxSender into a MailboxSender. Returns Some on success. ```rust pub fn upgrade(self: &Self) -> Option> { /* ... */ } ``` -------------------------------- ### Read Transaction Events Source: https://github.com/sierra-db/sierradb/blob/main/docs/Sierra Docs.md Reads all events belonging to a transaction, starting from a given event ID within a partition. Can optionally read only headers. Returns `Result, ReadError>`. ```rust pub async fn read_transaction(self: &Self, partition_id: PartitionId, first_event_id: Uuid, header_only: bool) -> Result, ReadError> { /* ... */ } ``` -------------------------------- ### Check Formatting with Cargo Source: https://github.com/sierra-db/sierradb/blob/main/RELEASING.md Verify that the code adheres to the project's formatting standards using `cargo fmt --check`. This is a required check before publishing. ```bash cargo fmt --check ``` -------------------------------- ### Replica Catch-Up Protocol Implementation Source: https://github.com/sierra-db/sierradb/blob/main/docs/Distributed Write Protocol Specification.md This Rust code snippet shows how a replica detects it is behind and requests missing events from the coordinator to synchronize its state. It then applies the received events and resumes normal processing. ```rust async fn catch_up_partition(&self, partition_id: PartitionId, from_seq: u64) { let coordinator = self.get_coordinator_for_partition(partition_id); // Request missing events let request = PartitionSyncRequest { partition_id, from_sequence: from_seq, to_sequence: None, // Get all available }; let events = coordinator.sync_partition(request).await?; // Apply events in order for event in events { self.apply_write_locally(event).await?; } // Resume normal processing self.resume_write_processing(partition_id).await; } ```