Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
duniter
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
timothe
duniter
Commits
5c5a99f9
Commit
5c5a99f9
authored
Sep 14, 2020
by
Éloïs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[feat] kv_typed: define trait TransactionalBackend
parent
eaae10e6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
114 additions
and
3 deletions
+114
-3
rust-libs/tools/kv_typed/src/backend.rs
rust-libs/tools/kv_typed/src/backend.rs
+16
-0
rust-libs/tools/kv_typed/src/backend/sled.rs
rust-libs/tools/kv_typed/src/backend/sled.rs
+3
-1
rust-libs/tools/kv_typed/src/backend/sled/transactional.rs
rust-libs/tools/kv_typed/src/backend/sled/transactional.rs
+83
-0
rust-libs/tools/kv_typed/src/error.rs
rust-libs/tools/kv_typed/src/error.rs
+8
-0
rust-libs/tools/kv_typed/src/lib.rs
rust-libs/tools/kv_typed/src/lib.rs
+4
-2
No files found.
rust-libs/tools/kv_typed/src/backend.rs
View file @
5c5a99f9
...
...
@@ -25,6 +25,22 @@ pub mod sled;
use
crate
::
*
;
pub
trait
TransactionalBackend
<
DbReader
:
From
<
Vec
<
Self
::
TxCol
>>
,
DbWriter
:
From
<
Vec
<
Self
::
TxCol
>>>
:
Backend
{
type
Err
:
Error
+
Send
+
Sync
+
'static
;
type
TxCol
:
BackendCol
;
fn
read
<
A
:
Debug
,
D
,
F
:
Fn
(
&
DbReader
)
->
TransactionResult
<
D
,
A
,
Self
::
Err
>>
(
&
self
,
f
:
F
,
)
->
TransactionResult
<
D
,
A
,
Self
::
Err
>
;
fn
write
<
A
:
Debug
,
F
:
Fn
(
&
DbWriter
)
->
TransactionResult
<
(),
A
,
Self
::
Err
>>
(
&
self
,
f
:
F
,
)
->
TransactionResult
<
(),
A
,
Self
::
Err
>
;
}
pub
trait
Backend
:
'static
+
Clone
+
Sized
{
const
NAME
:
&
'static
str
;
type
Col
:
BackendCol
;
...
...
rust-libs/tools/kv_typed/src/backend/sled.rs
View file @
5c5a99f9
...
...
@@ -15,10 +15,12 @@
//! Sled backend for KV Typed,
use
crate
::
*
;
mod
transactional
;
pub
use
sled
::
Config
;
use
crate
::
*
;
#[derive(Clone,
Debug)]
pub
struct
Sled
{
db
:
sled
::
Db
,
...
...
rust-libs/tools/kv_typed/src/backend/sled/transactional.rs
0 → 100644
View file @
5c5a99f9
// Copyright (C) 2020 Éloïs SANCHEZ.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Sled backend for KV Typed,
/*use crate::*;
use sled::transaction::{ConflictableTransactionError, Transactional, TransactionalTree};
enum AbortType<A> {
User(A),
Kv(KvError),
}
#[allow(missing_copy_implementations)]
pub struct SledTxCol(&'static TransactionalTree);
impl Debug for SledTxCol {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SledTxCol")
.field("0", &"TransactionalTree")
.finish()
}
}
impl<DbReader: From<Vec<SledTxCol>>, DbWriter> TransactionalBackend<DbReader, DbWriter> for Sled {
type Err = sled::Error;
type TxCol = SledTxCol;
fn read<A: Debug, D, F: Fn(&DbReader) -> TransactionResult<D, A, Self::Err>>(
&self,
f: F,
) -> TransactionResult<D, A, Self::Err> {
match self
.trees
.transaction::<_, D>(|tx_trees: &Vec<TransactionalTree>| {
let reader = DbReader::from(
tx_trees
.iter()
.map(|tx_tree| SledTxCol(unsafe { to_static_ref(tx_tree) }))
.collect(),
);
f(&reader).map_err(|e| match e {
TransactionError::Abort(a) => {
ConflictableTransactionError::Abort(AbortType::User(a))
}
TransactionError::BackendErr(e) => ConflictableTransactionError::Storage(e),
TransactionError::KvError(e) => {
ConflictableTransactionError::Abort(AbortType::Kv(e))
}
})
}) {
Ok(t) => Ok(t),
Err(e) => match e {
sled::transaction::TransactionError::Abort(a) => match a {
AbortType::User(a) => Err(TransactionError::Abort(a)),
AbortType::Kv(e) => Err(TransactionError::KvError(e)),
},
sled::transaction::TransactionError::Storage(e) => {
Err(TransactionError::BackendErr(e))
}
},
}
}
fn write<A: Debug, F: Fn(&DbWriter) -> TransactionResult<(), A, Self::Err>>(
&self,
_f: F,
) -> TransactionResult<(), A, Self::Err> {
todo!()
}
}*/
rust-libs/tools/kv_typed/src/error.rs
View file @
5c5a99f9
...
...
@@ -55,3 +55,11 @@ impl From<sled::Error> for KvError {
KvError
::
BackendError
(
Box
::
new
(
e
)
.into
())
}
}
pub
type
TransactionResult
<
D
,
A
,
BE
>
=
Result
<
D
,
TransactionError
<
A
,
BE
>>
;
#[derive(Debug)]
pub
enum
TransactionError
<
A
:
Debug
,
BE
:
Error
+
Send
+
Sync
+
'static
>
{
Abort
(
A
),
BackendErr
(
BE
),
KvError
(
KvError
),
}
rust-libs/tools/kv_typed/src/lib.rs
View file @
5c5a99f9
...
...
@@ -56,13 +56,15 @@ pub mod prelude {
pub
use
crate
::
backend
::
mock
::{
MockBackend
,
MockBackendCol
,
MockBackendIter
};
#[cfg(feature
=
"sled_backend"
)]
pub
use
crate
::
backend
::
sled
::{
Config
as
SledConf
,
Sled
};
pub
use
crate
::
backend
::{
Backend
,
BackendCol
};
pub
use
crate
::
backend
::{
Backend
,
BackendCol
,
TransactionalBackend
};
pub
use
crate
::
batch
::
Batch
;
#[cfg(feature
=
"mock"
)]
pub
use
crate
::
collection_ro
::
MockColRo
;
pub
use
crate
::
collection_ro
::{
ColRo
,
DbCollectionRo
};
pub
use
crate
::
collection_rw
::{
ColRw
,
DbCollectionRw
};
pub
use
crate
::
error
::{
DynErr
,
KvError
,
KvResult
,
StringErr
};
pub
use
crate
::
error
::{
DynErr
,
KvError
,
KvResult
,
StringErr
,
TransactionError
,
TransactionResult
,
};
pub
use
crate
::
event
::{
EventTrait
,
Events
};
#[cfg(feature
=
"explorer"
)]
pub
use
crate
::
explorer
::{
ExplorableKey
,
ExplorableValue
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment