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

Method run_client

src/compute/src/server.rs:372–422  ·  view source on GitHub ↗

Handles commands for a client connection, returns when the nonce changes.

(&mut self)

Source from the content-addressed store, hash-verified

370
371 /// Handles commands for a client connection, returns when the nonce changes.
372 fn run_client(&mut self) -> Result<Infallible, NonceChange> {
373 self.reconcile()?;
374
375 // The last time we did periodic maintenance.
376 let mut last_maintenance = Instant::now();
377
378 // Commence normal operation.
379 loop {
380 // Get the maintenance interval, default to zero if we don't have a compute state.
381 let maintenance_interval = self
382 .compute_state
383 .as_ref()
384 .map_or(Duration::ZERO, |state| state.server_maintenance_interval);
385
386 let now = Instant::now();
387 // Determine if we need to perform maintenance, which is true if `maintenance_interval`
388 // time has passed since the last maintenance.
389 let sleep_duration;
390 if now >= last_maintenance + maintenance_interval {
391 last_maintenance = now;
392 sleep_duration = None;
393
394 // Report frontier information back the coordinator.
395 if let Some(mut compute_state) = self.activate_compute() {
396 compute_state.compute_state.traces.maintenance();
397 compute_state.report_frontiers();
398 compute_state.report_metrics();
399 compute_state.check_expiration();
400 }
401
402 self.metrics.record_shared_row_metrics();
403 } else {
404 // We didn't perform maintenance, sleep until the next maintenance interval.
405 let next_maintenance = last_maintenance + maintenance_interval;
406 sleep_duration = Some(next_maintenance.saturating_duration_since(now))
407 };
408
409 // Step the timely worker, recording the time taken.
410 let timer = self.metrics.timely_step_duration_seconds.start_timer();
411 self.timely_worker.step_or_park(sleep_duration);
412 timer.observe_duration();
413
414 self.handle_pending_commands()?;
415
416 if let Some(mut compute_state) = self.activate_compute() {
417 compute_state.process_peeks();
418 compute_state.process_subscribes();
419 compute_state.process_copy_tos();
420 }
421 }
422 }
423
424 fn handle_pending_commands(&mut self) -> Result<(), NonceChange> {
425 while let Some(cmd) = self.command_rx.try_recv()? {

Callers 1

runMethod · 0.45

Calls 13

nowFunction · 0.85
activate_computeMethod · 0.80
maintenanceMethod · 0.80
report_frontiersMethod · 0.80
report_metricsMethod · 0.80
check_expirationMethod · 0.80
process_peeksMethod · 0.80
process_subscribesMethod · 0.80
process_copy_tosMethod · 0.80
reconcileMethod · 0.45

Tested by

no test coverage detected