Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: JeremyHi <[email protected]>
  • Loading branch information
WenyXu and fengjiachun committed Sep 16, 2023
1 parent c17fe3a commit 7aedd29
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/datanode/src/datanode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct Datanode {
opts: DatanodeOptions,
services: Option<Services>,
heartbeat_task: Option<HeartbeatTask>,
event_receiver: Option<RegionServerEventReceiver>,
region_event_receiver: Option<RegionServerEventReceiver>,
region_server: RegionServer,
greptimedb_telemetry_task: Arc<GreptimeDBTelemetryTask>,
}
Expand All @@ -85,7 +85,7 @@ impl Datanode {
pub async fn start_heartbeat(&mut self) -> Result<()> {
if let Some(task) = &self.heartbeat_task {
// Safety: The event_receiver must exist.
let receiver = self.event_receiver.take().unwrap();
let receiver = self.region_event_receiver.take().unwrap();
task.start(receiver).await?;
}
Ok(())
Expand Down Expand Up @@ -194,7 +194,7 @@ impl DatanodeBuilder {
let log_store = Self::build_log_store(&self.opts).await?;
// TODO(weny): Adds a noop event listener for standalone mode.

let (tx, event_receiver) = match mode {
let (tx, region_event_receiver) = match mode {
Mode::Distributed => {
let (tx, rx) = new_region_server_event_channel();
(Box::new(tx) as RegionServerEventListenerRef, Some(rx))
Expand Down Expand Up @@ -239,7 +239,7 @@ impl DatanodeBuilder {
heartbeat_task,
region_server,
greptimedb_telemetry_task,
event_receiver,
region_event_receiver,
})
}

Expand Down
8 changes: 4 additions & 4 deletions src/datanode/src/event_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ pub enum RegionServerEvent {

pub trait RegionServerEventListener: Sync + Send {
/// Called *after* a new region was created/opened.
fn register_region(&self, _region_id: RegionId) {}
fn on_register_region(&self, _region_id: RegionId) {}

/// Called *after* a region was closed.
fn deregister_region(&self, _region_id: RegionId) {}
fn on_deregister_region(&self, _region_id: RegionId) {}
}

pub type RegionServerEventListenerRef = Box<dyn RegionServerEventListener>;
Expand All @@ -39,7 +39,7 @@ impl RegionServerEventListener for NoopRegionServerEventListener {}
pub struct RegionServerEventSender(pub(crate) UnboundedSender<RegionServerEvent>);

impl RegionServerEventListener for RegionServerEventSender {
fn register_region(&self, region_id: RegionId) {
fn on_register_region(&self, region_id: RegionId) {
if let Err(e) = self.0.send(RegionServerEvent::Register(region_id)) {
error!(
"Failed to send registering region: {region_id} event, source: {}",
Expand All @@ -48,7 +48,7 @@ impl RegionServerEventListener for RegionServerEventSender {
}
}

fn deregister_region(&self, region_id: RegionId) {
fn on_deregister_region(&self, region_id: RegionId) {
if let Err(e) = self.0.send(RegionServerEvent::Deregister(region_id)) {
error!(
"Failed to send deregistering region: {region_id} event, source: {}",
Expand Down
4 changes: 2 additions & 2 deletions src/datanode/src/region_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ impl RegionServerInner {
RegionChange::Register(_) => {
info!("Region {region_id} is registered to engine {engine_type}");
self.region_map.insert(region_id, engine);
self.event_listener.register_region(region_id);
self.event_listener.on_register_region(region_id);
}
RegionChange::Deregisters => {
info!("Region {region_id} is deregistered from engine {engine_type}");
self.region_map
.remove(&region_id)
.map(|(id, engine)| engine.set_writable(id, false));
self.event_listener.deregister_region(region_id);
self.event_listener.on_deregister_region(region_id);
}
}

Expand Down

0 comments on commit 7aedd29

Please sign in to comment.