mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
rename taskstorage to storage
This commit is contained in:
parent
a318ceebe2
commit
15ffc62279
10 changed files with 32 additions and 36 deletions
|
@ -1,9 +1,9 @@
|
|||
use std::io;
|
||||
use taskchampion::{server, taskstorage, Replica, ServerConfig};
|
||||
use taskchampion::{server, storage, Replica, ServerConfig};
|
||||
use tempdir::TempDir;
|
||||
|
||||
pub(super) fn test_replica() -> Replica {
|
||||
let storage = taskstorage::InMemoryStorage::new();
|
||||
let storage = storage::InMemoryStorage::new();
|
||||
Replica::new(Box::new(storage))
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Replica Storage
|
||||
|
||||
Each replica has a storage backend.
|
||||
The interface for this backend is given in `crate::taskstorage::TaskStorage` and `TaskStorageTxn`.
|
||||
The interface for this backend is given in `crate::taskstorage::Storage` and `StorageTxn`.
|
||||
|
||||
The storage is transaction-protected, with the expectation of a serializable isolation level.
|
||||
The storage contains the following information:
|
||||
|
|
|
@ -9,7 +9,7 @@ synchronize with one another.
|
|||
|
||||
# Task Storage
|
||||
|
||||
The [`taskstorage`](crate::taskstorage) module supports pluggable storage for a replica's data.
|
||||
The [`storage`](crate::storage) module supports pluggable storage for a replica's data.
|
||||
An implementation is provided, but users of this crate can provide their own implementation as well.
|
||||
|
||||
# Server
|
||||
|
@ -30,7 +30,7 @@ mod replica;
|
|||
pub mod server;
|
||||
mod task;
|
||||
mod taskdb;
|
||||
pub mod taskstorage;
|
||||
pub mod storage;
|
||||
mod utils;
|
||||
mod workingset;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::errors::Error;
|
|||
use crate::server::Server;
|
||||
use crate::task::{Status, Task};
|
||||
use crate::taskdb::TaskDB;
|
||||
use crate::taskstorage::{KVStorage, Operation, TaskMap, TaskStorage};
|
||||
use crate::storage::{KVStorage, Operation, TaskMap, Storage};
|
||||
use crate::workingset::WorkingSet;
|
||||
use chrono::Utc;
|
||||
use failure::Fallible;
|
||||
|
@ -30,7 +30,7 @@ pub struct Replica {
|
|||
}
|
||||
|
||||
impl Replica {
|
||||
pub fn new(storage: Box<dyn TaskStorage>) -> Replica {
|
||||
pub fn new(storage: Box<dyn Storage>) -> Replica {
|
||||
Replica {
|
||||
taskdb: TaskDB::new(storage),
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ impl Replica {
|
|||
|
||||
#[cfg(test)]
|
||||
pub fn new_inmemory() -> Replica {
|
||||
Replica::new(Box::new(crate::taskstorage::InMemoryStorage::new()))
|
||||
Replica::new(Box::new(crate::storage::InMemoryStorage::new()))
|
||||
}
|
||||
|
||||
/// Update an existing task. If the value is Some, the property is added or updated. If the
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#![allow(clippy::new_without_default)]
|
||||
|
||||
use crate::taskstorage::{
|
||||
Operation, TaskMap, TaskStorage, TaskStorageTxn, VersionId, DEFAULT_BASE_VERSION,
|
||||
};
|
||||
use crate::storage::{Operation, Storage, StorageTxn, TaskMap, VersionId, DEFAULT_BASE_VERSION};
|
||||
use failure::{bail, Fallible};
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::HashMap;
|
||||
|
@ -42,7 +40,7 @@ impl<'t> Txn<'t> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'t> TaskStorageTxn for Txn<'t> {
|
||||
impl<'t> StorageTxn for Txn<'t> {
|
||||
fn get_task(&mut self, uuid: Uuid) -> Fallible<Option<TaskMap>> {
|
||||
match self.data_ref().tasks.get(&uuid) {
|
||||
None => Ok(None),
|
||||
|
@ -157,8 +155,8 @@ impl InMemoryStorage {
|
|||
}
|
||||
}
|
||||
|
||||
impl TaskStorage for InMemoryStorage {
|
||||
fn txn<'a>(&'a mut self) -> Fallible<Box<dyn TaskStorageTxn + 'a>> {
|
||||
impl Storage for InMemoryStorage {
|
||||
fn txn<'a>(&'a mut self) -> Fallible<Box<dyn StorageTxn + 'a>> {
|
||||
Ok(Box::new(Txn {
|
||||
storage: self,
|
||||
new_data: None,
|
|
@ -1,6 +1,4 @@
|
|||
use crate::taskstorage::{
|
||||
Operation, TaskMap, TaskStorage, TaskStorageTxn, VersionId, DEFAULT_BASE_VERSION,
|
||||
};
|
||||
use crate::storage::{Operation, Storage, StorageTxn, TaskMap, VersionId, DEFAULT_BASE_VERSION};
|
||||
use crate::utils::Key;
|
||||
use failure::{bail, Fallible};
|
||||
use kv::msgpack::Msgpack;
|
||||
|
@ -62,8 +60,8 @@ impl<'t> KVStorage<'t> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'t> TaskStorage for KVStorage<'t> {
|
||||
fn txn<'a>(&'a mut self) -> Fallible<Box<dyn TaskStorageTxn + 'a>> {
|
||||
impl<'t> Storage for KVStorage<'t> {
|
||||
fn txn<'a>(&'a mut self) -> Fallible<Box<dyn StorageTxn + 'a>> {
|
||||
Ok(Box::new(Txn {
|
||||
storage: self,
|
||||
txn: Some(self.store.write_txn()?),
|
||||
|
@ -104,7 +102,7 @@ impl<'t> Txn<'t> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'t> TaskStorageTxn for Txn<'t> {
|
||||
impl<'t> StorageTxn for Txn<'t> {
|
||||
fn get_task(&mut self, uuid: Uuid) -> Fallible<Option<TaskMap>> {
|
||||
let bucket = self.tasks_bucket();
|
||||
let buf = match self.kvtxn().get(bucket, uuid.into()) {
|
||||
|
@ -356,7 +354,7 @@ impl<'t> TaskStorageTxn for Txn<'t> {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::taskstorage::taskmap_with;
|
||||
use crate::storage::taskmap_with;
|
||||
use failure::Fallible;
|
||||
use tempdir::TempDir;
|
||||
|
|
@ -29,7 +29,7 @@ pub use crate::server::VersionId;
|
|||
/// The default for base_version.
|
||||
pub(crate) const DEFAULT_BASE_VERSION: Uuid = crate::server::NO_VERSION_ID;
|
||||
|
||||
/// A TaskStorage transaction, in which storage operations are performed.
|
||||
/// A Storage transaction, in which storage operations are performed.
|
||||
///
|
||||
/// # Concurrency
|
||||
///
|
||||
|
@ -40,9 +40,9 @@ pub(crate) const DEFAULT_BASE_VERSION: Uuid = crate::server::NO_VERSION_ID;
|
|||
/// # Commiting and Aborting
|
||||
///
|
||||
/// A transaction is not visible to other readers until it is committed with
|
||||
/// [`crate::taskstorage::TaskStorageTxn::commit`]. Transactions are aborted if they are dropped.
|
||||
/// [`crate::storage::StorageTxn::commit`]. Transactions are aborted if they are dropped.
|
||||
/// It is safe and performant to drop transactions that did not modify any data without committing.
|
||||
pub trait TaskStorageTxn {
|
||||
pub trait StorageTxn {
|
||||
/// Get an (immutable) task, if it is in the storage
|
||||
fn get_task(&mut self, uuid: Uuid) -> Fallible<Option<TaskMap>>;
|
||||
|
||||
|
@ -102,8 +102,8 @@ pub trait TaskStorageTxn {
|
|||
}
|
||||
|
||||
/// A trait for objects able to act as task storage. Most of the interesting behavior is in the
|
||||
/// [`crate::taskstorage::TaskStorageTxn`] trait.
|
||||
pub trait TaskStorage {
|
||||
/// [`crate::storage::StorageTxn`] trait.
|
||||
pub trait Storage {
|
||||
/// Begin a transaction
|
||||
fn txn<'a>(&'a mut self) -> Fallible<Box<dyn TaskStorageTxn + 'a>>;
|
||||
fn txn<'a>(&'a mut self) -> Fallible<Box<dyn StorageTxn + 'a>>;
|
||||
}
|
|
@ -125,8 +125,8 @@ impl Operation {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::storage::InMemoryStorage;
|
||||
use crate::taskdb::TaskDB;
|
||||
use crate::taskstorage::InMemoryStorage;
|
||||
use chrono::{Duration, Utc};
|
||||
use proptest::prelude::*;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::replica::Replica;
|
||||
use crate::taskstorage::TaskMap;
|
||||
use crate::storage::TaskMap;
|
||||
use chrono::prelude::*;
|
||||
use failure::{format_err, Fallible};
|
||||
use log::trace;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::errors::Error;
|
||||
use crate::server::{AddVersionResult, GetVersionResult, Server};
|
||||
use crate::taskstorage::{Operation, TaskMap, TaskStorage, TaskStorageTxn};
|
||||
use crate::storage::{Operation, Storage, StorageTxn, TaskMap};
|
||||
use failure::{format_err, Fallible};
|
||||
use log::{info, trace, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -12,7 +12,7 @@ use uuid::Uuid;
|
|||
/// 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 {
|
||||
storage: Box<dyn TaskStorage>,
|
||||
storage: Box<dyn Storage>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
@ -22,13 +22,13 @@ struct Version {
|
|||
|
||||
impl TaskDB {
|
||||
/// Create a new TaskDB with the given backend storage
|
||||
pub fn new(storage: Box<dyn TaskStorage>) -> TaskDB {
|
||||
pub fn new(storage: Box<dyn Storage>) -> TaskDB {
|
||||
TaskDB { storage }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn new_inmemory() -> TaskDB {
|
||||
TaskDB::new(Box::new(crate::taskstorage::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
|
||||
|
@ -45,7 +45,7 @@ impl TaskDB {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn apply_op(txn: &mut dyn TaskStorageTxn, op: &Operation) -> Fallible<()> {
|
||||
fn apply_op(txn: &mut dyn StorageTxn, op: &Operation) -> Fallible<()> {
|
||||
match op {
|
||||
Operation::Create { uuid } => {
|
||||
// insert if the task does not already exist
|
||||
|
@ -261,7 +261,7 @@ impl TaskDB {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn apply_version(txn: &mut dyn TaskStorageTxn, mut version: Version) -> Fallible<()> {
|
||||
fn apply_version(txn: &mut dyn StorageTxn, mut version: Version) -> Fallible<()> {
|
||||
// The situation here is that the server has already applied all server operations, and we
|
||||
// have already applied all local operations, so states have diverged by several
|
||||
// operations. We need to figure out what operations to apply locally and on the server in
|
||||
|
@ -358,7 +358,7 @@ impl TaskDB {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use crate::server::test::TestServer;
|
||||
use crate::taskstorage::InMemoryStorage;
|
||||
use crate::storage::InMemoryStorage;
|
||||
use chrono::Utc;
|
||||
use proptest::prelude::*;
|
||||
use std::collections::HashMap;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue