[
https://issues.apache.org/jira/browse/BEAM-7495?focusedWorklogId=260028&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-260028
]
ASF GitHub Bot logged work on BEAM-7495:
----------------------------------------
Author: ASF GitHub Bot
Created on: 14/Jun/19 00:30
Start Date: 14/Jun/19 00:30
Worklog Time Spent: 10m
Work Description: chamikaramj commented on pull request #8832:
[BEAM-7495] Add dynamic worker rebalancing to BigQuery Storage
URL: https://github.com/apache/beam/pull/8832#discussion_r293622391
##########
File path:
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryStorageStreamSource.java
##########
@@ -215,23 +223,101 @@ public T getCurrent() throws NoSuchElementException {
}
@Override
- protected long getCurrentOffset() throws NoSuchElementException {
- return currentOffset;
- }
-
- @Override
- public void close() {
+ public synchronized void close() {
storageClient.close();
}
@Override
public synchronized BigQueryStorageStreamSource<T> getCurrentSource() {
- return (BigQueryStorageStreamSource<T>) super.getCurrentSource();
+ return source;
}
@Override
- public boolean allowsDynamicSplitting() {
- return false;
+ public BoundedSource<T> splitAtFraction(double fraction) {
+ Metrics.counter(BigQueryStorageStreamReader.class,
"split-at-fraction-calls").inc();
+ LOGGER.info(
+ "Received split request for stream '{}' at fraction {}.",
+ source.stream.getName(),
+ fraction);
+
+ SplitReadStreamRequest splitRequest =
+ SplitReadStreamRequest.newBuilder()
+ .setOriginalStream(source.stream)
+ // TODO(aryann): Once we rebuild the generated client code, we
should change this to
+ // use setFraction().
+ .setUnknownFields(
+ UnknownFieldSet.newBuilder()
+ .addField(
+ 2,
+ UnknownFieldSet.Field.newBuilder()
+
.addFixed32(java.lang.Float.floatToIntBits((float) fraction))
+ .build())
+ .build())
+ .build();
+ SplitReadStreamResponse splitResponse =
storageClient.splitReadStream(splitRequest);
+
+ if (!splitResponse.hasPrimaryStream() ||
!splitResponse.hasRemainderStream()) {
+ // No more splits are possible!
+ Metrics.counter(
+ BigQueryStorageStreamReader.class,
+ "split-at-fraction-calls-failed-due-to-impossible-split-point")
+ .inc();
+ LOGGER.info("Stream '{}' cannot be split at {}.",
source.stream.getName(), fraction);
+ return null;
+ }
+
+ // We may be able to split this source. Before continuing, we pause the
reader thread and
+ // replace its current source with the primary stream iff the reader has
not moved past
+ // the split point.
+ synchronized (this) {
+ BigQueryServerStream<ReadRowsResponse> newResponseStream;
+ Iterator<ReadRowsResponse> newResponseIterator;
+ try {
+ newResponseStream =
+ storageClient.readRows(
+ ReadRowsRequest.newBuilder()
+ .setReadPosition(
+ StreamPosition.newBuilder()
+ .setStream(splitResponse.getPrimaryStream())
+ .setOffset(currentOffset + 1))
+ .build());
+ newResponseIterator = newResponseStream.iterator();
+ newResponseIterator.hasNext();
+ } catch (FailedPreconditionException e) {
+ // The current source has already moved past the split point, so
this split attempt
+ // is unsuccessful.
+ Metrics.counter(
+ BigQueryStorageStreamReader.class,
+ "split-at-fraction-calls-failed-due-to-bad-split-point")
+ .inc();
+ LOGGER.info(
+ "Split of stream '{}' abandoned because the primary stream is to
the left of "
+ + "the split fraction {}.",
+ source.stream.getName(),
+ fraction);
+ return null;
+ } catch (Exception e) {
+ Metrics.counter(
+ BigQueryStorageStreamReader.class,
+ "split-at-fraction-calls-failed-due-to-other-reasons")
+ .inc();
+ throw e;
Review comment:
Can we return null instead of raising an exception here so that the reader
can continue without performing this split ? Hopefully a split operation does
not result in original stream somehow being in an inconsistent state.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 260028)
Time Spent: 50m (was: 40m)
Remaining Estimate: 503h 10m (was: 503h 20m)
> Add support for dynamic worker re-balancing when reading BigQuery data using
> Cloud Dataflow
> -------------------------------------------------------------------------------------------
>
> Key: BEAM-7495
> URL: https://issues.apache.org/jira/browse/BEAM-7495
> Project: Beam
> Issue Type: New Feature
> Components: io-java-gcp
> Reporter: Aryan Naraghi
> Assignee: Aryan Naraghi
> Priority: Major
> Original Estimate: 504h
> Time Spent: 50m
> Remaining Estimate: 503h 10m
>
> Currently, the BigQuery connector for reading data using the BigQuery Storage
> API does not support any of the facilities on the source for Dataflow to
> split streams.
>
> On the server side, the BigQuery Storage API supports splitting streams at a
> fraction. By adding support to the connector, we enable Dataflow to split
> streams, which unlocks dynamic worker re-balancing.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)