From e40724b38195500f7f343b6d87c186973134db04 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 22 Apr 2021 11:48:05 +1000 Subject: [PATCH 01/38] Start of SQLite backed storage #131 --- Cargo.lock | 63 ++++ taskchampion/Cargo.toml | 1 + taskchampion/src/storage/mod.rs | 1 + taskchampion/src/storage/sqlite.rs | 495 +++++++++++++++++++++++++++++ 4 files changed, 560 insertions(+) create mode 100644 taskchampion/src/storage/sqlite.rs diff --git a/Cargo.lock b/Cargo.lock index 3d695cbfe..bdd220039 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -288,6 +288,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" + [[package]] name = "aho-corasick" version = "0.7.15" @@ -785,6 +791,18 @@ dependencies = [ "termcolor", ] +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + [[package]] name = "flate2" version = "1.0.20" @@ -1002,6 +1020,18 @@ name = "hashbrown" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashlink" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d99cf782f0dc4372d26846bec3de7804ceb5df083c2d4462c0b8d2330e894fa8" +dependencies = [ + "hashbrown", +] [[package]] name = "heck" @@ -1175,6 +1205,17 @@ version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" +[[package]] +name = "libsqlite3-sys" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19cb1effde5f834799ac5e5ef0e40d45027cd74f271b1de786ba8abb30e2164d" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linked-hash-map" version = "0.5.4" @@ -1868,6 +1909,21 @@ dependencies = [ "serde", ] +[[package]] +name = "rusqlite" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc783b7ddae608338003bac1fa00b6786a75a9675fbd8e87243ecfdea3f6ed2" +dependencies = [ + "bitflags", + "fallible-iterator", + "fallible-streaming-iterator", + "hashlink", + "libsqlite3-sys", + "memchr", + "smallvec", +] + [[package]] name = "rust-argon2" version = "0.8.3" @@ -2154,6 +2210,7 @@ dependencies = [ "lmdb-rkv 0.14.0", "log", "proptest", + "rusqlite", "serde", "serde_json", "tempfile", @@ -2589,6 +2646,12 @@ dependencies = [ "serde", ] +[[package]] +name = "vcpkg" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbdbff6266a24120518560b5dc983096efb98462e51d0d68169895b237be3e5d" + [[package]] name = "vec_map" version = "0.8.2" diff --git a/taskchampion/Cargo.toml b/taskchampion/Cargo.toml index 2505d1ef9..e5069cea6 100644 --- a/taskchampion/Cargo.toml +++ b/taskchampion/Cargo.toml @@ -22,6 +22,7 @@ lmdb-rkv = {version = "^0.14.0"} ureq = "^2.1.0" log = "^0.4.14" tindercrypt = { version = "^0.2.2", default-features = false } +rusqlite = { version = "0.25", features = ["bundled"] } [dev-dependencies] proptest = "^1.0.0" diff --git a/taskchampion/src/storage/mod.rs b/taskchampion/src/storage/mod.rs index b263fd56f..b4993b039 100644 --- a/taskchampion/src/storage/mod.rs +++ b/taskchampion/src/storage/mod.rs @@ -12,6 +12,7 @@ use uuid::Uuid; mod config; mod inmemory; mod kv; +mod sqlite; mod operation; pub use self::kv::KvStorage; diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs new file mode 100644 index 000000000..3992ae091 --- /dev/null +++ b/taskchampion/src/storage/sqlite.rs @@ -0,0 +1,495 @@ +use crate::storage::{Operation, Storage, StorageTxn, TaskMap, VersionId, DEFAULT_BASE_VERSION}; +use crate::utils::Key; +use anyhow::Context; +use rusqlite::Connection; +use serde::serde_if_integer128; +use std::path::Path; +use uuid::Uuid; + +#[derive(Debug, thiserror::Error)] +enum SqliteError { + #[error("SQLite transaction already committted")] + TransactionAlreadyCommitted, +} + +/// SqliteStorage is an on-disk storage backed by SQLite3. +pub struct SqliteStorage { + con: Connection, +} + +impl SqliteStorage { + pub fn new>(directory: P) -> anyhow::Result { + let db_file = directory.as_ref().join("taskchampion.sqlite3"); + let con = Connection::open(db_file)?; + con.execute( + "CREATE TABLE IF NOT EXISTS tasks (uuid STRING PRIMARY KEY, data STRING)", + [], + ) + .context("Creating table")?; + Ok(SqliteStorage { con }) + } +} + +struct Txn<'t> { + txn: Option>, +} + +impl<'t> Txn<'t> { + fn get_txn(&self) -> Result<&rusqlite::Transaction<'t>, SqliteError> { + self.txn + .as_ref() + .ok_or_else(|| SqliteError::TransactionAlreadyCommitted) + } +} + +impl Storage for SqliteStorage { + fn txn<'a>(&'a mut self) -> anyhow::Result> { + let txn = self.con.transaction()?; + Ok(Box::new(Txn { txn: Some(txn) })) + } +} + +impl<'t> StorageTxn for Txn<'t> { + fn get_task(&mut self, uuid: Uuid) -> anyhow::Result> { + let t = self.get_txn()?; + let result: Result = t.query_row( + "SELECT data FROM tasks WHERE uuid = ? LIMIT 1", + [&uuid.to_string()], + |r| r.get(0), + ); + + match result { + Ok(ref r) => { + let tm = serde_json::from_str(&r)?; + Ok(Some(tm)) + } + Err(rusqlite::Error::QueryReturnedNoRows) => Ok(None), + Err(e) => Err(anyhow::Error::from(e)), + } + } + + fn create_task(&mut self, uuid: Uuid) -> anyhow::Result { + let t = self.get_txn()?; + let count: usize = t.query_row( + "SELECT count(uuid) FROM tasks WHERE uuid = ?", + [&uuid.to_string()], + |x| x.get(0), + )?; + if count > 0 { + return Ok(false); + } + + let data = TaskMap::default(); + let data_str = serde_json::to_string(&data)?; + t.execute( + "INSERT INTO TASKS (uuid, data) VALUES (?, ?)", + [&uuid.to_string(), &data_str], + ) + .context("Create task query")?; + Ok(true) + } + + fn set_task(&mut self, uuid: Uuid, task: TaskMap) -> anyhow::Result<()> { + let t = self.get_txn()?; + let data_str = serde_json::to_string(&task)?; + t.execute( + "INSERT OR REPLACE INTO tasks (uuid, data) VALUES (?, ?)", + [&uuid.to_string(), &data_str], + ) + .context("Update task query")?; + Ok(()) + } + + fn delete_task(&mut self, uuid: Uuid) -> anyhow::Result { + let t = self.get_txn()?; + let changed = t + .execute("DELETE FROM tasks WHERE uuid = ?", [&uuid.to_string()]) + .context("Delete task query")?; + Ok(changed > 0) + } + + fn all_tasks(&mut self) -> anyhow::Result> { + todo!() + } + + fn all_task_uuids(&mut self) -> anyhow::Result> { + todo!() + } + + fn base_version(&mut self) -> anyhow::Result { + todo!() + } + + fn set_base_version(&mut self, version: VersionId) -> anyhow::Result<()> { + todo!() + } + + fn operations(&mut self) -> anyhow::Result> { + todo!() + } + + fn add_operation(&mut self, op: Operation) -> anyhow::Result<()> { + todo!() + } + + fn set_operations(&mut self, ops: Vec) -> anyhow::Result<()> { + todo!() + } + + fn get_working_set(&mut self) -> anyhow::Result>> { + todo!() + } + + fn add_to_working_set(&mut self, uuid: Uuid) -> anyhow::Result { + todo!() + } + + fn set_working_set_item(&mut self, index: usize, uuid: Option) -> anyhow::Result<()> { + todo!() + } + + fn clear_working_set(&mut self) -> anyhow::Result<()> { + todo!() + } + + fn commit(&mut self) -> anyhow::Result<()> { + let t = self + .txn + .take() + .ok_or(SqliteError::TransactionAlreadyCommitted)?; + t.commit().context("Committing transaction")?; + Ok(()) + } +} + +#[cfg(test)] +mod test { + use super::*; + use crate::storage::taskmap_with; + use tempfile::TempDir; + + #[test] + fn test_create() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + let uuid = Uuid::new_v4(); + { + let mut txn = storage.txn()?; + assert!(txn.create_task(uuid)?); + txn.commit()?; + } + { + let mut txn = storage.txn()?; + let task = txn.get_task(uuid)?; + assert_eq!(task, Some(taskmap_with(vec![]))); + } + Ok(()) + } + + #[test] + fn test_create_exists() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + let uuid = Uuid::new_v4(); + { + let mut txn = storage.txn()?; + assert!(txn.create_task(uuid)?); + txn.commit()?; + } + { + let mut txn = storage.txn()?; + assert!(!txn.create_task(uuid)?); + txn.commit()?; + } + Ok(()) + } + + #[test] + fn test_get_missing() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + let uuid = Uuid::new_v4(); + { + let mut txn = storage.txn()?; + let task = txn.get_task(uuid)?; + assert_eq!(task, None); + } + Ok(()) + } + + #[test] + fn test_set_task() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + let uuid = Uuid::new_v4(); + { + let mut txn = storage.txn()?; + txn.set_task(uuid, taskmap_with(vec![("k".to_string(), "v".to_string())]))?; + txn.commit()?; + } + { + let mut txn = storage.txn()?; + let task = txn.get_task(uuid)?; + assert_eq!( + task, + Some(taskmap_with(vec![("k".to_string(), "v".to_string())])) + ); + } + Ok(()) + } + + #[test] + fn test_delete_task_missing() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + let uuid = Uuid::new_v4(); + { + let mut txn = storage.txn()?; + assert!(!txn.delete_task(uuid)?); + } + Ok(()) + } + + #[test] + fn test_delete_task_exists() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + let uuid = Uuid::new_v4(); + { + let mut txn = storage.txn()?; + assert!(txn.create_task(uuid)?); + txn.commit()?; + } + { + let mut txn = storage.txn()?; + assert!(txn.delete_task(uuid)?); + } + Ok(()) + } + + #[test] + fn test_all_tasks_empty() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + { + let mut txn = storage.txn()?; + let tasks = txn.all_tasks()?; + assert_eq!(tasks, vec![]); + } + Ok(()) + } + + #[test] + fn test_all_tasks_and_uuids() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + let uuid1 = Uuid::new_v4(); + let uuid2 = Uuid::new_v4(); + { + let mut txn = storage.txn()?; + assert!(txn.create_task(uuid1.clone())?); + txn.set_task( + uuid1.clone(), + taskmap_with(vec![("num".to_string(), "1".to_string())]), + )?; + assert!(txn.create_task(uuid2.clone())?); + txn.set_task( + uuid2.clone(), + taskmap_with(vec![("num".to_string(), "2".to_string())]), + )?; + txn.commit()?; + } + { + let mut txn = storage.txn()?; + let mut tasks = txn.all_tasks()?; + + // order is nondeterministic, so sort by uuid + tasks.sort_by(|a, b| a.0.cmp(&b.0)); + + let mut exp = vec![ + ( + uuid1.clone(), + taskmap_with(vec![("num".to_string(), "1".to_string())]), + ), + ( + uuid2.clone(), + taskmap_with(vec![("num".to_string(), "2".to_string())]), + ), + ]; + exp.sort_by(|a, b| a.0.cmp(&b.0)); + + assert_eq!(tasks, exp); + } + { + let mut txn = storage.txn()?; + let mut uuids = txn.all_task_uuids()?; + uuids.sort(); + + let mut exp = vec![uuid1.clone(), uuid2.clone()]; + exp.sort(); + + assert_eq!(uuids, exp); + } + Ok(()) + } + + #[test] + fn test_base_version_default() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + { + let mut txn = storage.txn()?; + assert_eq!(txn.base_version()?, DEFAULT_BASE_VERSION); + } + Ok(()) + } + + #[test] + fn test_base_version_setting() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + let u = Uuid::new_v4(); + { + let mut txn = storage.txn()?; + txn.set_base_version(u)?; + txn.commit()?; + } + { + let mut txn = storage.txn()?; + assert_eq!(txn.base_version()?, u); + } + Ok(()) + } + + #[test] + fn test_operations() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + let uuid1 = Uuid::new_v4(); + let uuid2 = Uuid::new_v4(); + let uuid3 = Uuid::new_v4(); + + // create some operations + { + let mut txn = storage.txn()?; + txn.add_operation(Operation::Create { uuid: uuid1 })?; + txn.add_operation(Operation::Create { uuid: uuid2 })?; + txn.commit()?; + } + + // read them back + { + let mut txn = storage.txn()?; + let ops = txn.operations()?; + assert_eq!( + ops, + vec![ + Operation::Create { uuid: uuid1 }, + Operation::Create { uuid: uuid2 }, + ] + ); + } + + // set them to a different bunch + { + let mut txn = storage.txn()?; + txn.set_operations(vec![ + Operation::Delete { uuid: uuid2 }, + Operation::Delete { uuid: uuid1 }, + ])?; + txn.commit()?; + } + + // create some more operations (to test adding operations after clearing) + { + let mut txn = storage.txn()?; + txn.add_operation(Operation::Create { uuid: uuid3 })?; + txn.add_operation(Operation::Delete { uuid: uuid3 })?; + txn.commit()?; + } + + // read them back + { + let mut txn = storage.txn()?; + let ops = txn.operations()?; + assert_eq!( + ops, + vec![ + Operation::Delete { uuid: uuid2 }, + Operation::Delete { uuid: uuid1 }, + Operation::Create { uuid: uuid3 }, + Operation::Delete { uuid: uuid3 }, + ] + ); + } + Ok(()) + } + + #[test] + fn get_working_set_empty() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + + { + let mut txn = storage.txn()?; + let ws = txn.get_working_set()?; + assert_eq!(ws, vec![None]); + } + + Ok(()) + } + + #[test] + fn add_to_working_set() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + let uuid1 = Uuid::new_v4(); + let uuid2 = Uuid::new_v4(); + + { + let mut txn = storage.txn()?; + txn.add_to_working_set(uuid1)?; + txn.add_to_working_set(uuid2)?; + txn.commit()?; + } + + { + let mut txn = storage.txn()?; + let ws = txn.get_working_set()?; + assert_eq!(ws, vec![None, Some(uuid1), Some(uuid2)]); + } + + Ok(()) + } + + #[test] + fn clear_working_set() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + let uuid1 = Uuid::new_v4(); + let uuid2 = Uuid::new_v4(); + + { + let mut txn = storage.txn()?; + txn.add_to_working_set(uuid1)?; + txn.add_to_working_set(uuid2)?; + txn.commit()?; + } + + { + let mut txn = storage.txn()?; + txn.clear_working_set()?; + txn.add_to_working_set(uuid2)?; + txn.add_to_working_set(uuid1)?; + txn.commit()?; + } + + { + let mut txn = storage.txn()?; + let ws = txn.get_working_set()?; + assert_eq!(ws, vec![None, Some(uuid2), Some(uuid1)]); + } + + Ok(()) + } +} From 0f3729d4c86d212ad827c1e9d22ea5232b721dc4 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 22 Apr 2021 12:54:34 +1000 Subject: [PATCH 02/38] sqlite: Get all rows Needs some improvement to error handling --- taskchampion/src/storage/sqlite.rs | 40 ++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index 3992ae091..e38481ddc 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -1,7 +1,7 @@ use crate::storage::{Operation, Storage, StorageTxn, TaskMap, VersionId, DEFAULT_BASE_VERSION}; use crate::utils::Key; use anyhow::Context; -use rusqlite::Connection; +use rusqlite::{Connection, OptionalExtension}; use serde::serde_if_integer128; use std::path::Path; use uuid::Uuid; @@ -10,6 +10,8 @@ use uuid::Uuid; enum SqliteError { #[error("SQLite transaction already committted")] TransactionAlreadyCommitted, + #[error("Invalid UUID string from database: {0}")] + InvalidUuidString(String), } /// SqliteStorage is an on-disk storage backed by SQLite3. @@ -52,19 +54,17 @@ impl Storage for SqliteStorage { impl<'t> StorageTxn for Txn<'t> { fn get_task(&mut self, uuid: Uuid) -> anyhow::Result> { let t = self.get_txn()?; - let result: Result = t.query_row( - "SELECT data FROM tasks WHERE uuid = ? LIMIT 1", - [&uuid.to_string()], - |r| r.get(0), - ); + let result: Option = t + .query_row( + "SELECT data FROM tasks WHERE uuid = ? LIMIT 1", + [&uuid.to_string()], + |r| r.get(0), + ) + .optional()?; match result { - Ok(ref r) => { - let tm = serde_json::from_str(&r)?; - Ok(Some(tm)) - } - Err(rusqlite::Error::QueryReturnedNoRows) => Ok(None), - Err(e) => Err(anyhow::Error::from(e)), + None => Ok(None), + Some(r) => Ok(serde_json::from_str(&r)?), } } @@ -109,7 +109,21 @@ impl<'t> StorageTxn for Txn<'t> { } fn all_tasks(&mut self) -> anyhow::Result> { - todo!() + let t = self.get_txn()?; + let mut q = t.prepare("SELECT uuid, data FROM tasks")?; + let rows = q + .query_map([], |r| { + let uuid_str: String = r.get(0)?; + let data_str: String = r.get(1)?; + let uuid = Uuid::parse_str(&uuid_str).unwrap(); // FIXME: Remove unwrap + let data = serde_json::from_str(&data_str).unwrap(); // FIXME: Remove unwrap + Ok((uuid, data)) + })?; + let mut ret = vec![]; + for r in rows { + ret.push(r?); + } + Ok(ret) } fn all_task_uuids(&mut self) -> anyhow::Result> { From 4bd6c40daf5d47d5215d7f1f8b13af264bea8333 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 22 Apr 2021 13:31:15 +1000 Subject: [PATCH 03/38] Use uuid feature of rusqlite --- taskchampion/Cargo.toml | 2 +- taskchampion/src/storage/sqlite.rs | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/taskchampion/Cargo.toml b/taskchampion/Cargo.toml index e5069cea6..1f8b52828 100644 --- a/taskchampion/Cargo.toml +++ b/taskchampion/Cargo.toml @@ -22,7 +22,7 @@ lmdb-rkv = {version = "^0.14.0"} ureq = "^2.1.0" log = "^0.4.14" tindercrypt = { version = "^0.2.2", default-features = false } -rusqlite = { version = "0.25", features = ["bundled"] } +rusqlite = { version = "0.25", features = ["bundled", "uuid"] } [dev-dependencies] proptest = "^1.0.0" diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index e38481ddc..e989aa393 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -1,7 +1,7 @@ use crate::storage::{Operation, Storage, StorageTxn, TaskMap, VersionId, DEFAULT_BASE_VERSION}; use crate::utils::Key; use anyhow::Context; -use rusqlite::{Connection, OptionalExtension}; +use rusqlite::{Connection, OptionalExtension, params}; use serde::serde_if_integer128; use std::path::Path; use uuid::Uuid; @@ -57,7 +57,7 @@ impl<'t> StorageTxn for Txn<'t> { let result: Option = t .query_row( "SELECT data FROM tasks WHERE uuid = ? LIMIT 1", - [&uuid.to_string()], + [&uuid], |r| r.get(0), ) .optional()?; @@ -72,7 +72,7 @@ impl<'t> StorageTxn for Txn<'t> { let t = self.get_txn()?; let count: usize = t.query_row( "SELECT count(uuid) FROM tasks WHERE uuid = ?", - [&uuid.to_string()], + [&uuid], |x| x.get(0), )?; if count > 0 { @@ -83,7 +83,7 @@ impl<'t> StorageTxn for Txn<'t> { let data_str = serde_json::to_string(&data)?; t.execute( "INSERT INTO TASKS (uuid, data) VALUES (?, ?)", - [&uuid.to_string(), &data_str], + params![&uuid, &data_str], ) .context("Create task query")?; Ok(true) @@ -94,7 +94,7 @@ impl<'t> StorageTxn for Txn<'t> { let data_str = serde_json::to_string(&task)?; t.execute( "INSERT OR REPLACE INTO tasks (uuid, data) VALUES (?, ?)", - [&uuid.to_string(), &data_str], + params![&uuid, &data_str], ) .context("Update task query")?; Ok(()) @@ -103,7 +103,7 @@ impl<'t> StorageTxn for Txn<'t> { fn delete_task(&mut self, uuid: Uuid) -> anyhow::Result { let t = self.get_txn()?; let changed = t - .execute("DELETE FROM tasks WHERE uuid = ?", [&uuid.to_string()]) + .execute("DELETE FROM tasks WHERE uuid = ?", [&uuid]) .context("Delete task query")?; Ok(changed > 0) } @@ -113,9 +113,8 @@ impl<'t> StorageTxn for Txn<'t> { let mut q = t.prepare("SELECT uuid, data FROM tasks")?; let rows = q .query_map([], |r| { - let uuid_str: String = r.get(0)?; + let uuid: Uuid = r.get(0)?; let data_str: String = r.get(1)?; - let uuid = Uuid::parse_str(&uuid_str).unwrap(); // FIXME: Remove unwrap let data = serde_json::from_str(&data_str).unwrap(); // FIXME: Remove unwrap Ok((uuid, data)) })?; From a9b93e7c20beeb4d2cc1ff6d16b3667d0abc6bac Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 22 Apr 2021 13:33:54 +1000 Subject: [PATCH 04/38] Use names for row.get(...) --- taskchampion/src/storage/sqlite.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index e989aa393..dfafba7b9 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -58,7 +58,7 @@ impl<'t> StorageTxn for Txn<'t> { .query_row( "SELECT data FROM tasks WHERE uuid = ? LIMIT 1", [&uuid], - |r| r.get(0), + |r| r.get("data"), ) .optional()?; @@ -113,8 +113,8 @@ impl<'t> StorageTxn for Txn<'t> { let mut q = t.prepare("SELECT uuid, data FROM tasks")?; let rows = q .query_map([], |r| { - let uuid: Uuid = r.get(0)?; - let data_str: String = r.get(1)?; + let uuid: Uuid = r.get("uuid")?; + let data_str: String = r.get("data")?; let data = serde_json::from_str(&data_str).unwrap(); // FIXME: Remove unwrap Ok((uuid, data)) })?; From 11d0172bf805d3918d04933ee3c7bb934634eef6 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 22 Apr 2021 14:15:50 +1000 Subject: [PATCH 05/38] fmt --- taskchampion/src/storage/mod.rs | 2 +- taskchampion/src/storage/sqlite.rs | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/taskchampion/src/storage/mod.rs b/taskchampion/src/storage/mod.rs index b4993b039..a4c430b94 100644 --- a/taskchampion/src/storage/mod.rs +++ b/taskchampion/src/storage/mod.rs @@ -12,8 +12,8 @@ use uuid::Uuid; mod config; mod inmemory; mod kv; -mod sqlite; mod operation; +mod sqlite; pub use self::kv::KvStorage; pub use config::StorageConfig; diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index dfafba7b9..2dc2e7dbd 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -1,7 +1,7 @@ use crate::storage::{Operation, Storage, StorageTxn, TaskMap, VersionId, DEFAULT_BASE_VERSION}; use crate::utils::Key; use anyhow::Context; -use rusqlite::{Connection, OptionalExtension, params}; +use rusqlite::{params, Connection, OptionalExtension}; use serde::serde_if_integer128; use std::path::Path; use uuid::Uuid; @@ -111,13 +111,12 @@ impl<'t> StorageTxn for Txn<'t> { fn all_tasks(&mut self) -> anyhow::Result> { let t = self.get_txn()?; let mut q = t.prepare("SELECT uuid, data FROM tasks")?; - let rows = q - .query_map([], |r| { - let uuid: Uuid = r.get("uuid")?; - let data_str: String = r.get("data")?; - let data = serde_json::from_str(&data_str).unwrap(); // FIXME: Remove unwrap - Ok((uuid, data)) - })?; + let rows = q.query_map([], |r| { + let uuid: Uuid = r.get("uuid")?; + let data_str: String = r.get("data")?; + let data: TaskMap = serde_json::from_str(&data_str).unwrap(); // FIXME: Remove unwrap + Ok((uuid, data)) + })?; let mut ret = vec![]; for r in rows { ret.push(r?); From 305e6e2edee695094c76087b9a94cb8e4dc19400 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 22 Apr 2021 14:16:07 +1000 Subject: [PATCH 06/38] Appease clippy --- taskchampion/src/storage/sqlite.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index 2dc2e7dbd..e31076898 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -40,7 +40,7 @@ impl<'t> Txn<'t> { fn get_txn(&self) -> Result<&rusqlite::Transaction<'t>, SqliteError> { self.txn .as_ref() - .ok_or_else(|| SqliteError::TransactionAlreadyCommitted) + .ok_or(SqliteError::TransactionAlreadyCommitted) } } From 1959f0c63a8a6102bcb2a9670264adadfcd66cd3 Mon Sep 17 00:00:00 2001 From: dbr Date: Tue, 27 Apr 2021 19:35:45 +1000 Subject: [PATCH 07/38] Implement all_task_uuids and base version methods --- taskchampion/Cargo.toml | 2 +- taskchampion/src/storage/sqlite.rs | 49 +++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/taskchampion/Cargo.toml b/taskchampion/Cargo.toml index 1f8b52828..e5a1ab801 100644 --- a/taskchampion/Cargo.toml +++ b/taskchampion/Cargo.toml @@ -22,7 +22,7 @@ lmdb-rkv = {version = "^0.14.0"} ureq = "^2.1.0" log = "^0.4.14" tindercrypt = { version = "^0.2.2", default-features = false } -rusqlite = { version = "0.25", features = ["bundled", "uuid"] } +rusqlite = { version = "0.25", features = ["bundled", "uuid", "serde_json"] } [dev-dependencies] proptest = "^1.0.0" diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index e31076898..6aaf7b85a 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -23,11 +23,15 @@ impl SqliteStorage { pub fn new>(directory: P) -> anyhow::Result { let db_file = directory.as_ref().join("taskchampion.sqlite3"); let con = Connection::open(db_file)?; - con.execute( - "CREATE TABLE IF NOT EXISTS tasks (uuid STRING PRIMARY KEY, data STRING)", - [], - ) - .context("Creating table")?; + + let queries = vec![ + "CREATE TABLE IF NOT EXISTS tasks (uuid STRING PRIMARY KEY, data STRING);", + "CREATE TABLE IF NOT EXISTS sync_meta (key STRING PRIMARY KEY, value STRING);", + ]; + for q in queries { + con.execute(q, []).context("Creating table")?; + } + Ok(SqliteStorage { con }) } } @@ -110,6 +114,7 @@ impl<'t> StorageTxn for Txn<'t> { fn all_tasks(&mut self) -> anyhow::Result> { let t = self.get_txn()?; + let mut q = t.prepare("SELECT uuid, data FROM tasks")?; let rows = q.query_map([], |r| { let uuid: Uuid = r.get("uuid")?; @@ -117,6 +122,7 @@ impl<'t> StorageTxn for Txn<'t> { let data: TaskMap = serde_json::from_str(&data_str).unwrap(); // FIXME: Remove unwrap Ok((uuid, data)) })?; + let mut ret = vec![]; for r in rows { ret.push(r?); @@ -125,15 +131,42 @@ impl<'t> StorageTxn for Txn<'t> { } fn all_task_uuids(&mut self) -> anyhow::Result> { - todo!() + let t = self.get_txn()?; + + let mut q = t.prepare("SELECT uuid FROM tasks")?; + let rows = q.query_map([], |r| { + let uuid: Uuid = r.get("uuid")?; + Ok(uuid) + })?; + + let mut ret = vec![]; + for r in rows { + ret.push(r?); + } + Ok(ret) } fn base_version(&mut self) -> anyhow::Result { - todo!() + let t = self.get_txn()?; + + let mut version = t + .query_row( + "SELECT value FROM sync_meta WHERE key = 'base_version'", + [], + |r| r.get("value"), + ) + .optional()?; + Ok(version.unwrap_or(DEFAULT_BASE_VERSION)) } fn set_base_version(&mut self, version: VersionId) -> anyhow::Result<()> { - todo!() + let t = self.get_txn()?; + t.execute( + "INSERT OR REPLACE INTO sync_meta (key, value) VALUES (?, ?)", + params!["base_version", &version], + ) + .context("Set base version")?; + Ok(()) } fn operations(&mut self) -> anyhow::Result> { From 2b7e121e7ee1d515d89dda4569922428ff2bfcac Mon Sep 17 00:00:00 2001 From: dbr Date: Wed, 28 Apr 2021 12:35:50 +1000 Subject: [PATCH 08/38] Implement operations storage for SQLite --- taskchampion/src/storage/sqlite.rs | 38 +++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index 6aaf7b85a..d5bcc3dd9 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -26,6 +26,7 @@ impl SqliteStorage { let queries = vec![ "CREATE TABLE IF NOT EXISTS tasks (uuid STRING PRIMARY KEY, data STRING);", + "CREATE TABLE IF NOT EXISTS operations (id INTEGER PRIMARY KEY AUTOINCREMENT, data STRING);", "CREATE TABLE IF NOT EXISTS sync_meta (key STRING PRIMARY KEY, value STRING);", ]; for q in queries { @@ -170,15 +171,46 @@ impl<'t> StorageTxn for Txn<'t> { } fn operations(&mut self) -> anyhow::Result> { - todo!() + let t = self.get_txn()?; + + let mut q = t.prepare("SELECT data FROM operations ORDER BY id ASC")?; + let rows = q.query_map([], |r| { + let data_str: String = r.get("data")?; + let data: Operation = serde_json::from_str(&data_str).unwrap(); // FIXME: Remove unwrap + Ok(data) + })?; + + let mut ret = vec![]; + for r in rows { + ret.push(r?); + } + Ok(ret) } fn add_operation(&mut self, op: Operation) -> anyhow::Result<()> { - todo!() + let t = self.get_txn()?; + + let data_str = serde_json::to_string(&op)?; + t.execute( + "INSERT INTO operations (data) VALUES (?)", + params![&data_str], + ) + .context("Add operation query")?; + Ok(()) } fn set_operations(&mut self, ops: Vec) -> anyhow::Result<()> { - todo!() + let t = self.get_txn()?; + t.execute( + "DELETE FROM operations", + [], + ) + .context("Clear all existing operations")?; + + for o in ops { + self.add_operation(o)?; + } + Ok(()) } fn get_working_set(&mut self) -> anyhow::Result>> { From 5ae828b1ebedfc8ac7e6428a77c2d676888f259a Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 29 Apr 2021 00:09:54 +1000 Subject: [PATCH 09/38] Implement working set methods --- taskchampion/src/storage/sqlite.rs | 120 +++++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 5 deletions(-) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index d5bcc3dd9..fac09e817 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -25,9 +25,10 @@ impl SqliteStorage { let con = Connection::open(db_file)?; let queries = vec![ - "CREATE TABLE IF NOT EXISTS tasks (uuid STRING PRIMARY KEY, data STRING);", "CREATE TABLE IF NOT EXISTS operations (id INTEGER PRIMARY KEY AUTOINCREMENT, data STRING);", "CREATE TABLE IF NOT EXISTS sync_meta (key STRING PRIMARY KEY, value STRING);", + "CREATE TABLE IF NOT EXISTS tasks (uuid STRING PRIMARY KEY, data STRING);", + "CREATE TABLE IF NOT EXISTS working_set (id INTEGER PRIMARY KEY, uuid STRING);", ]; for q in queries { con.execute(q, []).context("Creating table")?; @@ -47,6 +48,18 @@ impl<'t> Txn<'t> { .as_ref() .ok_or(SqliteError::TransactionAlreadyCommitted) } + + fn get_next_working_set_number(&self) -> anyhow::Result { + let t = self.get_txn()?; + let result: Option = t + .query_row("SELECT COALESCE(MAX(id), 0) FROM working_set", [], |r| { + r.get(0) + }) + .optional() + .context("Getting highest working set ID")?; + + Ok(result.unwrap_or(0) + 1) + } } impl Storage for SqliteStorage { @@ -214,19 +227,64 @@ impl<'t> StorageTxn for Txn<'t> { } fn get_working_set(&mut self) -> anyhow::Result>> { - todo!() + let t = self.get_txn()?; + + let mut q = t.prepare("SELECT id, uuid FROM working_set ORDER BY id ASC")?; + let rows = q + .query_map([], |r| { + let id: usize = r.get("id")?; + let uuid: Uuid = r.get("uuid")?; + Ok((id, uuid)) + }) + .context("Get working set query")?; + + let rows: Vec> = rows.collect(); + let mut res = Vec::with_capacity(rows.len()); + for _ in 0..self.get_next_working_set_number().context("HUh")? { + res.push(None); + } + for r in rows { + let (id, uuid) = r?; + res[id as usize] = Some(uuid); + } + + Ok(res) } fn add_to_working_set(&mut self, uuid: Uuid) -> anyhow::Result { - todo!() + let t = self.get_txn()?; + + let next_working_id = self.get_next_working_set_number()?; + + t.execute( + "INSERT INTO working_set (id, uuid) VALUES (?, ?)", + params![next_working_id, &uuid], + ) + .context("Create task query")?; + + Ok(next_working_id) } fn set_working_set_item(&mut self, index: usize, uuid: Option) -> anyhow::Result<()> { - todo!() + let t = self.get_txn()?; + match uuid { + // Add or override item + Some(uuid) => t.execute( + "INSERT OR REPLACE INTO working_set (id, uuid) VALUES (?, ?)", + params![index, &uuid], + ), + // Setting to None removes the row from database + None => t.execute("DELETE FROM working_set WHERE id = ?", [index]), + } + .context("Set working set item query")?; + Ok(()) } fn clear_working_set(&mut self) -> anyhow::Result<()> { - todo!() + let t = self.get_txn()?; + t.execute("DELETE FROM working_set", []) + .context("Clear working set query")?; + Ok(()) } fn commit(&mut self) -> anyhow::Result<()> { @@ -569,4 +627,56 @@ mod test { Ok(()) } + + #[test] + fn set_working_set_item() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + let uuid1 = Uuid::new_v4(); + let uuid2 = Uuid::new_v4(); + + { + let mut txn = storage.txn()?; + txn.add_to_working_set(uuid1)?; + txn.add_to_working_set(uuid2)?; + txn.commit()?; + } + + { + let mut txn = storage.txn()?; + let ws = txn.get_working_set()?; + assert_eq!(ws, vec![None, Some(uuid1), Some(uuid2)]); + } + + // Clear one item + dbg!(1); + { + let mut txn = storage.txn()?; + let ws = txn.set_working_set_item(1, None)?; + txn.commit()?; + } + + dbg!(2); + { + let mut txn = storage.txn()?; + let ws = txn.get_working_set()?; + assert_eq!(ws, vec![None, None, Some(uuid2)]); + } + + dbg!(3); + // Override item + { + let mut txn = storage.txn()?; + let ws = txn.set_working_set_item(2, Some(uuid1))?; + txn.commit()?; + } + + { + let mut txn = storage.txn()?; + let ws = txn.get_working_set()?; + assert_eq!(ws, vec![None, None, Some(uuid1)]); + } + + Ok(()) + } } From cf70ef49ede09ecbac06d9928e83dd4bd20f3df4 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 29 Apr 2021 00:10:53 +1000 Subject: [PATCH 10/38] Minor tidying --- taskchampion/src/storage/sqlite.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index fac09e817..4f57ed3ab 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -100,7 +100,7 @@ impl<'t> StorageTxn for Txn<'t> { let data = TaskMap::default(); let data_str = serde_json::to_string(&data)?; t.execute( - "INSERT INTO TASKS (uuid, data) VALUES (?, ?)", + "INSERT INTO tasks (uuid, data) VALUES (?, ?)", params![&uuid, &data_str], ) .context("Create task query")?; @@ -214,11 +214,8 @@ impl<'t> StorageTxn for Txn<'t> { fn set_operations(&mut self, ops: Vec) -> anyhow::Result<()> { let t = self.get_txn()?; - t.execute( - "DELETE FROM operations", - [], - ) - .context("Clear all existing operations")?; + t.execute("DELETE FROM operations", []) + .context("Clear all existing operations")?; for o in ops { self.add_operation(o)?; From e06e33bee499875c276689995a804da013179efe Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 29 Apr 2021 00:20:13 +1000 Subject: [PATCH 11/38] Remove kv storage backend Now uses sqlite by default --- Cargo.lock | 30 +- taskchampion/Cargo.toml | 1 - taskchampion/src/storage/config.rs | 4 +- taskchampion/src/storage/kv.rs | 683 ----------------------------- taskchampion/src/storage/mod.rs | 3 +- 5 files changed, 7 insertions(+), 714 deletions(-) delete mode 100644 taskchampion/src/storage/kv.rs diff --git a/Cargo.lock b/Cargo.lock index bdd220039..8777c807b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1167,7 +1167,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb79e59d356a5ae85b13990bbb3649a293d64df1ca6e7890822076186527a9f7" dependencies = [ - "lmdb-rkv 0.12.3", + "lmdb-rkv", "rmp-serde", "serde", "thiserror", @@ -1231,19 +1231,7 @@ dependencies = [ "bitflags", "byteorder", "libc", - "lmdb-rkv-sys 0.9.6", -] - -[[package]] -name = "lmdb-rkv" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447a296f7aca299cfbb50f4e4f3d49451549af655fb7215d7f8c0c3d64bad42b" -dependencies = [ - "bitflags", - "byteorder", - "libc", - "lmdb-rkv-sys 0.11.0", + "lmdb-rkv-sys", ] [[package]] @@ -1257,17 +1245,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "lmdb-rkv-sys" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b27470ac25167b3afdfb6af8fcd3bc1be67de50ffbdaf4073378cfded6ae24a5" -dependencies = [ - "cc", - "libc", - "pkg-config", -] - [[package]] name = "lock_api" version = "0.4.3" @@ -1921,7 +1898,9 @@ dependencies = [ "hashlink", "libsqlite3-sys", "memchr", + "serde_json", "smallvec", + "uuid", ] [[package]] @@ -2207,7 +2186,6 @@ dependencies = [ "anyhow", "chrono", "kv", - "lmdb-rkv 0.14.0", "log", "proptest", "rusqlite", diff --git a/taskchampion/Cargo.toml b/taskchampion/Cargo.toml index e5a1ab801..196c2a7d8 100644 --- a/taskchampion/Cargo.toml +++ b/taskchampion/Cargo.toml @@ -18,7 +18,6 @@ chrono = { version = "^0.4.10", features = ["serde"] } anyhow = "1.0" thiserror = "1.0" kv = {version = "^0.10.0", features = ["msgpack-value"]} -lmdb-rkv = {version = "^0.14.0"} ureq = "^2.1.0" log = "^0.4.14" tindercrypt = { version = "^0.2.2", default-features = false } diff --git a/taskchampion/src/storage/config.rs b/taskchampion/src/storage/config.rs index 773baa035..a802e4a09 100644 --- a/taskchampion/src/storage/config.rs +++ b/taskchampion/src/storage/config.rs @@ -1,4 +1,4 @@ -use super::{InMemoryStorage, KvStorage, Storage}; +use super::{InMemoryStorage, SqliteStorage, 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> { Ok(match self { - StorageConfig::OnDisk { taskdb_dir } => Box::new(KvStorage::new(taskdb_dir)?), + StorageConfig::OnDisk { taskdb_dir } => Box::new(SqliteStorage::new(taskdb_dir)?), StorageConfig::InMemory => Box::new(InMemoryStorage::new()), }) } diff --git a/taskchampion/src/storage/kv.rs b/taskchampion/src/storage/kv.rs deleted file mode 100644 index e65e31dfa..000000000 --- a/taskchampion/src/storage/kv.rs +++ /dev/null @@ -1,683 +0,0 @@ -use crate::storage::{Operation, Storage, StorageTxn, TaskMap, VersionId, DEFAULT_BASE_VERSION}; -use crate::utils::Key; -use kv::msgpack::Msgpack; -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> { - store: Store, - tasks_bucket: Bucket<'t, Key, ValueBuf>>, - numbers_bucket: Bucket<'t, Integer, ValueBuf>>, - uuids_bucket: Bucket<'t, Integer, ValueBuf>>, - operations_bucket: Bucket<'t, Integer, ValueBuf>>, - working_set_bucket: Bucket<'t, Integer, ValueBuf>>, -} - -const BASE_VERSION: u64 = 1; -const NEXT_OPERATION: u64 = 2; -const NEXT_WORKING_SET_INDEX: u64 = 3; - -impl<'t> KvStorage<'t> { - pub fn new>(directory: P) -> anyhow::Result> { - let mut config = Config::default(directory); - config.bucket("tasks", None); - config.bucket("numbers", None); - config.bucket("uuids", None); - config.bucket("operations", None); - config.bucket("working_set", None); - let store = Store::new(config)?; - - // tasks are stored indexed by uuid - let tasks_bucket = store.bucket::>>(Some("tasks"))?; - - // this bucket contains various u64s, indexed by constants above - let numbers_bucket = store.int_bucket::>>(Some("numbers"))?; - - // this bucket contains various Uuids, indexed by constants above - let uuids_bucket = store.int_bucket::>>(Some("uuids"))?; - - // this bucket contains operations, numbered consecutively; the NEXT_OPERATION number gives - // the index of the next operation to insert - let operations_bucket = - store.int_bucket::>>(Some("operations"))?; - - // this bucket contains operations, numbered consecutively; the NEXT_WORKING_SET_INDEX - // number gives the index of the next operation to insert - let working_set_bucket = - store.int_bucket::>>(Some("working_set"))?; - - Ok(KvStorage { - store, - tasks_bucket, - numbers_bucket, - uuids_bucket, - operations_bucket, - working_set_bucket, - }) - } -} - -impl<'t> Storage for KvStorage<'t> { - fn txn<'a>(&'a mut self) -> anyhow::Result> { - Ok(Box::new(Txn { - storage: self, - txn: Some(self.store.write_txn()?), - })) - } -} - -struct Txn<'t> { - storage: &'t KvStorage<'t>, - txn: Option>, -} - -impl<'t> Txn<'t> { - // get the underlying kv Txn - fn kvtxn(&mut self) -> &mut kv::Txn<'t> { - if let Some(ref mut txn) = self.txn { - txn - } else { - panic!("cannot use transaction after commit"); - } - } - - // Access to buckets - fn tasks_bucket(&self) -> &'t Bucket<'t, Key, ValueBuf>> { - &self.storage.tasks_bucket - } - fn numbers_bucket(&self) -> &'t Bucket<'t, Integer, ValueBuf>> { - &self.storage.numbers_bucket - } - fn uuids_bucket(&self) -> &'t Bucket<'t, Integer, ValueBuf>> { - &self.storage.uuids_bucket - } - fn operations_bucket(&self) -> &'t Bucket<'t, Integer, ValueBuf>> { - &self.storage.operations_bucket - } - fn working_set_bucket(&self) -> &'t Bucket<'t, Integer, ValueBuf>> { - &self.storage.working_set_bucket - } -} - -impl<'t> StorageTxn for Txn<'t> { - fn get_task(&mut self, uuid: Uuid) -> anyhow::Result> { - let bucket = self.tasks_bucket(); - let buf = match self.kvtxn().get(bucket, uuid.into()) { - Ok(buf) => buf, - Err(Error::NotFound) => return Ok(None), - Err(e) => return Err(e.into()), - }; - let value = buf.inner()?.to_serde(); - Ok(Some(value)) - } - - fn create_task(&mut self, uuid: Uuid) -> anyhow::Result { - let bucket = self.tasks_bucket(); - let kvtxn = self.kvtxn(); - match kvtxn.get(bucket, uuid.into()) { - Err(Error::NotFound) => { - kvtxn.set(bucket, uuid.into(), Msgpack::to_value_buf(TaskMap::new())?)?; - Ok(true) - } - Err(e) => Err(e.into()), - Ok(_) => Ok(false), - } - } - - fn set_task(&mut self, uuid: Uuid, task: TaskMap) -> anyhow::Result<()> { - let bucket = self.tasks_bucket(); - let kvtxn = self.kvtxn(); - kvtxn.set(bucket, uuid.into(), Msgpack::to_value_buf(task)?)?; - Ok(()) - } - - fn delete_task(&mut self, uuid: Uuid) -> anyhow::Result { - let bucket = self.tasks_bucket(); - let kvtxn = self.kvtxn(); - match kvtxn.del(bucket, uuid.into()) { - Err(Error::NotFound) => Ok(false), - Err(e) => Err(e.into()), - Ok(_) => Ok(true), - } - } - - fn all_tasks(&mut self) -> anyhow::Result> { - let bucket = self.tasks_bucket(); - let kvtxn = self.kvtxn(); - let all_tasks: Result, Error> = kvtxn - .read_cursor(bucket)? - .iter() - .map(|(k, v)| Ok((k.into(), v.inner()?.to_serde()))) - .collect(); - Ok(all_tasks?) - } - - fn all_task_uuids(&mut self) -> anyhow::Result> { - let bucket = self.tasks_bucket(); - let kvtxn = self.kvtxn(); - Ok(kvtxn - .read_cursor(bucket)? - .iter() - .map(|(k, _)| k.into()) - .collect()) - } - - fn base_version(&mut self) -> anyhow::Result { - let bucket = self.uuids_bucket(); - let base_version = match self.kvtxn().get(bucket, BASE_VERSION.into()) { - Ok(buf) => buf, - Err(Error::NotFound) => return Ok(DEFAULT_BASE_VERSION), - Err(e) => return Err(e.into()), - } - .inner()? - .to_serde(); - Ok(base_version as VersionId) - } - - fn set_base_version(&mut self, version: VersionId) -> anyhow::Result<()> { - let uuids_bucket = self.uuids_bucket(); - let kvtxn = self.kvtxn(); - - kvtxn.set( - uuids_bucket, - BASE_VERSION.into(), - Msgpack::to_value_buf(version as Uuid)?, - )?; - Ok(()) - } - - fn operations(&mut self) -> anyhow::Result> { - let bucket = self.operations_bucket(); - let kvtxn = self.kvtxn(); - let all_ops: Result, Error> = kvtxn - .read_cursor(bucket)? - .iter() - .map(|(i, v)| Ok((i.into(), v.inner()?.to_serde()))) - .collect(); - let mut all_ops = all_ops?; - // sort by key.. - all_ops.sort_by(|a, b| a.0.cmp(&b.0)); - // and return the values.. - Ok(all_ops.iter().map(|(_, v)| v.clone()).collect()) - } - - fn add_operation(&mut self, op: Operation) -> anyhow::Result<()> { - let numbers_bucket = self.numbers_bucket(); - let operations_bucket = self.operations_bucket(); - let kvtxn = self.kvtxn(); - - let next_op = match kvtxn.get(numbers_bucket, NEXT_OPERATION.into()) { - Ok(buf) => buf.inner()?.to_serde(), - Err(Error::NotFound) => 0, - Err(e) => return Err(e.into()), - }; - - kvtxn.set( - operations_bucket, - next_op.into(), - Msgpack::to_value_buf(op)?, - )?; - kvtxn.set( - numbers_bucket, - NEXT_OPERATION.into(), - Msgpack::to_value_buf(next_op + 1)?, - )?; - Ok(()) - } - - fn set_operations(&mut self, ops: Vec) -> anyhow::Result<()> { - let numbers_bucket = self.numbers_bucket(); - let operations_bucket = self.operations_bucket(); - let kvtxn = self.kvtxn(); - - kvtxn.clear_db(operations_bucket)?; - - let mut i = 0u64; - for op in ops { - kvtxn.set(operations_bucket, i.into(), Msgpack::to_value_buf(op)?)?; - i += 1; - } - - kvtxn.set( - numbers_bucket, - NEXT_OPERATION.into(), - Msgpack::to_value_buf(i)?, - )?; - - Ok(()) - } - - fn get_working_set(&mut self) -> anyhow::Result>> { - let working_set_bucket = self.working_set_bucket(); - let numbers_bucket = self.numbers_bucket(); - let kvtxn = self.kvtxn(); - - let next_index = match kvtxn.get(numbers_bucket, NEXT_WORKING_SET_INDEX.into()) { - Ok(buf) => buf.inner()?.to_serde(), - Err(Error::NotFound) => 1, - Err(e) => return Err(e.into()), - }; - - let mut res = Vec::with_capacity(next_index as usize); - for _ in 0..next_index { - res.push(None) - } - - for (i, u) in kvtxn.read_cursor(working_set_bucket)?.iter() { - let i: u64 = i.into(); - res[i as usize] = Some(u.inner()?.to_serde()); - } - Ok(res) - } - - fn add_to_working_set(&mut self, uuid: Uuid) -> anyhow::Result { - let working_set_bucket = self.working_set_bucket(); - let numbers_bucket = self.numbers_bucket(); - let kvtxn = self.kvtxn(); - - let next_index = match kvtxn.get(numbers_bucket, NEXT_WORKING_SET_INDEX.into()) { - Ok(buf) => buf.inner()?.to_serde(), - Err(Error::NotFound) => 1, - Err(e) => return Err(e.into()), - }; - - kvtxn.set( - working_set_bucket, - next_index.into(), - Msgpack::to_value_buf(uuid)?, - )?; - kvtxn.set( - numbers_bucket, - NEXT_WORKING_SET_INDEX.into(), - Msgpack::to_value_buf(next_index + 1)?, - )?; - Ok(next_index as usize) - } - - fn set_working_set_item(&mut self, index: usize, uuid: Option) -> anyhow::Result<()> { - let working_set_bucket = self.working_set_bucket(); - let numbers_bucket = self.numbers_bucket(); - let kvtxn = self.kvtxn(); - let index = index as u64; - - let next_index = match kvtxn.get(numbers_bucket, NEXT_WORKING_SET_INDEX.into()) { - Ok(buf) => buf.inner()?.to_serde(), - Err(Error::NotFound) => 1, - Err(e) => return Err(e.into()), - }; - - if index >= next_index { - anyhow::bail!("Index {} is not in the working set", index); - } - - if let Some(uuid) = uuid { - kvtxn.set( - working_set_bucket, - index.into(), - Msgpack::to_value_buf(uuid)?, - )?; - } else { - kvtxn.del(working_set_bucket, index.into())?; - } - - Ok(()) - } - - fn clear_working_set(&mut self) -> anyhow::Result<()> { - let working_set_bucket = self.working_set_bucket(); - let numbers_bucket = self.numbers_bucket(); - let kvtxn = self.kvtxn(); - - kvtxn.clear_db(working_set_bucket)?; - kvtxn.set( - numbers_bucket, - NEXT_WORKING_SET_INDEX.into(), - Msgpack::to_value_buf(1)?, - )?; - - Ok(()) - } - - fn commit(&mut self) -> anyhow::Result<()> { - if let Some(kvtxn) = self.txn.take() { - kvtxn.commit()?; - } else { - panic!("transaction already committed"); - } - Ok(()) - } -} - -#[cfg(test)] -mod test { - use super::*; - use crate::storage::taskmap_with; - use tempfile::TempDir; - - #[test] - fn test_create() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let mut storage = KvStorage::new(&tmp_dir.path())?; - let uuid = Uuid::new_v4(); - { - let mut txn = storage.txn()?; - assert!(txn.create_task(uuid)?); - txn.commit()?; - } - { - let mut txn = storage.txn()?; - let task = txn.get_task(uuid)?; - assert_eq!(task, Some(taskmap_with(vec![]))); - } - Ok(()) - } - - #[test] - fn test_create_exists() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let mut storage = KvStorage::new(&tmp_dir.path())?; - let uuid = Uuid::new_v4(); - { - let mut txn = storage.txn()?; - assert!(txn.create_task(uuid)?); - txn.commit()?; - } - { - let mut txn = storage.txn()?; - assert!(!txn.create_task(uuid)?); - txn.commit()?; - } - Ok(()) - } - - #[test] - fn test_get_missing() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let mut storage = KvStorage::new(&tmp_dir.path())?; - let uuid = Uuid::new_v4(); - { - let mut txn = storage.txn()?; - let task = txn.get_task(uuid)?; - assert_eq!(task, None); - } - Ok(()) - } - - #[test] - fn test_set_task() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let mut storage = KvStorage::new(&tmp_dir.path())?; - let uuid = Uuid::new_v4(); - { - let mut txn = storage.txn()?; - txn.set_task(uuid, taskmap_with(vec![("k".to_string(), "v".to_string())]))?; - txn.commit()?; - } - { - let mut txn = storage.txn()?; - let task = txn.get_task(uuid)?; - assert_eq!( - task, - Some(taskmap_with(vec![("k".to_string(), "v".to_string())])) - ); - } - Ok(()) - } - - #[test] - fn test_delete_task_missing() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let mut storage = KvStorage::new(&tmp_dir.path())?; - let uuid = Uuid::new_v4(); - { - let mut txn = storage.txn()?; - assert!(!txn.delete_task(uuid)?); - } - Ok(()) - } - - #[test] - fn test_delete_task_exists() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let mut storage = KvStorage::new(&tmp_dir.path())?; - let uuid = Uuid::new_v4(); - { - let mut txn = storage.txn()?; - assert!(txn.create_task(uuid)?); - txn.commit()?; - } - { - let mut txn = storage.txn()?; - assert!(txn.delete_task(uuid)?); - } - Ok(()) - } - - #[test] - fn test_all_tasks_empty() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let mut storage = KvStorage::new(&tmp_dir.path())?; - { - let mut txn = storage.txn()?; - let tasks = txn.all_tasks()?; - assert_eq!(tasks, vec![]); - } - Ok(()) - } - - #[test] - fn test_all_tasks_and_uuids() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let mut storage = KvStorage::new(&tmp_dir.path())?; - let uuid1 = Uuid::new_v4(); - let uuid2 = Uuid::new_v4(); - { - let mut txn = storage.txn()?; - assert!(txn.create_task(uuid1.clone())?); - txn.set_task( - uuid1.clone(), - taskmap_with(vec![("num".to_string(), "1".to_string())]), - )?; - assert!(txn.create_task(uuid2.clone())?); - txn.set_task( - uuid2.clone(), - taskmap_with(vec![("num".to_string(), "2".to_string())]), - )?; - txn.commit()?; - } - { - let mut txn = storage.txn()?; - let mut tasks = txn.all_tasks()?; - - // order is nondeterministic, so sort by uuid - tasks.sort_by(|a, b| a.0.cmp(&b.0)); - - let mut exp = vec![ - ( - uuid1.clone(), - taskmap_with(vec![("num".to_string(), "1".to_string())]), - ), - ( - uuid2.clone(), - taskmap_with(vec![("num".to_string(), "2".to_string())]), - ), - ]; - exp.sort_by(|a, b| a.0.cmp(&b.0)); - - assert_eq!(tasks, exp); - } - { - let mut txn = storage.txn()?; - let mut uuids = txn.all_task_uuids()?; - uuids.sort(); - - let mut exp = vec![uuid1.clone(), uuid2.clone()]; - exp.sort(); - - assert_eq!(uuids, exp); - } - Ok(()) - } - - #[test] - fn test_base_version_default() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let mut storage = KvStorage::new(&tmp_dir.path())?; - { - let mut txn = storage.txn()?; - assert_eq!(txn.base_version()?, DEFAULT_BASE_VERSION); - } - Ok(()) - } - - #[test] - fn test_base_version_setting() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let mut storage = KvStorage::new(&tmp_dir.path())?; - let u = Uuid::new_v4(); - { - let mut txn = storage.txn()?; - txn.set_base_version(u)?; - txn.commit()?; - } - { - let mut txn = storage.txn()?; - assert_eq!(txn.base_version()?, u); - } - Ok(()) - } - - #[test] - fn test_operations() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let mut storage = KvStorage::new(&tmp_dir.path())?; - let uuid1 = Uuid::new_v4(); - let uuid2 = Uuid::new_v4(); - let uuid3 = Uuid::new_v4(); - - // create some operations - { - let mut txn = storage.txn()?; - txn.add_operation(Operation::Create { uuid: uuid1 })?; - txn.add_operation(Operation::Create { uuid: uuid2 })?; - txn.commit()?; - } - - // read them back - { - let mut txn = storage.txn()?; - let ops = txn.operations()?; - assert_eq!( - ops, - vec![ - Operation::Create { uuid: uuid1 }, - Operation::Create { uuid: uuid2 }, - ] - ); - } - - // set them to a different bunch - { - let mut txn = storage.txn()?; - txn.set_operations(vec![ - Operation::Delete { uuid: uuid2 }, - Operation::Delete { uuid: uuid1 }, - ])?; - txn.commit()?; - } - - // create some more operations (to test adding operations after clearing) - { - let mut txn = storage.txn()?; - txn.add_operation(Operation::Create { uuid: uuid3 })?; - txn.add_operation(Operation::Delete { uuid: uuid3 })?; - txn.commit()?; - } - - // read them back - { - let mut txn = storage.txn()?; - let ops = txn.operations()?; - assert_eq!( - ops, - vec![ - Operation::Delete { uuid: uuid2 }, - Operation::Delete { uuid: uuid1 }, - Operation::Create { uuid: uuid3 }, - Operation::Delete { uuid: uuid3 }, - ] - ); - } - Ok(()) - } - - #[test] - fn get_working_set_empty() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let mut storage = KvStorage::new(&tmp_dir.path())?; - - { - let mut txn = storage.txn()?; - let ws = txn.get_working_set()?; - assert_eq!(ws, vec![None]); - } - - Ok(()) - } - - #[test] - fn add_to_working_set() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let mut storage = KvStorage::new(&tmp_dir.path())?; - let uuid1 = Uuid::new_v4(); - let uuid2 = Uuid::new_v4(); - - { - let mut txn = storage.txn()?; - txn.add_to_working_set(uuid1)?; - txn.add_to_working_set(uuid2)?; - txn.commit()?; - } - - { - let mut txn = storage.txn()?; - let ws = txn.get_working_set()?; - assert_eq!(ws, vec![None, Some(uuid1), Some(uuid2)]); - } - - Ok(()) - } - - #[test] - fn clear_working_set() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let mut storage = KvStorage::new(&tmp_dir.path())?; - let uuid1 = Uuid::new_v4(); - let uuid2 = Uuid::new_v4(); - - { - let mut txn = storage.txn()?; - txn.add_to_working_set(uuid1)?; - txn.add_to_working_set(uuid2)?; - txn.commit()?; - } - - { - let mut txn = storage.txn()?; - txn.clear_working_set()?; - txn.add_to_working_set(uuid2)?; - txn.add_to_working_set(uuid1)?; - txn.commit()?; - } - - { - let mut txn = storage.txn()?; - let ws = txn.get_working_set()?; - assert_eq!(ws, vec![None, Some(uuid2), Some(uuid1)]); - } - - Ok(()) - } -} diff --git a/taskchampion/src/storage/mod.rs b/taskchampion/src/storage/mod.rs index a4c430b94..7520950e0 100644 --- a/taskchampion/src/storage/mod.rs +++ b/taskchampion/src/storage/mod.rs @@ -11,13 +11,12 @@ use uuid::Uuid; mod config; mod inmemory; -mod kv; mod operation; mod sqlite; -pub use self::kv::KvStorage; pub use config::StorageConfig; pub use inmemory::InMemoryStorage; +pub use sqlite::SqliteStorage; pub use operation::Operation; From d5724c4dc2ec9860c07b64363b1972a95cca15d3 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 29 Apr 2021 10:37:04 +1000 Subject: [PATCH 12/38] Unused --- taskchampion/src/storage/sqlite.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index 4f57ed3ab..f0eacf740 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -1,8 +1,6 @@ use crate::storage::{Operation, Storage, StorageTxn, TaskMap, VersionId, DEFAULT_BASE_VERSION}; -use crate::utils::Key; use anyhow::Context; use rusqlite::{params, Connection, OptionalExtension}; -use serde::serde_if_integer128; use std::path::Path; use uuid::Uuid; @@ -10,8 +8,6 @@ use uuid::Uuid; enum SqliteError { #[error("SQLite transaction already committted")] TransactionAlreadyCommitted, - #[error("Invalid UUID string from database: {0}")] - InvalidUuidString(String), } /// SqliteStorage is an on-disk storage backed by SQLite3. From cefd6fd6cc75a0a81729639fbe9678664bc95014 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 29 Apr 2021 10:39:29 +1000 Subject: [PATCH 13/38] Serialize Uuid as string for nicer debugging Also implement ToSql/FromSql for Operation/TaskMap so errors are handled properly --- Cargo.lock | 2 - taskchampion/Cargo.toml | 2 +- taskchampion/src/storage/sqlite.rs | 116 +++++++++++++++++++++-------- 3 files changed, 86 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8777c807b..c4ba8516d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1898,9 +1898,7 @@ dependencies = [ "hashlink", "libsqlite3-sys", "memchr", - "serde_json", "smallvec", - "uuid", ] [[package]] diff --git a/taskchampion/Cargo.toml b/taskchampion/Cargo.toml index 196c2a7d8..03a047c88 100644 --- a/taskchampion/Cargo.toml +++ b/taskchampion/Cargo.toml @@ -21,7 +21,7 @@ kv = {version = "^0.10.0", features = ["msgpack-value"]} ureq = "^2.1.0" log = "^0.4.14" tindercrypt = { version = "^0.2.2", default-features = false } -rusqlite = { version = "0.25", features = ["bundled", "uuid", "serde_json"] } +rusqlite = { version = "0.25", features = ["bundled"] } [dev-dependencies] proptest = "^1.0.0" diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index f0eacf740..9736287d3 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -1,5 +1,6 @@ use crate::storage::{Operation, Storage, StorageTxn, TaskMap, VersionId, DEFAULT_BASE_VERSION}; use anyhow::Context; +use rusqlite::types::{FromSql, ToSql}; use rusqlite::{params, Connection, OptionalExtension}; use std::path::Path; use uuid::Uuid; @@ -10,6 +11,64 @@ enum SqliteError { TransactionAlreadyCommitted, } +/// Newtype to allow implementing `FromSql` for foreign `uuid::Uuid` +struct StoredUuid(Uuid); + +/// Conversion from Uuid stored as a string (rusqlite's uuid feature stores as binary blob) +impl FromSql for StoredUuid { + fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { + let u = Uuid::parse_str(value.as_str()?) + .map_err(|_| rusqlite::types::FromSqlError::InvalidType)?; + Ok(StoredUuid(u)) + } +} + +/// Store Uuid as string in database +impl ToSql for StoredUuid { + fn to_sql(&self) -> rusqlite::Result> { + let s = self.0.to_string(); + Ok(s.into()) + } +} + +/// Wraps [`TaskMap`] (type alias for HashMap) so we can implement rusqlite conversion traits for it +struct StoredTaskMap(TaskMap); + +impl FromSql for StoredTaskMap { + fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { + let o: TaskMap = serde_json::from_str(value.as_str()?) + .map_err(|_| rusqlite::types::FromSqlError::InvalidType)?; + Ok(StoredTaskMap(o)) + } +} + +impl ToSql for StoredTaskMap { + fn to_sql(&self) -> rusqlite::Result> { + let s = serde_json::to_string(&self.0) + .map_err(|e| rusqlite::Error::ToSqlConversionFailure(Box::new(e)))?; + Ok(s.into()) + } +} + + +/// Stores [`Operation`] in SQLite +impl FromSql for Operation { + fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { + let o: Operation = serde_json::from_str(value.as_str()?) + .map_err(|_| rusqlite::types::FromSqlError::InvalidType)?; + Ok(o) + } +} + +impl ToSql for Operation { + fn to_sql(&self) -> rusqlite::Result> { + let s = serde_json::to_string(&self) + .map_err(|e| rusqlite::Error::ToSqlConversionFailure(Box::new(e)))?; + Ok(s.into()) + } +} + + /// SqliteStorage is an on-disk storage backed by SQLite3. pub struct SqliteStorage { con: Connection, @@ -68,25 +127,23 @@ impl Storage for SqliteStorage { impl<'t> StorageTxn for Txn<'t> { fn get_task(&mut self, uuid: Uuid) -> anyhow::Result> { let t = self.get_txn()?; - let result: Option = t + let result: Option = t .query_row( "SELECT data FROM tasks WHERE uuid = ? LIMIT 1", - [&uuid], + [&StoredUuid(uuid)], |r| r.get("data"), ) .optional()?; - match result { - None => Ok(None), - Some(r) => Ok(serde_json::from_str(&r)?), - } + // Get task from "stored" wrapper + Ok(result.and_then(|t: StoredTaskMap| Some(t.0))) } fn create_task(&mut self, uuid: Uuid) -> anyhow::Result { let t = self.get_txn()?; let count: usize = t.query_row( "SELECT count(uuid) FROM tasks WHERE uuid = ?", - [&uuid], + [&StoredUuid(uuid)], |x| x.get(0), )?; if count > 0 { @@ -94,10 +151,9 @@ impl<'t> StorageTxn for Txn<'t> { } let data = TaskMap::default(); - let data_str = serde_json::to_string(&data)?; t.execute( "INSERT INTO tasks (uuid, data) VALUES (?, ?)", - params![&uuid, &data_str], + params![&StoredUuid(uuid), &StoredTaskMap(data)], ) .context("Create task query")?; Ok(true) @@ -105,10 +161,9 @@ impl<'t> StorageTxn for Txn<'t> { fn set_task(&mut self, uuid: Uuid, task: TaskMap) -> anyhow::Result<()> { let t = self.get_txn()?; - let data_str = serde_json::to_string(&task)?; t.execute( "INSERT OR REPLACE INTO tasks (uuid, data) VALUES (?, ?)", - params![&uuid, &data_str], + params![&StoredUuid(uuid), &StoredTaskMap(task)], ) .context("Update task query")?; Ok(()) @@ -117,7 +172,7 @@ impl<'t> StorageTxn for Txn<'t> { fn delete_task(&mut self, uuid: Uuid) -> anyhow::Result { let t = self.get_txn()?; let changed = t - .execute("DELETE FROM tasks WHERE uuid = ?", [&uuid]) + .execute("DELETE FROM tasks WHERE uuid = ?", [&StoredUuid(uuid)]) .context("Delete task query")?; Ok(changed > 0) } @@ -127,10 +182,9 @@ impl<'t> StorageTxn for Txn<'t> { let mut q = t.prepare("SELECT uuid, data FROM tasks")?; let rows = q.query_map([], |r| { - let uuid: Uuid = r.get("uuid")?; - let data_str: String = r.get("data")?; - let data: TaskMap = serde_json::from_str(&data_str).unwrap(); // FIXME: Remove unwrap - Ok((uuid, data)) + let uuid: StoredUuid = r.get("uuid")?; + let data: StoredTaskMap = r.get("data")?; + Ok((uuid.0, data.0)) })?; let mut ret = vec![]; @@ -145,8 +199,8 @@ impl<'t> StorageTxn for Txn<'t> { let mut q = t.prepare("SELECT uuid FROM tasks")?; let rows = q.query_map([], |r| { - let uuid: Uuid = r.get("uuid")?; - Ok(uuid) + let uuid: StoredUuid = r.get("uuid")?; + Ok(uuid.0) })?; let mut ret = vec![]; @@ -159,21 +213,23 @@ impl<'t> StorageTxn for Txn<'t> { fn base_version(&mut self) -> anyhow::Result { let t = self.get_txn()?; - let mut version = t + let version: Option = t .query_row( "SELECT value FROM sync_meta WHERE key = 'base_version'", [], |r| r.get("value"), ) .optional()?; - Ok(version.unwrap_or(DEFAULT_BASE_VERSION)) + Ok(version + .and_then(|u| Some(u.0)) + .unwrap_or(DEFAULT_BASE_VERSION)) } fn set_base_version(&mut self, version: VersionId) -> anyhow::Result<()> { let t = self.get_txn()?; t.execute( "INSERT OR REPLACE INTO sync_meta (key, value) VALUES (?, ?)", - params!["base_version", &version], + params!["base_version", &StoredUuid(version)], ) .context("Set base version")?; Ok(()) @@ -184,8 +240,7 @@ impl<'t> StorageTxn for Txn<'t> { let mut q = t.prepare("SELECT data FROM operations ORDER BY id ASC")?; let rows = q.query_map([], |r| { - let data_str: String = r.get("data")?; - let data: Operation = serde_json::from_str(&data_str).unwrap(); // FIXME: Remove unwrap + let data: Operation = r.get("data")?; Ok(data) })?; @@ -199,10 +254,9 @@ impl<'t> StorageTxn for Txn<'t> { fn add_operation(&mut self, op: Operation) -> anyhow::Result<()> { let t = self.get_txn()?; - let data_str = serde_json::to_string(&op)?; t.execute( "INSERT INTO operations (data) VALUES (?)", - params![&data_str], + params![&op], ) .context("Add operation query")?; Ok(()) @@ -226,8 +280,8 @@ impl<'t> StorageTxn for Txn<'t> { let rows = q .query_map([], |r| { let id: usize = r.get("id")?; - let uuid: Uuid = r.get("uuid")?; - Ok((id, uuid)) + let uuid: StoredUuid = r.get("uuid")?; + Ok((id, uuid.0)) }) .context("Get working set query")?; @@ -251,7 +305,7 @@ impl<'t> StorageTxn for Txn<'t> { t.execute( "INSERT INTO working_set (id, uuid) VALUES (?, ?)", - params![next_working_id, &uuid], + params![next_working_id, &StoredUuid(uuid)], ) .context("Create task query")?; @@ -264,7 +318,7 @@ impl<'t> StorageTxn for Txn<'t> { // Add or override item Some(uuid) => t.execute( "INSERT OR REPLACE INTO working_set (id, uuid) VALUES (?, ?)", - params![index, &uuid], + params![index, &StoredUuid(uuid)], ), // Setting to None removes the row from database None => t.execute("DELETE FROM working_set WHERE id = ?", [index]), @@ -645,7 +699,7 @@ mod test { dbg!(1); { let mut txn = storage.txn()?; - let ws = txn.set_working_set_item(1, None)?; + txn.set_working_set_item(1, None)?; txn.commit()?; } @@ -660,7 +714,7 @@ mod test { // Override item { let mut txn = storage.txn()?; - let ws = txn.set_working_set_item(2, Some(uuid1))?; + txn.set_working_set_item(2, Some(uuid1))?; txn.commit()?; } From e479c25c34c362a2db5e6e2175be2337d43d6fc5 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 29 Apr 2021 10:41:17 +1000 Subject: [PATCH 14/38] Tidier --- taskchampion/src/storage/sqlite.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index 9736287d3..344650598 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -136,7 +136,7 @@ impl<'t> StorageTxn for Txn<'t> { .optional()?; // Get task from "stored" wrapper - Ok(result.and_then(|t: StoredTaskMap| Some(t.0))) + Ok(result.map(|t| t.0)) } fn create_task(&mut self, uuid: Uuid) -> anyhow::Result { @@ -221,7 +221,7 @@ impl<'t> StorageTxn for Txn<'t> { ) .optional()?; Ok(version - .and_then(|u| Some(u.0)) + .map(|u| u.0) .unwrap_or(DEFAULT_BASE_VERSION)) } From 23531d73c43072df44da41bd6a3afc5be70f56d5 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 29 Apr 2021 10:57:43 +1000 Subject: [PATCH 15/38] Remove debug junk --- taskchampion/src/storage/sqlite.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index 344650598..837cbba36 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -696,21 +696,18 @@ mod test { } // Clear one item - dbg!(1); { let mut txn = storage.txn()?; txn.set_working_set_item(1, None)?; txn.commit()?; } - dbg!(2); { let mut txn = storage.txn()?; let ws = txn.get_working_set()?; assert_eq!(ws, vec![None, None, Some(uuid2)]); } - dbg!(3); // Override item { let mut txn = storage.txn()?; From a3c9a76f1d70341d11be073a8aba21685f6975ec Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 29 Apr 2021 10:58:34 +1000 Subject: [PATCH 16/38] Explicit check that rusqlite::Transaction isn't auto-commited on drop --- taskchampion/src/storage/sqlite.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index 837cbba36..35944de29 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -350,6 +350,35 @@ mod test { use crate::storage::taskmap_with; use tempfile::TempDir; + #[test] + fn drop_transaction() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let mut storage = SqliteStorage::new(&tmp_dir.path())?; + let uuid1 = Uuid::new_v4(); + let uuid2 = Uuid::new_v4(); + + { + let mut txn = storage.txn()?; + assert!(txn.create_task(uuid1)?); + txn.commit()?; + } + + { + let mut txn = storage.txn()?; + assert!(txn.create_task(uuid2)?); + std::mem::drop(txn); // Unnecessary explicit drop of transaction + } + + { + let mut txn = storage.txn()?; + let uuids = txn.all_task_uuids()?; + + assert_eq!(uuids, [uuid1]); + } + + Ok(()) + } + #[test] fn test_create() -> anyhow::Result<()> { let tmp_dir = TempDir::new()?; From ff894f6ff634a9dc5d6d2b7511c258d4c0e8d102 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 29 Apr 2021 11:01:46 +1000 Subject: [PATCH 17/38] Comments and rustfmt --- taskchampion/src/storage/sqlite.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index 35944de29..91eaf1f8a 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -34,6 +34,7 @@ impl ToSql for StoredUuid { /// Wraps [`TaskMap`] (type alias for HashMap) so we can implement rusqlite conversion traits for it struct StoredTaskMap(TaskMap); +/// Parses TaskMap stored as JSON in string column impl FromSql for StoredTaskMap { fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { let o: TaskMap = serde_json::from_str(value.as_str()?) @@ -42,6 +43,7 @@ impl FromSql for StoredTaskMap { } } +/// Stores TaskMap in string column impl ToSql for StoredTaskMap { fn to_sql(&self) -> rusqlite::Result> { let s = serde_json::to_string(&self.0) @@ -50,7 +52,6 @@ impl ToSql for StoredTaskMap { } } - /// Stores [`Operation`] in SQLite impl FromSql for Operation { fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { @@ -60,6 +61,7 @@ impl FromSql for Operation { } } +/// Parsers Operation stored as JSON in string column impl ToSql for Operation { fn to_sql(&self) -> rusqlite::Result> { let s = serde_json::to_string(&self) @@ -68,7 +70,6 @@ impl ToSql for Operation { } } - /// SqliteStorage is an on-disk storage backed by SQLite3. pub struct SqliteStorage { con: Connection, @@ -220,9 +221,7 @@ impl<'t> StorageTxn for Txn<'t> { |r| r.get("value"), ) .optional()?; - Ok(version - .map(|u| u.0) - .unwrap_or(DEFAULT_BASE_VERSION)) + Ok(version.map(|u| u.0).unwrap_or(DEFAULT_BASE_VERSION)) } fn set_base_version(&mut self, version: VersionId) -> anyhow::Result<()> { @@ -254,11 +253,8 @@ impl<'t> StorageTxn for Txn<'t> { fn add_operation(&mut self, op: Operation) -> anyhow::Result<()> { let t = self.get_txn()?; - t.execute( - "INSERT INTO operations (data) VALUES (?)", - params![&op], - ) - .context("Add operation query")?; + t.execute("INSERT INTO operations (data) VALUES (?)", params![&op]) + .context("Add operation query")?; Ok(()) } From 60ff0a8d11fcc63dcd071aa94af8bfee157562d7 Mon Sep 17 00:00:00 2001 From: dbr Date: Thu, 29 Apr 2021 16:00:22 +1000 Subject: [PATCH 18/38] Very WIP (i.e broken) start of SQLite storage in server --- Cargo.lock | 3 + sync-server/Cargo.toml | 3 + sync-server/src/storage/mod.rs | 3 + sync-server/src/storage/sqlite.rs | 270 ++++++++++++++++++++++++++++++ 4 files changed, 279 insertions(+) create mode 100644 sync-server/src/storage/sqlite.rs diff --git a/Cargo.lock b/Cargo.lock index c4ba8516d..75eabf642 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2228,8 +2228,11 @@ dependencies = [ "futures", "kv", "log", + "rusqlite", "serde", + "serde_json", "tempfile", + "thiserror", "uuid", ] diff --git a/sync-server/Cargo.toml b/sync-server/Cargo.toml index 2a42298be..c9d665ba0 100644 --- a/sync-server/Cargo.toml +++ b/sync-server/Cargo.toml @@ -10,12 +10,15 @@ edition = "2018" uuid = { version = "^0.8.2", features = ["serde", "v4"] } actix-web = "^3.3.2" anyhow = "1.0" +thiserror = "1.0" futures = "^0.3.8" serde = "^1.0.125" +serde_json = "^1.0" kv = {version = "^0.10.0", features = ["msgpack-value"]} clap = "^2.33.0" log = "^0.4.14" env_logger = "^0.8.3" +rusqlite = { version = "0.25", features = ["bundled"] } [dev-dependencies] actix-rt = "^2.2.0" diff --git a/sync-server/src/storage/mod.rs b/sync-server/src/storage/mod.rs index 1d1cbe139..41fb400e9 100644 --- a/sync-server/src/storage/mod.rs +++ b/sync-server/src/storage/mod.rs @@ -6,6 +6,9 @@ mod inmemory; #[cfg(test)] pub(crate) use inmemory::InMemoryStorage; +mod sqlite; +pub(crate) use self::sqlite::SqliteStorage; + mod kv; pub(crate) use self::kv::KvStorage; diff --git a/sync-server/src/storage/sqlite.rs b/sync-server/src/storage/sqlite.rs new file mode 100644 index 000000000..a6eaa0df4 --- /dev/null +++ b/sync-server/src/storage/sqlite.rs @@ -0,0 +1,270 @@ +use super::{Client, Storage, StorageTxn, Uuid, Version}; +use rusqlite::types::{FromSql, ToSql}; +use rusqlite::{params, Connection, OptionalExtension}; +use std::path::Path; +use std::sync::{Arc, Mutex}; +use anyhow::Context; + +#[derive(Debug, thiserror::Error)] +enum SqliteError { + #[error("SQLite transaction already committted")] + TransactionAlreadyCommitted, +} + + +/// Newtype to allow implementing `FromSql` for foreign `uuid::Uuid` +struct StoredUuid(Uuid); + +/// Conversion from Uuid stored as a string (rusqlite's uuid feature stores as binary blob) +impl FromSql for StoredUuid { + fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { + let u = Uuid::parse_str(value.as_str()?) + .map_err(|_| rusqlite::types::FromSqlError::InvalidType)?; + Ok(StoredUuid(u)) + } +} + +/// Store Uuid as string in database +impl ToSql for StoredUuid { + fn to_sql(&self) -> rusqlite::Result> { + let s = self.0.to_string(); + Ok(s.into()) + } +} + +/// Stores [`Client`] in SQLite +impl FromSql for Client { + fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { + let o: Client = serde_json::from_str(value.as_str()?) + .map_err(|_| rusqlite::types::FromSqlError::InvalidType)?; + Ok(o) + } +} + +/// Parsers Operation stored as JSON in string column +impl ToSql for Client { + fn to_sql(&self) -> rusqlite::Result> { + let s = serde_json::to_string(&self) + .map_err(|e| rusqlite::Error::ToSqlConversionFailure(Box::new(e)))?; + Ok(s.into()) + } +} + + + +/// DB Key for versions: concatenation of client_key and parent_version_id +type VersionDbKey = [u8; 32]; + +fn version_db_key(client_key: Uuid, parent_version_id: Uuid) -> VersionDbKey { + let mut key = [0u8; 32]; + key[..16].clone_from_slice(client_key.as_bytes()); + key[16..].clone_from_slice(parent_version_id.as_bytes()); + key +} + +/// Key for clients: just the client_key +type ClientDbKey = [u8; 16]; + +fn client_db_key(client_key: Uuid) -> ClientDbKey { + *client_key.as_bytes() +} + +/// An on-disk storage backend which uses SQLite +pub(crate) struct SqliteStorage { + db_file: std::path::PathBuf, +} + +impl SqliteStorage { + fn new_connection(&self) -> anyhow::Result { + Ok(Connection::open(&self.db_file)?) + } + + pub fn new>(directory: P) -> anyhow::Result { + let db_file = directory.as_ref().join("taskchampion-sync-server.sqlite3"); + + let o = SqliteStorage { db_file }; + + { + let mut con = o.new_connection()?; + let txn = con.transaction()?; + + let queries = vec![ + "CREATE TABLE IF NOT EXISTS clients (id INTEGER PRIMARY KEY AUTOINCREMENT, data STRING);", + ]; + for q in queries { + txn.execute(q, []).context("Creating table")?; + } + txn.commit()?; + } + + Ok(o) + } +} + +impl Storage for SqliteStorage { + fn txn<'a>(&'a self) -> anyhow::Result> { + let mut con = self.new_connection()?; + let mut t = Txn{con, txn: None}; + Ok(Box::new(t)) + } +} + +struct Txn<'t> { + con: Connection, + txn: Option<&'t rusqlite::Transaction<'t>>, +} + +impl <'t>Txn<'t> { + fn get_txn(&mut self) -> Result<&'t rusqlite::Transaction, SqliteError> { + Ok(&self.con.transaction().unwrap()) + } +} + + +impl <'t>StorageTxn for Txn<'t> { + fn get_client(&mut self, client_key: Uuid) -> anyhow::Result> { + let t = self.get_txn()?; + let result: Option = t + .query_row( + "SELECT data FROM clients WHERE client_key = ? LIMIT 1", + [&StoredUuid(client_key)], + |r| r.get("data"), + ) + .optional()?; + + Ok(result) + } + + fn new_client(&mut self, client_key: Uuid, latest_version_id: Uuid) -> anyhow::Result<()> { + let t = self.get_txn()?; + + let client = Client{ latest_version_id }; + t.execute( + "INSERT OR REPLACE INTO clients (client_key, latest_version_id) VALUES (?, ?)", + params![&StoredUuid(latest_version_id), &client], + ) + .context("Create client query")?; + Ok(()) + } + + fn set_client_latest_version_id( + &mut self, + client_key: Uuid, + latest_version_id: Uuid, + ) -> anyhow::Result<()> { + // Implementation is same as new_client + self.new_client(client_key, latest_version_id) + } + + fn get_version_by_parent( + &mut self, + client_key: Uuid, + parent_version_id: Uuid, + ) -> anyhow::Result> { + todo!() + } + + fn add_version( + &mut self, + client_key: Uuid, + version_id: Uuid, + parent_version_id: Uuid, + history_segment: Vec, + ) -> anyhow::Result<()> { + let version = Version { + version_id, + parent_version_id, + history_segment, + }; + todo!(); + Ok(()) + } + + fn commit(&mut self) -> anyhow::Result<()> { + let t = self + .txn + .take() + .ok_or(SqliteError::TransactionAlreadyCommitted)?; + t.commit().context("Committing transaction")?; + Ok(()) + } +} + +#[cfg(test)] +mod test { + use super::*; + use tempfile::TempDir; + + #[test] + fn test_get_client_empty() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let storage = SqliteStorage::new(&tmp_dir.path())?; + let mut txn = storage.txn()?; + let maybe_client = txn.get_client(Uuid::new_v4())?; + assert!(maybe_client.is_none()); + Ok(()) + } + + #[test] + fn test_client_storage() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let storage = SqliteStorage::new(&tmp_dir.path())?; + let mut txn = storage.txn()?; + + let client_key = Uuid::new_v4(); + let latest_version_id = Uuid::new_v4(); + txn.new_client(client_key, latest_version_id)?; + + let client = txn.get_client(client_key)?.unwrap(); + assert_eq!(client.latest_version_id, latest_version_id); + + let latest_version_id = Uuid::new_v4(); + txn.set_client_latest_version_id(client_key, latest_version_id)?; + + let client = txn.get_client(client_key)?.unwrap(); + assert_eq!(client.latest_version_id, latest_version_id); + + Ok(()) + } + + #[test] + fn test_gvbp_empty() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let storage = SqliteStorage::new(&tmp_dir.path())?; + let mut txn = storage.txn()?; + let maybe_version = txn.get_version_by_parent(Uuid::new_v4(), Uuid::new_v4())?; + assert!(maybe_version.is_none()); + Ok(()) + } + + #[test] + fn test_add_version_and_gvbp() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let storage = SqliteStorage::new(&tmp_dir.path())?; + let mut txn = storage.txn()?; + + let client_key = Uuid::new_v4(); + let version_id = Uuid::new_v4(); + let parent_version_id = Uuid::new_v4(); + let history_segment = b"abc".to_vec(); + txn.add_version( + client_key, + version_id, + parent_version_id, + history_segment.clone(), + )?; + let version = txn + .get_version_by_parent(client_key, parent_version_id)? + .unwrap(); + + assert_eq!( + version, + Version { + version_id, + parent_version_id, + history_segment, + } + ); + Ok(()) + } +} From 7ff54ed0dedc5b20a2dc696074304f80b6b93130 Mon Sep 17 00:00:00 2001 From: dbr Date: Fri, 7 May 2021 22:24:55 +1000 Subject: [PATCH 19/38] WIP. Open new connection for each transaction as workaround --- sync-server/src/storage/sqlite.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/sync-server/src/storage/sqlite.rs b/sync-server/src/storage/sqlite.rs index a6eaa0df4..98ac5feab 100644 --- a/sync-server/src/storage/sqlite.rs +++ b/sync-server/src/storage/sqlite.rs @@ -103,20 +103,20 @@ impl SqliteStorage { impl Storage for SqliteStorage { fn txn<'a>(&'a self) -> anyhow::Result> { - let mut con = self.new_connection()?; - let mut t = Txn{con, txn: None}; + let con = self.new_connection()?; + let t = Txn{con, txn: None}; Ok(Box::new(t)) } } struct Txn<'t> { con: Connection, - txn: Option<&'t rusqlite::Transaction<'t>>, + txn: Option>, } impl <'t>Txn<'t> { - fn get_txn(&mut self) -> Result<&'t rusqlite::Transaction, SqliteError> { - Ok(&self.con.transaction().unwrap()) + fn get_txn(&mut self) -> Result { + Ok(self.con.transaction().unwrap()) } } @@ -171,20 +171,28 @@ impl <'t>StorageTxn for Txn<'t> { parent_version_id: Uuid, history_segment: Vec, ) -> anyhow::Result<()> { + let t = self.get_txn()?; + let version = Version { version_id, parent_version_id, history_segment, }; - todo!(); + + t.execute( + "INSERT INTO versions (client_key, id, parent, history_segment)", + params![], + ).context("Add version query")?; + Ok(()) } fn commit(&mut self) -> anyhow::Result<()> { - let t = self + let t: rusqlite::Transaction = self .txn .take() - .ok_or(SqliteError::TransactionAlreadyCommitted)?; + .unwrap(); + //.ok_or(SqliteError::TransactionAlreadyCommitted)?; t.commit().context("Committing transaction")?; Ok(()) } From 027225d2a3a62dd5443776aa1c0f4820a61cbdde Mon Sep 17 00:00:00 2001 From: dbr Date: Sat, 8 May 2021 22:09:48 +1000 Subject: [PATCH 20/38] More WIP. Workaround for !Send SQLite causing problems as each get_txn creates a new transaction --- sync-server/src/storage/sqlite.rs | 51 ++++++++++++++++--------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/sync-server/src/storage/sqlite.rs b/sync-server/src/storage/sqlite.rs index 98ac5feab..81343b35d 100644 --- a/sync-server/src/storage/sqlite.rs +++ b/sync-server/src/storage/sqlite.rs @@ -1,9 +1,9 @@ use super::{Client, Storage, StorageTxn, Uuid, Version}; +use anyhow::Context; use rusqlite::types::{FromSql, ToSql}; use rusqlite::{params, Connection, OptionalExtension}; use std::path::Path; use std::sync::{Arc, Mutex}; -use anyhow::Context; #[derive(Debug, thiserror::Error)] enum SqliteError { @@ -11,7 +11,6 @@ enum SqliteError { TransactionAlreadyCommitted, } - /// Newtype to allow implementing `FromSql` for foreign `uuid::Uuid` struct StoredUuid(Uuid); @@ -50,8 +49,6 @@ impl ToSql for Client { } } - - /// DB Key for versions: concatenation of client_key and parent_version_id type VersionDbKey = [u8; 32]; @@ -89,7 +86,8 @@ impl SqliteStorage { let txn = con.transaction()?; let queries = vec![ - "CREATE TABLE IF NOT EXISTS clients (id INTEGER PRIMARY KEY AUTOINCREMENT, data STRING);", + "CREATE TABLE IF NOT EXISTS clients (client_key STRING PRIMARY KEY, latest_version_id STRING);", + "CREATE TABLE IF NOT EXISTS versions (id STRING PRIMARY KEY, client_key STRING, parent STRING, history_segment STRING);", ]; for q in queries { txn.execute(q, []).context("Creating table")?; @@ -104,7 +102,7 @@ impl SqliteStorage { impl Storage for SqliteStorage { fn txn<'a>(&'a self) -> anyhow::Result> { let con = self.new_connection()?; - let t = Txn{con, txn: None}; + let t = Txn { con, txn: None }; Ok(Box::new(t)) } } @@ -114,23 +112,28 @@ struct Txn<'t> { txn: Option>, } -impl <'t>Txn<'t> { +impl<'t> Txn<'t> { fn get_txn(&mut self) -> Result { Ok(self.con.transaction().unwrap()) } } - -impl <'t>StorageTxn for Txn<'t> { +impl<'t> StorageTxn for Txn<'t> { fn get_client(&mut self, client_key: Uuid) -> anyhow::Result> { let t = self.get_txn()?; let result: Option = t .query_row( - "SELECT data FROM clients WHERE client_key = ? LIMIT 1", + "SELECT latest_version_id FROM clients WHERE client_key = ? LIMIT 1", [&StoredUuid(client_key)], - |r| r.get("data"), + |r| { + let latest_version_id: StoredUuid = r.get(0)?; + Ok(Client { + latest_version_id: latest_version_id.0, + }) + }, ) - .optional()?; + .optional() + .context("Get client query")?; Ok(result) } @@ -138,10 +141,9 @@ impl <'t>StorageTxn for Txn<'t> { fn new_client(&mut self, client_key: Uuid, latest_version_id: Uuid) -> anyhow::Result<()> { let t = self.get_txn()?; - let client = Client{ latest_version_id }; t.execute( "INSERT OR REPLACE INTO clients (client_key, latest_version_id) VALUES (?, ?)", - params![&StoredUuid(latest_version_id), &client], + params![&StoredUuid(client_key), &StoredUuid(latest_version_id)], ) .context("Create client query")?; Ok(()) @@ -173,16 +175,16 @@ impl <'t>StorageTxn for Txn<'t> { ) -> anyhow::Result<()> { let t = self.get_txn()?; - let version = Version { - version_id, - parent_version_id, - history_segment, - }; - t.execute( - "INSERT INTO versions (client_key, id, parent, history_segment)", - params![], - ).context("Add version query")?; + "INSERT INTO versions (id, client_key, parent, history_segment) VALUES(?, ?, ?, ?)", + params![ + StoredUuid(version_id), + StoredUuid(client_key), + StoredUuid(parent_version_id), + history_segment + ], + ) + .context("Add version query")?; Ok(()) } @@ -191,8 +193,7 @@ impl <'t>StorageTxn for Txn<'t> { let t: rusqlite::Transaction = self .txn .take() - .unwrap(); - //.ok_or(SqliteError::TransactionAlreadyCommitted)?; + .ok_or(SqliteError::TransactionAlreadyCommitted)?; t.commit().context("Committing transaction")?; Ok(()) } From 991b29da6cd58aaa3dbfb9a0c5a857e7ea0eca83 Mon Sep 17 00:00:00 2001 From: dbr Date: Fri, 21 May 2021 15:52:07 +1000 Subject: [PATCH 21/38] WIP --- sync-server/src/storage/sqlite.rs | 1 - taskchampion/src/server/local.rs | 118 +++++++++++++++--------------- 2 files changed, 57 insertions(+), 62 deletions(-) diff --git a/sync-server/src/storage/sqlite.rs b/sync-server/src/storage/sqlite.rs index 81343b35d..e974e33ef 100644 --- a/sync-server/src/storage/sqlite.rs +++ b/sync-server/src/storage/sqlite.rs @@ -3,7 +3,6 @@ use anyhow::Context; use rusqlite::types::{FromSql, ToSql}; use rusqlite::{params, Connection, OptionalExtension}; use std::path::Path; -use std::sync::{Arc, Mutex}; #[derive(Debug, thiserror::Error)] enum SqliteError { diff --git a/taskchampion/src/server/local.rs b/taskchampion/src/server/local.rs index bdd3c5dbd..aab3d86c1 100644 --- a/taskchampion/src/server/local.rs +++ b/taskchampion/src/server/local.rs @@ -1,12 +1,34 @@ + use rusqlite::params; + use anyhow::Context; use crate::server::{ AddVersionResult, GetVersionResult, HistorySegment, Server, VersionId, NO_VERSION_ID, }; -use crate::utils::Key; -use kv::msgpack::Msgpack; -use kv::{Bucket, Config, Error, Integer, Serde, Store, ValueBuf}; use serde::{Deserialize, Serialize}; use std::path::Path; use uuid::Uuid; +use rusqlite::types::{FromSql, ToSql}; + use rusqlite::OptionalExtension; + +// FIXME: Duplicated +/// Newtype to allow implementing `FromSql` for foreign `uuid::Uuid` +pub struct StoredUuid(Uuid); + +/// Conversion from Uuid stored as a string (rusqlite's uuid feature stores as binary blob) +impl FromSql for StoredUuid { + fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { + let u = Uuid::parse_str(value.as_str()?) + .map_err(|_| rusqlite::types::FromSqlError::InvalidType)?; + Ok(StoredUuid(u)) + } +} + +/// Store Uuid as string in database +impl ToSql for StoredUuid { + fn to_sql(&self) -> rusqlite::Result> { + let s = self.0.to_string(); + Ok(s.into()) + } +} #[derive(Serialize, Deserialize, Debug)] struct Version { @@ -15,58 +37,48 @@ struct Version { history_segment: HistorySegment, } -pub struct LocalServer<'t> { - store: Store, - // NOTE: indexed by parent_version_id! - versions_bucket: Bucket<'t, Key, ValueBuf>>, - latest_version_bucket: Bucket<'t, Integer, ValueBuf>>, +pub struct LocalServer { + con: rusqlite::Connection, } -impl<'t> LocalServer<'t> { - /// A test server has no notion of clients, signatures, encryption, etc. - pub fn new>(directory: P) -> anyhow::Result> { - let mut config = Config::default(directory); - config.bucket("versions", None); - config.bucket("numbers", None); - config.bucket("latest_version", None); - config.bucket("operations", None); - config.bucket("working_set", None); - let store = Store::new(config)?; +impl LocalServer { + fn txn<'a>(&'a mut self) -> anyhow::Result { + let txn = self.con.transaction()?; + Ok(txn) + } - // versions are stored indexed by VersionId (uuid) - let versions_bucket = store.bucket::>>(Some("versions"))?; + /// A server which has no notion of clients, signatures, encryption, etc. + pub fn new>(directory: P) -> anyhow::Result { + let db_file = directory.as_ref().join("taskchampion-local-sync-server.sqlite3"); + let con = rusqlite::Connection::open(&db_file)?; - // this bucket contains the latest version at key 0 - let latest_version_bucket = - store.int_bucket::>>(Some("latest_version"))?; + let queries = vec![ + "CREATE TABLE IF NOT EXISTS data (key STRING PRIMARY KEY, value STRING);", + ]; + for q in queries { + con.execute(q, []).context("Creating table")?; + } Ok(LocalServer { - store, - versions_bucket, - latest_version_bucket, + con, }) } fn get_latest_version_id(&mut self) -> anyhow::Result { - let txn = self.store.read_txn()?; - let base_version = match txn.get(&self.latest_version_bucket, 0.into()) { - Ok(buf) => buf, - Err(Error::NotFound) => return Ok(NO_VERSION_ID), - Err(e) => return Err(e.into()), - } - .inner()? - .to_serde(); - Ok(base_version as VersionId) + let t = self.txn()?; + let result: Option = t.query_row("SELECT value FROM data WHERE key = latest_version_id LIMIT 1", rusqlite::params![], |r| r.get(0)).optional()?; + Ok(result.map(|x| x.0).unwrap_or(NO_VERSION_ID)) } fn set_latest_version_id(&mut self, version_id: VersionId) -> anyhow::Result<()> { - let mut txn = self.store.write_txn()?; - txn.set( - &self.latest_version_bucket, - 0.into(), - Msgpack::to_value_buf(version_id as Uuid)?, - )?; - txn.commit()?; + + let t = self.txn()?; + t.execute( + "INSERT OR REPLACE INTO tasks (uuid, data) VALUES (?, ?)", + params![&StoredUuid(version_id)], + ) + .context("Update task query")?; + t.commit()?; Ok(()) } @@ -74,31 +86,15 @@ impl<'t> LocalServer<'t> { &mut self, parent_version_id: VersionId, ) -> anyhow::Result> { - let txn = self.store.read_txn()?; - - let version = match txn.get(&self.versions_bucket, parent_version_id.into()) { - Ok(buf) => buf, - Err(Error::NotFound) => return Ok(None), - Err(e) => return Err(e.into()), - } - .inner()? - .to_serde(); - Ok(Some(version)) + todo!() } fn add_version_by_parent_version_id(&mut self, version: Version) -> anyhow::Result<()> { - let mut txn = self.store.write_txn()?; - txn.set( - &self.versions_bucket, - version.parent_version_id.into(), - Msgpack::to_value_buf(version)?, - )?; - txn.commit()?; - Ok(()) + todo!() } } -impl<'t> Server for LocalServer<'t> { +impl Server for LocalServer { // TODO: better transaction isolation for add_version (gets and sets should be in the same // transaction) From f91f7972445baec3c1033e458eae71153fb8cf98 Mon Sep 17 00:00:00 2001 From: dbr Date: Fri, 28 May 2021 11:38:46 +1000 Subject: [PATCH 22/38] Implement storage for local server --- taskchampion/src/server/local.rs | 67 +++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/taskchampion/src/server/local.rs b/taskchampion/src/server/local.rs index aab3d86c1..47f8e5cc3 100644 --- a/taskchampion/src/server/local.rs +++ b/taskchampion/src/server/local.rs @@ -1,13 +1,13 @@ - use rusqlite::params; - use anyhow::Context; use crate::server::{ AddVersionResult, GetVersionResult, HistorySegment, Server, VersionId, NO_VERSION_ID, }; +use anyhow::Context; +use rusqlite::params; +use rusqlite::types::{FromSql, ToSql}; +use rusqlite::OptionalExtension; use serde::{Deserialize, Serialize}; use std::path::Path; use uuid::Uuid; -use rusqlite::types::{FromSql, ToSql}; - use rusqlite::OptionalExtension; // FIXME: Duplicated /// Newtype to allow implementing `FromSql` for foreign `uuid::Uuid` @@ -30,6 +30,14 @@ impl ToSql for StoredUuid { } } +impl FromSql for Version { + fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { + let u = serde_json::from_str(value.as_str()?) + .map_err(|_| rusqlite::types::FromSqlError::InvalidType)?; + Ok(u) + } +} + #[derive(Serialize, Deserialize, Debug)] struct Version { version_id: VersionId, @@ -49,32 +57,38 @@ impl LocalServer { /// A server which has no notion of clients, signatures, encryption, etc. pub fn new>(directory: P) -> anyhow::Result { - let db_file = directory.as_ref().join("taskchampion-local-sync-server.sqlite3"); + let db_file = directory + .as_ref() + .join("taskchampion-local-sync-server.sqlite3"); let con = rusqlite::Connection::open(&db_file)?; let queries = vec![ "CREATE TABLE IF NOT EXISTS data (key STRING PRIMARY KEY, value STRING);", + "CREATE TABLE IF NOT EXISTS versions (version_id STRING PRIMARY KEY, parent_version_id STRING, data STRING);", ]; for q in queries { con.execute(q, []).context("Creating table")?; } - Ok(LocalServer { - con, - }) + Ok(LocalServer { con }) } fn get_latest_version_id(&mut self) -> anyhow::Result { let t = self.txn()?; - let result: Option = t.query_row("SELECT value FROM data WHERE key = latest_version_id LIMIT 1", rusqlite::params![], |r| r.get(0)).optional()?; + let result: Option = t + .query_row( + "SELECT value FROM data WHERE key = 'latest_version_id' LIMIT 1", + rusqlite::params![], + |r| r.get(0), + ) + .optional()?; Ok(result.map(|x| x.0).unwrap_or(NO_VERSION_ID)) } fn set_latest_version_id(&mut self, version_id: VersionId) -> anyhow::Result<()> { - let t = self.txn()?; t.execute( - "INSERT OR REPLACE INTO tasks (uuid, data) VALUES (?, ?)", + "INSERT OR REPLACE INTO data (key, value) VALUES ('latest_version_id', ?)", params![&StoredUuid(version_id)], ) .context("Update task query")?; @@ -86,11 +100,38 @@ impl LocalServer { &mut self, parent_version_id: VersionId, ) -> anyhow::Result> { - todo!() + let t = self.txn()?; + let r = t.query_row( + "SELECT version_id, parent_version_id, data FROM versions WHERE parent_version_id = ?", + params![&StoredUuid(parent_version_id)], + |r| { + let version_id: StoredUuid = r.get("version_id")?; + let parent_version_id: StoredUuid = r.get("parent_version_id")?; + + Ok(Version{ + version_id: version_id.0, + parent_version_id: parent_version_id.0, + history_segment: r.get("data")?, + })} + ) + .optional() + .context("Get version query") + ?; + Ok(r) } fn add_version_by_parent_version_id(&mut self, version: Version) -> anyhow::Result<()> { - todo!() + let t = self.txn()?; + t.execute( + "INSERT INTO versions (version_id, parent_version_id, data) VALUES (?, ?, ?)", + params![ + StoredUuid(version.version_id), + StoredUuid(version.parent_version_id), + version.history_segment + ], + )?; + t.commit()?; + Ok(()) } } From 98f2ab51cb0c381f42698211d24682a06db57ea5 Mon Sep 17 00:00:00 2001 From: dbr Date: Fri, 28 May 2021 12:09:36 +1000 Subject: [PATCH 23/38] Functional sqlite backend ..but not too efficient, creating a new connection pretty much per-query --- sync-server/src/storage/sqlite.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/sync-server/src/storage/sqlite.rs b/sync-server/src/storage/sqlite.rs index e974e33ef..bce885af1 100644 --- a/sync-server/src/storage/sqlite.rs +++ b/sync-server/src/storage/sqlite.rs @@ -86,7 +86,7 @@ impl SqliteStorage { let queries = vec![ "CREATE TABLE IF NOT EXISTS clients (client_key STRING PRIMARY KEY, latest_version_id STRING);", - "CREATE TABLE IF NOT EXISTS versions (id STRING PRIMARY KEY, client_key STRING, parent STRING, history_segment STRING);", + "CREATE TABLE IF NOT EXISTS versions (version_id STRING PRIMARY KEY, client_key STRING, parent_version_id STRING, history_segment STRING);", ]; for q in queries { txn.execute(q, []).context("Creating table")?; @@ -145,6 +145,7 @@ impl<'t> StorageTxn for Txn<'t> { params![&StoredUuid(client_key), &StoredUuid(latest_version_id)], ) .context("Create client query")?; + t.commit()?; Ok(()) } @@ -162,7 +163,24 @@ impl<'t> StorageTxn for Txn<'t> { client_key: Uuid, parent_version_id: Uuid, ) -> anyhow::Result> { - todo!() + let t = self.get_txn()?; + let r = t.query_row( + "SELECT version_id, parent_version_id, history_segment FROM versions WHERE parent_version_id = ? AND client_key = ?", + params![&StoredUuid(parent_version_id), &StoredUuid(client_key)], + |r| { + let version_id: StoredUuid = r.get("version_id")?; + let parent_version_id: StoredUuid = r.get("parent_version_id")?; + + Ok(Version{ + version_id: version_id.0, + parent_version_id: parent_version_id.0, + history_segment: r.get("history_segment")?, + })} + ) + .optional() + .context("Get version query") + ?; + Ok(r) } fn add_version( @@ -175,7 +193,7 @@ impl<'t> StorageTxn for Txn<'t> { let t = self.get_txn()?; t.execute( - "INSERT INTO versions (id, client_key, parent, history_segment) VALUES(?, ?, ?, ?)", + "INSERT INTO versions (version_id, client_key, parent_version_id, history_segment) VALUES(?, ?, ?, ?)", params![ StoredUuid(version_id), StoredUuid(client_key), @@ -184,7 +202,7 @@ impl<'t> StorageTxn for Txn<'t> { ], ) .context("Add version query")?; - + t.commit()?; Ok(()) } From baa6b59e398311c11afc8a3f4b33b592c2047055 Mon Sep 17 00:00:00 2001 From: dbr Date: Fri, 28 May 2021 12:10:18 +1000 Subject: [PATCH 24/38] Remove KvStorage --- Cargo.lock | 70 +--------- sync-server/Cargo.toml | 1 - sync-server/src/main.rs | 4 +- sync-server/src/storage/kv.rs | 241 --------------------------------- sync-server/src/storage/mod.rs | 3 - taskchampion/Cargo.toml | 1 - 6 files changed, 4 insertions(+), 316 deletions(-) delete mode 100644 sync-server/src/storage/kv.rs diff --git a/Cargo.lock b/Cargo.lock index 75eabf642..41b9a1ed3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "actix-codec" version = "0.3.0" @@ -1161,19 +1163,6 @@ dependencies = [ "winapi-build", ] -[[package]] -name = "kv" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb79e59d356a5ae85b13990bbb3649a293d64df1ca6e7890822076186527a9f7" -dependencies = [ - "lmdb-rkv", - "rmp-serde", - "serde", - "thiserror", - "toml", -] - [[package]] name = "language-tags" version = "0.2.2" @@ -1222,29 +1211,6 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" -[[package]] -name = "lmdb-rkv" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "605061e5465304475be2041f19967a900175ea1b6d8f47fbab84a84fb8c48452" -dependencies = [ - "bitflags", - "byteorder", - "libc", - "lmdb-rkv-sys", -] - -[[package]] -name = "lmdb-rkv-sys" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7982ba0460e939e26a52ee12c8075deab0ebd44ed21881f656841b70e021b7c8" -dependencies = [ - "cc", - "libc", - "pkg-config", -] - [[package]] name = "lock_api" version = "0.4.3" @@ -1865,27 +1831,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "rmp" -version = "0.8.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f55e5fa1446c4d5dd1f5daeed2a4fe193071771a2636274d0d7a3b082aa7ad6" -dependencies = [ - "byteorder", - "num-traits", -] - -[[package]] -name = "rmp-serde" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ce7d70c926fe472aed493b902010bccc17fa9f7284145cb8772fd22fdb052d8" -dependencies = [ - "byteorder", - "rmp", - "serde", -] - [[package]] name = "rusqlite" version = "0.25.1" @@ -2183,7 +2128,6 @@ version = "0.3.0" dependencies = [ "anyhow", "chrono", - "kv", "log", "proptest", "rusqlite", @@ -2226,7 +2170,6 @@ dependencies = [ "clap", "env_logger", "futures", - "kv", "log", "rusqlite", "serde", @@ -2454,15 +2397,6 @@ dependencies = [ "tokio 0.2.25", ] -[[package]] -name = "toml" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" -dependencies = [ - "serde", -] - [[package]] name = "tracing" version = "0.1.25" diff --git a/sync-server/Cargo.toml b/sync-server/Cargo.toml index c9d665ba0..6c66f6726 100644 --- a/sync-server/Cargo.toml +++ b/sync-server/Cargo.toml @@ -14,7 +14,6 @@ thiserror = "1.0" futures = "^0.3.8" serde = "^1.0.125" serde_json = "^1.0" -kv = {version = "^0.10.0", features = ["msgpack-value"]} clap = "^2.33.0" log = "^0.4.14" env_logger = "^0.8.3" diff --git a/sync-server/src/main.rs b/sync-server/src/main.rs index 2ae65ae5c..394031738 100644 --- a/sync-server/src/main.rs +++ b/sync-server/src/main.rs @@ -1,6 +1,6 @@ #![deny(clippy::all)] -use crate::storage::{KvStorage, Storage}; +use crate::storage::{SqliteStorage, Storage}; use actix_web::{get, middleware::Logger, web, App, HttpServer, Responder, Scope}; use api::{api_scope, ServerState}; use clap::Arg; @@ -56,7 +56,7 @@ async fn main() -> anyhow::Result<()> { let data_dir = matches.value_of("data-dir").unwrap(); let port = matches.value_of("port").unwrap(); - let server_box: Box = Box::new(KvStorage::new(data_dir)?); + let server_box: Box = Box::new(SqliteStorage::new(data_dir)?); let server_state = ServerState::new(server_box); log::warn!("Serving on port {}", port); diff --git a/sync-server/src/storage/kv.rs b/sync-server/src/storage/kv.rs deleted file mode 100644 index bd5fa3502..000000000 --- a/sync-server/src/storage/kv.rs +++ /dev/null @@ -1,241 +0,0 @@ -use super::{Client, Storage, StorageTxn, Uuid, Version}; -use kv::msgpack::Msgpack; -use kv::{Bucket, Config, Error, Serde, Store, ValueBuf}; -use std::path::Path; - -/// DB Key for versions: concatenation of client_key and parent_version_id -type VersionDbKey = [u8; 32]; - -fn version_db_key(client_key: Uuid, parent_version_id: Uuid) -> VersionDbKey { - let mut key = [0u8; 32]; - key[..16].clone_from_slice(client_key.as_bytes()); - key[16..].clone_from_slice(parent_version_id.as_bytes()); - key -} - -/// Key for clients: just the client_key -type ClientDbKey = [u8; 16]; - -fn client_db_key(client_key: Uuid) -> ClientDbKey { - *client_key.as_bytes() -} - -/// KvStorage is an on-disk storage backend which uses LMDB via the `kv` crate. -pub(crate) struct KvStorage<'t> { - store: Store, - clients_bucket: Bucket<'t, ClientDbKey, ValueBuf>>, - versions_bucket: Bucket<'t, VersionDbKey, ValueBuf>>, -} - -impl<'t> KvStorage<'t> { - pub fn new>(directory: P) -> anyhow::Result> { - let mut config = Config::default(directory); - config.bucket("clients", None); - config.bucket("versions", None); - - let store = Store::new(config)?; - - let clients_bucket = - store.bucket::>>(Some("clients"))?; - let versions_bucket = - store.bucket::>>(Some("versions"))?; - - Ok(KvStorage { - store, - clients_bucket, - versions_bucket, - }) - } -} - -impl<'t> Storage for KvStorage<'t> { - fn txn<'a>(&'a self) -> anyhow::Result> { - Ok(Box::new(Txn { - storage: self, - txn: Some(self.store.write_txn()?), - })) - } -} - -struct Txn<'t> { - storage: &'t KvStorage<'t>, - txn: Option>, -} - -impl<'t> Txn<'t> { - // get the underlying kv Txn - fn kvtxn(&mut self) -> &mut kv::Txn<'t> { - if let Some(ref mut txn) = self.txn { - txn - } else { - panic!("cannot use transaction after commit"); - } - } - - fn clients_bucket(&self) -> &'t Bucket<'t, ClientDbKey, ValueBuf>> { - &self.storage.clients_bucket - } - fn versions_bucket(&self) -> &'t Bucket<'t, VersionDbKey, ValueBuf>> { - &self.storage.versions_bucket - } -} - -impl<'t> StorageTxn for Txn<'t> { - fn get_client(&mut self, client_key: Uuid) -> anyhow::Result> { - let key = client_db_key(client_key); - let bucket = self.clients_bucket(); - let kvtxn = self.kvtxn(); - - let client = match kvtxn.get(&bucket, key) { - Ok(buf) => buf, - Err(Error::NotFound) => return Ok(None), - Err(e) => return Err(e.into()), - } - .inner()? - .to_serde(); - Ok(Some(client)) - } - - fn new_client(&mut self, client_key: Uuid, latest_version_id: Uuid) -> anyhow::Result<()> { - let key = client_db_key(client_key); - let bucket = self.clients_bucket(); - let kvtxn = self.kvtxn(); - let client = Client { latest_version_id }; - kvtxn.set(&bucket, key, Msgpack::to_value_buf(client)?)?; - Ok(()) - } - - fn set_client_latest_version_id( - &mut self, - client_key: Uuid, - latest_version_id: Uuid, - ) -> anyhow::Result<()> { - // implementation is the same as new_client.. - self.new_client(client_key, latest_version_id) - } - - fn get_version_by_parent( - &mut self, - client_key: Uuid, - parent_version_id: Uuid, - ) -> anyhow::Result> { - let key = version_db_key(client_key, parent_version_id); - let bucket = self.versions_bucket(); - let kvtxn = self.kvtxn(); - let version = match kvtxn.get(&bucket, key) { - Ok(buf) => buf, - Err(Error::NotFound) => return Ok(None), - Err(e) => return Err(e.into()), - } - .inner()? - .to_serde(); - Ok(Some(version)) - } - - fn add_version( - &mut self, - client_key: Uuid, - version_id: Uuid, - parent_version_id: Uuid, - history_segment: Vec, - ) -> anyhow::Result<()> { - let key = version_db_key(client_key, parent_version_id); - let bucket = self.versions_bucket(); - let kvtxn = self.kvtxn(); - let version = Version { - version_id, - parent_version_id, - history_segment, - }; - kvtxn.set(&bucket, key, Msgpack::to_value_buf(version)?)?; - Ok(()) - } - - fn commit(&mut self) -> anyhow::Result<()> { - if let Some(kvtxn) = self.txn.take() { - kvtxn.commit()?; - } else { - panic!("transaction already committed"); - } - Ok(()) - } -} - -#[cfg(test)] -mod test { - use super::*; - use tempfile::TempDir; - - #[test] - fn test_get_client_empty() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let storage = KvStorage::new(&tmp_dir.path())?; - let mut txn = storage.txn()?; - let maybe_client = txn.get_client(Uuid::new_v4())?; - assert!(maybe_client.is_none()); - Ok(()) - } - - #[test] - fn test_client_storage() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let storage = KvStorage::new(&tmp_dir.path())?; - let mut txn = storage.txn()?; - - let client_key = Uuid::new_v4(); - let latest_version_id = Uuid::new_v4(); - txn.new_client(client_key, latest_version_id)?; - - let client = txn.get_client(client_key)?.unwrap(); - assert_eq!(client.latest_version_id, latest_version_id); - - let latest_version_id = Uuid::new_v4(); - txn.set_client_latest_version_id(client_key, latest_version_id)?; - - let client = txn.get_client(client_key)?.unwrap(); - assert_eq!(client.latest_version_id, latest_version_id); - - Ok(()) - } - - #[test] - fn test_gvbp_empty() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let storage = KvStorage::new(&tmp_dir.path())?; - let mut txn = storage.txn()?; - let maybe_version = txn.get_version_by_parent(Uuid::new_v4(), Uuid::new_v4())?; - assert!(maybe_version.is_none()); - Ok(()) - } - - #[test] - fn test_add_version_and_gvbp() -> anyhow::Result<()> { - let tmp_dir = TempDir::new()?; - let storage = KvStorage::new(&tmp_dir.path())?; - let mut txn = storage.txn()?; - - let client_key = Uuid::new_v4(); - let version_id = Uuid::new_v4(); - let parent_version_id = Uuid::new_v4(); - let history_segment = b"abc".to_vec(); - txn.add_version( - client_key, - version_id, - parent_version_id, - history_segment.clone(), - )?; - let version = txn - .get_version_by_parent(client_key, parent_version_id)? - .unwrap(); - - assert_eq!( - version, - Version { - version_id, - parent_version_id, - history_segment, - } - ); - Ok(()) - } -} diff --git a/sync-server/src/storage/mod.rs b/sync-server/src/storage/mod.rs index 41fb400e9..f9a2fc699 100644 --- a/sync-server/src/storage/mod.rs +++ b/sync-server/src/storage/mod.rs @@ -9,9 +9,6 @@ pub(crate) use inmemory::InMemoryStorage; mod sqlite; pub(crate) use self::sqlite::SqliteStorage; -mod kv; -pub(crate) use self::kv::KvStorage; - #[derive(Clone, PartialEq, Debug, Serialize, Deserialize)] pub(crate) struct Client { pub(crate) latest_version_id: Uuid, diff --git a/taskchampion/Cargo.toml b/taskchampion/Cargo.toml index 03a047c88..2231395fa 100644 --- a/taskchampion/Cargo.toml +++ b/taskchampion/Cargo.toml @@ -17,7 +17,6 @@ serde_json = "^1.0" chrono = { version = "^0.4.10", features = ["serde"] } anyhow = "1.0" thiserror = "1.0" -kv = {version = "^0.10.0", features = ["msgpack-value"]} ureq = "^2.1.0" log = "^0.4.14" tindercrypt = { version = "^0.2.2", default-features = false } From 3c8c7d4888e8cf77ecfc809a8d16f55b627fa50f Mon Sep 17 00:00:00 2001 From: dbr Date: Fri, 28 May 2021 12:19:49 +1000 Subject: [PATCH 25/38] Updated Cargo.lock --- Cargo.lock | 2802 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2802 insertions(+) create mode 100644 Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 000000000..c65d01171 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,2802 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "actix-codec" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78d1833b3838dbe990df0f1f87baf640cf6146e898166afe401839d1b001e570" +dependencies = [ + "bitflags", + "bytes 0.5.6", + "futures-core", + "futures-sink", + "log", + "pin-project 0.4.28", + "tokio 0.2.25", + "tokio-util", +] + +[[package]] +name = "actix-connect" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "177837a10863f15ba8d3ae3ec12fac1099099529ed20083a27fdfe247381d0dc" +dependencies = [ + "actix-codec", + "actix-rt 1.1.1", + "actix-service", + "actix-utils", + "derive_more", + "either", + "futures-util", + "http", + "log", + "trust-dns-proto", + "trust-dns-resolver", +] + +[[package]] +name = "actix-http" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "452299e87817ae5673910e53c243484ca38be3828db819b6011736fc6982e874" +dependencies = [ + "actix-codec", + "actix-connect", + "actix-rt 1.1.1", + "actix-service", + "actix-threadpool", + "actix-utils", + "base64", + "bitflags", + "brotli2", + "bytes 0.5.6", + "cookie", + "copyless", + "derive_more", + "either", + "encoding_rs", + "flate2", + "futures-channel", + "futures-core", + "futures-util", + "fxhash", + "h2", + "http", + "httparse", + "indexmap", + "itoa", + "language-tags", + "lazy_static", + "log", + "mime", + "percent-encoding", + "pin-project 1.0.7", + "rand 0.7.3", + "regex", + "serde", + "serde_json", + "serde_urlencoded", + "sha-1", + "slab", + "time 0.2.26", +] + +[[package]] +name = "actix-macros" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ca8ce00b267af8ccebbd647de0d61e0674b6e61185cc7a592ff88772bed655" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "actix-macros" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbcb2b608f0accc2f5bcf3dd872194ce13d94ee45b571487035864cf966b04ef" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "actix-router" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ad299af73649e1fc893e333ccf86f377751eb95ff875d095131574c6f43452c" +dependencies = [ + "bytestring", + "http", + "log", + "regex", + "serde", +] + +[[package]] +name = "actix-rt" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "143fcc2912e0d1de2bcf4e2f720d2a60c28652ab4179685a1ee159e0fb3db227" +dependencies = [ + "actix-macros 0.1.3", + "actix-threadpool", + "copyless", + "futures-channel", + "futures-util", + "smallvec", + "tokio 0.2.25", +] + +[[package]] +name = "actix-rt" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc7d7cd957c9ed92288a7c3c96af81fa5291f65247a76a34dac7b6af74e52ba0" +dependencies = [ + "actix-macros 0.2.0", + "futures-core", + "tokio 1.6.0", +] + +[[package]] +name = "actix-server" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45407e6e672ca24784baa667c5d32ef109ccdd8d5e0b5ebb9ef8a67f4dfb708e" +dependencies = [ + "actix-codec", + "actix-rt 1.1.1", + "actix-service", + "actix-utils", + "futures-channel", + "futures-util", + "log", + "mio 0.6.23", + "mio-uds", + "num_cpus", + "slab", + "socket2", +] + +[[package]] +name = "actix-service" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0052435d581b5be835d11f4eb3bce417c8af18d87ddf8ace99f8e67e595882bb" +dependencies = [ + "futures-util", + "pin-project 0.4.28", +] + +[[package]] +name = "actix-testing" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47239ca38799ab74ee6a8a94d1ce857014b2ac36f242f70f3f75a66f691e791c" +dependencies = [ + "actix-macros 0.1.3", + "actix-rt 1.1.1", + "actix-server", + "actix-service", + "log", + "socket2", +] + +[[package]] +name = "actix-threadpool" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d209f04d002854b9afd3743032a27b066158817965bf5d036824d19ac2cc0e30" +dependencies = [ + "derive_more", + "futures-channel", + "lazy_static", + "log", + "num_cpus", + "parking_lot", + "threadpool", +] + +[[package]] +name = "actix-tls" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24789b7d7361cf5503a504ebe1c10806896f61e96eca9a7350e23001aca715fb" +dependencies = [ + "actix-codec", + "actix-service", + "actix-utils", + "futures-util", +] + +[[package]] +name = "actix-utils" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9022dec56632d1d7979e59af14f0597a28a830a9c1c7fec8b2327eb9f16b5a" +dependencies = [ + "actix-codec", + "actix-rt 1.1.1", + "actix-service", + "bitflags", + "bytes 0.5.6", + "either", + "futures-channel", + "futures-sink", + "futures-util", + "log", + "pin-project 0.4.28", + "slab", +] + +[[package]] +name = "actix-web" +version = "3.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e641d4a172e7faa0862241a20ff4f1f5ab0ab7c279f00c2d4587b77483477b86" +dependencies = [ + "actix-codec", + "actix-http", + "actix-macros 0.1.3", + "actix-router", + "actix-rt 1.1.1", + "actix-server", + "actix-service", + "actix-testing", + "actix-threadpool", + "actix-tls", + "actix-utils", + "actix-web-codegen", + "awc", + "bytes 0.5.6", + "derive_more", + "encoding_rs", + "futures-channel", + "futures-core", + "futures-util", + "fxhash", + "log", + "mime", + "pin-project 1.0.7", + "regex", + "serde", + "serde_json", + "serde_urlencoded", + "socket2", + "time 0.2.26", + "tinyvec", + "url", +] + +[[package]] +name = "actix-web-codegen" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad26f77093333e0e7c6ffe54ebe3582d908a104e448723eec6d43d08b07143fb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "ahash" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98" +dependencies = [ + "getrandom 0.2.3", + "once_cell", + "version_check", +] + +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "anyhow" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" + +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + +[[package]] +name = "ascii" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" + +[[package]] +name = "assert_cmd" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f57fec1ac7e4de72dcc69811795f1a7172ed06012f80a5d1ee651b62484f588" +dependencies = [ + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "async-trait" +version = "0.1.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b98e84bbb4cbcdd97da190ba0c58a1bb0de2c1fdf67d159e192ed766aeca722" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "awc" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b381e490e7b0cfc37ebc54079b0413d8093ef43d14a4e4747083f7fa47a9e691" +dependencies = [ + "actix-codec", + "actix-http", + "actix-rt 1.1.1", + "actix-service", + "base64", + "bytes 0.5.6", + "cfg-if 1.0.0", + "derive_more", + "futures-core", + "log", + "mime", + "percent-encoding", + "rand 0.7.3", + "serde", + "serde_json", + "serde_urlencoded", +] + +[[package]] +name = "base-x" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bit-set" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "bitvec" +version = "0.19.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2b_simd" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "brotli-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4445dea95f4c2b41cde57cc9fee236ae4dbae88d8fcbdb4750fc1bb5d86aaecd" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "brotli2" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cb036c3eade309815c15ddbacec5b22c4d1f3983a774ab2eac2e3e9ea85568e" +dependencies = [ + "brotli-sys", + "libc", +] + +[[package]] +name = "bstr" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90682c8d613ad3373e66de8c6411e0ae2ab2571e879d2efbf73558cc66f21279" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" + +[[package]] +name = "bytes" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" + +[[package]] +name = "bytestring" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90706ba19e97b90786e19dc0d5e2abd80008d99d4c0c5d1ad0b5e72cec7c494d" +dependencies = [ + "bytes 1.0.1", +] + +[[package]] +name = "cc" +version = "1.0.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "serde", + "time 0.1.43", + "winapi 0.3.9", +] + +[[package]] +name = "chunked_transfer" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" + +[[package]] +name = "clap" +version = "2.33.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap 0.11.0", + "unicode-width", + "vec_map", +] + +[[package]] +name = "combine" +version = "3.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680" +dependencies = [ + "ascii", + "byteorder", + "either", + "memchr", + "unreachable", +] + +[[package]] +name = "const_fn" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f92cfa0fd5690b3cf8c1ef2cabbd9b7ef22fa53cf5e1f92b05103f6d5d1cf6e7" + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cookie" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951" +dependencies = [ + "percent-encoding", + "time 0.2.26", + "version_check", +] + +[[package]] +name = "copyless" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536" + +[[package]] +name = "cpufeatures" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed00c67cb5d0a7d64a44f6ad2668db7e7530311dd53ea79bcd4fb022c64911c8" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4feb231f0d4d6af81aed15928e58ecf5816aa62a2393e2c82f46973e92a9a278" +dependencies = [ + "autocfg", + "cfg-if 1.0.0", + "lazy_static", +] + +[[package]] +name = "csv" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" +dependencies = [ + "bstr", + "csv-core", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" +dependencies = [ + "memchr", +] + +[[package]] +name = "derive_more" +version = "0.99.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc7b9cef1e351660e5443924e4f43ab25fbbed3e9a5f052df3677deb4d6b320" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "difference" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "dirs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" +dependencies = [ + "libc", + "redox_users 0.3.5", + "winapi 0.3.9", +] + +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if 1.0.0", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users 0.4.0", + "winapi 0.3.9", +] + +[[package]] +name = "discard" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + +[[package]] +name = "encoding_rs" +version = "0.8.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "enum-as-inner" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c5f0096a91d210159eceb2ff5e1c4da18388a170e1e3ce948aac9c8fdbbf595" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "env_logger" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + +[[package]] +name = "flate2" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0" +dependencies = [ + "cfg-if 1.0.0", + "crc32fast", + "libc", + "miniz_oxide", +] + +[[package]] +name = "float-cmp" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1267f4ac4f343772758f7b1bdcbe767c218bbab93bb432acbf5162bbf85a6c4" +dependencies = [ + "num-traits", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +dependencies = [ + "bitflags", + "fuchsia-zircon-sys", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" + +[[package]] +name = "funty" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" + +[[package]] +name = "futures" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7e43a803dae2fa37c1f6a8fe121e1f7bf9548b4dfc0522a42f34145dadfc27" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1" + +[[package]] +name = "futures-executor" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "badaa6a909fac9e7236d0620a2f57f7664640c56575b71a7552fbd68deafab79" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1" + +[[package]] +name = "futures-macro" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121" +dependencies = [ + "autocfg", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282" + +[[package]] +name = "futures-task" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae" + +[[package]] +name = "futures-util" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967" +dependencies = [ + "autocfg", + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite 0.2.6", + "pin-utils", + "proc-macro-hack", + "proc-macro-nested", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.10.2+wasi-snapshot-preview1", +] + +[[package]] +name = "h2" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" +dependencies = [ + "bytes 0.5.6", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio 0.2.25", + "tokio-util", + "tracing", + "tracing-futures", +] + +[[package]] +name = "hashbrown" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashlink" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf" +dependencies = [ + "hashbrown 0.11.2", +] + +[[package]] +name = "heck" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +dependencies = [ + "libc", +] + +[[package]] +name = "hostname" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +dependencies = [ + "libc", + "match_cfg", + "winapi 0.3.9", +] + +[[package]] +name = "http" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" +dependencies = [ + "bytes 1.0.1", + "fnv", + "itoa", +] + +[[package]] +name = "httparse" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a87b616e37e93c22fb19bcd386f02f3af5ea98a25670ad0fce773de23c5e68" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" +dependencies = [ + "autocfg", + "hashbrown 0.9.1", +] + +[[package]] +name = "instant" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "iovec" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +dependencies = [ + "libc", +] + +[[package]] +name = "ipconfig" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7e2f18aece9709094573a9f24f483c4f65caa4298e2f7ae1b71cc65d853fad7" +dependencies = [ + "socket2", + "widestring", + "winapi 0.3.9", + "winreg", +] + +[[package]] +name = "itoa" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" + +[[package]] +name = "js-sys" +version = "0.3.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + +[[package]] +name = "language-tags" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lexical-core" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe" +dependencies = [ + "arrayvec", + "bitflags", + "cfg-if 1.0.0", + "ryu", + "static_assertions", +] + +[[package]] +name = "libc" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" + +[[package]] +name = "libsqlite3-sys" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290b64917f8b0cb885d9de0f9959fe1f775d7fa12f1da2db9001c1c8ab60f89d" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "linked-hash-map" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" + +[[package]] +name = "lock_api" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "lru-cache" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "match_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" + +[[package]] +name = "matches" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" + +[[package]] +name = "memchr" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" + +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg", +] + +[[package]] +name = "mio" +version = "0.6.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" +dependencies = [ + "cfg-if 0.1.10", + "fuchsia-zircon", + "fuchsia-zircon-sys", + "iovec", + "kernel32-sys", + "libc", + "log", + "miow 0.2.2", + "net2", + "slab", + "winapi 0.2.8", +] + +[[package]] +name = "mio" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" +dependencies = [ + "libc", + "log", + "miow 0.3.7", + "ntapi", + "winapi 0.3.9", +] + +[[package]] +name = "mio-uds" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" +dependencies = [ + "iovec", + "libc", + "mio 0.6.23", +] + +[[package]] +name = "miow" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" +dependencies = [ + "kernel32-sys", + "net2", + "winapi 0.2.8", + "ws2_32-sys", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "net2" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "nom" +version = "6.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2" +dependencies = [ + "bitvec", + "funty", + "lexical-core", + "memchr", + "version_check", +] + +[[package]] +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "parking_lot" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall 0.2.8", + "smallvec", + "winapi 0.3.9", +] + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pin-project" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918192b5c59119d51e0cd221f4d49dde9112824ba717369e903c97d076083d0f" +dependencies = [ + "pin-project-internal 0.4.28", +] + +[[package]] +name = "pin-project" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4" +dependencies = [ + "pin-project-internal 1.0.7", +] + +[[package]] +name = "pin-project-internal" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be26700300be6d9d23264c73211d8190e755b6b5ca7a1b28230025511b52a5e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" + +[[package]] +name = "pin-project-lite" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" + +[[package]] +name = "ppv-lite86" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" + +[[package]] +name = "predicates" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f49cfaf7fdaa3bfacc6fa3e7054e65148878354a5cfddcf661df4c851f8021df" +dependencies = [ + "difference", + "float-cmp", + "normalize-line-endings", + "predicates-core", + "regex", +] + +[[package]] +name = "predicates-core" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451" + +[[package]] +name = "predicates-tree" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2" +dependencies = [ + "predicates-core", + "treeline", +] + +[[package]] +name = "prettytable-rs" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fd04b170004fa2daccf418a7f8253aaf033c27760b5f225889024cf66d7ac2e" +dependencies = [ + "atty", + "csv", + "encode_unicode", + "lazy_static", + "term", + "unicode-width", +] + +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro-nested" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" + +[[package]] +name = "proc-macro2" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "proptest" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0d9cc07f18492d879586c92b485def06bc850da3118075cd45d50e9c95b0e5" +dependencies = [ + "bit-set", + "bitflags", + "byteorder", + "lazy_static", + "num-traits", + "quick-error 2.0.1", + "rand 0.8.3", + "rand_chacha 0.3.0", + "rand_xorshift", + "regex-syntax", + "rusty-fork", + "tempfile", +] + +[[package]] +name = "protobuf" +version = "2.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45604fc7a88158e7d514d8e22e14ac746081e7a70d7690074dd0029ee37458d6" + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quick-error" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" + +[[package]] +name = "quote" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc 0.2.0", +] + +[[package]] +name = "rand" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +dependencies = [ + "libc", + "rand_chacha 0.3.0", + "rand_core 0.6.2", + "rand_hc 0.3.0", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.2", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +dependencies = [ + "getrandom 0.2.3", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +dependencies = [ + "rand_core 0.6.2", +] + +[[package]] +name = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core 0.6.2", +] + +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + +[[package]] +name = "redox_syscall" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" +dependencies = [ + "getrandom 0.1.16", + "redox_syscall 0.1.57", + "rust-argon2", +] + +[[package]] +name = "redox_users" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" +dependencies = [ + "getrandom 0.2.3", + "redox_syscall 0.2.8", +] + +[[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" +dependencies = [ + "byteorder", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "resolv-conf" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00" +dependencies = [ + "hostname", + "quick-error 1.2.3", +] + +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi 0.3.9", +] + +[[package]] +name = "rusqlite" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57adcf67c8faaf96f3248c2a7b419a0dbc52ebe36ba83dd57fe83827c1ea4eb3" +dependencies = [ + "bitflags", + "fallible-iterator", + "fallible-streaming-iterator", + "hashlink", + "libsqlite3-sys", + "memchr", + "smallvec", +] + +[[package]] +name = "rust-argon2" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" +dependencies = [ + "base64", + "blake2b_simd", + "constant_time_eq", + "crossbeam-utils", +] + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + +[[package]] +name = "rustls" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" +dependencies = [ + "base64", + "log", + "ring", + "sct", + "webpki", +] + +[[package]] +name = "rusty-fork" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" +dependencies = [ + "fnv", + "quick-error 1.2.3", + "tempfile", + "wait-timeout", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "sct" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "serde" +version = "1.0.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha-1" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c4cfa741c5832d0ef7fab46cabed29c2aae926db0b11bb2069edd8db5e64e16" +dependencies = [ + "block-buffer", + "cfg-if 1.0.0", + "cpufeatures", + "digest", + "opaque-debug", +] + +[[package]] +name = "sha1" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" + +[[package]] +name = "signal-hook-registry" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" + +[[package]] +name = "smallvec" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" + +[[package]] +name = "smawk" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" + +[[package]] +name = "socket2" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "standback" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" +dependencies = [ + "version_check", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "stdweb" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" +dependencies = [ + "discard", + "rustc_version", + "stdweb-derive", + "stdweb-internal-macros", + "stdweb-internal-runtime", + "wasm-bindgen", +] + +[[package]] +name = "stdweb-derive" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_derive", + "syn", +] + +[[package]] +name = "stdweb-internal-macros" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" +dependencies = [ + "base-x", + "proc-macro2", + "quote", + "serde", + "serde_derive", + "serde_json", + "sha1", + "syn", +] + +[[package]] +name = "stdweb-internal-runtime" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "syn" +version = "1.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "taskchampion" +version = "0.3.0" +dependencies = [ + "anyhow", + "chrono", + "log", + "proptest", + "rusqlite", + "serde", + "serde_json", + "tempfile", + "thiserror", + "tindercrypt", + "ureq", + "uuid", +] + +[[package]] +name = "taskchampion-cli" +version = "0.3.0" +dependencies = [ + "anyhow", + "assert_cmd", + "atty", + "dirs-next", + "env_logger", + "log", + "nom", + "predicates", + "prettytable-rs", + "taskchampion", + "tempfile", + "termcolor", + "textwrap 0.13.4", + "toml", + "toml_edit", +] + +[[package]] +name = "taskchampion-sync-server" +version = "0.3.0" +dependencies = [ + "actix-rt 2.2.0", + "actix-web", + "anyhow", + "clap", + "env_logger", + "futures", + "log", + "rusqlite", + "serde", + "serde_json", + "tempfile", + "thiserror", + "uuid", +] + +[[package]] +name = "tempfile" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "rand 0.8.3", + "redox_syscall 0.2.8", + "remove_dir_all", + "winapi 0.3.9", +] + +[[package]] +name = "term" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42" +dependencies = [ + "byteorder", + "dirs", + "winapi 0.3.9", +] + +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "terminal_size" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" +dependencies = [ + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "textwrap" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd05616119e612a8041ef58f2b578906cc2531a6069047ae092cfb86a325d835" +dependencies = [ + "smawk", + "terminal_size", + "unicode-width", +] + +[[package]] +name = "thiserror" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[package]] +name = "time" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +dependencies = [ + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "time" +version = "0.2.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08a8cbfbf47955132d0202d1662f49b2423ae35862aee471f3ba4b133358f372" +dependencies = [ + "const_fn", + "libc", + "standback", + "stdweb", + "time-macros", + "version_check", + "winapi 0.3.9", +] + +[[package]] +name = "time-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" +dependencies = [ + "proc-macro-hack", + "time-macros-impl", +] + +[[package]] +name = "time-macros-impl" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "standback", + "syn", +] + +[[package]] +name = "tindercrypt" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f34fd5cc8db265f27abf29e8a3cec5cc643ae9f3f9ae39f08a77dc4add375b6d" +dependencies = [ + "protobuf", + "rand 0.7.3", + "ring", + "thiserror", +] + +[[package]] +name = "tinyvec" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tokio" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" +dependencies = [ + "bytes 0.5.6", + "futures-core", + "iovec", + "lazy_static", + "libc", + "memchr", + "mio 0.6.23", + "mio-uds", + "pin-project-lite 0.1.12", + "signal-hook-registry", + "slab", + "winapi 0.3.9", +] + +[[package]] +name = "tokio" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd3076b5c8cc18138b8f8814895c11eb4de37114a5d127bafdc5e55798ceef37" +dependencies = [ + "autocfg", + "libc", + "mio 0.7.11", + "once_cell", + "parking_lot", + "pin-project-lite 0.2.6", + "signal-hook-registry", + "winapi 0.3.9", +] + +[[package]] +name = "tokio-util" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" +dependencies = [ + "bytes 0.5.6", + "futures-core", + "futures-sink", + "log", + "pin-project-lite 0.1.12", + "tokio 0.2.25", +] + +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09391a441b373597cf0888d2b052dcf82c5be4fee05da3636ae30fb57aad8484" +dependencies = [ + "chrono", + "combine", + "linked-hash-map", +] + +[[package]] +name = "tracing" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" +dependencies = [ + "cfg-if 1.0.0", + "log", + "pin-project-lite 0.2.6", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project 1.0.7", + "tracing", +] + +[[package]] +name = "treeline" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" + +[[package]] +name = "trust-dns-proto" +version = "0.19.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cad71a0c0d68ab9941d2fb6e82f8fb2e86d9945b94e1661dd0aaea2b88215a9" +dependencies = [ + "async-trait", + "cfg-if 1.0.0", + "enum-as-inner", + "futures", + "idna", + "lazy_static", + "log", + "rand 0.7.3", + "smallvec", + "thiserror", + "tokio 0.2.25", + "url", +] + +[[package]] +name = "trust-dns-resolver" +version = "0.19.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "710f593b371175db53a26d0b38ed2978fafb9e9e8d3868b1acd753ea18df0ceb" +dependencies = [ + "cfg-if 0.1.10", + "futures", + "ipconfig", + "lazy_static", + "log", + "lru-cache", + "resolv-conf", + "smallvec", + "thiserror", + "tokio 0.2.25", + "trust-dns-proto", +] + +[[package]] +name = "typenum" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" + +[[package]] +name = "unicode-bidi" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" +dependencies = [ + "matches", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" + +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "unreachable" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" +dependencies = [ + "void", +] + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "ureq" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2475a6781e9bc546e7b64f4013d2f4032c8c6a40fcffd7c6f4ee734a890972ab" +dependencies = [ + "base64", + "chunked_transfer", + "log", + "once_cell", + "rustls", + "url", + "webpki", + "webpki-roots", +] + +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom 0.2.3", + "serde", +] + +[[package]] +name = "vcpkg" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "025ce40a007e1907e58d5bc1a594def78e5573bb0b1160bc389634e8f12e4faa" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "wasm-bindgen" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" + +[[package]] +name = "web-sys" +version = "0.3.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki" +version = "0.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" +dependencies = [ + "webpki", +] + +[[package]] +name = "widestring" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" + +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winreg" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "ws2_32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + +[[package]] +name = "wyz" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" From 0f6323e2dee4a545f7aefcec17f420fa930db4f1 Mon Sep 17 00:00:00 2001 From: dbr Date: Fri, 28 May 2021 20:35:57 +1000 Subject: [PATCH 26/38] Unused --- sync-server/src/storage/sqlite.rs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/sync-server/src/storage/sqlite.rs b/sync-server/src/storage/sqlite.rs index bce885af1..a4b91134b 100644 --- a/sync-server/src/storage/sqlite.rs +++ b/sync-server/src/storage/sqlite.rs @@ -48,23 +48,6 @@ impl ToSql for Client { } } -/// DB Key for versions: concatenation of client_key and parent_version_id -type VersionDbKey = [u8; 32]; - -fn version_db_key(client_key: Uuid, parent_version_id: Uuid) -> VersionDbKey { - let mut key = [0u8; 32]; - key[..16].clone_from_slice(client_key.as_bytes()); - key[16..].clone_from_slice(parent_version_id.as_bytes()); - key -} - -/// Key for clients: just the client_key -type ClientDbKey = [u8; 16]; - -fn client_db_key(client_key: Uuid) -> ClientDbKey { - *client_key.as_bytes() -} - /// An on-disk storage backend which uses SQLite pub(crate) struct SqliteStorage { db_file: std::path::PathBuf, From 7c665c9a771048964fd73b5d67455ca32bf98f7e Mon Sep 17 00:00:00 2001 From: dbr Date: Fri, 28 May 2021 20:41:03 +1000 Subject: [PATCH 27/38] Clippy things --- sync-server/src/storage/sqlite.rs | 7 ++++++- taskchampion/src/server/local.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sync-server/src/storage/sqlite.rs b/sync-server/src/storage/sqlite.rs index a4b91134b..bfdf2a8b2 100644 --- a/sync-server/src/storage/sqlite.rs +++ b/sync-server/src/storage/sqlite.rs @@ -8,6 +8,8 @@ use std::path::Path; enum SqliteError { #[error("SQLite transaction already committted")] TransactionAlreadyCommitted, + #[error("Failed to create SQLite transaction")] + CreateTransactionFailed, } /// Newtype to allow implementing `FromSql` for foreign `uuid::Uuid` @@ -96,7 +98,10 @@ struct Txn<'t> { impl<'t> Txn<'t> { fn get_txn(&mut self) -> Result { - Ok(self.con.transaction().unwrap()) + Ok(self + .con + .transaction() + .map_err(|_e| SqliteError::CreateTransactionFailed)?) } } diff --git a/taskchampion/src/server/local.rs b/taskchampion/src/server/local.rs index 47f8e5cc3..8b5dfa9a7 100644 --- a/taskchampion/src/server/local.rs +++ b/taskchampion/src/server/local.rs @@ -50,7 +50,7 @@ pub struct LocalServer { } impl LocalServer { - fn txn<'a>(&'a mut self) -> anyhow::Result { + fn txn(&mut self) -> anyhow::Result { let txn = self.con.transaction()?; Ok(txn) } From e72b990ea293e16cbcf381dea7cc6af0eecdfc90 Mon Sep 17 00:00:00 2001 From: dbr Date: Tue, 15 Jun 2021 20:01:47 +1000 Subject: [PATCH 28/38] Avoid error if DB folder does not exist --- taskchampion/src/storage/sqlite.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index 91eaf1f8a..e517b4b00 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -77,9 +77,14 @@ pub struct SqliteStorage { impl SqliteStorage { pub fn new>(directory: P) -> anyhow::Result { + // Ensure parent folder exists + std::fs::create_dir_all(&directory)?; + + // Open (or create) database let db_file = directory.as_ref().join("taskchampion.sqlite3"); let con = Connection::open(db_file)?; + // Initialize database let queries = vec![ "CREATE TABLE IF NOT EXISTS operations (id INTEGER PRIMARY KEY AUTOINCREMENT, data STRING);", "CREATE TABLE IF NOT EXISTS sync_meta (key STRING PRIMARY KEY, value STRING);", From c3bc93f6315ea960dc9921fbae733e3a7ba7e081 Mon Sep 17 00:00:00 2001 From: dbr Date: Tue, 15 Jun 2021 22:02:32 +1000 Subject: [PATCH 29/38] Clipplease --- cli/src/argparse/command.rs | 1 - sync-server/src/storage/sqlite.rs | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cli/src/argparse/command.rs b/cli/src/argparse/command.rs index 1748b86d0..ad7cbd61a 100644 --- a/cli/src/argparse/command.rs +++ b/cli/src/argparse/command.rs @@ -72,7 +72,6 @@ mod test { ); } - #[test] fn test_cleaning_command_name() { assert_eq!( diff --git a/sync-server/src/storage/sqlite.rs b/sync-server/src/storage/sqlite.rs index bfdf2a8b2..528c2fac6 100644 --- a/sync-server/src/storage/sqlite.rs +++ b/sync-server/src/storage/sqlite.rs @@ -98,10 +98,9 @@ struct Txn<'t> { impl<'t> Txn<'t> { fn get_txn(&mut self) -> Result { - Ok(self - .con + self.con .transaction() - .map_err(|_e| SqliteError::CreateTransactionFailed)?) + .map_err(|_e| SqliteError::CreateTransactionFailed) } } From 75f0447c7b72599502f35cc973c69d9c3d376ad6 Mon Sep 17 00:00:00 2001 From: dbr Date: Tue, 15 Jun 2021 22:09:54 +1000 Subject: [PATCH 30/38] Fix empty-dir problem with server also, and add tests --- sync-server/src/storage/sqlite.rs | 12 ++++++++++++ taskchampion/src/storage/sqlite.rs | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/sync-server/src/storage/sqlite.rs b/sync-server/src/storage/sqlite.rs index 528c2fac6..cb080e2f8 100644 --- a/sync-server/src/storage/sqlite.rs +++ b/sync-server/src/storage/sqlite.rs @@ -61,6 +61,7 @@ impl SqliteStorage { } pub fn new>(directory: P) -> anyhow::Result { + std::fs::create_dir_all(&directory)?; let db_file = directory.as_ref().join("taskchampion-sync-server.sqlite3"); let o = SqliteStorage { db_file }; @@ -208,6 +209,17 @@ mod test { use super::*; use tempfile::TempDir; + #[test] + fn test_emtpy_dir() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let non_existant = tmp_dir.path().join("subdir"); + let storage = SqliteStorage::new(&non_existant)?; + let mut txn = storage.txn()?; + let maybe_client = txn.get_client(Uuid::new_v4())?; + assert!(maybe_client.is_none()); + Ok(()) + } + #[test] fn test_get_client_empty() -> anyhow::Result<()> { let tmp_dir = TempDir::new()?; diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index e517b4b00..b6ff83027 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -351,6 +351,25 @@ mod test { use crate::storage::taskmap_with; use tempfile::TempDir; + #[test] + fn test_empty_dir() -> anyhow::Result<()> { + let tmp_dir = TempDir::new()?; + let non_existant = tmp_dir.path().join("subdir"); + let mut storage = SqliteStorage::new(&non_existant)?; + let uuid = Uuid::new_v4(); + { + let mut txn = storage.txn()?; + assert!(txn.create_task(uuid)?); + txn.commit()?; + } + { + let mut txn = storage.txn()?; + let task = txn.get_task(uuid)?; + assert_eq!(task, Some(taskmap_with(vec![]))); + } + Ok(()) + } + #[test] fn drop_transaction() -> anyhow::Result<()> { let tmp_dir = TempDir::new()?; From 86deed3197f5fdf8c83f4698cb5861ca0843b817 Mon Sep 17 00:00:00 2001 From: dbr Date: Wed, 16 Jun 2021 11:22:17 +1000 Subject: [PATCH 31/38] Remove unused Transaction from Txn Also note about why StorageTxn isn't implemented --- sync-server/src/storage/sqlite.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/sync-server/src/storage/sqlite.rs b/sync-server/src/storage/sqlite.rs index cb080e2f8..be075f62b 100644 --- a/sync-server/src/storage/sqlite.rs +++ b/sync-server/src/storage/sqlite.rs @@ -87,17 +87,16 @@ impl SqliteStorage { impl Storage for SqliteStorage { fn txn<'a>(&'a self) -> anyhow::Result> { let con = self.new_connection()?; - let t = Txn { con, txn: None }; + let t = Txn { con }; Ok(Box::new(t)) } } -struct Txn<'t> { +struct Txn { con: Connection, - txn: Option>, } -impl<'t> Txn<'t> { +impl Txn { fn get_txn(&mut self) -> Result { self.con .transaction() @@ -105,7 +104,7 @@ impl<'t> Txn<'t> { } } -impl<'t> StorageTxn for Txn<'t> { +impl StorageTxn for Txn { fn get_client(&mut self, client_key: Uuid) -> anyhow::Result> { let t = self.get_txn()?; let result: Option = t @@ -195,11 +194,10 @@ impl<'t> StorageTxn for Txn<'t> { } fn commit(&mut self) -> anyhow::Result<()> { - let t: rusqlite::Transaction = self - .txn - .take() - .ok_or(SqliteError::TransactionAlreadyCommitted)?; - t.commit().context("Committing transaction")?; + // FIXME: Note the queries aren't currently run in a + // transaction, as storing the transaction object and a pooled + // connection in the `Txn` object is complex. + // https://github.com/taskchampion/taskchampion/pull/206#issuecomment-860336073 Ok(()) } } From 477bf9e3283129549e5677956dff2b884e722389 Mon Sep 17 00:00:00 2001 From: dbr/Ben Date: Sat, 4 Sep 2021 12:05:30 +0930 Subject: [PATCH 32/38] Tweaks from code review Co-authored-by: Dustin J. Mitchell --- sync-server/src/storage/sqlite.rs | 4 ++-- taskchampion/src/storage/sqlite.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sync-server/src/storage/sqlite.rs b/sync-server/src/storage/sqlite.rs index be075f62b..0fec8d9d1 100644 --- a/sync-server/src/storage/sqlite.rs +++ b/sync-server/src/storage/sqlite.rs @@ -41,7 +41,7 @@ impl FromSql for Client { } } -/// Parsers Operation stored as JSON in string column +/// Parses Operation stored as JSON in string column impl ToSql for Client { fn to_sql(&self) -> rusqlite::Result> { let s = serde_json::to_string(&self) @@ -72,7 +72,7 @@ impl SqliteStorage { let queries = vec![ "CREATE TABLE IF NOT EXISTS clients (client_key STRING PRIMARY KEY, latest_version_id STRING);", - "CREATE TABLE IF NOT EXISTS versions (version_id STRING PRIMARY KEY, client_key STRING, parent_version_id STRING, history_segment STRING);", + "CREATE TABLE IF NOT EXISTS versions (version_id STRING PRIMARY KEY, client_key STRING, parent_version_id STRING, history_segment BLOB);", ]; for q in queries { txn.execute(q, []).context("Creating table")?; diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index b6ff83027..fed95d455 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -288,7 +288,7 @@ impl<'t> StorageTxn for Txn<'t> { let rows: Vec> = rows.collect(); let mut res = Vec::with_capacity(rows.len()); - for _ in 0..self.get_next_working_set_number().context("HUh")? { + for _ in 0..self.get_next_working_set_number().context("Getting working set number")? { res.push(None); } for r in rows { From 1d627994371559af815ce7646fcdfd3364f55613 Mon Sep 17 00:00:00 2001 From: dbr Date: Sat, 4 Sep 2021 12:53:29 +1000 Subject: [PATCH 33/38] Deduplicate StoredUuid wrapper --- taskchampion/src/server/local.rs | 30 +----------------------------- taskchampion/src/storage/mod.rs | 2 +- taskchampion/src/storage/sqlite.rs | 2 +- 3 files changed, 3 insertions(+), 31 deletions(-) diff --git a/taskchampion/src/server/local.rs b/taskchampion/src/server/local.rs index 8b5dfa9a7..12d50a5db 100644 --- a/taskchampion/src/server/local.rs +++ b/taskchampion/src/server/local.rs @@ -1,6 +1,7 @@ use crate::server::{ AddVersionResult, GetVersionResult, HistorySegment, Server, VersionId, NO_VERSION_ID, }; +use crate::storage::sqlite::StoredUuid; use anyhow::Context; use rusqlite::params; use rusqlite::types::{FromSql, ToSql}; @@ -9,35 +10,6 @@ use serde::{Deserialize, Serialize}; use std::path::Path; use uuid::Uuid; -// FIXME: Duplicated -/// Newtype to allow implementing `FromSql` for foreign `uuid::Uuid` -pub struct StoredUuid(Uuid); - -/// Conversion from Uuid stored as a string (rusqlite's uuid feature stores as binary blob) -impl FromSql for StoredUuid { - fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { - let u = Uuid::parse_str(value.as_str()?) - .map_err(|_| rusqlite::types::FromSqlError::InvalidType)?; - Ok(StoredUuid(u)) - } -} - -/// Store Uuid as string in database -impl ToSql for StoredUuid { - fn to_sql(&self) -> rusqlite::Result> { - let s = self.0.to_string(); - Ok(s.into()) - } -} - -impl FromSql for Version { - fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { - let u = serde_json::from_str(value.as_str()?) - .map_err(|_| rusqlite::types::FromSqlError::InvalidType)?; - Ok(u) - } -} - #[derive(Serialize, Deserialize, Debug)] struct Version { version_id: VersionId, diff --git a/taskchampion/src/storage/mod.rs b/taskchampion/src/storage/mod.rs index 7520950e0..18e64a9bb 100644 --- a/taskchampion/src/storage/mod.rs +++ b/taskchampion/src/storage/mod.rs @@ -12,7 +12,7 @@ use uuid::Uuid; mod config; mod inmemory; mod operation; -mod sqlite; +pub(crate) mod sqlite; pub use config::StorageConfig; pub use inmemory::InMemoryStorage; diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index fed95d455..63fb3bad5 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -12,7 +12,7 @@ enum SqliteError { } /// Newtype to allow implementing `FromSql` for foreign `uuid::Uuid` -struct StoredUuid(Uuid); +pub(crate) struct StoredUuid(pub(crate) Uuid); /// Conversion from Uuid stored as a string (rusqlite's uuid feature stores as binary blob) impl FromSql for StoredUuid { From 89e9a42374d096e3fcfdca6a32bb19746d04bb2a Mon Sep 17 00:00:00 2001 From: dbr Date: Sat, 4 Sep 2021 13:02:03 +1000 Subject: [PATCH 34/38] Refactor calculation of next working set ID As per Dustin's code-review comment --- taskchampion/src/storage/sqlite.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index 63fb3bad5..55f7f7793 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -112,14 +112,14 @@ impl<'t> Txn<'t> { fn get_next_working_set_number(&self) -> anyhow::Result { let t = self.get_txn()?; - let result: Option = t - .query_row("SELECT COALESCE(MAX(id), 0) FROM working_set", [], |r| { + let next_id: Option = t + .query_row("SELECT COALESCE(MAX(id), 0) + 1 FROM working_set", [], |r| { r.get(0) }) .optional() .context("Getting highest working set ID")?; - Ok(result.unwrap_or(0) + 1) + Ok(next_id.unwrap_or(0)) } } From 5db04ee1afc79472d70a61216b23a621591e56de Mon Sep 17 00:00:00 2001 From: dbr Date: Sat, 4 Sep 2021 13:05:10 +1000 Subject: [PATCH 35/38] Tidying --- taskchampion/src/server/local.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/taskchampion/src/server/local.rs b/taskchampion/src/server/local.rs index 12d50a5db..657d60881 100644 --- a/taskchampion/src/server/local.rs +++ b/taskchampion/src/server/local.rs @@ -4,7 +4,6 @@ use crate::server::{ use crate::storage::sqlite::StoredUuid; use anyhow::Context; use rusqlite::params; -use rusqlite::types::{FromSql, ToSql}; use rusqlite::OptionalExtension; use serde::{Deserialize, Serialize}; use std::path::Path; From f8ed4cecdd9d71233c210a7456c209f8a53674f0 Mon Sep 17 00:00:00 2001 From: dbr Date: Sat, 4 Sep 2021 13:05:21 +1000 Subject: [PATCH 36/38] Reset operation auto-increment ID --- taskchampion/src/storage/sqlite.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index 55f7f7793..0e56479fe 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -267,6 +267,8 @@ impl<'t> StorageTxn for Txn<'t> { let t = self.get_txn()?; t.execute("DELETE FROM operations", []) .context("Clear all existing operations")?; + t.execute("DELETE FROM sqlite_sequence WHERE name = 'operations'", []) + .context("Clear all existing operations")?; for o in ops { self.add_operation(o)?; From a4b67d9f4ef1bf10ed7d5811064db18bc73bae35 Mon Sep 17 00:00:00 2001 From: dbr Date: Sat, 4 Sep 2021 13:29:03 +1000 Subject: [PATCH 37/38] Remove unused error variant --- sync-server/src/storage/sqlite.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/sync-server/src/storage/sqlite.rs b/sync-server/src/storage/sqlite.rs index 0fec8d9d1..34cdd05b7 100644 --- a/sync-server/src/storage/sqlite.rs +++ b/sync-server/src/storage/sqlite.rs @@ -6,8 +6,6 @@ use std::path::Path; #[derive(Debug, thiserror::Error)] enum SqliteError { - #[error("SQLite transaction already committted")] - TransactionAlreadyCommitted, #[error("Failed to create SQLite transaction")] CreateTransactionFailed, } From 11a3b7882bc1c7b9cf84b260e4f36f130a420817 Mon Sep 17 00:00:00 2001 From: dbr Date: Fri, 10 Sep 2021 10:03:46 +1000 Subject: [PATCH 38/38] Changelog entry! --- .changelogs/2021-09-10-sqlstore.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .changelogs/2021-09-10-sqlstore.md diff --git a/.changelogs/2021-09-10-sqlstore.md b/.changelogs/2021-09-10-sqlstore.md new file mode 100644 index 000000000..b0151816c --- /dev/null +++ b/.changelogs/2021-09-10-sqlstore.md @@ -0,0 +1 @@ +- Breaking: Removed the KV based storage backend in client and server, and replaced with SQLite ([Issue #131](https://github.com/taskchampion/taskchampion/issues/131), [PR #206](https://github.com/taskchampion/taskchampion/pull/206))