ckb_rocksdb/ops/
flush.rs

1use crate::ffi;
2use crate::{ColumnFamily, Error, FlushOptions, handle::Handle};
3
4pub trait Flush {
5    //// Flushes database memtables to SST files on the disk.
6    fn flush_opt(&self, flushopts: &FlushOptions) -> Result<(), Error>;
7
8    /// Flushes database memtables to SST files on the disk using default options.
9    fn flush(&self) -> Result<(), Error> {
10        self.flush_opt(&FlushOptions::default())
11    }
12}
13
14#[allow(dead_code)]
15pub trait FlushCF {
16    /// Flushes database memtables to SST files on the disk for a given column family.
17    fn flush_cf_opt(&self, cf: &ColumnFamily, flushopts: &FlushOptions) -> Result<(), Error>;
18
19    /// Flushes database memtables to SST files on the disk for a given column family using default
20    /// options.
21    fn flush_cf(&self, cf: &ColumnFamily) -> Result<(), Error> {
22        self.flush_cf_opt(cf, &FlushOptions::default())
23    }
24}
25
26impl<T> Flush for T
27where
28    T: Handle<ffi::rocksdb_t> + super::Write,
29{
30    fn flush_opt(&self, flushopts: &FlushOptions) -> Result<(), Error> {
31        unsafe {
32            ffi_try!(ffi::rocksdb_flush(self.handle(), flushopts.inner,));
33        }
34        Ok(())
35    }
36}
37
38impl<T> FlushCF for T
39where
40    T: Handle<ffi::rocksdb_t> + super::Write,
41{
42    fn flush_cf_opt(&self, cf: &ColumnFamily, flushopts: &FlushOptions) -> Result<(), Error> {
43        unsafe {
44            ffi_try!(ffi::rocksdb_flush_cf(
45                self.handle(),
46                flushopts.inner,
47                cf.inner,
48            ));
49        }
50        Ok(())
51    }
52}