Checkpoint and Restore
Creating a Checkpoint
Section titled “Creating a Checkpoint”To create a checkpoint, use the create_checkpoint
function provided by SlateDB.
This operation captures a consistent and durable view of the database state, anchored to a specific manifest version.
use slatedb::admin::AdminBuilder;use slatedb::config::CheckpointOptions;use slatedb::object_store::memory::InMemory;use slatedb::Db;use std::{sync::Arc, time::Duration};
#[tokio::main]async fn main() -> anyhow::Result<()> { let path = "/tmp/slatedb-checkpoint"; let object_store = Arc::new(InMemory::new()); let db = Db::open(path, object_store.clone()).await?;
db.close().await?;
let admin = AdminBuilder::new(path, object_store).build();
let result = admin .create_detached_checkpoint(&CheckpointOptions { lifetime: Some(Duration::from_secs(3600)), // expires in 1 hour ..Default::default() }) .await?;
println!( "Created checkpoint: ID = {}, Manifest = {}", result.id, result.manifest_id );
Ok(())}
Refreshing a Checkpoint
Section titled “Refreshing a Checkpoint”To extend the lifetime of an existing checkpoint, use Db::refresh_checkpoint
.
This updates the checkpoint’s expiration time, ensuring that the referenced SSTs remain protected from garbage collection for the specified duration.
use slatedb::admin::AdminBuilder;use slatedb::config::CheckpointOptions;use slatedb::object_store::memory::InMemory;use slatedb::Db;use std::{sync::Arc, time::Duration};
#[tokio::main]async fn main() -> anyhow::Result<()> { let path = "/tmp/slatedb-checkpoint"; let object_store = Arc::new(InMemory::new()); let db = Db::open(path, object_store.clone()).await?;
db.close().await?;
let admin = AdminBuilder::new(path, object_store).build();
let result = admin .create_detached_checkpoint(&CheckpointOptions { lifetime: Some(Duration::from_secs(3600)), // expires in 1 hour ..Default::default() }) .await?;
admin .refresh_checkpoint(result.id, Some(Duration::from_secs(7200))) .await?;
println!( "Checkpoint refreshed with extended 2-hour lifetime. ID: {}", result.id );
Ok(())}
Deleting a Checkpoint
Section titled “Deleting a Checkpoint”To remove a checkpoint, use Db::delete_checkpoint
.
This deletes the checkpoint metadata from the manifest, allowing the garbage collector to eventually reclaim any unreferenced SST files associated with that checkpoint.
use slatedb::admin::AdminBuilder;use slatedb::config::CheckpointOptions;use slatedb::object_store::memory::InMemory;use slatedb::Db;use std::{sync::Arc, time::Duration};
#[tokio::main]async fn main() -> anyhow::Result<()> { let path = "/tmp/slatedb-checkpoint"; let object_store = Arc::new(InMemory::new()); let db = Db::open(path, object_store.clone()).await?;
db.close().await?;
let admin = AdminBuilder::new(path, object_store).build();
let result = admin .create_detached_checkpoint(&CheckpointOptions { lifetime: Some(Duration::from_secs(3600)), // expires in 1 hour ..Default::default() }) .await?;
admin.delete_checkpoint(result.id).await?;
println!("Deleted checkpoint: ID = {}", result.id);
Ok(())}