Skip to content

Commit

Permalink
add file listing to database abstraction.
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Volk <[email protected]>
  • Loading branch information
jevolk committed Mar 23, 2024
1 parent 56edb35 commit f07f082
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/database/abstraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub(crate) trait KeyValueDatabaseEngine: Send + Sync {
fn backup(&self) -> Result<(), Box<dyn Error>> { unimplemented!() }

fn backup_list(&self) -> Result<String> { Ok(String::new()) }

fn file_list(&self) -> Result<String> { Ok(String::new()) }
}

pub(crate) trait KvTree: Send + Sync {
Expand Down
24 changes: 24 additions & 0 deletions src/database/abstraction/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,30 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
Ok(res)
}

fn file_list(&self) -> Result<String> {
match self.rocks.live_files() {
Err(e) => Ok(String::from(e)),
Ok(files) => {
let mut res = String::new();
for file in files {
let _ = std::fmt::write(
&mut res,
format_args!(
"<code>L{} {:<13} {:7}+ {:4}- {:9}</code> {}<br>",
file.level,
file.name,
file.num_entries,
file.num_deletions,
file.size,
file.column_family_name,
),
);
}
Ok(res)
},
}
}

// TODO: figure out if this is needed for rocksdb
#[allow(dead_code)]
fn clear_caches(&self) {}
Expand Down
2 changes: 2 additions & 0 deletions src/database/key_value/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,6 @@ lasttimelinecount_cache: {lasttimelinecount_cache}\n"
fn backup(&self) -> Result<(), Box<dyn std::error::Error>> { self.db.backup() }

fn backup_list(&self) -> Result<String> { self.db.backup_list() }

fn file_list(&self) -> Result<String> { self.db.file_list() }
}
1 change: 1 addition & 0 deletions src/service/globals/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ pub trait Data: Send + Sync {
fn bump_database_version(&self, new_version: u64) -> Result<()>;
fn backup(&self) -> Result<(), Box<dyn Error>> { unimplemented!() }
fn backup_list(&self) -> Result<String> { Ok(String::new()) }
fn file_list(&self) -> Result<String> { Ok(String::new()) }
}

0 comments on commit f07f082

Please sign in to comment.