diff --git a/src/db_impl.rs b/src/db_impl.rs index 6f4af7f..075c419 100644 --- a/src/db_impl.rs +++ b/src/db_impl.rs @@ -279,7 +279,6 @@ impl DB { save_manifest = true; mem = MemTable::new(cmp.clone()); } - batch.clear(); } // Check if we can reuse the last log file. diff --git a/src/db_iter.rs b/src/db_iter.rs index e0f5e05..93a1a1f 100644 --- a/src/db_iter.rs +++ b/src/db_iter.rs @@ -33,7 +33,7 @@ pub struct DBIterator { } impl DBIterator { - pub fn new( + pub(crate) fn new( cmp: Rc>, vset: Shared, iter: MergingIter, diff --git a/src/disk_env.rs b/src/disk_env.rs index fb314b8..56e7fcb 100644 --- a/src/disk_env.rs +++ b/src/disk_env.rs @@ -161,7 +161,7 @@ impl Env for PosixDiskEnv { ) } else { let f = locks.remove(&l.id).unwrap(); - if f.unlock().is_err() { + if FileExt::unlock(&f).is_err() { return err(StatusCode::LockError, &format!("unlock failed: {}", l.id)); } Ok(()) diff --git a/src/lib.rs b/src/lib.rs index 921aea0..649e5d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -109,5 +109,6 @@ pub use filter::{BloomPolicy, FilterPolicy}; pub use mem_env::MemEnv; pub use options::{in_memory, CompressorList, Options}; pub use skipmap::SkipMap; +pub use snapshot::Snapshot; pub use types::LdbIterator; pub use write_batch::WriteBatch; diff --git a/src/snapshot.rs b/src/snapshot.rs index 9f597ad..7c48b67 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -22,6 +22,8 @@ impl Drop for InnerSnapshot { } } +/// Can be obtained from [`DB::get_snapshot`](crate::DB::get_snapshot), and used +/// in some methods of the DB. #[derive(Clone)] pub struct Snapshot { inner: Rc, diff --git a/src/write_batch.rs b/src/write_batch.rs index 3a6a47d..82dff33 100644 --- a/src/write_batch.rs +++ b/src/write_batch.rs @@ -11,15 +11,26 @@ const HEADER_SIZE: usize = 12; /// A WriteBatch contains entries to be written to a MemTable (for example) in a compact form. /// -/// The storage format is (with the respective length in bytes) +/// The storage format has a 12-byte header: an 8-byte little-endian sequence number, followed by +/// a 4-byte little-endian count of entries. The header's sequence number is zero until the +/// WriteBatch is encoded with a given sequence number. /// -/// [tag: 1, keylen: ~var, key: keylen, vallen: ~var, val: vallen] +/// After the header are entries with one of the following formats +/// (with respective lengths in bytes, where ~var denotes a varint): +/// - [tag: 1, keylen: ~var, key: keylen] +/// - [tag: 1, keylen: ~var, key: keylen, vallen: ~var, val: vallen] +/// +/// A WriteBatch entry for `delete` uses a tag of 0 and the first format (with only a key). +/// +/// A WriteBatch entry for `put` uses a tag of 1 and the second format +/// (that includes both a key and value). pub struct WriteBatch { entries: Vec, } impl WriteBatch { - pub(crate) fn new() -> WriteBatch { + /// Initializes an empty WriteBatch with only a 12-byte header, set to zero. + pub fn new() -> WriteBatch { let mut v = Vec::with_capacity(128); v.resize(HEADER_SIZE, 0); @@ -60,9 +71,10 @@ impl WriteBatch { self.set_count(c + 1); } - /// Clear the contents of a WriteBatch. + /// Clear the contents of a WriteBatch, and set the 12 header bytes to 0. pub fn clear(&mut self) { - self.entries.clear() + self.entries.clear(); + self.entries.resize(HEADER_SIZE, 0); } fn byte_size(&self) -> usize {