Adds replicas of an instance.
(
&mut self,
instance_id: ComputeInstanceId,
replica_id: ReplicaId,
location: ClusterReplicaLocation,
config: ComputeReplicaConfig,
)
| 698 | |
| 699 | /// Adds replicas of an instance. |
| 700 | pub fn add_replica_to_instance( |
| 701 | &mut self, |
| 702 | instance_id: ComputeInstanceId, |
| 703 | replica_id: ReplicaId, |
| 704 | location: ClusterReplicaLocation, |
| 705 | config: ComputeReplicaConfig, |
| 706 | ) -> Result<(), ReplicaCreationError> { |
| 707 | use ReplicaCreationError::*; |
| 708 | |
| 709 | let instance = self.instance(instance_id)?; |
| 710 | |
| 711 | // Validation |
| 712 | if instance.replicas.contains(&replica_id) { |
| 713 | return Err(ReplicaExists(replica_id)); |
| 714 | } |
| 715 | |
| 716 | let (enable_logging, interval) = match config.logging.interval { |
| 717 | Some(interval) => (true, interval), |
| 718 | None => (false, Duration::from_secs(1)), |
| 719 | }; |
| 720 | |
| 721 | let expiration_offset = COMPUTE_REPLICA_EXPIRATION_OFFSET.get(&self.dyncfg); |
| 722 | |
| 723 | // Capture dictionary compression once, at replica creation, and hold it fixed for the |
| 724 | // replica's lifetime (see `InstanceConfig::arrangement_dictionary_compression`). This is |
| 725 | // why a later flip of the flag only affects replicas created afterwards. |
| 726 | let arrangement_dictionary_compression = |
| 727 | ENABLE_ARRANGEMENT_DICTIONARY_COMPRESSION_ALPHA.get(&self.dyncfg); |
| 728 | |
| 729 | let replica_config = ReplicaConfig { |
| 730 | location, |
| 731 | logging: LoggingConfig { |
| 732 | interval, |
| 733 | enable_logging, |
| 734 | log_logging: config.logging.log_logging, |
| 735 | index_logs: Default::default(), |
| 736 | }, |
| 737 | grpc_client: self.config.grpc_client.clone(), |
| 738 | expiration_offset: (!expiration_offset.is_zero()).then_some(expiration_offset), |
| 739 | arrangement_dictionary_compression, |
| 740 | }; |
| 741 | |
| 742 | let instance = self.instance_mut(instance_id).expect("validated"); |
| 743 | instance.replicas.insert(replica_id); |
| 744 | |
| 745 | instance.call(move |i| { |
| 746 | i.add_replica(replica_id, replica_config, None) |
| 747 | .expect("validated") |
| 748 | }); |
| 749 | |
| 750 | Ok(()) |
| 751 | } |
| 752 | |
| 753 | /// Removes a replica from an instance, including its service in the orchestrator. |
| 754 | pub fn drop_replica( |
no test coverage detected