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

Method create_instance

src/compute-client/src/controller.rs:507–564  ·  view source on GitHub ↗

Create a compute instance.

(
        &mut self,
        id: ComputeInstanceId,
        arranged_logs: BTreeMap<LogVariant, GlobalId>,
        workload_class: Option<String>,
    )

Source from the content-addressed store, hash-verified

505impl ComputeController {
506 /// Create a compute instance.
507 pub fn create_instance(
508 &mut self,
509 id: ComputeInstanceId,
510 arranged_logs: BTreeMap<LogVariant, GlobalId>,
511 workload_class: Option<String>,
512 ) -> Result<(), InstanceExists> {
513 if self.instances.contains_key(&id) {
514 return Err(InstanceExists(id));
515 }
516
517 let mut collections = BTreeMap::new();
518 let mut logs = Vec::with_capacity(arranged_logs.len());
519 for (&log, &id) in &arranged_logs {
520 let collection = Collection::new_log();
521 let shared = collection.shared.clone();
522 collections.insert(id, collection);
523 logs.push((log, id, shared));
524 }
525
526 let client = InstanceClient::spawn(
527 id,
528 self.build_info,
529 Arc::clone(&self.storage_collections),
530 self.peek_stash_persist_location.clone(),
531 logs,
532 self.metrics.for_instance(id),
533 self.now.clone(),
534 self.wallclock_lag.clone(),
535 Arc::clone(&self.dyncfg),
536 self.response_tx.clone(),
537 self.introspection_tx.clone(),
538 self.read_only,
539 );
540
541 let instance = InstanceState::new(client, collections);
542 self.instances.insert(id, instance);
543
544 self.instance_workload_classes
545 .lock()
546 .expect("lock poisoned")
547 .insert(id, workload_class.clone());
548
549 let instance = self.instances.get_mut(&id).expect("instance just added");
550 if self.initialized {
551 instance.call(Instance::initialization_complete);
552 }
553
554 // The replica also receives the current dyncfg create-time, folded into `CreateInstance`
555 // so create-time setup observes synced values. This `UpdateConfiguration` is still
556 // required: it carries the rest of `ComputeParameters` (workload class, max result size,
557 // tracing) and syncs the dyncfg into the persist config and metrics, none of which ride in
558 // `CreateInstance`. The overlapping dyncfg application is idempotent.
559 let mut config_params = self.config.clone();
560 config_params.workload_class = Some(workload_class);
561 instance.call(|i| i.update_configuration(config_params));
562
563 Ok(())
564 }

Callers 1

create_clusterMethod · 0.45

Calls 14

InstanceExistsClass · 0.85
spawnFunction · 0.85
cloneFunction · 0.85
contains_keyMethod · 0.80
expectMethod · 0.80
lockMethod · 0.80
lenMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45
pushMethod · 0.45
for_instanceMethod · 0.45
get_mutMethod · 0.45

Tested by

no test coverage detected