Skip to content

Commit

Permalink
Rename PromiseMetadata -> Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper committed May 16, 2024
1 parent aa891f8 commit f310dea
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
14 changes: 7 additions & 7 deletions crates/partition-store/src/promise_table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use bytestring::ByteString;
use futures::Stream;
use futures_util::stream;
use restate_storage_api::promise_table::{
OwnedPromiseRow, PromiseMetadata, PromiseTable, ReadOnlyPromiseTable,
OwnedPromiseRow, Promise, PromiseTable, ReadOnlyPromiseTable,
};
use restate_storage_api::{Result, StorageError};
use restate_types::identifiers::{PartitionKey, ServiceId, WithPartitionKey};
Expand Down Expand Up @@ -49,7 +49,7 @@ fn get_promise_metadata<S: StorageAccess>(
storage: &mut S,
service_id: &ServiceId,
key: &ByteString,
) -> Result<Option<PromiseMetadata>> {
) -> Result<Option<Promise>> {
storage.get_value(create_key(service_id, key))
}

Expand All @@ -60,7 +60,7 @@ fn all_promise_metadata<S: StorageAccess>(
let iter = storage.iterator_from(TableScan::FullScanPartitionKeyRange::<PromiseKey>(range));
stream::iter(OwnedIterator::new(iter).map(|(mut k, mut v)| {
let key = PromiseKey::deserialize_from(&mut k)?;
let metadata = StorageCodec::decode::<PromiseMetadata, _>(&mut v)
let metadata = StorageCodec::decode::<Promise, _>(&mut v)
.map_err(|err| StorageError::Generic(err.into()))?;

let (partition_key, service_name, service_key, promise_key) = key.into_inner_ok_or()?;
Expand All @@ -82,7 +82,7 @@ fn put_promise_metadata<S: StorageAccess>(
storage: &mut S,
service_id: &ServiceId,
key: &ByteString,
metadata: PromiseMetadata,
metadata: Promise,
) {
storage.put_kv(create_key(service_id, key), metadata);
}
Expand All @@ -108,7 +108,7 @@ impl ReadOnlyPromiseTable for PartitionStore {
&mut self,
service_id: &ServiceId,
key: &ByteString,
) -> Result<Option<PromiseMetadata>> {
) -> Result<Option<Promise>> {
get_promise_metadata(self, service_id, key)
}

Expand All @@ -125,7 +125,7 @@ impl<'a> ReadOnlyPromiseTable for RocksDBTransaction<'a> {
&mut self,
service_id: &ServiceId,
key: &ByteString,
) -> Result<Option<PromiseMetadata>> {
) -> Result<Option<Promise>> {
get_promise_metadata(self, service_id, key)
}

Expand All @@ -142,7 +142,7 @@ impl<'a> PromiseTable for RocksDBTransaction<'a> {
&mut self,
service_id: &ServiceId,
key: &ByteString,
metadata: PromiseMetadata,
metadata: Promise,
) {
put_promise_metadata(self, service_id, key, metadata)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/partition-store/tests/promise_table_test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::storage_test_environment;
use bytes::Bytes;
use bytestring::ByteString;
use restate_storage_api::promise_table::{
PromiseMetadata, PromiseState, PromiseTable, ReadOnlyPromiseTable,
Promise, PromiseState, PromiseTable, ReadOnlyPromiseTable,
};
use restate_storage_api::Transaction;
use restate_types::identifiers::{InvocationId, InvocationUuid, JournalEntryId, ServiceId};
Expand All @@ -29,15 +29,15 @@ const PROMISE_KEY_1: ByteString = ByteString::from_static("prom1");
const PROMISE_KEY_2: ByteString = ByteString::from_static("prom2");
const PROMISE_KEY_3: ByteString = ByteString::from_static("prom3");

const PROMISE_METADATA_COMPLETED: PromiseMetadata = PromiseMetadata {
const PROMISE_METADATA_COMPLETED: Promise = Promise {
state: PromiseState::Completed(EntryResult::Success(Bytes::from_static(b"{}"))),
};

#[tokio::test]
async fn test_promise_table() {
let mut rocksdb = storage_test_environment().await;

let promise_metadata_not_completed = PromiseMetadata {
let promise_metadata_not_completed = Promise {
state: PromiseState::NotCompleted(vec![
JournalEntryId::from_parts(
InvocationId::from_parts(
Expand Down
10 changes: 5 additions & 5 deletions crates/storage-api/src/promise_table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ impl Default for PromiseState {
}

#[derive(Debug, Clone, PartialEq, Default)]
pub struct PromiseMetadata {
pub struct Promise {
pub state: PromiseState,
}

protobuf_storage_encode_decode!(PromiseMetadata);
protobuf_storage_encode_decode!(Promise);

Check failure on line 37 in crates/storage-api/src/promise_table/mod.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-22.04)

cannot find type `Promise` in module `$crate::storage::v1`

#[derive(Debug, Clone, PartialEq)]
pub struct OwnedPromiseRow {
pub service_id: ServiceId,
pub key: ByteString,
pub metadata: PromiseMetadata,
pub metadata: Promise,
}

pub trait ReadOnlyPromiseTable {
fn get_promise(
&mut self,
service_id: &ServiceId,
key: &ByteString,
) -> impl Future<Output = Result<Option<PromiseMetadata>>> + Send;
) -> impl Future<Output = Result<Option<Promise>>> + Send;

fn all_promises(
&mut self,
Expand All @@ -61,7 +61,7 @@ pub trait PromiseTable: ReadOnlyPromiseTable {
&mut self,
service_id: &ServiceId,
key: &ByteString,
metadata: PromiseMetadata,
metadata: Promise,
) -> impl Future<Output = ()> + Send;

fn delete_all_promises(&mut self, service_id: &ServiceId) -> impl Future<Output = ()> + Send;
Expand Down
8 changes: 4 additions & 4 deletions crates/storage-api/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2159,8 +2159,8 @@ pub mod v1 {
}
}

impl From<crate::promise_table::PromiseMetadata> for PromiseMetadata {
fn from(value: crate::promise_table::PromiseMetadata) -> Self {
impl From<crate::promise_table::Promise> for PromiseMetadata {
fn from(value: crate::promise_table::Promise) -> Self {
match value.state {
crate::promise_table::PromiseState::Completed(e) => PromiseMetadata {
state: Some(promise_metadata::State::CompletedState(
Expand All @@ -2185,11 +2185,11 @@ pub mod v1 {
}
}

impl TryFrom<PromiseMetadata> for crate::promise_table::PromiseMetadata {
impl TryFrom<PromiseMetadata> for crate::promise_table::Promise {
type Error = ConversionError;

fn try_from(value: PromiseMetadata) -> Result<Self, Self::Error> {
Ok(crate::promise_table::PromiseMetadata {
Ok(crate::promise_table::Promise {
state: match value.state.ok_or(ConversionError::missing_field("state"))? {
promise_metadata::State::CompletedState(s) => {
crate::promise_table::PromiseState::Completed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use restate_storage_api::invocation_status_table::{
};
use restate_storage_api::journal_table::{JournalEntry, ReadOnlyJournalTable};
use restate_storage_api::outbox_table::OutboxMessage;
use restate_storage_api::promise_table::{PromiseMetadata, PromiseState, ReadOnlyPromiseTable};
use restate_storage_api::promise_table::{Promise, PromiseState, ReadOnlyPromiseTable};
use restate_storage_api::service_status_table::VirtualObjectStatus;
use restate_storage_api::timer_table::Timer;
use restate_storage_api::Result as StorageResult;
Expand Down Expand Up @@ -1376,7 +1376,7 @@ where
let promise_metadata = state.get_promise(&service_id, &key).await?;

match promise_metadata {
Some(PromiseMetadata {
Some(Promise {
state: PromiseState::Completed(result),
}) => {
// Result is already available
Expand All @@ -1392,22 +1392,22 @@ where
Completion::new(entry_index, completion_result),
);
}
Some(PromiseMetadata {
Some(Promise {
state: PromiseState::NotCompleted(mut v),
}) => {
v.push(JournalEntryId::from_parts(invocation_id, entry_index));
effects.put_promise(
service_id,
key,
PromiseMetadata {
Promise {
state: PromiseState::NotCompleted(v),
},
)
}
None => effects.put_promise(
service_id,
key,
PromiseMetadata {
Promise {
state: PromiseState::NotCompleted(vec![
JournalEntryId::from_parts(invocation_id, entry_index),
]),
Expand Down Expand Up @@ -1440,7 +1440,7 @@ where
let promise_metadata = state.get_promise(&service_id, &key).await?;

let completion_result = match promise_metadata {
Some(PromiseMetadata {
Some(Promise {
state: PromiseState::Completed(result),
}) => result.into(),
_ => CompletionResult::Empty,
Expand Down Expand Up @@ -1487,13 +1487,13 @@ where
effects.put_promise(
service_id,
key,
PromiseMetadata {
Promise {
state: PromiseState::Completed(completion),
},
);
CompletionResult::Empty
}
Some(PromiseMetadata {
Some(Promise {
state: PromiseState::NotCompleted(listeners),
}) => {
// Send response to listeners
Expand All @@ -1512,13 +1512,13 @@ where
effects.put_promise(
service_id,
key,
PromiseMetadata {
Promise {
state: PromiseState::Completed(completion),
},
);
CompletionResult::Empty
}
Some(PromiseMetadata {
Some(Promise {
state: PromiseState::Completed(_),
}) => {
// Conflict!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl ReadOnlyPromiseTable for StateReaderMock {
&mut self,
_service_id: &ServiceId,
_key: &ByteString,
) -> StorageResult<Option<PromiseMetadata>> {
) -> StorageResult<Option<Promise>> {
unimplemented!();
}

Expand Down
10 changes: 5 additions & 5 deletions crates/worker/src/partition/state_machine/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use restate_storage_api::invocation_status_table::{
};
use restate_storage_api::invocation_status_table::{InvocationStatus, JournalMetadata};
use restate_storage_api::outbox_table::OutboxMessage;
use restate_storage_api::promise_table::PromiseMetadata;
use restate_storage_api::promise_table::Promise;
use restate_storage_api::promise_table::PromiseState;
use restate_storage_api::timer_table::{Timer, TimerKey};
use restate_types::errors::InvocationErrorCode;
Expand Down Expand Up @@ -107,7 +107,7 @@ pub(crate) enum Effect {
PutPromise {
service_id: ServiceId,
key: ByteString,
metadata: PromiseMetadata,
metadata: Promise,
},
ClearAllPromises {
service_id: ServiceId,
Expand Down Expand Up @@ -438,7 +438,7 @@ impl Effect {
service_id,
key,
metadata:
PromiseMetadata {
Promise {
state: PromiseState::Completed(_),
},
} => {
Expand All @@ -448,7 +448,7 @@ impl Effect {
service_id,
key,
metadata:
PromiseMetadata {
Promise {
state: PromiseState::NotCompleted(_),
},
} => {
Expand Down Expand Up @@ -1032,7 +1032,7 @@ impl Effects {
&mut self,
service_id: ServiceId,
key: ByteString,
promise_metadata: PromiseMetadata,
promise_metadata: Promise,
) {
self.effects.push(Effect::PutPromise {
service_id,
Expand Down
6 changes: 3 additions & 3 deletions crates/worker/src/partition/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use restate_storage_api::invocation_status_table::{
};
use restate_storage_api::journal_table::{JournalEntry, ReadOnlyJournalTable};
use restate_storage_api::outbox_table::{OutboxMessage, OutboxTable};
use restate_storage_api::promise_table::{OwnedPromiseRow, PromiseMetadata};
use restate_storage_api::promise_table::{OwnedPromiseRow, Promise};
use restate_storage_api::service_status_table::{
ReadOnlyVirtualObjectStatusTable, VirtualObjectStatus,
};
Expand Down Expand Up @@ -636,7 +636,7 @@ where
&mut self,
service_id: &ServiceId,
key: &ByteString,
) -> impl Future<Output = StorageResult<Option<PromiseMetadata>>> + Send {
) -> impl Future<Output = StorageResult<Option<Promise>>> + Send {
self.inner.get_promise(service_id, key)
}

Expand All @@ -658,7 +658,7 @@ where
&mut self,
service_id: &ServiceId,
key: &ByteString,
metadata: PromiseMetadata,
metadata: Promise,
) -> impl Future<Output = ()> + Send {
self.inner.put_promise(service_id, key, metadata)
}
Expand Down

0 comments on commit f310dea

Please sign in to comment.