Handles commands for a client connection, returns when the nonce changes.
(&mut self)
| 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()? { |
no test coverage detected