-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from pubky/feat/non-blocking-writes
Feat/non blocking writes
- Loading branch information
Showing
9 changed files
with
467 additions
and
214 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,24 @@ | ||
use heed::{types::Bytes, Database}; | ||
use pkarr::PublicKey; | ||
use heed::{types::Bytes, Database, RoTxn}; | ||
|
||
use crate::database::DB; | ||
|
||
use super::entries::Entry; | ||
|
||
/// hash of the blob => bytes. | ||
/// (entry timestamp | chunk_index BE) => bytes | ||
pub type BlobsTable = Database<Bytes, Bytes>; | ||
|
||
pub const BLOBS_TABLE: &str = "blobs"; | ||
|
||
impl DB { | ||
pub fn get_blob( | ||
pub fn read_entry_content<'txn>( | ||
&self, | ||
public_key: &PublicKey, | ||
path: &str, | ||
) -> anyhow::Result<Option<bytes::Bytes>> { | ||
let rtxn = self.env.read_txn()?; | ||
|
||
let key = format!("{public_key}/{path}"); | ||
|
||
let result = if let Some(bytes) = self.tables.entries.get(&rtxn, &key)? { | ||
let entry = Entry::deserialize(bytes)?; | ||
|
||
self.tables | ||
.blobs | ||
.get(&rtxn, entry.content_hash())? | ||
.map(|blob| bytes::Bytes::from(blob[8..].to_vec())) | ||
} else { | ||
None | ||
}; | ||
|
||
rtxn.commit()?; | ||
|
||
Ok(result) | ||
rtxn: &'txn RoTxn, | ||
entry: &Entry, | ||
) -> anyhow::Result<impl Iterator<Item = Result<&'txn [u8], heed::Error>> + 'txn> { | ||
Ok(self | ||
.tables | ||
.blobs | ||
.prefix_iter(rtxn, &entry.timestamp().to_bytes())? | ||
.map(|i| i.map(|(_, bytes)| bytes))) | ||
} | ||
} |
Oops, something went wrong.