-
Notifications
You must be signed in to change notification settings - Fork 45
[client] Allow bootstrap endpoint with unknown server type #622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,12 +36,14 @@ pub struct ServerNode { | |
|
|
||
| impl ServerNode { | ||
| pub fn new(id: i32, host: String, port: u32, server_type: ServerType) -> ServerNode { | ||
| let uid = match &server_type { | ||
| ServerType::CoordinatorServer => format!("cs-{id}"), | ||
| ServerType::TabletServer => format!("ts-{id}"), | ||
| ServerType::Unknown => format!("unknown-{host}:{port}"), | ||
| }; | ||
| ServerNode { | ||
| id, | ||
| uid: match server_type { | ||
| ServerType::CoordinatorServer => format!("cs-{id}"), | ||
| ServerType::TabletServer => format!("ts-{id}"), | ||
| }, | ||
| uid, | ||
| host, | ||
| port, | ||
| server_type, | ||
|
|
@@ -77,20 +79,23 @@ impl ServerNode { | |
| pub enum ServerType { | ||
| TabletServer, | ||
| CoordinatorServer, | ||
| Unknown, | ||
| } | ||
|
|
||
| impl ServerType { | ||
| pub fn to_type_id(&self) -> i32 { | ||
| match self { | ||
| ServerType::CoordinatorServer => 1, | ||
| ServerType::TabletServer => 2, | ||
| ServerType::Unknown => -1, | ||
| } | ||
| } | ||
|
|
||
| pub fn from_type_id(type_id: i32) -> Option<ServerType> { | ||
| match type_id { | ||
| 1 => Some(ServerType::CoordinatorServer), | ||
| 2 => Some(ServerType::TabletServer), | ||
| -1 => Some(ServerType::Unknown), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for any unrecognized id, should we return None or Unknown? |
||
| _ => None, | ||
| } | ||
| } | ||
|
|
@@ -101,6 +106,7 @@ impl fmt::Display for ServerType { | |
| match self { | ||
| ServerType::TabletServer => write!(f, "TabletServer"), | ||
| ServerType::CoordinatorServer => write!(f, "CoordinatorServer"), | ||
| ServerType::Unknown => write!(f, "Unknown"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,6 +156,10 @@ fn validate_server_type( | |
| expected: &ServerType, | ||
| response_server_type: Option<i32>, | ||
| ) -> Result<(), Error> { | ||
| if *expected == ServerType::Unknown { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| // For forward-compat with servers that do not populate `server_type`, validation is skipped. | ||
| let Some(type_id) = response_server_type else { | ||
| return Ok(()); | ||
|
|
@@ -1268,6 +1272,21 @@ mod tests { | |
| ) | ||
| .is_ok() | ||
| ); | ||
| assert!( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should a simple integration test case be made in existing IT testing with unknown type/bootstrapping against tablet server?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an integration test covering bootstrapping from a tablet server endpoint. The test uses the shared cluster's tablet plaintext listener as bootstrap_servers, creates a FlussConnection, and verifies server node discovery returns both coordinator and tablet nodes. |
||
| validate_server_type( | ||
| &ServerType::Unknown, | ||
| Some(ServerType::CoordinatorServer.to_type_id()), | ||
| ) | ||
| .is_ok() | ||
| ); | ||
| assert!( | ||
| validate_server_type( | ||
| &ServerType::Unknown, | ||
| Some(ServerType::TabletServer.to_type_id()), | ||
| ) | ||
| .is_ok() | ||
| ); | ||
| assert!(validate_server_type(&ServerType::Unknown, Some(99),).is_ok()); | ||
|
|
||
| // Mismatch: connected to a coordinator while expecting a tablet server | ||
| // (and vice versa). | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should update api-reference for this too