Merge pull request #176 from djmitche/ignore-clippy-identifier-caps

fix some clippy stuff
This commit is contained in:
Dustin J. Mitchell 2021-03-29 19:33:02 -04:00 committed by GitHub
commit 98fdb15b75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 88 additions and 83 deletions

View file

@ -2,5 +2,5 @@ use thiserror::Error;
#[derive(Debug, Error, Eq, PartialEq, Clone)]
pub enum Error {
#[error("Task Database Error: {}", _0)]
DBError(String),
DbError(String),
}

View file

@ -2,7 +2,7 @@ use crate::errors::Error;
use crate::server::Server;
use crate::storage::{Operation, Storage, TaskMap};
use crate::task::{Status, Task};
use crate::taskdb::TaskDB;
use crate::taskdb::TaskDb;
use crate::workingset::WorkingSet;
use chrono::Utc;
use log::trace;
@ -24,13 +24,13 @@ use uuid::Uuid;
/// pending tasks are automatically added to the working set, and the working set is "renumbered"
/// during the garbage-collection process.
pub struct Replica {
taskdb: TaskDB,
taskdb: TaskDb,
}
impl Replica {
pub fn new(storage: Box<dyn Storage>) -> Replica {
Replica {
taskdb: TaskDB::new(storage),
taskdb: TaskDb::new(storage),
}
}
@ -112,7 +112,7 @@ impl Replica {
// check that it already exists; this is a convenience check, as the task may already exist
// when this Create operation is finally sync'd with operations from other replicas
if self.taskdb.get_task(uuid)?.is_none() {
return Err(Error::DBError(format!("Task {} does not exist", uuid)).into());
return Err(Error::DbError(format!("Task {} does not exist", uuid)).into());
}
self.taskdb.apply(Operation::Delete { uuid })?;
trace!("task {} deleted", uuid);

View file

@ -1,4 +1,4 @@
use super::{InMemoryStorage, KVStorage, Storage};
use super::{InMemoryStorage, KvStorage, Storage};
use std::path::PathBuf;
/// The configuration required for a replica's storage.
@ -15,7 +15,7 @@ pub enum StorageConfig {
impl StorageConfig {
pub fn into_storage(self) -> anyhow::Result<Box<dyn Storage>> {
Ok(match self {
StorageConfig::OnDisk { taskdb_dir } => Box::new(KVStorage::new(taskdb_dir)?),
StorageConfig::OnDisk { taskdb_dir } => Box::new(KvStorage::new(taskdb_dir)?),
StorageConfig::InMemory => Box::new(InMemoryStorage::new()),
})
}

View file

@ -5,8 +5,8 @@ use kv::{Bucket, Config, Error, Integer, Serde, Store, ValueBuf};
use std::path::Path;
use uuid::Uuid;
/// KVStorage is an on-disk storage backend which uses LMDB via the `kv` crate.
pub struct KVStorage<'t> {
/// KvStorage is an on-disk storage backend which uses LMDB via the `kv` crate.
pub struct KvStorage<'t> {
store: Store,
tasks_bucket: Bucket<'t, Key, ValueBuf<Msgpack<TaskMap>>>,
numbers_bucket: Bucket<'t, Integer, ValueBuf<Msgpack<u64>>>,
@ -19,8 +19,8 @@ const BASE_VERSION: u64 = 1;
const NEXT_OPERATION: u64 = 2;
const NEXT_WORKING_SET_INDEX: u64 = 3;
impl<'t> KVStorage<'t> {
pub fn new<P: AsRef<Path>>(directory: P) -> anyhow::Result<KVStorage<'t>> {
impl<'t> KvStorage<'t> {
pub fn new<P: AsRef<Path>>(directory: P) -> anyhow::Result<KvStorage<'t>> {
let mut config = Config::default(directory);
config.bucket("tasks", None);
config.bucket("numbers", None);
@ -48,7 +48,7 @@ impl<'t> KVStorage<'t> {
let working_set_bucket =
store.int_bucket::<ValueBuf<Msgpack<Uuid>>>(Some("working_set"))?;
Ok(KVStorage {
Ok(KvStorage {
store,
tasks_bucket,
numbers_bucket,
@ -59,7 +59,7 @@ impl<'t> KVStorage<'t> {
}
}
impl<'t> Storage for KVStorage<'t> {
impl<'t> Storage for KvStorage<'t> {
fn txn<'a>(&'a mut self) -> anyhow::Result<Box<dyn StorageTxn + 'a>> {
Ok(Box::new(Txn {
storage: self,
@ -69,7 +69,7 @@ impl<'t> Storage for KVStorage<'t> {
}
struct Txn<'t> {
storage: &'t KVStorage<'t>,
storage: &'t KvStorage<'t>,
txn: Option<kv::Txn<'t>>,
}
@ -359,7 +359,7 @@ mod test {
#[test]
fn test_create() -> anyhow::Result<()> {
let tmp_dir = TempDir::new("test")?;
let mut storage = KVStorage::new(&tmp_dir.path())?;
let mut storage = KvStorage::new(&tmp_dir.path())?;
let uuid = Uuid::new_v4();
{
let mut txn = storage.txn()?;
@ -377,7 +377,7 @@ mod test {
#[test]
fn test_create_exists() -> anyhow::Result<()> {
let tmp_dir = TempDir::new("test")?;
let mut storage = KVStorage::new(&tmp_dir.path())?;
let mut storage = KvStorage::new(&tmp_dir.path())?;
let uuid = Uuid::new_v4();
{
let mut txn = storage.txn()?;
@ -395,7 +395,7 @@ mod test {
#[test]
fn test_get_missing() -> anyhow::Result<()> {
let tmp_dir = TempDir::new("test")?;
let mut storage = KVStorage::new(&tmp_dir.path())?;
let mut storage = KvStorage::new(&tmp_dir.path())?;
let uuid = Uuid::new_v4();
{
let mut txn = storage.txn()?;
@ -408,7 +408,7 @@ mod test {
#[test]
fn test_set_task() -> anyhow::Result<()> {
let tmp_dir = TempDir::new("test")?;
let mut storage = KVStorage::new(&tmp_dir.path())?;
let mut storage = KvStorage::new(&tmp_dir.path())?;
let uuid = Uuid::new_v4();
{
let mut txn = storage.txn()?;
@ -429,7 +429,7 @@ mod test {
#[test]
fn test_delete_task_missing() -> anyhow::Result<()> {
let tmp_dir = TempDir::new("test")?;
let mut storage = KVStorage::new(&tmp_dir.path())?;
let mut storage = KvStorage::new(&tmp_dir.path())?;
let uuid = Uuid::new_v4();
{
let mut txn = storage.txn()?;
@ -441,7 +441,7 @@ mod test {
#[test]
fn test_delete_task_exists() -> anyhow::Result<()> {
let tmp_dir = TempDir::new("test")?;
let mut storage = KVStorage::new(&tmp_dir.path())?;
let mut storage = KvStorage::new(&tmp_dir.path())?;
let uuid = Uuid::new_v4();
{
let mut txn = storage.txn()?;
@ -458,7 +458,7 @@ mod test {
#[test]
fn test_all_tasks_empty() -> anyhow::Result<()> {
let tmp_dir = TempDir::new("test")?;
let mut storage = KVStorage::new(&tmp_dir.path())?;
let mut storage = KvStorage::new(&tmp_dir.path())?;
{
let mut txn = storage.txn()?;
let tasks = txn.all_tasks()?;
@ -470,7 +470,7 @@ mod test {
#[test]
fn test_all_tasks_and_uuids() -> anyhow::Result<()> {
let tmp_dir = TempDir::new("test")?;
let mut storage = KVStorage::new(&tmp_dir.path())?;
let mut storage = KvStorage::new(&tmp_dir.path())?;
let uuid1 = Uuid::new_v4();
let uuid2 = Uuid::new_v4();
{
@ -524,7 +524,7 @@ mod test {
#[test]
fn test_base_version_default() -> anyhow::Result<()> {
let tmp_dir = TempDir::new("test")?;
let mut storage = KVStorage::new(&tmp_dir.path())?;
let mut storage = KvStorage::new(&tmp_dir.path())?;
{
let mut txn = storage.txn()?;
assert_eq!(txn.base_version()?, DEFAULT_BASE_VERSION);
@ -535,7 +535,7 @@ mod test {
#[test]
fn test_base_version_setting() -> anyhow::Result<()> {
let tmp_dir = TempDir::new("test")?;
let mut storage = KVStorage::new(&tmp_dir.path())?;
let mut storage = KvStorage::new(&tmp_dir.path())?;
let u = Uuid::new_v4();
{
let mut txn = storage.txn()?;
@ -552,7 +552,7 @@ mod test {
#[test]
fn test_operations() -> anyhow::Result<()> {
let tmp_dir = TempDir::new("test")?;
let mut storage = KVStorage::new(&tmp_dir.path())?;
let mut storage = KvStorage::new(&tmp_dir.path())?;
let uuid1 = Uuid::new_v4();
let uuid2 = Uuid::new_v4();
let uuid3 = Uuid::new_v4();
@ -616,7 +616,7 @@ mod test {
#[test]
fn get_working_set_empty() -> anyhow::Result<()> {
let tmp_dir = TempDir::new("test")?;
let mut storage = KVStorage::new(&tmp_dir.path())?;
let mut storage = KvStorage::new(&tmp_dir.path())?;
{
let mut txn = storage.txn()?;
@ -630,7 +630,7 @@ mod test {
#[test]
fn add_to_working_set() -> anyhow::Result<()> {
let tmp_dir = TempDir::new("test")?;
let mut storage = KVStorage::new(&tmp_dir.path())?;
let mut storage = KvStorage::new(&tmp_dir.path())?;
let uuid1 = Uuid::new_v4();
let uuid2 = Uuid::new_v4();
@ -653,7 +653,7 @@ mod test {
#[test]
fn clear_working_set() -> anyhow::Result<()> {
let tmp_dir = TempDir::new("test")?;
let mut storage = KVStorage::new(&tmp_dir.path())?;
let mut storage = KvStorage::new(&tmp_dir.path())?;
let uuid1 = Uuid::new_v4();
let uuid2 = Uuid::new_v4();

View file

@ -14,7 +14,7 @@ mod inmemory;
mod kv;
mod operation;
pub use self::kv::KVStorage;
pub use self::kv::KvStorage;
pub use config::StorageConfig;
pub use inmemory::InMemoryStorage;
@ -83,7 +83,7 @@ pub trait StorageTxn {
fn operations(&mut self) -> Result<Vec<Operation>>;
/// Add an operation to the end of the list of operations in the storage. Note that this
/// merely *stores* the operation; it is up to the TaskDB to apply it.
/// merely *stores* the operation; it is up to the TaskDb to apply it.
fn add_operation(&mut self, op: Operation) -> Result<()>;
/// Replace the current list of operations with a new list.

View file

@ -126,7 +126,7 @@ impl Operation {
mod test {
use super::*;
use crate::storage::InMemoryStorage;
use crate::taskdb::TaskDB;
use crate::taskdb::TaskDb;
use chrono::{Duration, Utc};
use proptest::prelude::*;
@ -145,7 +145,7 @@ mod test {
// check that the two operation sequences have the same effect, enforcing the invariant of
// the transform function.
let mut db1 = TaskDB::new_inmemory();
let mut db1 = TaskDb::new_inmemory();
if let Some(ref o) = setup {
db1.apply(o.clone()).unwrap();
}
@ -154,7 +154,7 @@ mod test {
db1.apply(o).unwrap();
}
let mut db2 = TaskDB::new_inmemory();
let mut db2 = TaskDb::new_inmemory();
if let Some(ref o) = setup {
db2.apply(o.clone()).unwrap();
}
@ -307,8 +307,8 @@ mod test {
fn transform_invariant_holds(o1 in operation_strategy(), o2 in operation_strategy()) {
let (o1p, o2p) = Operation::transform(o1.clone(), o2.clone());
let mut db1 = TaskDB::new(Box::new(InMemoryStorage::new()));
let mut db2 = TaskDB::new(Box::new(InMemoryStorage::new()));
let mut db1 = TaskDb::new(Box::new(InMemoryStorage::new()));
let mut db2 = TaskDb::new(Box::new(InMemoryStorage::new()));
// Ensure that any expected tasks already exist
if let Operation::Update{ ref uuid, .. } = o1 {

View file

@ -7,10 +7,10 @@ use std::collections::HashSet;
use std::str;
use uuid::Uuid;
/// A TaskDB is the backend for a replica. It manages the storage, operations, synchronization,
/// A TaskDb is the backend for a replica. It manages the storage, operations, synchronization,
/// and so on, and all the invariants that come with it. It leaves the meaning of particular task
/// properties to the replica and task implementations.
pub struct TaskDB {
pub struct TaskDb {
storage: Box<dyn Storage>,
}
@ -19,24 +19,24 @@ struct Version {
operations: Vec<Operation>,
}
impl TaskDB {
/// Create a new TaskDB with the given backend storage
pub fn new(storage: Box<dyn Storage>) -> TaskDB {
TaskDB { storage }
impl TaskDb {
/// Create a new TaskDb with the given backend storage
pub fn new(storage: Box<dyn Storage>) -> TaskDb {
TaskDb { storage }
}
#[cfg(test)]
pub fn new_inmemory() -> TaskDB {
TaskDB::new(Box::new(crate::storage::InMemoryStorage::new()))
pub fn new_inmemory() -> TaskDb {
TaskDb::new(Box::new(crate::storage::InMemoryStorage::new()))
}
/// Apply an operation to the TaskDB. Aside from synchronization operations, this is the only way
/// to modify the TaskDB. In cases where an operation does not make sense, this function will do
/// nothing and return an error (but leave the TaskDB in a consistent state).
/// Apply an operation to the TaskDb. Aside from synchronization operations, this is the only way
/// to modify the TaskDb. In cases where an operation does not make sense, this function will do
/// nothing and return an error (but leave the TaskDb in a consistent state).
pub fn apply(&mut self, op: Operation) -> anyhow::Result<()> {
// TODO: differentiate error types here?
let mut txn = self.storage.txn()?;
if let err @ Err(_) = TaskDB::apply_op(txn.as_mut(), &op) {
if let err @ Err(_) = TaskDb::apply_op(txn.as_mut(), &op) {
return err;
}
txn.add_operation(op)?;
@ -49,12 +49,12 @@ impl TaskDB {
Operation::Create { uuid } => {
// insert if the task does not already exist
if !txn.create_task(*uuid)? {
return Err(Error::DBError(format!("Task {} already exists", uuid)).into());
return Err(Error::DbError(format!("Task {} already exists", uuid)).into());
}
}
Operation::Delete { ref uuid } => {
if !txn.delete_task(*uuid)? {
return Err(Error::DBError(format!("Task {} does not exist", uuid)).into());
return Err(Error::DbError(format!("Task {} does not exist", uuid)).into());
}
}
Operation::Update {
@ -71,7 +71,7 @@ impl TaskDB {
};
txn.set_task(*uuid, task)?;
} else {
return Err(Error::DBError(format!("Task {} does not exist", uuid)).into());
return Err(Error::DbError(format!("Task {} does not exist", uuid)).into());
}
}
}
@ -213,7 +213,7 @@ impl TaskDB {
// apply this verison and update base_version in storage
info!("applying version {:?} from server", version_id);
TaskDB::apply_version(txn.as_mut(), version)?;
TaskDb::apply_version(txn.as_mut(), version)?;
txn.set_base_version(version_id)?;
base_version_id = version_id;
} else {
@ -313,7 +313,7 @@ impl TaskDB {
}
}
if let Some(o) = svr_op {
if let Err(e) = TaskDB::apply_op(txn, &o) {
if let Err(e) = TaskDb::apply_op(txn, &o) {
warn!("Invalid operation when syncing: {} (ignored)", e);
}
}
@ -367,7 +367,7 @@ mod tests {
#[test]
fn test_apply_create() {
let mut db = TaskDB::new_inmemory();
let mut db = TaskDb::new_inmemory();
let uuid = Uuid::new_v4();
let op = Operation::Create { uuid };
db.apply(op.clone()).unwrap();
@ -378,7 +378,7 @@ mod tests {
#[test]
fn test_apply_create_exists() {
let mut db = TaskDB::new_inmemory();
let mut db = TaskDb::new_inmemory();
let uuid = Uuid::new_v4();
let op = Operation::Create { uuid };
db.apply(op.clone()).unwrap();
@ -393,7 +393,7 @@ mod tests {
#[test]
fn test_apply_create_update() {
let mut db = TaskDB::new_inmemory();
let mut db = TaskDb::new_inmemory();
let uuid = Uuid::new_v4();
let op1 = Operation::Create { uuid };
db.apply(op1.clone()).unwrap();
@ -414,7 +414,7 @@ mod tests {
#[test]
fn test_apply_create_update_delete_prop() {
let mut db = TaskDB::new_inmemory();
let mut db = TaskDb::new_inmemory();
let uuid = Uuid::new_v4();
let op1 = Operation::Create { uuid };
db.apply(op1.clone()).unwrap();
@ -456,7 +456,7 @@ mod tests {
#[test]
fn test_apply_update_does_not_exist() {
let mut db = TaskDB::new_inmemory();
let mut db = TaskDb::new_inmemory();
let uuid = Uuid::new_v4();
let op = Operation::Update {
uuid,
@ -475,7 +475,7 @@ mod tests {
#[test]
fn test_apply_create_delete() {
let mut db = TaskDB::new_inmemory();
let mut db = TaskDb::new_inmemory();
let uuid = Uuid::new_v4();
let op1 = Operation::Create { uuid };
db.apply(op1.clone()).unwrap();
@ -489,7 +489,7 @@ mod tests {
#[test]
fn test_apply_delete_not_present() {
let mut db = TaskDB::new_inmemory();
let mut db = TaskDb::new_inmemory();
let uuid = Uuid::new_v4();
let op1 = Operation::Delete { uuid };
@ -513,7 +513,7 @@ mod tests {
}
fn rebuild_working_set(renumber: bool) -> anyhow::Result<()> {
let mut db = TaskDB::new_inmemory();
let mut db = TaskDb::new_inmemory();
let mut uuids = vec![];
uuids.push(Uuid::new_v4());
println!("uuids[0]: {:?} - pending, not in working set", uuids[0]);
@ -526,7 +526,7 @@ mod tests {
uuids.push(Uuid::new_v4());
println!("uuids[4]: {:?} - pending, in working set", uuids[4]);
// add everything to the TaskDB
// add everything to the TaskDb
for uuid in &uuids {
db.apply(Operation::Create { uuid: *uuid })?;
}
@ -598,8 +598,8 @@ mod tests {
Ok(())
}
fn newdb() -> TaskDB {
TaskDB::new(Box::new(InMemoryStorage::new()))
fn newdb() -> TaskDb {
TaskDb::new(Box::new(InMemoryStorage::new()))
}
#[test]
@ -751,7 +751,7 @@ mod tests {
#[test]
// check that various sequences of operations on mulitple db's do not get the db's into an
// incompatible state. The main concern here is that there might be a sequence of create
// and delete operations that results in a task existing in one TaskDB but not existing in
// and delete operations that results in a task existing in one TaskDb but not existing in
// another. So, the generated sequences focus on a single task UUID.
fn transform_sequences_of_operations(action_sequence in action_sequence_strategy()) {
let mut server: Box<dyn Server> = Box::new(TestServer::new());