aboutsummaryrefslogtreecommitdiff
path: root/src/db/lib.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2024-03-14 17:24:53 +0100
committerAlex Auvolat <alex@adnab.me>2024-03-15 10:57:22 +0100
commit8dff278b7227007d8a2c2f6c6d6f76c0c5d7a1ac (patch)
tree6fa6fff6b64a1f5f4c74b72cce9ca30c971f5d55 /src/db/lib.rs
parenta80ce6ab5ad9834c3721eeb4f626d53c9a8bb1f4 (diff)
downloadgarage-8dff278b7227007d8a2c2f6c6d6f76c0c5d7a1ac.tar.gz
garage-8dff278b7227007d8a2c2f6c6d6f76c0c5d7a1ac.zip
[db-snapshot] Implement db snapshotting logic in garage_db
Diffstat (limited to 'src/db/lib.rs')
-rw-r--r--src/db/lib.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/db/lib.rs b/src/db/lib.rs
index 0fb457ce..7f19172f 100644
--- a/src/db/lib.rs
+++ b/src/db/lib.rs
@@ -19,6 +19,7 @@ use core::ops::{Bound, RangeBounds};
use std::borrow::Cow;
use std::cell::Cell;
+use std::path::PathBuf;
use std::sync::Arc;
use err_derive::Error;
@@ -48,6 +49,12 @@ pub type TxValueIter<'a> = Box<dyn std::iter::Iterator<Item = TxOpResult<(Value,
#[error(display = "{}", _0)]
pub struct Error(pub Cow<'static, str>);
+impl From<std::io::Error> for Error {
+ fn from(e: std::io::Error) -> Error {
+ Error(format!("IO: {}", e).into())
+ }
+}
+
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Error)]
@@ -129,6 +136,10 @@ impl Db {
}
}
+ pub fn snapshot(&self, path: &PathBuf) -> Result<()> {
+ self.0.snapshot(path)
+ }
+
pub fn import(&self, other: &Db) -> Result<()> {
let existing_trees = self.list_trees()?;
if !existing_trees.is_empty() {
@@ -325,6 +336,7 @@ pub(crate) trait IDb: Send + Sync {
fn engine(&self) -> String;
fn open_tree(&self, name: &str) -> Result<usize>;
fn list_trees(&self) -> Result<Vec<String>>;
+ fn snapshot(&self, path: &PathBuf) -> Result<()>;
fn get(&self, tree: usize, key: &[u8]) -> Result<Option<Value>>;
fn len(&self, tree: usize) -> Result<usize>;