Skip to content

Commit

Permalink
Update member names
Browse files Browse the repository at this point in the history
  • Loading branch information
DouglasDwyer committed Oct 22, 2023
1 parent e5aa450 commit 14693c0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 26 deletions.
9 changes: 2 additions & 7 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,6 @@ impl Database {
Self::builder().open(path)
}

/// Opens a redb database for the given backend.
pub fn open_backend(backend: impl StorageBackend) -> Result<Database, DatabaseError> {
Self::builder().open_backend(backend)
}

pub(crate) fn start_write_transaction(&self) -> TransactionId {
let mut live_write_transaction = self.live_write_transaction.lock().unwrap();
while live_write_transaction.is_some() {
Expand Down Expand Up @@ -857,8 +852,8 @@ impl Builder {
)
}

/// Opens the database with the given backend.
pub fn open_backend(&self, backend: impl StorageBackend) -> Result<Database, DatabaseError> {
/// Open an existing or create a new database with the given backend.
pub fn create_backend(&self, backend: impl StorageBackend) -> Result<Database, DatabaseError> {
Database::new(
Box::new(backend),
self.page_size,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub use multimap_table::{
pub use table::{Drain, DrainFilter, Range, ReadOnlyTable, ReadableTable, Table};
pub use transactions::{DatabaseStats, Durability, ReadTransaction, WriteTransaction};
pub use tree_store::file_backend::FileBackend;
pub use tree_store::{AccessGuard, AccessGuardMut, MemoryBackend, Savepoint};
pub use tree_store::{AccessGuard, AccessGuardMut, InMemoryBackend, Savepoint};
pub use types::{RedbKey, RedbValue, TypeName};

type Result<T = (), E = StorageError> = std::result::Result<T, E>;
Expand Down
2 changes: 1 addition & 1 deletion src/tree_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) use btree_base::{LeafAccessor, LeafMutator, RawLeafBuilder, BRANCH, L
pub(crate) use btree_iters::{
AllPageNumbersBtreeIter, BtreeDrain, BtreeDrainFilter, BtreeRangeIter,
};
pub use page_store::{file_backend, MemoryBackend, Savepoint};
pub use page_store::{file_backend, InMemoryBackend, Savepoint};
pub(crate) use page_store::{
CachePriority, Page, PageHint, PageNumber, SerializedSavepoint, TransactionalMemory,
FILE_FORMAT_VERSION, MAX_VALUE_LENGTH, PAGE_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,20 @@ use std::sync::*;

/// Acts as temporal in-memory database storage.
#[derive(Debug, Default)]
pub struct MemoryBackend(RwLock<Vec<u8>>);
pub struct InMemoryBackend(RwLock<Vec<u8>>);

impl MemoryBackend {
impl InMemoryBackend {
fn out_of_range() -> io::Error {
io::Error::new(io::ErrorKind::InvalidInput, "Index out-of-range.")
}
}

impl MemoryBackend {
impl InMemoryBackend {
/// Creates a new, empty memory backend.
pub fn new() -> Self {
Self::default()
}

/// Creates a memory backend with the specified initial capacity.
pub fn with_capacity(capacity: usize) -> Self {
Self(RwLock::new(Vec::with_capacity(capacity)))
}

/// Obtains the inner memory for this backend.
pub fn into_inner(self) -> Vec<u8> {
self.0.into_inner().expect("Could not get inner vector.")
}

/// Gets a read guard for this backend.
fn read(&self) -> RwLockReadGuard<'_, Vec<u8>> {
self.0.read().expect("Could not acquire read lock.")
Expand All @@ -39,13 +29,13 @@ impl MemoryBackend {
}
}

impl From<Vec<u8>> for MemoryBackend {
impl From<Vec<u8>> for InMemoryBackend {
fn from(value: Vec<u8>) -> Self {
Self(RwLock::new(value))
}
}

impl StorageBackend for MemoryBackend {
impl StorageBackend for InMemoryBackend {
fn len(&self) -> Result<u64, io::Error> {
Ok(self.read().len() as u64)
}
Expand Down
4 changes: 2 additions & 2 deletions src/tree_store/page_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod cached_file;
pub mod file_backend;
mod header;
mod layout;
mod memory_backend;
mod in_memory_backend;
mod page_manager;
mod region;
mod savepoint;
Expand All @@ -14,7 +14,7 @@ mod xxh3;

pub(crate) use base::{Page, PageHint, PageNumber, MAX_VALUE_LENGTH};
pub(crate) use header::PAGE_SIZE;
pub use memory_backend::MemoryBackend;
pub use in_memory_backend::InMemoryBackend;
pub(crate) use page_manager::{xxh3_checksum, TransactionalMemory, FILE_FORMAT_VERSION};
pub use savepoint::Savepoint;
pub(crate) use savepoint::SerializedSavepoint;
Expand Down

0 comments on commit 14693c0

Please sign in to comment.