mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-22 07:50:38 +00:00
feat: meta refactor (#339)
* feat: heartbeat handler * chore: heartbeat handlers lock refactor * chore: store rpc req/res wrapper * chore: router rpc/res wrapper * chore: const method(request_header) * chore: rm unnessary const fn & refactor HeartbeatHandler * chore: refactor CreateRequest * chore: HeartbeatAccumulator * chore: improve router req/res convert * fix: register race condition
This commit is contained in:
@@ -24,11 +24,7 @@ message Error {
|
||||
|
||||
message Peer {
|
||||
uint64 id = 1;
|
||||
Endpoint endpoint = 2;
|
||||
}
|
||||
|
||||
message Endpoint {
|
||||
string addr = 1;
|
||||
string addr = 2;
|
||||
}
|
||||
|
||||
message TableName {
|
||||
|
||||
@@ -88,5 +88,5 @@ message AskLeaderRequest {
|
||||
message AskLeaderResponse {
|
||||
ResponseHeader header = 1;
|
||||
|
||||
Endpoint leader = 2;
|
||||
Peer leader = 2;
|
||||
}
|
||||
|
||||
@@ -8,19 +8,21 @@ service Router {
|
||||
// Fetch routing information for tables. The smallest unit is the complete
|
||||
// routing information(all regions) of a table.
|
||||
//
|
||||
// ```text
|
||||
// table_1
|
||||
// table_name
|
||||
// table_schema
|
||||
// regions
|
||||
// region_1
|
||||
// mutate_endpoint
|
||||
// select_endpoint_1, select_endpoint_2
|
||||
// leader_peer
|
||||
// follower_peer_1, follower_peer_2
|
||||
// region_2
|
||||
// mutate_endpoint
|
||||
// select_endpoint_1, select_endpoint_2, select_endpoint_3
|
||||
// leader_peer
|
||||
// follower_peer_1, follower_peer_2, follower_peer_3
|
||||
// region_xxx
|
||||
// table_2
|
||||
// ...
|
||||
// ```
|
||||
//
|
||||
rpc Route(RouteRequest) returns (RouteResponse) {}
|
||||
|
||||
|
||||
@@ -2,56 +2,19 @@ tonic::include_proto!("greptime.v1.meta");
|
||||
|
||||
pub const PROTOCOL_VERSION: u64 = 1;
|
||||
|
||||
impl Peer {
|
||||
pub fn new(id: u64, addr: impl AsRef<str>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
endpoint: Some(addr.as_ref().into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for Endpoint {
|
||||
fn from(s: &str) -> Self {
|
||||
Self {
|
||||
addr: s.to_string(),
|
||||
}
|
||||
}
|
||||
pub const fn request_header((cluster_id, member_id): (u64, u64)) -> Option<RequestHeader> {
|
||||
Some(RequestHeader::new((cluster_id, member_id)))
|
||||
}
|
||||
|
||||
impl RequestHeader {
|
||||
pub fn new(cluster_id: u64, member_id: u64) -> Self {
|
||||
#[inline]
|
||||
pub const fn new((cluster_id, member_id): (u64, u64)) -> Self {
|
||||
Self {
|
||||
protocol_version: PROTOCOL_VERSION,
|
||||
cluster_id,
|
||||
member_id,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_id((cluster_id, member_id): (u64, u64)) -> Self {
|
||||
Self {
|
||||
protocol_version: PROTOCOL_VERSION,
|
||||
cluster_id,
|
||||
member_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HeartbeatRequest {
|
||||
pub fn new(header: RequestHeader) -> Self {
|
||||
Self {
|
||||
header: Some(header),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AskLeaderRequest {
|
||||
pub fn new(header: RequestHeader) -> Self {
|
||||
Self {
|
||||
header: Some(header),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TableName {
|
||||
@@ -69,13 +32,6 @@ impl TableName {
|
||||
}
|
||||
|
||||
impl RouteRequest {
|
||||
pub fn new(header: RequestHeader) -> Self {
|
||||
Self {
|
||||
header: Some(header),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_table(mut self, table_name: TableName) -> Self {
|
||||
self.table_names.push(table_name);
|
||||
self
|
||||
@@ -83,14 +39,6 @@ impl RouteRequest {
|
||||
}
|
||||
|
||||
impl CreateRequest {
|
||||
pub fn new(header: RequestHeader, table_name: TableName) -> Self {
|
||||
Self {
|
||||
header: Some(header),
|
||||
table_name: Some(table_name),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_partition(mut self, partition: Partition) -> Self {
|
||||
self.partitions.push(partition);
|
||||
self
|
||||
@@ -128,20 +76,3 @@ impl Partition {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_peer() {
|
||||
let peer = Peer::new(1, "test_addr");
|
||||
assert_eq!(1, peer.id);
|
||||
assert_eq!(
|
||||
Endpoint {
|
||||
addr: "test_addr".to_string()
|
||||
},
|
||||
peer.endpoint.unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user