MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / target_replica

Method target_replica

src/compute-client/src/controller/instance.rs:1182–1209  ·  view source on GitHub ↗

Determine the target replica for a compute command. Retrieves the collection named by the command, and returns the target replica if it is set, and None if not set, or the command doesn't name a collection. Panics if a create-dataflow command names collections that have different target replicas. It is an error to construct such an object and would indicate a bug in [`Self::create_dataflow`].

(&self, cmd: &ComputeCommand)

Source from the content-addressed store, hash-verified

1180 /// target replicas. It is an error to construct such an object and would
1181 /// indicate a bug in [`Self::create_dataflow`].
1182 fn target_replica(&self, cmd: &ComputeCommand) -> Option<ReplicaId> {
1183 match &cmd {
1184 ComputeCommand::Schedule(id)
1185 | ComputeCommand::AllowWrites(id)
1186 | ComputeCommand::AllowCompaction { id, .. } => {
1187 self.expect_collection(*id).target_replica
1188 }
1189 ComputeCommand::CreateDataflow(desc) => {
1190 let mut target_replica = None;
1191 for id in desc.export_ids() {
1192 if let Some(replica) = self.expect_collection(id).target_replica {
1193 if target_replica.is_some() {
1194 assert_eq!(target_replica, Some(replica));
1195 }
1196 target_replica = Some(replica);
1197 }
1198 }
1199 target_replica
1200 }
1201 // Skip Peek as we don't allow replica-targeted indexes.
1202 ComputeCommand::Peek(_)
1203 | ComputeCommand::Hello { .. }
1204 | ComputeCommand::CreateInstance(_)
1205 | ComputeCommand::InitializationComplete
1206 | ComputeCommand::UpdateConfiguration(_)
1207 | ComputeCommand::CancelPeek { .. } => None,
1208 }
1209 }
1210
1211 /// Add a new instance replica, by ID.
1212 #[mz_ore::instrument(level = "debug")]

Callers 2

sendMethod · 0.80
add_replicaMethod · 0.80

Calls 3

export_idsMethod · 0.80
is_someMethod · 0.80
expect_collectionMethod · 0.45

Tested by

no test coverage detected