-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1/3 Implement improved API implementation for database #227
Changes from all commits
b5fcb1e
a219894
50b0507
b11233c
1e398dd
57d2f37
6a30d8c
b3946be
5da1623
15ee034
bf5c697
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,9 @@ use crate::{ | |
CachedSpace, MemStoreR, SpaceWrite, StoreConfig, StoreDelta, StoreRevMut, StoreRevShared, | ||
ZeroStore, PAGE_SIZE_NBIT, | ||
}, | ||
v2::api::Proof, | ||
v2::api::{self, Proof}, | ||
}; | ||
use async_trait::async_trait; | ||
use bytemuck::{cast_slice, AnyBitPattern}; | ||
use metered::{metered, HitCount}; | ||
use parking_lot::{Mutex, RwLock}; | ||
|
@@ -28,7 +29,7 @@ use std::{ | |
collections::VecDeque, | ||
error::Error, | ||
fmt, | ||
io::{Cursor, Write}, | ||
io::{Cursor, ErrorKind, Write}, | ||
mem::size_of, | ||
num::NonZeroUsize, | ||
os::fd::{AsFd, BorrowedFd}, | ||
|
@@ -272,6 +273,43 @@ pub struct DbRev<S> { | |
merkle: Merkle<S>, | ||
} | ||
|
||
#[async_trait] | ||
impl<S: ShaleStore<Node> + Send + Sync> api::DbView for DbRev<S> { | ||
async fn root_hash(&self) -> Result<api::HashKey, api::Error> { | ||
self.merkle | ||
.root_hash(self.header.kv_root) | ||
.map(|h| *h) | ||
.map_err(|e| api::Error::IO(std::io::Error::new(ErrorKind::Other, e))) | ||
} | ||
|
||
async fn val<K: api::KeyType>(&self, key: K) -> Result<Option<Vec<u8>>, api::Error> { | ||
let obj_ref = self.merkle.get(key, self.header.kv_root); | ||
match obj_ref { | ||
Err(e) => Err(api::Error::IO(std::io::Error::new(ErrorKind::Other, e))), | ||
Ok(obj) => match obj { | ||
None => Ok(None), | ||
Some(inner) => Ok(Some(inner.as_ref().to_owned())), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Naming is hard.., we discussed to no longer use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to stop using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. This is one of those sweep tasks we can assign as a good first issue. Anyone want to create one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's trivial to unravel all the |
||
}, | ||
} | ||
} | ||
|
||
async fn single_key_proof<K: api::KeyType, N: AsRef<[u8]> + Send>( | ||
&self, | ||
_key: K, | ||
) -> Result<Option<Proof<N>>, api::Error> { | ||
todo!() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If these are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's why this is 1/3 :) |
||
|
||
async fn range_proof<K: api::KeyType, V, N>( | ||
&self, | ||
_first_key: Option<K>, | ||
_last_key: Option<K>, | ||
_limit: usize, | ||
) -> Result<Option<api::RangeProof<K, V, N>>, api::Error> { | ||
todo!() | ||
} | ||
} | ||
|
||
impl<S: ShaleStore<Node> + Send + Sync> DbRev<S> { | ||
fn flush_dirty(&mut self) -> Option<()> { | ||
self.header.flush_dirty(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's infuriating that you had to change this.
When we complete the following, we will be able to put it back:
#290
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed 😢