-
Notifications
You must be signed in to change notification settings - Fork 44
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
Auto provision #2058
Merged
+174
−113
Merged
Auto provision #2058
Changes from all commits
Commits
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
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 |
---|---|---|
|
@@ -22,12 +22,8 @@ use tokio::time; | |
use tokio::time::{Instant, Interval, MissedTickBehavior}; | ||
use tracing::{debug, info, warn}; | ||
|
||
use super::cluster_state_refresher::{ClusterStateRefresher, ClusterStateWatcher}; | ||
use crate::cluster_controller::logs_controller::LogsController; | ||
use crate::cluster_controller::observed_cluster_state::ObservedClusterState; | ||
use crate::cluster_controller::scheduler::Scheduler; | ||
use restate_bifrost::{Bifrost, BifrostAdmin}; | ||
use restate_core::metadata_store::MetadataStoreClient; | ||
use restate_core::metadata_store::{retry_on_network_error, MetadataStoreClient}; | ||
use restate_core::network::rpc_router::RpcRouter; | ||
use restate_core::network::{ | ||
Incoming, MessageRouterBuilder, NetworkSender, Networking, TransportConnect, | ||
|
@@ -41,11 +37,18 @@ use restate_types::config::{AdminOptions, Configuration}; | |
use restate_types::identifiers::{PartitionId, SnapshotId}; | ||
use restate_types::live::Live; | ||
use restate_types::logs::{LogId, Lsn, SequenceNumber}; | ||
use restate_types::metadata_store::keys::PARTITION_TABLE_KEY; | ||
use restate_types::net::cluster_controller::{AttachRequest, AttachResponse}; | ||
use restate_types::net::metadata::MetadataKind; | ||
use restate_types::net::partition_processor_manager::CreateSnapshotRequest; | ||
use restate_types::partition_table::PartitionTable; | ||
use restate_types::{GenerationalNodeId, Version}; | ||
|
||
use super::cluster_state_refresher::{ClusterStateRefresher, ClusterStateWatcher}; | ||
use crate::cluster_controller::logs_controller::LogsController; | ||
use crate::cluster_controller::observed_cluster_state::ObservedClusterState; | ||
use crate::cluster_controller::scheduler::Scheduler; | ||
|
||
#[derive(Debug, thiserror::Error, CodedError)] | ||
pub enum Error { | ||
#[error("error")] | ||
|
@@ -221,11 +224,8 @@ impl<T: TransportConnect> Service<T> { | |
bifrost: Bifrost, | ||
all_partitions_started_tx: Option<oneshot::Sender<()>>, | ||
) -> anyhow::Result<()> { | ||
// Make sure we have partition table before starting | ||
let _ = self | ||
.metadata | ||
.wait_for_version(MetadataKind::PartitionTable, Version::MIN) | ||
.await?; | ||
self.init_partition_table().await?; | ||
|
||
let bifrost_admin = | ||
BifrostAdmin::new(&bifrost, &self.metadata_writer, &self.metadata_store_client); | ||
|
||
|
@@ -248,26 +248,36 @@ impl<T: TransportConnect> Service<T> { | |
)?; | ||
} | ||
|
||
self.task_center.spawn_child( | ||
TaskKind::SystemService, | ||
"cluster-controller-metadata-sync", | ||
None, | ||
sync_cluster_controller_metadata(self.metadata.clone()), | ||
)?; | ||
|
||
let configuration = self.configuration.live_load(); | ||
|
||
let mut scheduler = Scheduler::init( | ||
configuration, | ||
self.task_center.clone(), | ||
self.metadata_store_client.clone(), | ||
self.networking.clone(), | ||
) | ||
.await?; | ||
|
||
let mut logs_controller = LogsController::init( | ||
configuration, | ||
self.metadata.clone(), | ||
bifrost.clone(), | ||
self.metadata_store_client.clone(), | ||
self.metadata_writer.clone(), | ||
self.configuration.live_load().bifrost.default_provider, | ||
) | ||
.await?; | ||
|
||
let mut observed_cluster_state = ObservedClusterState::default(); | ||
|
||
let mut logs_watcher = self.metadata.watch(MetadataKind::Logs); | ||
let mut partition_watcher = self.metadata.watch(MetadataKind::PartitionTable); | ||
let mut partition_table_watcher = self.metadata.watch(MetadataKind::PartitionTable); | ||
let mut logs = self.metadata.updateable_logs_metadata(); | ||
let mut partition_table = self.metadata.updateable_partition_table(); | ||
|
||
|
@@ -297,8 +307,12 @@ impl<T: TransportConnect> Service<T> { | |
// tell the scheduler about potentially newly provisioned logs | ||
scheduler.on_logs_update(logs.live_load(), partition_table.live_load()).await? | ||
} | ||
Ok(_) = partition_watcher.changed() => { | ||
logs_controller.on_partition_table_update(partition_table.live_load()) | ||
Ok(_) = partition_table_watcher.changed() => { | ||
let partition_table = partition_table.live_load(); | ||
let logs = logs.live_load(); | ||
|
||
logs_controller.on_partition_table_update(partition_table); | ||
scheduler.on_logs_update(logs, partition_table).await?; | ||
} | ||
Some(cmd) = self.command_rx.recv() => { | ||
self.on_cluster_cmd(cmd, bifrost_admin).await; | ||
|
@@ -320,6 +334,36 @@ impl<T: TransportConnect> Service<T> { | |
} | ||
} | ||
|
||
async fn init_partition_table(&mut self) -> anyhow::Result<()> { | ||
let configuration = self.configuration.live_load(); | ||
|
||
let partition_table = retry_on_network_error( | ||
Comment on lines
+337
to
+340
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: Might be worth logging that we are initializing 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. Yes, will add it. |
||
configuration.common.network_error_retry_policy.clone(), | ||
|| { | ||
self.metadata_store_client | ||
.get_or_insert(PARTITION_TABLE_KEY.clone(), || { | ||
let partition_table = if configuration.common.auto_provision_partitions { | ||
PartitionTable::with_equally_sized_partitions( | ||
Version::MIN, | ||
configuration.common.bootstrap_num_partitions(), | ||
) | ||
} else { | ||
PartitionTable::with_equally_sized_partitions(Version::MIN, 0) | ||
}; | ||
|
||
debug!("Initializing the partition table with '{partition_table:?}'"); | ||
|
||
partition_table | ||
}) | ||
}, | ||
) | ||
.await?; | ||
|
||
self.metadata_writer.update(partition_table).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn trim_logs( | ||
&self, | ||
bifrost_admin: BifrostAdmin<'_>, | ||
|
@@ -488,6 +532,35 @@ impl<T: TransportConnect> Service<T> { | |
} | ||
} | ||
|
||
async fn sync_cluster_controller_metadata(metadata: Metadata) -> anyhow::Result<()> { | ||
// todo make this configurable | ||
let mut interval = time::interval(Duration::from_secs(10)); | ||
interval.set_missed_tick_behavior(MissedTickBehavior::Delay); | ||
|
||
let mut cancel = std::pin::pin!(cancellation_watcher()); | ||
|
||
loop { | ||
tokio::select! { | ||
_ = &mut cancel => { | ||
break; | ||
}, | ||
_ = interval.tick() => { | ||
tokio::select! { | ||
_ = &mut cancel => { | ||
break; | ||
}, | ||
_ = futures::future::join3( | ||
metadata.sync(MetadataKind::NodesConfiguration, TargetVersion::Latest), | ||
metadata.sync(MetadataKind::PartitionTable, TargetVersion::Latest), | ||
metadata.sync(MetadataKind::Logs, TargetVersion::Latest)) => {} | ||
} | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn signal_all_partitions_started( | ||
mut cluster_state_watcher: ClusterStateWatcher, | ||
metadata: Metadata, | ||
|
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.
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.
Not a blocker, but I'd have loved if we rely more on Live configuration for a more reactive experience.
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.
Once the
LogsController
depends on values in theConfiguration
apart from theinit
phase, then this sounds like a good idea.