-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Please make sure there is an issue that this PR is correlated to. --> ## Changes <!-- If there are frontend changes, please include screenshots. -->
- Loading branch information
1 parent
12f01f7
commit 293be3d
Showing
89 changed files
with
1,075 additions
and
655 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use anyhow::*; | ||
use foundationdb as fdb; | ||
use prost::Message; | ||
use serde::Serialize; | ||
|
||
use crate::{key::Key, metadata::Metadata}; | ||
|
||
#[derive(Default)] | ||
pub(crate) struct EntryBuilder { | ||
metadata: Option<Metadata>, | ||
value: Vec<u8>, | ||
next_idx: usize, | ||
} | ||
|
||
impl EntryBuilder { | ||
pub(crate) fn add_sub_key(&mut self, sub_key: SubKey) -> Result<()> { | ||
match sub_key { | ||
SubKey::Metadata(value) => { | ||
// We ignore setting the metadata again because it means the same key was given twice in the | ||
// input keys for `ActorKv::get`. We don't perform automatic deduplication. | ||
if self.metadata.is_none() { | ||
self.metadata = Some(Metadata::decode(value.value())?); | ||
} | ||
} | ||
SubKey::Chunk(idx, value) => { | ||
// We don't perform deduplication on the input keys for `ActorKv::get` so we might have | ||
// duplicate data chunks. This idx check ignores chunks that were already passed and ensures | ||
// contiguity. | ||
if idx == self.next_idx { | ||
self.value.extend(value.value()); | ||
self.next_idx = idx + 1; | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub(crate) fn build(self, key: &Key) -> Result<Entry> { | ||
ensure!(!self.value.is_empty(), "empty value at key {key:?}"); | ||
|
||
Ok(Entry { | ||
metadata: self | ||
.metadata | ||
.with_context(|| format!("no metadata for key {key:?}"))?, | ||
value: self.value, | ||
}) | ||
} | ||
} | ||
|
||
/// Represents a Rivet KV value. | ||
#[derive(Serialize)] | ||
pub struct Entry { | ||
pub metadata: Metadata, | ||
pub value: Vec<u8>, | ||
} | ||
|
||
/// Represents FDB keys within a Rivet KV key. | ||
pub(crate) enum SubKey { | ||
Metadata(fdb::future::FdbValue), | ||
Chunk(usize, fdb::future::FdbValue), | ||
} |
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
Oops, something went wrong.