Skip to content

Commit

Permalink
feat: add skip_wal_replay to OpenRegion instruction (#2977)
Browse files Browse the repository at this point in the history
feat: add skip_wal_replay to OpenRegion instruction
  • Loading branch information
WenyXu authored Dec 23, 2023
1 parent d7b2e79 commit 06fd7fd
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/common/meta/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ pub struct OpenRegion {
pub region_options: HashMap<String, String>,
#[serde(default)]
pub region_wal_options: HashMap<String, String>,
#[serde(default)]
pub skip_wal_replay: bool,
}

impl OpenRegion {
Expand All @@ -106,12 +108,14 @@ impl OpenRegion {
path: &str,
region_options: HashMap<String, String>,
region_wal_options: HashMap<String, String>,
skip_wal_replay: bool,
) -> Self {
Self {
region_ident,
region_storage_path: path.to_string(),
region_options,
region_wal_options,
skip_wal_replay,
}
}
}
Expand Down Expand Up @@ -227,12 +231,13 @@ mod tests {
"test/foo",
HashMap::new(),
HashMap::new(),
false,
));

let serialized = serde_json::to_string(&open_region).unwrap();

assert_eq!(
r#"{"OpenRegion":{"region_ident":{"cluster_id":1,"datanode_id":2,"table_id":1024,"region_number":1,"engine":"mito2"},"region_storage_path":"test/foo","region_options":{},"region_wal_options":{}}}"#,
r#"{"OpenRegion":{"region_ident":{"cluster_id":1,"datanode_id":2,"table_id":1024,"region_number":1,"engine":"mito2"},"region_storage_path":"test/foo","region_options":{},"region_wal_options":{},"skip_wal_replay":false}}"#,
serialized
);

Expand Down Expand Up @@ -289,6 +294,7 @@ mod tests {
region_storage_path,
region_options,
region_wal_options: HashMap::new(),
skip_wal_replay: false,
};
assert_eq!(expected, deserialized);
}
Expand Down
6 changes: 4 additions & 2 deletions src/datanode/src/heartbeat/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ impl RegionHeartbeatResponseHandler {
region_storage_path,
region_options,
region_wal_options,
}) => Ok(Box::new(|region_server| {
skip_wal_replay,
}) => Ok(Box::new(move |region_server| {
Box::pin(async move {
let region_id = Self::region_ident_to_region_id(&region_ident);
// TODO(niebayes): extends region options with region_wal_options.
Expand All @@ -64,7 +65,7 @@ impl RegionHeartbeatResponseHandler {
engine: region_ident.engine,
region_dir: region_dir(&region_storage_path, region_id),
options: region_options,
skip_wal_replay: false,
skip_wal_replay,
});
let result = region_server.handle_request(region_id, request).await;

Expand Down Expand Up @@ -244,6 +245,7 @@ mod tests {
path,
HashMap::new(),
HashMap::new(),
false,
))
}

Expand Down
1 change: 1 addition & 0 deletions src/meta-srv/src/procedure/region_failover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ mod tests {
&path,
HashMap::new(),
HashMap::new(),
false
)))
.unwrap(),
))
Expand Down
3 changes: 3 additions & 0 deletions src/meta-srv/src/procedure/region_failover/activate_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl ActivateRegion {
&region_storage_path,
region_options.clone(),
region_wal_options.clone(),
false,
));

self.region_storage_path = Some(region_storage_path);
Expand Down Expand Up @@ -236,6 +237,7 @@ mod tests {
&env.path,
HashMap::new(),
HashMap::new(),
false
)))
.unwrap(),
))
Expand Down Expand Up @@ -307,6 +309,7 @@ mod tests {
&env.path,
HashMap::new(),
HashMap::new(),
false
)))
.unwrap(),
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl OpenCandidateRegion {
&region_storage_path,
region_options,
region_wal_options,
true,
));

Ok(open_instruction)
Expand Down Expand Up @@ -215,6 +216,7 @@ mod tests {
region_storage_path: "/bar/foo/region/".to_string(),
region_options: Default::default(),
region_wal_options: Default::default(),
skip_wal_replay: true,
})
}

Expand Down

0 comments on commit 06fd7fd

Please sign in to comment.