BenWhitehead commented on a change in pull request #15005: URL: https://github.com/apache/beam/pull/15005#discussion_r668061600
########## File path: sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/firestore/FirestoreV1ReadFn.java ########## @@ -0,0 +1,633 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.io.gcp.firestore; + +import static java.util.Objects.requireNonNull; + +import com.google.api.gax.paging.AbstractPage; +import com.google.api.gax.paging.AbstractPagedListResponse; +import com.google.api.gax.rpc.ServerStream; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.firestore.v1.FirestoreClient.ListCollectionIdsPage; +import com.google.cloud.firestore.v1.FirestoreClient.ListCollectionIdsPagedResponse; +import com.google.cloud.firestore.v1.FirestoreClient.ListDocumentsPage; +import com.google.cloud.firestore.v1.FirestoreClient.ListDocumentsPagedResponse; +import com.google.cloud.firestore.v1.FirestoreClient.PartitionQueryPage; +import com.google.cloud.firestore.v1.FirestoreClient.PartitionQueryPagedResponse; +import com.google.cloud.firestore.v1.stub.FirestoreStub; +import com.google.firestore.v1.BatchGetDocumentsRequest; +import com.google.firestore.v1.BatchGetDocumentsResponse; +import com.google.firestore.v1.Cursor; +import com.google.firestore.v1.ListCollectionIdsRequest; +import com.google.firestore.v1.ListCollectionIdsResponse; +import com.google.firestore.v1.ListDocumentsRequest; +import com.google.firestore.v1.ListDocumentsResponse; +import com.google.firestore.v1.PartitionQueryRequest; +import com.google.firestore.v1.PartitionQueryResponse; +import com.google.firestore.v1.RunQueryRequest; +import com.google.firestore.v1.RunQueryResponse; +import com.google.firestore.v1.StructuredQuery; +import com.google.firestore.v1.StructuredQuery.Direction; +import com.google.firestore.v1.StructuredQuery.FieldReference; +import com.google.firestore.v1.StructuredQuery.Order; +import com.google.firestore.v1.Value; +import com.google.protobuf.Message; +import com.google.protobuf.ProtocolStringList; +import java.io.Serializable; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import org.apache.beam.sdk.extensions.gcp.options.GcpOptions; +import org.apache.beam.sdk.io.gcp.firestore.FirestoreDoFn.NonWindowAwareDoFn; +import org.apache.beam.sdk.io.gcp.firestore.FirestoreV1Fn.HasRpcAttemptContext; +import org.apache.beam.sdk.io.gcp.firestore.RpcQos.RpcAttempt.Context; +import org.apache.beam.sdk.transforms.DoFn; +import org.apache.beam.sdk.transforms.display.DisplayData; +import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.joda.time.Instant; + +/** + * A collection of {@link org.apache.beam.sdk.transforms.DoFn DoFn}s for each of the supported read + * RPC methods from the Cloud Firestore V1 API. + */ +final class FirestoreV1ReadFn { + + /** + * {@link DoFn} for Firestore V1 {@link RunQueryRequest}s. + * + * <p>This Fn uses a stream to obtain responses, each response from the stream will be output to + * the next stage of the pipeline. Each response from the stream represents an individual document + * with the associated metadata. + * + * <p>If an error is encountered while reading from the stream, the stream will attempt to resume + * rather than starting over. The restarting of the stream will continue within the scope of the + * completion of the request (meaning any possibility of resumption is contingent upon an attempt + * being available in the Qos budget). + * + * <p>All request quality-of-service is managed via the instance of {@link RpcQos} associated with + * the lifecycle of this Fn. + */ + static final class RunQueryFn Review comment: On both the read and write path, if the workers is throttling for some backoff it is reported via `Metrics.counter("throttlingMs").inc(throttleDuration.getMillis())`. In the case of read, the only time a throttle would would occur is if RPCs are failing and backoff kicks in. In the case of write, in addition or RPC failure backoff, a worker can be throttled as part of write ramp up, or if RPC are not failing, but writes within those RPCs are failing and the client side adaptive throttler kicks in to try and bring the error rate down. ########## File path: sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/firestore/FirestoreDoFn.java ########## @@ -46,6 +46,22 @@ @StartBundle public abstract void startBundle(DoFn<InT, OutT>.StartBundleContext context) throws Exception; + abstract static class NonWindowAwareDoFn<InT, OutT> extends FirestoreDoFn<InT, OutT> { Review comment: Done, and I've renamed it to a more accurate name. ########## File path: sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/firestore/FirestoreV1.java ########## @@ -59,6 +89,80 @@ * * <h3>Operations</h3> * + * <h4>Read</h4> + * + * <p>The currently supported read operations and their execution behavior are as follows: + * + * <table> + * <tbody> + * <tr> + * <th>RPC</th> + * <th>Execution Behavior</th> + * </tr> + * <tr> + * <td>PartitionQuery</td> + * <td>Parallel Streaming</td> + * </tr> + * <tr> + * <td>RunQuery</td> + * <td>Sequential Streaming</td> + * </tr> + * <tr> + * <td>BatchGet</td> + * <td>Sequential Streaming</td> + * </tr> + * <tr> + * <td>ListCollectionIds</td> + * <td>Sequential Paginated</td> + * </tr> + * <tr> + * <td>ListDocuments</td> + * <td>Sequential Paginated</td> + * </tr> + * </tbody> + * </table> + * + * <p>PartitionQuery should be preferred over other options if at all possible, becuase it has the + * ability to parallelize execution of multiple queries for specific sub-ranges of the full results. + * + * <p>You should only ever use ListDocuments if the use of <a target="_blank" rel="noopener + * noreferrer" + * href="https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.ListDocumentsRequest">{@code + * show_missing}</a> is needed to access a document. RunQuery and PartitionQuery will always be + * faster if the use of {@code show_missing} is not needed. + * + * <p><b>Example Usage</b> + * + * <pre>{@code + * PCollection<PartitionQueryRequest> partitionQueryRequests = ...; Review comment: I've updated the javadocs to use links instead of just text, and also pulled the code samples up into the table which outlines the behavior and links to the class with full rpc cross links. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
