-
Notifications
You must be signed in to change notification settings - Fork 496
[client] List databases return database summary infos. #2515
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?
Conversation
wuchong
left a comment
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.
@loserwang1024 I left some comments.
| public Stat getStat(String path) throws Exception { | ||
| return zkClient.checkExists().forPath(path); |
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.
Why make this change? The previous implementation was clearer and safer. The current one doesn’t properly handle the case where the znode does not exist, which can lead to runtime errors or undefined behavior.
| return getChildren(DatabasesZNode.path()); | ||
| } | ||
|
|
||
| public Optional<DatabaseSummary> getDatabaseSummary(String databaseName) throws Exception { |
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.
The current implementation still triggers N separate I/O operations—one for each database—which can significantly increase latency. To mitigate this, we can optimize by performing these requests asynchronously in the background.
Specifically, you can:
-
Introduce a new method in
ZooKeeperClient:getStatsInBackground(Collection<String> paths)
This method should wrap the existing
handleRequestInBackgroundand use a newly definedZkGetStatRequesttype to fetch stats for multiple paths concurrently. TakegetDataInBackgroundas an example. -
Then, add a new high-level method:
List<DatabaseSummary> listDatabaseSummaries(Collection<String> databaseNames)
which calls
getStatsInBackgroundto retrieve all necessary ZooKeeper stats in parallel and constructs theDatabaseSummaryobjects efficiently.
This approach reduces end-to-end latency by eliminating sequential I/O and leveraging concurrent background requests.
| CompletableFuture<List<String>> listDatabases(); | ||
|
|
||
| /** List all databases' summary information in fluss cluster asynchronously. */ | ||
| CompletableFuture<List<DatabaseSummary>> listDatabases(ListDatabaseOption option); |
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.
Rename the method to listDatabaseSummaries() without any parameters. If user would like only returning database names, they can use listDatabases().
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.
With the ListDatabaseOption option, if we want to support additional capabilities later (such as paginated queries), there's no need to add a new method.
|
|
||
| // list databases request and response | ||
| message ListDatabasesRequest { | ||
| optional bool database_name_only = 1; |
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.
For legacy clients, this new field will be missing, which typically causes the boolean to default to false. This creates a risk of backward incompatibility: the server might return the full summary instead of just the names, effectively changing the behavior for old clients.
While we could technically work around this by checking request.hasDatabaseNameOnly() && !request.isDatabaseNameOnly(), this logic is counter-intuitive and error-prone.
Suggestion: A better design would be to use bool include_summary instead of database_name_only. So, for legacy clients, the default value (false) and empty value (unset this field) are consistent and correctly imply 'do not include summary,' automatically preserving the existing behavior without requiring complex null-checks.
| private final @Nullable Long createdTime; | ||
| private final @Nullable Integer tableCount; |
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 suggest making these fields non-nullable and using primitive types (long and int) instead of their boxed counterparts.
If users need database names, they should call listDatabases() directly—rather than fetching database summaries and then discarding them.
This approach makes the API clearer, more predictable, and deterministic in behavior.
Purpose
Linked issue: close #2514
Brief change log
Tests
API and Format
Documentation