add some compaction related interfaces

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-01-18 12:05:07 +00:00
parent 8ab825b12c
commit dda27ffcb1
7 changed files with 188 additions and 8 deletions

View file

@ -18,9 +18,16 @@ use std::{
};
use conduwuit::{debug, info, warn, Err, Result};
use rocksdb::{AsColumnFamilyRef, BoundColumnFamily, DBCommon, DBWithThreadMode, MultiThreaded};
use rocksdb::{
AsColumnFamilyRef, BoundColumnFamily, DBCommon, DBWithThreadMode, MultiThreaded,
WaitForCompactOptions,
};
use crate::{pool::Pool, result, Context};
use crate::{
pool::Pool,
util::{map_err, result},
Context,
};
pub struct Engine {
pub(super) read_only: bool,
@ -55,12 +62,22 @@ impl Engine {
#[tracing::instrument(skip(self), level = "debug")]
pub fn flush(&self) -> Result { result(DBCommon::flush_wal(&self.db, false)) }
#[tracing::instrument(skip(self), level = "debug")]
#[tracing::instrument(skip(self), level = "info")]
pub fn sort(&self) -> Result {
let flushoptions = rocksdb::FlushOptions::default();
result(DBCommon::flush_opt(&self.db, &flushoptions))
}
#[tracing::instrument(skip(self), level = "info")]
pub fn wait_compactions(&self) -> Result {
let mut opts = WaitForCompactOptions::default();
opts.set_abort_on_pause(true);
opts.set_flush(false);
opts.set_timeout(0);
self.db.wait_for_compact(&opts).map_err(map_err)
}
/// Query for database property by null-terminated name which is expected to
/// have a result with an integer representation. This is intended for
/// low-overhead programmatic use.