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

Method add_collection

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

Add a collection to the instance state. # Panics Panics if a collection with the same ID exists already.

(
        &mut self,
        id: GlobalId,
        as_of: Antichain<Timestamp>,
        shared: SharedCollectionState,
        storage_dependencies: BTreeMap<GlobalId, ReadHold>,
        compute_depen

Source from the content-addressed store, hash-verified

280 ///
281 /// Panics if a collection with the same ID exists already.
282 fn add_collection(
283 &mut self,
284 id: GlobalId,
285 as_of: Antichain<Timestamp>,
286 shared: SharedCollectionState,
287 storage_dependencies: BTreeMap<GlobalId, ReadHold>,
288 compute_dependencies: BTreeMap<GlobalId, ReadHold>,
289 replica_input_read_holds: Vec<ReadHold>,
290 write_only: bool,
291 storage_sink: bool,
292 initial_as_of: Option<Antichain<Timestamp>>,
293 refresh_schedule: Option<RefreshSchedule>,
294 target_replica: Option<ReplicaId>,
295 ) {
296 // Add global collection state.
297 let dependency_ids: Vec<GlobalId> = compute_dependencies
298 .keys()
299 .chain(storage_dependencies.keys())
300 .copied()
301 .collect();
302 let introspection = CollectionIntrospection::new(
303 id,
304 self.introspection_tx.clone(),
305 as_of.clone(),
306 storage_sink,
307 initial_as_of,
308 refresh_schedule,
309 dependency_ids,
310 );
311 let mut state = CollectionState::new(
312 id,
313 as_of.clone(),
314 shared,
315 storage_dependencies,
316 compute_dependencies,
317 Arc::clone(&self.read_hold_tx),
318 introspection,
319 );
320 state.target_replica = target_replica;
321 // If the collection is write-only, clear its read policy to reflect that.
322 if write_only {
323 state.read_policy = None;
324 }
325
326 if let Some(previous) = self.collections.insert(id, state) {
327 panic!("attempt to add a collection with existing ID {id} (previous={previous:?}");
328 }
329
330 // Add per-replica collection state.
331 for replica in self.replicas.values_mut() {
332 if target_replica.is_some_and(|id| id != replica.id) {
333 continue;
334 }
335 replica.add_collection(id, as_of.clone(), replica_input_read_holds.clone());
336 }
337 }
338
339 fn remove_collection(&mut self, id: GlobalId) {

Callers 2

add_replica_stateMethod · 0.80
create_dataflowMethod · 0.80

Calls 8

cloneFunction · 0.85
values_mutMethod · 0.80
collectMethod · 0.45
keysMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45
for_collectionMethod · 0.45
is_transientMethod · 0.45

Tested by

no test coverage detected