Consistently use "config" instead of "conf"

This commit is contained in:
Tyler Neely 2018-09-30 23:46:36 +02:00
parent 7a6212421d
commit c5e3ce3b4f
9 changed files with 128 additions and 134 deletions

View File

@ -62,9 +62,9 @@ impl Materializer for TestMaterializer {
}
fn main() {
let conf = pagecache::ConfigBuilder::new().temporary(true);
let config = pagecache::ConfigBuilder::new().temporary(true);
let pc: pagecache::PageCache<TestMaterializer, _, _> =
pagecache::PageCache::start(conf.build());
pagecache::PageCache::start(config.build());
{
let guard = pin();
let id = pc.allocate(&guard);
@ -87,4 +87,3 @@ fn main() {
}
}
```

View File

@ -404,7 +404,7 @@ impl Config {
})?;
}
self.verify_conf_changes_ok()?;
self.verify_config_changes_ok()?;
// open the data file
let mut options = fs::OpenOptions::new();
@ -426,7 +426,7 @@ impl Config {
Ok(())
}
// panics if conf options are outside of advised range
// panics if config options are outside of advised range
fn validate(&self) -> Result<(), ()> {
supported!(
self.inner.io_bufs <= 32,
@ -480,7 +480,7 @@ impl Config {
Ok(())
}
fn verify_conf_changes_ok(&self) -> Result<(), ()> {
fn verify_config_changes_ok(&self) -> Result<(), ()> {
match self.read_config() {
Ok(Some(mut old)) => {
let old_tmp = old.tmp_path;
@ -517,7 +517,7 @@ impl Config {
let crc: u64 = crc64(&*bytes);
let crc_arr = u64_to_arr(crc);
let path = self.conf_path();
let path = self.config_path();
let mut f = std::fs::OpenOptions::new()
.write(true)
@ -534,7 +534,7 @@ impl Config {
}
fn read_config(&self) -> std::io::Result<Option<ConfigBuilder>> {
let path = self.conf_path();
let path = self.config_path();
let f_res =
std::fs::OpenOptions::new().read(true).open(&path);
@ -592,7 +592,7 @@ impl Config {
path
}
fn conf_path(&self) -> PathBuf {
fn config_path(&self) -> PathBuf {
let mut path = self.get_path();
path.push("conf");
path

View File

@ -1,6 +1,7 @@
use super::*;
use io::{read_blob, LogReader};
// explicitly
use super::LogReader;
/// A pointer to a location on disk or an off-log blob.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]

View File

@ -1,73 +0,0 @@
//! This module contains the systems that deal with files
//! directly.
use std::cell::UnsafeCell;
use std::fmt::{self, Debug};
use std::io;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::SeqCst;
use bincode::{deserialize, serialize};
use serde::de::DeserializeOwned;
use serde::Serialize;
use super::*;
mod blob_io;
mod iobuf;
mod iterator;
mod materializer;
mod page_cache;
mod parallel_io;
mod reader;
mod reservation;
mod segment;
mod snapshot;
pub mod log;
pub(crate) use self::log::EXTERNAL_VALUE_LEN;
pub use self::log::LogRead;
pub(crate) use self::blob_io::{
gc_blobs, read_blob, remove_blob, write_blob,
};
pub(crate) use self::reader::LogReader;
#[doc(hidden)]
pub use self::snapshot::{read_snapshot_or_default, Snapshot};
#[doc(hidden)]
use self::log::{
MessageHeader, MessageKind, SegmentHeader, SegmentTrailer,
};
pub use self::log::Log;
pub use self::materializer::{Materializer, NullMaterializer};
pub use self::page_cache::{CacheEntry, PageCache, PageGet};
pub use self::reservation::Reservation;
pub use self::segment::SegmentMode;
use self::iobuf::IoBufs;
use self::iterator::LogIter;
use self::page_cache::{LoggedUpdate, Update};
use self::parallel_io::Pio;
use self::segment::{raw_segment_iter_from, SegmentAccountant};
use self::snapshot::{advance_snapshot, PageState};
// This message should be skipped to preserve linearizability.
const FAILED_FLUSH: u8 = 0;
// This message represents valid data, stored inline.
const SUCCESSFUL_FLUSH: u8 = 1;
// This message represents valid data, stored externally.
const SUCCESSFUL_EXTERNAL_FLUSH: u8 = 2;
// This message represents a pad.
const SEGMENT_PAD: u8 = 3;
// The EVIL_BYTE is written to force detection of
// a corruption when dealing with unused segment space.
const EVIL_BYTE: u8 = 6;

View File

@ -48,13 +48,9 @@ use ds::Stack;
/// general-purpose configuration
pub use config::{Config, ConfigBuilder};
pub use diskptr::DiskPtr;
pub use io::{
read_snapshot_or_default, CacheEntry, Log, LogRead, Materializer,
NullMaterializer, PageCache, PageGet, SegmentMode,
};
#[doc(hidden)]
pub use self::io::log::{
pub use self::log::{
MSG_HEADER_LEN, SEG_HEADER_LEN, SEG_TRAILER_LEN,
};
@ -78,21 +74,41 @@ macro_rules! rep_no_copy {
}};
}
mod blob_io;
mod config;
mod diskptr;
mod ds;
mod hash;
mod io;
mod iobuf;
mod iterator;
mod materializer;
mod metrics;
mod pagecache;
mod parallel_io;
mod periodic;
mod reader;
mod reservation;
mod result;
mod segment;
mod snapshot;
mod tx;
pub mod log;
use ds::*;
use hash::{crc16_arr, crc64};
use historian::Histo;
use metrics::Metrics;
use std::cell::UnsafeCell;
use std::fmt::{self, Debug};
use std::io;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::SeqCst;
use bincode::{deserialize, serialize};
use serde::de::DeserializeOwned;
use serde::Serialize;
/// An offset for a storage file segment.
pub type SegmentID = usize;
@ -108,7 +124,7 @@ pub type Lsn = i64;
/// A page identifier.
pub type PageID = usize;
type PagePtrInner<'g, P> = epoch::Shared<'g, Node<io::CacheEntry<P>>>;
type PagePtrInner<'g, P> = epoch::Shared<'g, Node<CacheEntry<P>>>;
/// A pointer to shared lock-free state bound by a pinned epoch's lifetime.
#[derive(Debug, Clone, PartialEq)]
@ -240,3 +256,48 @@ fn arr_to_u32(arr: [u8; 4]) -> u32 {
fn u32_to_arr(u: u32) -> [u8; 4] {
[u as u8, (u >> 8) as u8, (u >> 16) as u8, (u >> 24) as u8]
}
use self::log::EXTERNAL_VALUE_LEN;
pub use self::log::LogRead;
use self::blob_io::{gc_blobs, read_blob, remove_blob, write_blob};
use self::reader::LogReader;
#[doc(hidden)]
pub use self::snapshot::{read_snapshot_or_default, Snapshot};
#[doc(hidden)]
use self::log::{
MessageHeader, MessageKind, SegmentHeader, SegmentTrailer,
};
pub use self::log::Log;
pub use self::materializer::{Materializer, NullMaterializer};
pub use self::pagecache::{CacheEntry, PageCache, PageGet};
pub use self::reservation::Reservation;
pub use self::segment::SegmentMode;
use self::iobuf::IoBufs;
use self::iterator::LogIter;
use self::pagecache::{LoggedUpdate, Update};
use self::parallel_io::Pio;
use self::segment::{raw_segment_iter_from, SegmentAccountant};
use self::snapshot::{advance_snapshot, PageState};
// This message should be skipped to preserve linearizability.
const FAILED_FLUSH: u8 = 0;
// This message represents valid data, stored inline.
const SUCCESSFUL_FLUSH: u8 = 1;
// This message represents valid data, stored externally.
const SUCCESSFUL_EXTERNAL_FLUSH: u8 = 2;
// This message represents a pad.
const SEGMENT_PAD: u8 = 3;
// The EVIL_BYTE is written to force detection of
// a corruption when dealing with unused segment space.
const EVIL_BYTE: u8 = 6;

View File

@ -1,3 +1,30 @@
//! # Working with `Log`
//!
//! ```
//! let config = pagecache::ConfigBuilder::new()
//! .temporary(true)
//! .segment_mode(pagecache::SegmentMode::Linear)
//! .build();
//! let log = pagecache::Log::start_raw_log(config).unwrap();
//! let (first_lsn, _first_offset) = log.write(b"1".to_vec()).unwrap();
//! log.write(b"22".to_vec()).unwrap();
//! log.write(b"333".to_vec()).unwrap();
//!
//! // stick an abort in the middle, which should not be returned
//! let res = log.reserve(b"never_gonna_hit_disk".to_vec()).unwrap();
//! res.abort().unwrap();
//!
//! log.write(b"4444".to_vec());
//! let (last_lsn, _last_offset) = log.write(b"55555".to_vec()).unwrap();
//! log.make_stable(last_lsn).unwrap();
//! let mut iter = log.iter_from(first_lsn);
//! assert_eq!(iter.next().unwrap().2, b"1".to_vec());
//! assert_eq!(iter.next().unwrap().2, b"22".to_vec());
//! assert_eq!(iter.next().unwrap().2, b"333".to_vec());
//! assert_eq!(iter.next().unwrap().2, b"4444".to_vec());
//! assert_eq!(iter.next().unwrap().2, b"55555".to_vec());
//! assert_eq!(iter.next(), None);
//! ```
use std::sync::Arc;
use super::*;
@ -19,34 +46,6 @@ pub(crate) const EXTERNAL_VALUE_LEN: usize =
/// reservations placed at known log offsets, used
/// for writing persistent data structures that need
/// to know where to find persisted bits in the future.
///
/// # Working with `Log`
///
/// ```
/// let conf = pagecache::ConfigBuilder::new()
/// .temporary(true)
/// .segment_mode(pagecache::SegmentMode::Linear)
/// .build();
/// let log = pagecache::Log::start_raw_log(conf).unwrap();
/// let (first_lsn, _first_offset) = log.write(b"1".to_vec()).unwrap();
/// log.write(b"22".to_vec()).unwrap();
/// log.write(b"333".to_vec()).unwrap();
///
/// // stick an abort in the middle, which should not be returned
/// let res = log.reserve(b"never_gonna_hit_disk".to_vec()).unwrap();
/// res.abort().unwrap();
///
/// log.write(b"4444".to_vec());
/// let (last_lsn, _last_offset) = log.write(b"55555".to_vec()).unwrap();
/// log.make_stable(last_lsn).unwrap();
/// let mut iter = log.iter_from(first_lsn);
/// assert_eq!(iter.next().unwrap().2, b"1".to_vec());
/// assert_eq!(iter.next().unwrap().2, b"22".to_vec());
/// assert_eq!(iter.next().unwrap().2, b"333".to_vec());
/// assert_eq!(iter.next().unwrap().2, b"4444".to_vec());
/// assert_eq!(iter.next().unwrap().2, b"55555".to_vec());
/// assert_eq!(iter.next(), None);
/// ```
pub struct Log {
/// iobufs is the underlying lock-free IO write buffer.
iobufs: Arc<IoBufs>,
@ -197,7 +196,7 @@ impl Log {
}
// SegmentAccountant access for coordination with the `PageCache`
pub(in io) fn with_sa<B, F>(&self, f: F) -> B
pub(crate) fn with_sa<B, F>(&self, f: F) -> B
where
F: FnOnce(&mut SegmentAccountant) -> B,
{

View File

@ -193,9 +193,9 @@ where
/// }
///
/// fn main() {
/// let conf = pagecache::ConfigBuilder::new().temporary(true).build();
/// let config = pagecache::ConfigBuilder::new().temporary(true).build();
/// let pc: pagecache::PageCache<TestMaterializer, _, _> =
/// pagecache::PageCache::start(conf).unwrap();
/// pagecache::PageCache::start(config).unwrap();
/// {
/// let guard = pin();
/// let id = pc.allocate(&guard).unwrap();

View File

@ -69,9 +69,9 @@ impl Reactor for IdGen {
type Peer = String;
type Message = Msg;
fn start(conf: IdGenConf) -> Result<IdGen, ()> {
fn start(config: IdGenConf) -> Result<IdGen, ()> {
Ok(IdGen {
peers: conf.peers,
peers: config.peers,
in_flight: HashMap::new(),
req_counter: 0,
})

View File

@ -1,3 +1,9 @@
Warning: Unknown configuration option `fn_call_width`
Warning: Unknown configuration option `ideal_width`
Warning: Unknown configuration option `reorder_imported_names`
Warning: Unknown configuration option `reorder_imports_in_group`
Warning: Unknown configuration option `struct_lit_multiline_style`
Warning: Unknown configuration option `where_style`
//! An example of how to build multi-key transactions on top of
//! sled's single-key atomicity guarantees.
//!
@ -25,15 +31,13 @@ use std::sync::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};
use sled::{Config, DbResult, Error, Tree};
macro_rules! rep_no_copy {
($e:expr; $n:expr) => {
{
let mut v = Vec::with_capacity($n);
for _ in 0..$n {
v.push($e);
}
v
($e:expr; $n:expr) => {{
let mut v = Vec::with_capacity($n);
for _ in 0..$n {
v.push($e);
}
};
v
}};
}
type TxId = u64;
@ -240,8 +244,8 @@ impl<'a> Tx<'a> {
#[test]
fn it_works() {
let conf = sled::ConfigBuilder::new().temporary(true).build();
let txdb = TxDb::start(conf).unwrap();
let config = sled::ConfigBuilder::new().temporary(true).build();
let txdb = TxDb::start(config).unwrap();
let mut tx = txdb.tx();
tx.set(b"cats".to_vec(), b"meow".to_vec());
@ -256,7 +260,10 @@ fn it_works() {
tx.get(b"dogs".to_vec());
assert_eq!(
tx.execute(),
Ok(TxRet::Committed(vec![(b"dogs".to_vec(), Some(b"meow".to_vec()))]))
Ok(TxRet::Committed(vec![(
b"dogs".to_vec(),
Some(b"meow".to_vec())
)]))
);
let mut tx = txdb.tx();