Skip to content
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

Add BrokerClient implementation #17382

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

abhishekrb19
Copy link
Contributor

@abhishekrb19 abhishekrb19 commented Oct 19, 2024

This patch is extracted from 17353 to make reviewing easier. It includes additional test coverage and javadocs compared to the original patch.

Changes:

  • Added BrokerClient and BrokerClientImpl to the sql package that leverages the ServiceClient functionality; similar to OverlordClient and CoordinatorClient implementations in the server module.
  • For now, only two broker API stubs are added: submitSqlTask() and fetchExplainPlanInformation().
  • Note that there is already a org.apache.druid.discovery.BrokerClient in the server module that's used by MSQE for a specific use case. This client has a weird contract though, and its retry mechanism is not robust. We should plan to remove it in the future, but for now, it has been marked as deprecated in favor of the new BrokerClient added in this patch.
  • Added a new POJO class ExplainPlanInformation that encapsulates explain plan info.
  • Clean up ExplainAttributesTest a bit and added serde verification.

In this patch, the BrokerClient and the related BrokerServiceModule that injects it is unused. It will be used by the scheduled batch supervisor running on the Overlord to interact with the Broker.

This PR has:

  • been self-reviewed.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • been tested in a test Druid cluster.

…lan.

- Add BrokerClient that leverages the ServiceClient functionality. Add a couple of
client APIs that are useful to the scheduled batch supervisor implementation.

- Add ExplainPlanInformation class that contains information about a single plan.
  The BrokerClient leverages this.
Copy link
Contributor

@kfaraz kfaraz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments, otherwise looks good.

* classes present in the sql module.
* </p>
*/
public class BrokerServiceModule extends ServiceClientModule
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:
Why extend ServiceClientModule?
I think the only required method from ServiceClientModule is makeServiceClientFactory().
I guess it is okay to copy over that method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, makeServiceClientFactory() and the constants for number of retries and connection threads to use. So I left it to avoid duplication.

* at least for the native query explain, but there's currently no use case for it.
* </p>
*/
public class ExplainPlanInformation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to ExplainPlan?

return attributes;
}

private static class ExplainAttributesDeserializer extends JsonDeserializer<ExplainAttributes>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the custom deserializer needed? I don't see it doing anything special.

Copy link
Contributor Author

@abhishekrb19 abhishekrb19 Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explain plan response contains objects encoded as strings, so jackson needs a way to convert the Json string into individual attributes. Another option is to add a @JsonCreator String constructor in ExplainAttributes itself besides the existing constructor, which would essentially do the same thing as ExplainAttributesDeserializer#deserialize.

Without this, the tests in ExplainPlanTest would fail with an error:

by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `org.apache.druid.sql.calcite.planner.ExplainAttributes` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('{"statementType":"INSERT","targetDataSource":"foo","pa...

For now, I have added a comment for the deserializer here since this is needed only for ExplainPlan. Please let me know if you prefer one approach or the other.

*
* @param sqlQuery the SQL query for which the {@code EXPLAIN PLAN FOR} information is to be fetched
*/
ListenableFuture<List<ExplainPlanInformation>> fetchExplainPlanInformation(SqlQuery sqlQuery);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ListenableFuture<List<ExplainPlanInformation>> fetchExplainPlanInformation(SqlQuery sqlQuery);
ListenableFuture<List<ExplainPlanInformation>> fetchExplainPlan(SqlQuery sqlQuery);

ListenableFuture<SqlTaskStatus> submitSqlTask(SqlQuery sqlQuery);

/**
* Fetches the explain plan information for the given {@code sqlQuery}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if the javadoc also mentioned the HTTP endpoint being hit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants