From 7d5d6c43253c7a8f1905f5a202729a580fa8dea4 Mon Sep 17 00:00:00 2001 From: Przemyslaw Hugh Kaznowski Date: Thu, 26 Oct 2023 14:17:31 +0100 Subject: [PATCH] Revert breaking change on key clash and introduce new error (#2823) --- lib/src/err/mod.rs | 15 ++++++++++----- lib/src/kvs/fdb/mod.rs | 2 +- lib/src/kvs/rocksdb/mod.rs | 2 +- lib/src/kvs/speedb/mod.rs | 2 +- lib/src/kvs/tikv/mod.rs | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/src/err/mod.rs b/lib/src/err/mod.rs index cd2e25a7..bd99eff7 100644 --- a/lib/src/err/mod.rs +++ b/lib/src/err/mod.rs @@ -79,8 +79,9 @@ pub enum Error { TxConditionNotMet, /// The key being inserted in the transaction already exists - #[error("The key being inserted already exists: {0}")] - TxKeyAlreadyExists(KeyCategory), + #[error("The key being inserted already exists")] + #[deprecated(note = "Use TxKeyAlreadyExistsCategory")] + TxKeyAlreadyExists, /// The key exceeds a limit set by the KV store #[error("Record id or key is too large")] @@ -713,6 +714,10 @@ pub enum Error { /// Auth was expected to be set but was unknown #[error("Auth was expected to be set but was unknown")] UnknownAuth, + + /// The key being inserted in the transaction already exists + #[error("The key being inserted already exists: {0}")] + TxKeyAlreadyExistsCategory(KeyCategory), } impl From for String { @@ -738,7 +743,7 @@ impl From for Error { fn from(e: echodb::err::Error) -> Error { match e { echodb::err::Error::KeyAlreadyExists => { - Error::TxKeyAlreadyExists(crate::key::error::KeyCategory::Unknown) + Error::TxKeyAlreadyExistsCategory(crate::key::error::KeyCategory::Unknown) } echodb::err::Error::ValNotExpectedValue => Error::TxConditionNotMet, _ => Error::Tx(e.to_string()), @@ -751,7 +756,7 @@ impl From for Error { fn from(e: indxdb::err::Error) -> Error { match e { indxdb::err::Error::KeyAlreadyExists => { - Error::TxKeyAlreadyExists(crate::key::error::KeyCategory::Unknown) + Error::TxKeyAlreadyExistsCategory(crate::key::error::KeyCategory::Unknown) } indxdb::err::Error::ValNotExpectedValue => Error::TxConditionNotMet, _ => Error::Tx(e.to_string()), @@ -764,7 +769,7 @@ impl From for Error { fn from(e: tikv::Error) -> Error { match e { tikv::Error::DuplicateKeyInsertion => { - Error::TxKeyAlreadyExists(crate::key::error::KeyCategory::Unknown) + Error::TxKeyAlreadyExistsCategory(crate::key::error::KeyCategory::Unknown) } tikv::Error::KeyError(ke) if ke.abort.contains("KeyTooLarge") => Error::TxKeyTooLarge, tikv::Error::RegionError(re) if re.raft_entry_too_large.is_some() => Error::TxTooLarge, diff --git a/lib/src/kvs/fdb/mod.rs b/lib/src/kvs/fdb/mod.rs index de42beae..9febaf1f 100644 --- a/lib/src/kvs/fdb/mod.rs +++ b/lib/src/kvs/fdb/mod.rs @@ -320,7 +320,7 @@ impl Transaction { } let key: Vec = key.into(); if self.exi(key.clone().as_slice()).await? { - return Err(Error::TxKeyAlreadyExists(category)); + return Err(Error::TxKeyAlreadyExistsCategory(category)); } // Set the key let key: &[u8] = &key[..]; diff --git a/lib/src/kvs/rocksdb/mod.rs b/lib/src/kvs/rocksdb/mod.rs index 6c0b98b0..65fd0d87 100644 --- a/lib/src/kvs/rocksdb/mod.rs +++ b/lib/src/kvs/rocksdb/mod.rs @@ -293,7 +293,7 @@ impl Transaction { // Set the key if empty match inner.get_opt(&key, &self.ro)? { None => inner.put(key, val)?, - _ => return Err(Error::TxKeyAlreadyExists(category)), + _ => return Err(Error::TxKeyAlreadyExistsCategory(category)), }; // Return result Ok(()) diff --git a/lib/src/kvs/speedb/mod.rs b/lib/src/kvs/speedb/mod.rs index 7fd7f9b1..508e931f 100644 --- a/lib/src/kvs/speedb/mod.rs +++ b/lib/src/kvs/speedb/mod.rs @@ -293,7 +293,7 @@ impl Transaction { // Set the key if empty match inner.get_opt(&key, &self.ro)? { None => inner.put(key, val)?, - _ => return Err(Error::TxKeyAlreadyExists(category)), + _ => return Err(Error::TxKeyAlreadyExistsCategory(category)), }; // Return result Ok(()) diff --git a/lib/src/kvs/tikv/mod.rs b/lib/src/kvs/tikv/mod.rs index f9e2b0b6..7d4f1ce8 100644 --- a/lib/src/kvs/tikv/mod.rs +++ b/lib/src/kvs/tikv/mod.rs @@ -292,7 +292,7 @@ impl Transaction { // Set the key if empty match self.inner.key_exists(key.clone()).await? { false => self.inner.put(key, val).await?, - _ => return Err(Error::TxKeyAlreadyExists(category)), + _ => return Err(Error::TxKeyAlreadyExistsCategory(category)), }; // Return result Ok(())