-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fix pinot connector ignoring certain exceptions silently #25424
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
Closed
rhodo
wants to merge
5
commits into
trinodb:master
from
rhodo:add_config_for_pinot_metadata_exception
Closed
Changes from 4 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,8 +20,10 @@ | |
| import com.google.inject.Inject; | ||
| import io.trino.plugin.pinot.PinotErrorCode; | ||
| import io.trino.plugin.pinot.PinotException; | ||
| import io.trino.plugin.pinot.PinotSessionProperties; | ||
| import io.trino.plugin.pinot.PinotSplit; | ||
| import io.trino.plugin.pinot.query.PinotProxyGrpcRequestBuilder; | ||
| import io.trino.spi.connector.ConnectorSession; | ||
| import jakarta.annotation.PreDestroy; | ||
| import org.apache.pinot.common.config.GrpcConfig; | ||
| import org.apache.pinot.common.datatable.DataTable; | ||
|
|
@@ -60,9 +62,16 @@ public class PinotGrpcDataFetcher | |
| private boolean isPinotDataFetched; | ||
| private final RowCountChecker rowCountChecker; | ||
| private long estimatedMemoryUsageInBytes; | ||
|
|
||
| public PinotGrpcDataFetcher(PinotGrpcServerQueryClient pinotGrpcClient, PinotSplit split, String query, RowCountChecker rowCountChecker) | ||
| private final ConnectorSession session; | ||
|
|
||
| public PinotGrpcDataFetcher( | ||
| ConnectorSession session, | ||
| PinotGrpcServerQueryClient pinotGrpcClient, | ||
| PinotSplit split, | ||
| String query, | ||
| RowCountChecker rowCountChecker) | ||
| { | ||
| this.session = requireNonNull(session, "session is null"); | ||
| this.pinotGrpcClient = requireNonNull(pinotGrpcClient, "pinotGrpcClient is null"); | ||
| this.split = requireNonNull(split, "split is null"); | ||
| this.query = requireNonNull(query, "query is null"); | ||
|
|
@@ -98,7 +107,7 @@ public void fetchData() | |
| { | ||
| long startTimeNanos = System.nanoTime(); | ||
| String serverHost = split.getSegmentHost().orElseThrow(() -> new PinotException(PinotErrorCode.PINOT_INVALID_PQL_GENERATED, Optional.empty(), "Expected the segment split to contain the host")); | ||
| this.responseIterator = pinotGrpcClient.queryPinot(query, serverHost, split.getSegments()); | ||
| this.responseIterator = pinotGrpcClient.queryPinot(query, serverHost, split.getSegments(), session); | ||
| readTimeNanos += System.nanoTime() - startTimeNanos; | ||
| isPinotDataFetched = true; | ||
| } | ||
|
|
@@ -136,9 +145,9 @@ public void shutdown() | |
| } | ||
|
|
||
| @Override | ||
| public PinotDataFetcher create(String query, PinotSplit split) | ||
| public PinotDataFetcher create(ConnectorSession session, String query, PinotSplit split) | ||
| { | ||
| return new PinotGrpcDataFetcher(queryClient, split, query, new RowCountChecker(limitForSegmentQueries, query)); | ||
| return new PinotGrpcDataFetcher(session, queryClient, split, query, new RowCountChecker(limitForSegmentQueries, query)); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -239,7 +248,7 @@ private PinotGrpcServerQueryClient(PinotHostMapper pinotHostMapper, PinotGrpcSer | |
| this.proxyUri = pinotGrpcServerQueryClientConfig.getProxyUri(); | ||
| } | ||
|
|
||
| public Iterator<PinotDataTableWithSize> queryPinot(String query, String serverHost, List<String> segments) | ||
| public Iterator<PinotDataTableWithSize> queryPinot(String query, String serverHost, List<String> segments, ConnectorSession session) | ||
| { | ||
| HostAndPort mappedHostAndPort = pinotHostMapper.getServerGrpcHostAndPort(serverHost, grpcPort); | ||
| // GrpcQueryClient does not implement Closeable. The idle timeout is 30 minutes (grpc default). | ||
|
|
@@ -257,19 +266,21 @@ public Iterator<PinotDataTableWithSize> queryPinot(String query, String serverHo | |
| grpcRequestBuilder.setHostName(mappedHostAndPort.getHost()).setPort(grpcPort); | ||
| } | ||
| Server.ServerRequest serverRequest = grpcRequestBuilder.build(); | ||
| return new ResponseIterator(client.submit(serverRequest), query); | ||
| return new ResponseIterator(client.submit(serverRequest), query, session); | ||
| } | ||
|
|
||
| public static class ResponseIterator | ||
| extends AbstractIterator<PinotDataTableWithSize> | ||
| { | ||
| private final Iterator<Server.ServerResponse> responseIterator; | ||
| private final String query; | ||
| private final ConnectorSession session; | ||
|
|
||
| public ResponseIterator(Iterator<Server.ServerResponse> responseIterator, String query) | ||
| public ResponseIterator(Iterator<Server.ServerResponse> responseIterator, String query, ConnectorSession session) | ||
|
ebyhr marked this conversation as resolved.
Outdated
|
||
| { | ||
| this.responseIterator = requireNonNull(responseIterator, "responseIterator is null"); | ||
| this.query = requireNonNull(query, "query is null"); | ||
| this.session = requireNonNull(session, "session is null"); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -280,7 +291,8 @@ protected PinotDataTableWithSize computeNext() | |
| } | ||
| Server.ServerResponse response = responseIterator.next(); | ||
| String responseType = response.getMetadataMap().get(MetadataKeys.RESPONSE_TYPE); | ||
| if (responseType.equals(ResponseType.METADATA)) { | ||
| if (responseType.equals(ResponseType.METADATA) | ||
| && !PinotSessionProperties.isGrpcQueryEnforceMetadataException(session)) { | ||
|
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. The idea is that instead of using metadata type to signal the end of data, we rely on response iterator check here to signal the end of data
ebyhr marked this conversation as resolved.
Outdated
|
||
| return endOfData(); | ||
| } | ||
| ByteBuffer buffer = response.getPayload().asReadOnlyByteBuffer(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm not a fan of making exception handling configurable based on a configuration.
@elonazoulay Do you have any other idea?
Uh oh!
There was an error while loading. Please reload this page.
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 agree, especially since it's a choice between empty results masking an exception or a query failure with detailed exception (so it can be investigated and resolved).
Is there any issue with always surfacing exceptions when the query fails?
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.
Thanks for reviewing! One reason we were considering making this behavior configurable is that, today, there are cases where partial results are returned instead of raising an exception—for example, when one or a few segments are missing for a table. Some users may be fine with receiving most of the query's result, while others, especially those with stricter consistency requirements, might prefer to get an explicit segment-missing exception.
That said, if we can align on always surfacing exceptions, it would certainly simplify the logic.
(cc @xiangfu0)