From df1d0e5b8782fddd042ba4307a0337f27629dc5b Mon Sep 17 00:00:00 2001 From: Weny Xu Date: Mon, 18 Sep 2023 20:07:42 +0900 Subject: [PATCH] refactor: rename coordination to require_lease_before_startup (#2431) --- config/datanode.example.toml | 6 +++--- src/datanode/src/config.rs | 4 ++-- src/datanode/src/datanode.rs | 22 +++++++++++----------- tests/conf/datanode-test.toml.template | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/config/datanode.example.toml b/config/datanode.example.toml index 808cc855d5a1..ddea4523fe1b 100644 --- a/config/datanode.example.toml +++ b/config/datanode.example.toml @@ -8,9 +8,9 @@ rpc_addr = "127.0.0.1:3001" rpc_hostname = "127.0.0.1" # The number of gRPC server worker threads, 8 by default. rpc_runtime_size = 8 -# Start services after regions are coordinated. -# It will block the datanode start if it can't receive the heartbeat from metasrv. -coordination = false +# Start services after regions have obtained leases. +# It will block the datanode start if it can't receive leases in the heartbeat from metasrv. +require_lease_before_startup = false [heartbeat] # Interval for sending heartbeat messages to the Metasrv in milliseconds, 5000 by default. diff --git a/src/datanode/src/config.rs b/src/datanode/src/config.rs index dbcf944cffca..61001f2e39d1 100644 --- a/src/datanode/src/config.rs +++ b/src/datanode/src/config.rs @@ -320,7 +320,7 @@ impl From<&DatanodeOptions> for StorageEngineConfig { pub struct DatanodeOptions { pub mode: Mode, pub node_id: Option, - pub coordination: bool, + pub require_lease_before_startup: bool, pub rpc_addr: String, pub rpc_hostname: Option, pub rpc_runtime_size: usize, @@ -340,7 +340,7 @@ impl Default for DatanodeOptions { Self { mode: Mode::Standalone, node_id: None, - coordination: false, + require_lease_before_startup: false, rpc_addr: "127.0.0.1:3001".to_string(), rpc_hostname: None, rpc_runtime_size: 8, diff --git a/src/datanode/src/datanode.rs b/src/datanode/src/datanode.rs index ab567121e7b8..d0bcd7737b86 100644 --- a/src/datanode/src/datanode.rs +++ b/src/datanode/src/datanode.rs @@ -72,7 +72,7 @@ pub struct Datanode { region_event_receiver: Option, region_server: RegionServer, greptimedb_telemetry_task: Arc, - coordinated_notifier: Option>, + leases_notifier: Option>, } impl Datanode { @@ -91,15 +91,14 @@ impl Datanode { // Safety: The event_receiver must exist. let receiver = self.region_event_receiver.take().unwrap(); - task.start(receiver, self.coordinated_notifier.clone()) - .await?; + task.start(receiver, self.leases_notifier.clone()).await?; } Ok(()) } - /// If `coordinated_notifier` exists, it waits for all regions to be coordinated. + /// If `leases_notifier` exists, it waits until leases have been obtained in all regions. pub async fn wait_coordinated(&mut self) { - if let Some(notifier) = self.coordinated_notifier.take() { + if let Some(notifier) = self.leases_notifier.take() { notifier.notified().await; } } @@ -249,11 +248,12 @@ impl DatanodeBuilder { ) .await; - let coordinated_notifier = if self.opts.coordination && matches!(mode, Mode::Distributed) { - Some(Arc::new(Notify::new())) - } else { - None - }; + let leases_notifier = + if self.opts.require_lease_before_startup && matches!(mode, Mode::Distributed) { + Some(Arc::new(Notify::new())) + } else { + None + }; Ok(Datanode { opts: self.opts, @@ -262,7 +262,7 @@ impl DatanodeBuilder { region_server, greptimedb_telemetry_task, region_event_receiver, - coordinated_notifier, + leases_notifier, }) } diff --git a/tests/conf/datanode-test.toml.template b/tests/conf/datanode-test.toml.template index 4a692e97423c..2aa63829033f 100644 --- a/tests/conf/datanode-test.toml.template +++ b/tests/conf/datanode-test.toml.template @@ -3,7 +3,7 @@ mode = 'distributed' rpc_addr = '127.0.0.1:4100' rpc_hostname = '127.0.0.1' rpc_runtime_size = 8 -coordination = true +require_lease_before_startup = true [wal] file_size = '1GB'