mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Fix upper_case_acronyms
lint
This commit is contained in:
parent
c42cc3bdcb
commit
fdeadfd981
10 changed files with 78 additions and 78 deletions
|
@ -1,6 +1,6 @@
|
||||||
#![deny(clippy::all)]
|
#![deny(clippy::all)]
|
||||||
|
|
||||||
use crate::storage::{KVStorage, Storage};
|
use crate::storage::{KvStorage, Storage};
|
||||||
use actix_web::{get, middleware::Logger, web, App, HttpServer, Responder, Scope};
|
use actix_web::{get, middleware::Logger, web, App, HttpServer, Responder, Scope};
|
||||||
use api::{api_scope, ServerState};
|
use api::{api_scope, ServerState};
|
||||||
use clap::Arg;
|
use clap::Arg;
|
||||||
|
@ -56,7 +56,7 @@ async fn main() -> anyhow::Result<()> {
|
||||||
let data_dir = matches.value_of("data-dir").unwrap();
|
let data_dir = matches.value_of("data-dir").unwrap();
|
||||||
let port = matches.value_of("port").unwrap();
|
let port = matches.value_of("port").unwrap();
|
||||||
|
|
||||||
let server_box: Box<dyn Storage> = Box::new(KVStorage::new(data_dir)?);
|
let server_box: Box<dyn Storage> = Box::new(KvStorage::new(data_dir)?);
|
||||||
let server_state = ServerState::new(server_box);
|
let server_state = ServerState::new(server_box);
|
||||||
|
|
||||||
log::warn!("Serving on port {}", port);
|
log::warn!("Serving on port {}", port);
|
||||||
|
|
|
@ -20,15 +20,15 @@ fn client_db_key(client_key: Uuid) -> ClientDbKey {
|
||||||
*client_key.as_bytes()
|
*client_key.as_bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// KVStorage is an on-disk storage backend which uses LMDB via the `kv` crate.
|
/// KvStorage is an on-disk storage backend which uses LMDB via the `kv` crate.
|
||||||
pub(crate) struct KVStorage<'t> {
|
pub(crate) struct KvStorage<'t> {
|
||||||
store: Store,
|
store: Store,
|
||||||
clients_bucket: Bucket<'t, ClientDbKey, ValueBuf<Msgpack<Client>>>,
|
clients_bucket: Bucket<'t, ClientDbKey, ValueBuf<Msgpack<Client>>>,
|
||||||
versions_bucket: Bucket<'t, VersionDbKey, ValueBuf<Msgpack<Version>>>,
|
versions_bucket: Bucket<'t, VersionDbKey, ValueBuf<Msgpack<Version>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'t> KVStorage<'t> {
|
impl<'t> KvStorage<'t> {
|
||||||
pub fn new<P: AsRef<Path>>(directory: P) -> anyhow::Result<KVStorage<'t>> {
|
pub fn new<P: AsRef<Path>>(directory: P) -> anyhow::Result<KvStorage<'t>> {
|
||||||
let mut config = Config::default(directory);
|
let mut config = Config::default(directory);
|
||||||
config.bucket("clients", None);
|
config.bucket("clients", None);
|
||||||
config.bucket("versions", None);
|
config.bucket("versions", None);
|
||||||
|
@ -40,7 +40,7 @@ impl<'t> KVStorage<'t> {
|
||||||
let versions_bucket =
|
let versions_bucket =
|
||||||
store.bucket::<VersionDbKey, ValueBuf<Msgpack<Version>>>(Some("versions"))?;
|
store.bucket::<VersionDbKey, ValueBuf<Msgpack<Version>>>(Some("versions"))?;
|
||||||
|
|
||||||
Ok(KVStorage {
|
Ok(KvStorage {
|
||||||
store,
|
store,
|
||||||
clients_bucket,
|
clients_bucket,
|
||||||
versions_bucket,
|
versions_bucket,
|
||||||
|
@ -48,7 +48,7 @@ impl<'t> KVStorage<'t> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'t> Storage for KVStorage<'t> {
|
impl<'t> Storage for KvStorage<'t> {
|
||||||
fn txn<'a>(&'a self) -> anyhow::Result<Box<dyn StorageTxn + 'a>> {
|
fn txn<'a>(&'a self) -> anyhow::Result<Box<dyn StorageTxn + 'a>> {
|
||||||
Ok(Box::new(Txn {
|
Ok(Box::new(Txn {
|
||||||
storage: self,
|
storage: self,
|
||||||
|
@ -58,7 +58,7 @@ impl<'t> Storage for KVStorage<'t> {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Txn<'t> {
|
struct Txn<'t> {
|
||||||
storage: &'t KVStorage<'t>,
|
storage: &'t KvStorage<'t>,
|
||||||
txn: Option<kv::Txn<'t>>,
|
txn: Option<kv::Txn<'t>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_client_empty() -> anyhow::Result<()> {
|
fn test_get_client_empty() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
let tmp_dir = TempDir::new("test")?;
|
||||||
let storage = KVStorage::new(&tmp_dir.path())?;
|
let storage = KvStorage::new(&tmp_dir.path())?;
|
||||||
let mut txn = storage.txn()?;
|
let mut txn = storage.txn()?;
|
||||||
let maybe_client = txn.get_client(Uuid::new_v4())?;
|
let maybe_client = txn.get_client(Uuid::new_v4())?;
|
||||||
assert!(maybe_client.is_none());
|
assert!(maybe_client.is_none());
|
||||||
|
@ -179,7 +179,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_client_storage() -> anyhow::Result<()> {
|
fn test_client_storage() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
let tmp_dir = TempDir::new("test")?;
|
||||||
let storage = KVStorage::new(&tmp_dir.path())?;
|
let storage = KvStorage::new(&tmp_dir.path())?;
|
||||||
let mut txn = storage.txn()?;
|
let mut txn = storage.txn()?;
|
||||||
|
|
||||||
let client_key = Uuid::new_v4();
|
let client_key = Uuid::new_v4();
|
||||||
|
@ -201,7 +201,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gvbp_empty() -> anyhow::Result<()> {
|
fn test_gvbp_empty() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
let tmp_dir = TempDir::new("test")?;
|
||||||
let storage = KVStorage::new(&tmp_dir.path())?;
|
let storage = KvStorage::new(&tmp_dir.path())?;
|
||||||
let mut txn = storage.txn()?;
|
let mut txn = storage.txn()?;
|
||||||
let maybe_version = txn.get_version_by_parent(Uuid::new_v4(), Uuid::new_v4())?;
|
let maybe_version = txn.get_version_by_parent(Uuid::new_v4(), Uuid::new_v4())?;
|
||||||
assert!(maybe_version.is_none());
|
assert!(maybe_version.is_none());
|
||||||
|
@ -211,7 +211,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_add_version_and_gvbp() -> anyhow::Result<()> {
|
fn test_add_version_and_gvbp() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
let tmp_dir = TempDir::new("test")?;
|
||||||
let storage = KVStorage::new(&tmp_dir.path())?;
|
let storage = KvStorage::new(&tmp_dir.path())?;
|
||||||
let mut txn = storage.txn()?;
|
let mut txn = storage.txn()?;
|
||||||
|
|
||||||
let client_key = Uuid::new_v4();
|
let client_key = Uuid::new_v4();
|
||||||
|
|
|
@ -7,7 +7,7 @@ mod inmemory;
|
||||||
pub(crate) use inmemory::InMemoryStorage;
|
pub(crate) use inmemory::InMemoryStorage;
|
||||||
|
|
||||||
mod kv;
|
mod kv;
|
||||||
pub(crate) use self::kv::KVStorage;
|
pub(crate) use self::kv::KvStorage;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
|
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
|
||||||
pub(crate) struct Client {
|
pub(crate) struct Client {
|
||||||
|
|
|
@ -2,5 +2,5 @@ use thiserror::Error;
|
||||||
#[derive(Debug, Error, Eq, PartialEq, Clone)]
|
#[derive(Debug, Error, Eq, PartialEq, Clone)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Task Database Error: {}", _0)]
|
#[error("Task Database Error: {}", _0)]
|
||||||
DBError(String),
|
DbError(String),
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::errors::Error;
|
||||||
use crate::server::Server;
|
use crate::server::Server;
|
||||||
use crate::storage::{Operation, Storage, TaskMap};
|
use crate::storage::{Operation, Storage, TaskMap};
|
||||||
use crate::task::{Status, Task};
|
use crate::task::{Status, Task};
|
||||||
use crate::taskdb::TaskDB;
|
use crate::taskdb::TaskDb;
|
||||||
use crate::workingset::WorkingSet;
|
use crate::workingset::WorkingSet;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use log::trace;
|
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"
|
/// pending tasks are automatically added to the working set, and the working set is "renumbered"
|
||||||
/// during the garbage-collection process.
|
/// during the garbage-collection process.
|
||||||
pub struct Replica {
|
pub struct Replica {
|
||||||
taskdb: TaskDB,
|
taskdb: TaskDb,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Replica {
|
impl Replica {
|
||||||
pub fn new(storage: Box<dyn Storage>) -> Replica {
|
pub fn new(storage: Box<dyn Storage>) -> Replica {
|
||||||
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
|
// 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
|
// when this Create operation is finally sync'd with operations from other replicas
|
||||||
if self.taskdb.get_task(uuid)?.is_none() {
|
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 })?;
|
self.taskdb.apply(Operation::Delete { uuid })?;
|
||||||
trace!("task {} deleted", uuid);
|
trace!("task {} deleted", uuid);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::{InMemoryStorage, KVStorage, Storage};
|
use super::{InMemoryStorage, KvStorage, Storage};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
/// The configuration required for a replica's storage.
|
/// The configuration required for a replica's storage.
|
||||||
|
@ -15,7 +15,7 @@ pub enum StorageConfig {
|
||||||
impl StorageConfig {
|
impl StorageConfig {
|
||||||
pub fn into_storage(self) -> anyhow::Result<Box<dyn Storage>> {
|
pub fn into_storage(self) -> anyhow::Result<Box<dyn Storage>> {
|
||||||
Ok(match self {
|
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()),
|
StorageConfig::InMemory => Box::new(InMemoryStorage::new()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ use kv::{Bucket, Config, Error, Integer, Serde, Store, ValueBuf};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
/// KVStorage is an on-disk storage backend which uses LMDB via the `kv` crate.
|
/// KvStorage is an on-disk storage backend which uses LMDB via the `kv` crate.
|
||||||
pub struct KVStorage<'t> {
|
pub struct KvStorage<'t> {
|
||||||
store: Store,
|
store: Store,
|
||||||
tasks_bucket: Bucket<'t, Key, ValueBuf<Msgpack<TaskMap>>>,
|
tasks_bucket: Bucket<'t, Key, ValueBuf<Msgpack<TaskMap>>>,
|
||||||
numbers_bucket: Bucket<'t, Integer, ValueBuf<Msgpack<u64>>>,
|
numbers_bucket: Bucket<'t, Integer, ValueBuf<Msgpack<u64>>>,
|
||||||
|
@ -19,8 +19,8 @@ const BASE_VERSION: u64 = 1;
|
||||||
const NEXT_OPERATION: u64 = 2;
|
const NEXT_OPERATION: u64 = 2;
|
||||||
const NEXT_WORKING_SET_INDEX: u64 = 3;
|
const NEXT_WORKING_SET_INDEX: u64 = 3;
|
||||||
|
|
||||||
impl<'t> KVStorage<'t> {
|
impl<'t> KvStorage<'t> {
|
||||||
pub fn new<P: AsRef<Path>>(directory: P) -> anyhow::Result<KVStorage<'t>> {
|
pub fn new<P: AsRef<Path>>(directory: P) -> anyhow::Result<KvStorage<'t>> {
|
||||||
let mut config = Config::default(directory);
|
let mut config = Config::default(directory);
|
||||||
config.bucket("tasks", None);
|
config.bucket("tasks", None);
|
||||||
config.bucket("numbers", None);
|
config.bucket("numbers", None);
|
||||||
|
@ -48,7 +48,7 @@ impl<'t> KVStorage<'t> {
|
||||||
let working_set_bucket =
|
let working_set_bucket =
|
||||||
store.int_bucket::<ValueBuf<Msgpack<Uuid>>>(Some("working_set"))?;
|
store.int_bucket::<ValueBuf<Msgpack<Uuid>>>(Some("working_set"))?;
|
||||||
|
|
||||||
Ok(KVStorage {
|
Ok(KvStorage {
|
||||||
store,
|
store,
|
||||||
tasks_bucket,
|
tasks_bucket,
|
||||||
numbers_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>> {
|
fn txn<'a>(&'a mut self) -> anyhow::Result<Box<dyn StorageTxn + 'a>> {
|
||||||
Ok(Box::new(Txn {
|
Ok(Box::new(Txn {
|
||||||
storage: self,
|
storage: self,
|
||||||
|
@ -69,7 +69,7 @@ impl<'t> Storage for KVStorage<'t> {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Txn<'t> {
|
struct Txn<'t> {
|
||||||
storage: &'t KVStorage<'t>,
|
storage: &'t KvStorage<'t>,
|
||||||
txn: Option<kv::Txn<'t>>,
|
txn: Option<kv::Txn<'t>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,7 +359,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create() -> anyhow::Result<()> {
|
fn test_create() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
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 uuid = Uuid::new_v4();
|
||||||
{
|
{
|
||||||
let mut txn = storage.txn()?;
|
let mut txn = storage.txn()?;
|
||||||
|
@ -377,7 +377,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_exists() -> anyhow::Result<()> {
|
fn test_create_exists() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
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 uuid = Uuid::new_v4();
|
||||||
{
|
{
|
||||||
let mut txn = storage.txn()?;
|
let mut txn = storage.txn()?;
|
||||||
|
@ -395,7 +395,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_missing() -> anyhow::Result<()> {
|
fn test_get_missing() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
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 uuid = Uuid::new_v4();
|
||||||
{
|
{
|
||||||
let mut txn = storage.txn()?;
|
let mut txn = storage.txn()?;
|
||||||
|
@ -408,7 +408,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_set_task() -> anyhow::Result<()> {
|
fn test_set_task() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
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 uuid = Uuid::new_v4();
|
||||||
{
|
{
|
||||||
let mut txn = storage.txn()?;
|
let mut txn = storage.txn()?;
|
||||||
|
@ -429,7 +429,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_delete_task_missing() -> anyhow::Result<()> {
|
fn test_delete_task_missing() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
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 uuid = Uuid::new_v4();
|
||||||
{
|
{
|
||||||
let mut txn = storage.txn()?;
|
let mut txn = storage.txn()?;
|
||||||
|
@ -441,7 +441,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_delete_task_exists() -> anyhow::Result<()> {
|
fn test_delete_task_exists() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
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 uuid = Uuid::new_v4();
|
||||||
{
|
{
|
||||||
let mut txn = storage.txn()?;
|
let mut txn = storage.txn()?;
|
||||||
|
@ -458,7 +458,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_all_tasks_empty() -> anyhow::Result<()> {
|
fn test_all_tasks_empty() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
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 mut txn = storage.txn()?;
|
||||||
let tasks = txn.all_tasks()?;
|
let tasks = txn.all_tasks()?;
|
||||||
|
@ -470,7 +470,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_all_tasks_and_uuids() -> anyhow::Result<()> {
|
fn test_all_tasks_and_uuids() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
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 uuid1 = Uuid::new_v4();
|
||||||
let uuid2 = Uuid::new_v4();
|
let uuid2 = Uuid::new_v4();
|
||||||
{
|
{
|
||||||
|
@ -524,7 +524,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_base_version_default() -> anyhow::Result<()> {
|
fn test_base_version_default() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
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 mut txn = storage.txn()?;
|
||||||
assert_eq!(txn.base_version()?, DEFAULT_BASE_VERSION);
|
assert_eq!(txn.base_version()?, DEFAULT_BASE_VERSION);
|
||||||
|
@ -535,7 +535,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_base_version_setting() -> anyhow::Result<()> {
|
fn test_base_version_setting() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
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 u = Uuid::new_v4();
|
||||||
{
|
{
|
||||||
let mut txn = storage.txn()?;
|
let mut txn = storage.txn()?;
|
||||||
|
@ -552,7 +552,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_operations() -> anyhow::Result<()> {
|
fn test_operations() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
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 uuid1 = Uuid::new_v4();
|
||||||
let uuid2 = Uuid::new_v4();
|
let uuid2 = Uuid::new_v4();
|
||||||
let uuid3 = Uuid::new_v4();
|
let uuid3 = Uuid::new_v4();
|
||||||
|
@ -616,7 +616,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn get_working_set_empty() -> anyhow::Result<()> {
|
fn get_working_set_empty() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
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 mut txn = storage.txn()?;
|
||||||
|
@ -630,7 +630,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn add_to_working_set() -> anyhow::Result<()> {
|
fn add_to_working_set() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
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 uuid1 = Uuid::new_v4();
|
||||||
let uuid2 = Uuid::new_v4();
|
let uuid2 = Uuid::new_v4();
|
||||||
|
|
||||||
|
@ -653,7 +653,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn clear_working_set() -> anyhow::Result<()> {
|
fn clear_working_set() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new("test")?;
|
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 uuid1 = Uuid::new_v4();
|
||||||
let uuid2 = Uuid::new_v4();
|
let uuid2 = Uuid::new_v4();
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ mod inmemory;
|
||||||
mod kv;
|
mod kv;
|
||||||
mod operation;
|
mod operation;
|
||||||
|
|
||||||
pub use self::kv::KVStorage;
|
pub use self::kv::KvStorage;
|
||||||
pub use config::StorageConfig;
|
pub use config::StorageConfig;
|
||||||
pub use inmemory::InMemoryStorage;
|
pub use inmemory::InMemoryStorage;
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ pub trait StorageTxn {
|
||||||
fn operations(&mut self) -> Result<Vec<Operation>>;
|
fn operations(&mut self) -> Result<Vec<Operation>>;
|
||||||
|
|
||||||
/// Add an operation to the end of the list of operations in the storage. Note that this
|
/// 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<()>;
|
fn add_operation(&mut self, op: Operation) -> Result<()>;
|
||||||
|
|
||||||
/// Replace the current list of operations with a new list.
|
/// Replace the current list of operations with a new list.
|
||||||
|
|
|
@ -126,7 +126,7 @@ impl Operation {
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::storage::InMemoryStorage;
|
use crate::storage::InMemoryStorage;
|
||||||
use crate::taskdb::TaskDB;
|
use crate::taskdb::TaskDb;
|
||||||
use chrono::{Duration, Utc};
|
use chrono::{Duration, Utc};
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ mod test {
|
||||||
|
|
||||||
// check that the two operation sequences have the same effect, enforcing the invariant of
|
// check that the two operation sequences have the same effect, enforcing the invariant of
|
||||||
// the transform function.
|
// the transform function.
|
||||||
let mut db1 = TaskDB::new_inmemory();
|
let mut db1 = TaskDb::new_inmemory();
|
||||||
if let Some(ref o) = setup {
|
if let Some(ref o) = setup {
|
||||||
db1.apply(o.clone()).unwrap();
|
db1.apply(o.clone()).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ mod test {
|
||||||
db1.apply(o).unwrap();
|
db1.apply(o).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut db2 = TaskDB::new_inmemory();
|
let mut db2 = TaskDb::new_inmemory();
|
||||||
if let Some(ref o) = setup {
|
if let Some(ref o) = setup {
|
||||||
db2.apply(o.clone()).unwrap();
|
db2.apply(o.clone()).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -307,8 +307,8 @@ mod test {
|
||||||
fn transform_invariant_holds(o1 in operation_strategy(), o2 in operation_strategy()) {
|
fn transform_invariant_holds(o1 in operation_strategy(), o2 in operation_strategy()) {
|
||||||
let (o1p, o2p) = Operation::transform(o1.clone(), o2.clone());
|
let (o1p, o2p) = Operation::transform(o1.clone(), o2.clone());
|
||||||
|
|
||||||
let mut db1 = TaskDB::new(Box::new(InMemoryStorage::new()));
|
let mut db1 = TaskDb::new(Box::new(InMemoryStorage::new()));
|
||||||
let mut db2 = TaskDB::new(Box::new(InMemoryStorage::new()));
|
let mut db2 = TaskDb::new(Box::new(InMemoryStorage::new()));
|
||||||
|
|
||||||
// Ensure that any expected tasks already exist
|
// Ensure that any expected tasks already exist
|
||||||
if let Operation::Update{ ref uuid, .. } = o1 {
|
if let Operation::Update{ ref uuid, .. } = o1 {
|
||||||
|
|
|
@ -7,10 +7,10 @@ use std::collections::HashSet;
|
||||||
use std::str;
|
use std::str;
|
||||||
use uuid::Uuid;
|
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
|
/// 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.
|
/// properties to the replica and task implementations.
|
||||||
pub struct TaskDB {
|
pub struct TaskDb {
|
||||||
storage: Box<dyn Storage>,
|
storage: Box<dyn Storage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,24 +19,24 @@ struct Version {
|
||||||
operations: Vec<Operation>,
|
operations: Vec<Operation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TaskDB {
|
impl TaskDb {
|
||||||
/// Create a new TaskDB with the given backend storage
|
/// Create a new TaskDb with the given backend storage
|
||||||
pub fn new(storage: Box<dyn Storage>) -> TaskDB {
|
pub fn new(storage: Box<dyn Storage>) -> TaskDb {
|
||||||
TaskDB { storage }
|
TaskDb { storage }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn new_inmemory() -> TaskDB {
|
pub fn new_inmemory() -> TaskDb {
|
||||||
TaskDB::new(Box::new(crate::storage::InMemoryStorage::new()))
|
TaskDb::new(Box::new(crate::storage::InMemoryStorage::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply an operation to the TaskDB. Aside from synchronization operations, this is the only way
|
/// 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
|
/// 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).
|
/// nothing and return an error (but leave the TaskDb in a consistent state).
|
||||||
pub fn apply(&mut self, op: Operation) -> anyhow::Result<()> {
|
pub fn apply(&mut self, op: Operation) -> anyhow::Result<()> {
|
||||||
// TODO: differentiate error types here?
|
// TODO: differentiate error types here?
|
||||||
let mut txn = self.storage.txn()?;
|
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;
|
return err;
|
||||||
}
|
}
|
||||||
txn.add_operation(op)?;
|
txn.add_operation(op)?;
|
||||||
|
@ -49,12 +49,12 @@ impl TaskDB {
|
||||||
Operation::Create { uuid } => {
|
Operation::Create { uuid } => {
|
||||||
// insert if the task does not already exist
|
// insert if the task does not already exist
|
||||||
if !txn.create_task(*uuid)? {
|
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 } => {
|
Operation::Delete { ref uuid } => {
|
||||||
if !txn.delete_task(*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 {
|
Operation::Update {
|
||||||
|
@ -71,7 +71,7 @@ impl TaskDB {
|
||||||
};
|
};
|
||||||
txn.set_task(*uuid, task)?;
|
txn.set_task(*uuid, task)?;
|
||||||
} else {
|
} 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
|
// apply this verison and update base_version in storage
|
||||||
info!("applying version {:?} from server", version_id);
|
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)?;
|
txn.set_base_version(version_id)?;
|
||||||
base_version_id = version_id;
|
base_version_id = version_id;
|
||||||
} else {
|
} else {
|
||||||
|
@ -313,7 +313,7 @@ impl TaskDB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(o) = svr_op {
|
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);
|
warn!("Invalid operation when syncing: {} (ignored)", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -367,7 +367,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_apply_create() {
|
fn test_apply_create() {
|
||||||
let mut db = TaskDB::new_inmemory();
|
let mut db = TaskDb::new_inmemory();
|
||||||
let uuid = Uuid::new_v4();
|
let uuid = Uuid::new_v4();
|
||||||
let op = Operation::Create { uuid };
|
let op = Operation::Create { uuid };
|
||||||
db.apply(op.clone()).unwrap();
|
db.apply(op.clone()).unwrap();
|
||||||
|
@ -378,7 +378,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_apply_create_exists() {
|
fn test_apply_create_exists() {
|
||||||
let mut db = TaskDB::new_inmemory();
|
let mut db = TaskDb::new_inmemory();
|
||||||
let uuid = Uuid::new_v4();
|
let uuid = Uuid::new_v4();
|
||||||
let op = Operation::Create { uuid };
|
let op = Operation::Create { uuid };
|
||||||
db.apply(op.clone()).unwrap();
|
db.apply(op.clone()).unwrap();
|
||||||
|
@ -393,7 +393,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_apply_create_update() {
|
fn test_apply_create_update() {
|
||||||
let mut db = TaskDB::new_inmemory();
|
let mut db = TaskDb::new_inmemory();
|
||||||
let uuid = Uuid::new_v4();
|
let uuid = Uuid::new_v4();
|
||||||
let op1 = Operation::Create { uuid };
|
let op1 = Operation::Create { uuid };
|
||||||
db.apply(op1.clone()).unwrap();
|
db.apply(op1.clone()).unwrap();
|
||||||
|
@ -414,7 +414,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_apply_create_update_delete_prop() {
|
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 uuid = Uuid::new_v4();
|
||||||
let op1 = Operation::Create { uuid };
|
let op1 = Operation::Create { uuid };
|
||||||
db.apply(op1.clone()).unwrap();
|
db.apply(op1.clone()).unwrap();
|
||||||
|
@ -456,7 +456,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_apply_update_does_not_exist() {
|
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 uuid = Uuid::new_v4();
|
||||||
let op = Operation::Update {
|
let op = Operation::Update {
|
||||||
uuid,
|
uuid,
|
||||||
|
@ -475,7 +475,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_apply_create_delete() {
|
fn test_apply_create_delete() {
|
||||||
let mut db = TaskDB::new_inmemory();
|
let mut db = TaskDb::new_inmemory();
|
||||||
let uuid = Uuid::new_v4();
|
let uuid = Uuid::new_v4();
|
||||||
let op1 = Operation::Create { uuid };
|
let op1 = Operation::Create { uuid };
|
||||||
db.apply(op1.clone()).unwrap();
|
db.apply(op1.clone()).unwrap();
|
||||||
|
@ -489,7 +489,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_apply_delete_not_present() {
|
fn test_apply_delete_not_present() {
|
||||||
let mut db = TaskDB::new_inmemory();
|
let mut db = TaskDb::new_inmemory();
|
||||||
let uuid = Uuid::new_v4();
|
let uuid = Uuid::new_v4();
|
||||||
|
|
||||||
let op1 = Operation::Delete { uuid };
|
let op1 = Operation::Delete { uuid };
|
||||||
|
@ -513,7 +513,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rebuild_working_set(renumber: bool) -> anyhow::Result<()> {
|
fn rebuild_working_set(renumber: bool) -> anyhow::Result<()> {
|
||||||
let mut db = TaskDB::new_inmemory();
|
let mut db = TaskDb::new_inmemory();
|
||||||
let mut uuids = vec![];
|
let mut uuids = vec![];
|
||||||
uuids.push(Uuid::new_v4());
|
uuids.push(Uuid::new_v4());
|
||||||
println!("uuids[0]: {:?} - pending, not in working set", uuids[0]);
|
println!("uuids[0]: {:?} - pending, not in working set", uuids[0]);
|
||||||
|
@ -526,7 +526,7 @@ mod tests {
|
||||||
uuids.push(Uuid::new_v4());
|
uuids.push(Uuid::new_v4());
|
||||||
println!("uuids[4]: {:?} - pending, in working set", uuids[4]);
|
println!("uuids[4]: {:?} - pending, in working set", uuids[4]);
|
||||||
|
|
||||||
// add everything to the TaskDB
|
// add everything to the TaskDb
|
||||||
for uuid in &uuids {
|
for uuid in &uuids {
|
||||||
db.apply(Operation::Create { uuid: *uuid })?;
|
db.apply(Operation::Create { uuid: *uuid })?;
|
||||||
}
|
}
|
||||||
|
@ -598,8 +598,8 @@ mod tests {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn newdb() -> TaskDB {
|
fn newdb() -> TaskDb {
|
||||||
TaskDB::new(Box::new(InMemoryStorage::new()))
|
TaskDb::new(Box::new(InMemoryStorage::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -751,7 +751,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
// check that various sequences of operations on mulitple db's do not get the db's into an
|
// 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
|
// 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.
|
// another. So, the generated sequences focus on a single task UUID.
|
||||||
fn transform_sequences_of_operations(action_sequence in action_sequence_strategy()) {
|
fn transform_sequences_of_operations(action_sequence in action_sequence_strategy()) {
|
||||||
let mut server: Box<dyn Server> = Box::new(TestServer::new());
|
let mut server: Box<dyn Server> = Box::new(TestServer::new());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue