Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/db_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/db_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct DBIterator {
}

impl DBIterator {
pub fn new(
pub(crate) fn new(
cmp: Rc<Box<dyn Cmp>>,
vset: Shared<VersionSet>,
iter: MergingIter,
Expand Down
2 changes: 1 addition & 1 deletion src/disk_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 2 additions & 0 deletions src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InnerSnapshot>,
Expand Down
22 changes: 17 additions & 5 deletions src/write_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
}

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);

Expand Down Expand Up @@ -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 {
Expand Down
Loading