-
Notifications
You must be signed in to change notification settings - Fork 37
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
[wip] object store metastore #2309
Draft
igalshilman
wants to merge
3
commits into
restatedev:main
Choose a base branch
from
igalshilman:s3metastore
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+863
−3
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
181 changes: 181 additions & 0 deletions
181
crates/core/src/metadata_store/providers/objstore/glue.rs
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,181 @@ | ||
// Copyright (c) 2024 - Restate Software, Inc., Restate GmbH. | ||
// All rights reserved. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the LICENSE file. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0. | ||
|
||
use std::pin; | ||
|
||
use bytestring::ByteString; | ||
use restate_types::Version; | ||
use tokio::select; | ||
use tokio::sync::oneshot::Sender; | ||
use tracing::warn; | ||
|
||
use crate::cancellation_watcher; | ||
use crate::metadata_store::providers::objstore::optimistic_store::OptimisticLockingMetadataStoreBuilder; | ||
use crate::metadata_store::{MetadataStore, Precondition, ReadError, VersionedValue, WriteError}; | ||
|
||
#[derive(Debug)] | ||
pub(crate) enum Commands { | ||
Get { | ||
key: ByteString, | ||
tx: Sender<Result<Option<VersionedValue>, ReadError>>, | ||
}, | ||
GetVersion { | ||
key: ByteString, | ||
tx: Sender<Result<Option<Version>, ReadError>>, | ||
}, | ||
Put { | ||
key: ByteString, | ||
value: VersionedValue, | ||
precondition: Precondition, | ||
tx: Sender<Result<(), WriteError>>, | ||
}, | ||
Delete { | ||
key: ByteString, | ||
precondition: Precondition, | ||
tx: Sender<Result<(), WriteError>>, | ||
}, | ||
} | ||
|
||
pub(crate) struct Server { | ||
receiver: tokio::sync::mpsc::UnboundedReceiver<Commands>, | ||
builder: OptimisticLockingMetadataStoreBuilder, | ||
} | ||
|
||
impl Server { | ||
pub(crate) fn new( | ||
builder: OptimisticLockingMetadataStoreBuilder, | ||
receiver: tokio::sync::mpsc::UnboundedReceiver<Commands>, | ||
) -> Self { | ||
Self { builder, receiver } | ||
} | ||
|
||
pub(crate) async fn run(self) -> anyhow::Result<()> { | ||
let Server { | ||
mut receiver, | ||
builder, | ||
} = self; | ||
|
||
let mut shutdown = pin::pin!(cancellation_watcher()); | ||
|
||
let mut delegate = match builder.build().await { | ||
Ok(delegate) => delegate, | ||
Err(err) => { | ||
warn!(error = ?err, "error while loading latest metastore version."); | ||
return Err(err); | ||
} | ||
}; | ||
|
||
loop { | ||
select! { | ||
_ = &mut shutdown => { | ||
// stop accepting messages | ||
return Ok(()); | ||
} | ||
Some(cmd) = receiver.recv() => { | ||
match cmd { | ||
Commands::Get{key,tx } => { | ||
let res = delegate.get(key).await; | ||
let _ = tx.send(res); | ||
} | ||
Commands::GetVersion{key,tx } => { | ||
let _ = tx.send(delegate.get_version(key).await); | ||
} | ||
Commands::Put{key,value,precondition,tx } => { | ||
let _ = tx.send(delegate.put(key, value, precondition).await); | ||
} | ||
Commands::Delete{key,precondition,tx } => { | ||
let _ = tx.send(delegate.delete(key, precondition).await); | ||
} | ||
} | ||
} | ||
else => { | ||
tracing::info!("input channel is closed, exiting the metadata polling loop."); | ||
break; | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Client { | ||
sender: tokio::sync::mpsc::UnboundedSender<Commands>, | ||
} | ||
|
||
impl Client { | ||
pub fn new(sender: tokio::sync::mpsc::UnboundedSender<Commands>) -> Self { | ||
Self { sender } | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl MetadataStore for Client { | ||
async fn get(&self, key: ByteString) -> Result<Option<VersionedValue>, ReadError> { | ||
let (tx, rx) = tokio::sync::oneshot::channel(); | ||
|
||
self.sender | ||
.send(Commands::Get { key, tx }) | ||
.map_err(|_| ReadError::Internal("Object store fetch channel ".into()))?; | ||
|
||
rx.await.map_err(|_| { | ||
ReadError::Internal("Object store fetch channel disconnected".to_string()) | ||
})? | ||
} | ||
|
||
async fn get_version(&self, key: ByteString) -> Result<Option<Version>, ReadError> { | ||
let (tx, rx) = tokio::sync::oneshot::channel(); | ||
|
||
self.sender | ||
.send(Commands::GetVersion { key, tx }) | ||
.map_err(|_| ReadError::Internal("Object store fetch channel ".into()))?; | ||
|
||
rx.await.map_err(|_| { | ||
ReadError::Internal("Object store fetch channel disconnected".to_string()) | ||
})? | ||
} | ||
|
||
async fn put( | ||
&self, | ||
key: ByteString, | ||
value: VersionedValue, | ||
precondition: Precondition, | ||
) -> Result<(), WriteError> { | ||
let (tx, rx) = tokio::sync::oneshot::channel(); | ||
|
||
self.sender | ||
.send(Commands::Put { | ||
key, | ||
value, | ||
precondition, | ||
tx, | ||
}) | ||
.map_err(|_| WriteError::Internal("Object store channel ".into()))?; | ||
|
||
rx.await | ||
.map_err(|_| WriteError::Internal("Object store channel disconnected".to_string()))? | ||
} | ||
|
||
async fn delete(&self, key: ByteString, precondition: Precondition) -> Result<(), WriteError> { | ||
let (tx, rx) = tokio::sync::oneshot::channel(); | ||
|
||
self.sender | ||
.send(Commands::Delete { | ||
key, | ||
precondition, | ||
tx, | ||
}) | ||
.map_err(|_| WriteError::Internal("Object store fetch channel ".into()))?; | ||
|
||
rx.await.map_err(|_| { | ||
WriteError::Internal("Object store fetch channel disconnected".to_string()) | ||
})? | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would a bounded sender also work?