From 5bfa889ad61b336b6264f2f485829967f695393c Mon Sep 17 00:00:00 2001 From: Evan Greco Date: Mon, 26 Feb 2024 22:14:11 +0000 Subject: [PATCH 1/4] feat: Add RetrySettings use to Write API samples. --- .../bigquerystorage/WriteBufferedStream.java | 13 +++++++++++++ .../bigquerystorage/WriteCommittedStream.java | 13 +++++++++++++ .../bigquerystorage/WritePendingStream.java | 14 +++++++++++++- .../bigquerystorage/WriteToDefaultStream.java | 14 +++++++++++++- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteBufferedStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteBufferedStream.java index 26bb0d5510..3aad2d6b33 100644 --- a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteBufferedStream.java +++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteBufferedStream.java @@ -17,7 +17,9 @@ package com.example.bigquerystorage; // [START bigquerystorage_jsonstreamwriter_buffered] + import com.google.api.core.ApiFuture; +import com.google.api.gax.retrying.RetrySettings; import com.google.cloud.bigquery.storage.v1.AppendRowsResponse; import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient; import com.google.cloud.bigquery.storage.v1.CreateWriteStreamRequest; @@ -33,6 +35,7 @@ import java.util.concurrent.ExecutionException; import org.json.JSONArray; import org.json.JSONObject; +import org.threeten.bp.Duration; public class WriteBufferedStream { @@ -61,11 +64,21 @@ public static void writeBufferedStream(String projectId, String datasetName, Str .build(); WriteStream writeStream = client.createWriteStream(createWriteStreamRequest); + // Configure in-stream automatic retry settings. + RetrySettings retrySettings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(500)) + .setRetryDelayMultiplier(1.1) + .setMaxAttempts(5) + .setMaxRetryDelay(Duration.ofMinutes(1)) + .build(); + // Use the JSON stream writer to send records in JSON format. // For more information about JsonStreamWriter, see: // https://googleapis.dev/java/google-cloud-bigquerystorage/latest/com/google/cloud/bigquery/storage/v1beta2/JsonStreamWriter.html try (JsonStreamWriter writer = JsonStreamWriter.newBuilder(writeStream.getName(), writeStream.getTableSchema()) + .setRetrySettings(retrySettings) .build()) { // Write two batches to the stream, each with 10 JSON records. for (int i = 0; i < 2; i++) { diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteCommittedStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteCommittedStream.java index c8c9334374..b510a4b5f1 100644 --- a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteCommittedStream.java +++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteCommittedStream.java @@ -17,9 +17,11 @@ package com.example.bigquerystorage; // [START bigquerystorage_jsonstreamwriter_committed] + import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutureCallback; import com.google.api.core.ApiFutures; +import com.google.api.gax.retrying.RetrySettings; import com.google.cloud.bigquery.storage.v1.AppendRowsResponse; import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient; import com.google.cloud.bigquery.storage.v1.CreateWriteStreamRequest; @@ -37,6 +39,7 @@ import javax.annotation.concurrent.GuardedBy; import org.json.JSONArray; import org.json.JSONObject; +import org.threeten.bp.Duration; public class WriteCommittedStream { @@ -113,11 +116,21 @@ void initialize(TableName parentTable, BigQueryWriteClient client) .build(); WriteStream writeStream = client.createWriteStream(createWriteStreamRequest); + // Configure in-stream automatic retry settings. + RetrySettings retrySettings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(500)) + .setRetryDelayMultiplier(1.1) + .setMaxAttempts(5) + .setMaxRetryDelay(Duration.ofMinutes(1)) + .build(); + // Use the JSON stream writer to send records in JSON format. // For more information about JsonStreamWriter, see: // https://googleapis.dev/java/google-cloud-bigquerystorage/latest/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.html streamWriter = JsonStreamWriter.newBuilder(writeStream.getName(), writeStream.getTableSchema(), client) + .setRetrySettings(retrySettings) .build(); } diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java index 76f59a0e17..3a74f1558a 100644 --- a/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java +++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java @@ -21,6 +21,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutureCallback; import com.google.api.core.ApiFutures; +import com.google.api.gax.retrying.RetrySettings; import com.google.cloud.bigquery.storage.v1.AppendRowsResponse; import com.google.cloud.bigquery.storage.v1.BatchCommitWriteStreamsRequest; import com.google.cloud.bigquery.storage.v1.BatchCommitWriteStreamsResponse; @@ -41,6 +42,7 @@ import javax.annotation.concurrent.GuardedBy; import org.json.JSONArray; import org.json.JSONObject; +import org.threeten.bp.Duration; public class WritePendingStream { @@ -129,6 +131,15 @@ void initialize(TableName parentTable, BigQueryWriteClient client) // https://googleapis.dev/java/google-cloud-bigquerystorage/latest/com/google/cloud/bigquery/storage/v1/WriteStream.Type.html WriteStream stream = WriteStream.newBuilder().setType(WriteStream.Type.PENDING).build(); + // Configure in-stream automatic retry settings. + RetrySettings retrySettings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(500)) + .setRetryDelayMultiplier(1.1) + .setMaxAttempts(5) + .setMaxRetryDelay(Duration.ofMinutes(1)) + .build(); + CreateWriteStreamRequest createWriteStreamRequest = CreateWriteStreamRequest.newBuilder() .setParent(parentTable.toString()) @@ -140,7 +151,8 @@ void initialize(TableName parentTable, BigQueryWriteClient client) // For more information about JsonStreamWriter, see: // https://googleapis.dev/java/google-cloud-bigquerystorage/latest/com/google/cloud/bigquery/storage/v1beta2/JsonStreamWriter.html streamWriter = - JsonStreamWriter.newBuilder(writeStream.getName(), writeStream.getTableSchema()).build(); + JsonStreamWriter.newBuilder(writeStream.getName(), writeStream.getTableSchema()) + .setRetrySettings(retrySettings).build(); } public void append(JSONArray data, long offset) diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java index feccef61f0..a368a9d546 100644 --- a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java +++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java @@ -22,6 +22,7 @@ import com.google.api.core.ApiFutureCallback; import com.google.api.core.ApiFutures; import com.google.api.gax.core.FixedExecutorProvider; +import com.google.api.gax.retrying.RetrySettings; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.BigQueryOptions; import com.google.cloud.bigquery.QueryJobConfiguration; @@ -49,6 +50,7 @@ import javax.annotation.concurrent.GuardedBy; import org.json.JSONArray; import org.json.JSONObject; +import org.threeten.bp.Duration; public class WriteToDefaultStream { @@ -62,7 +64,7 @@ public static void runWriteToDefaultStream() } private static ByteString buildByteString() { - byte[] bytes = new byte[] {1, 2, 3, 4, 5}; + byte[] bytes = new byte[]{1, 2, 3, 4, 5}; return ByteString.copyFrom(bytes); } @@ -163,6 +165,15 @@ private static class DataWriter { public void initialize(TableName parentTable) throws DescriptorValidationException, IOException, InterruptedException { + // Configure in-stream automatic retry settings. + RetrySettings retrySettings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(500)) + .setRetryDelayMultiplier(1.1) + .setMaxAttempts(5) + .setMaxRetryDelay(Duration.ofMinutes(1)) + .build(); + // Use the JSON stream writer to send records in JSON format. Specify the table name to write // to the default stream. // For more information about JsonStreamWriter, see: @@ -183,6 +194,7 @@ public void initialize(TableName parentTable) // column, apply the default value to the missing value field. .setDefaultMissingValueInterpretation( AppendRowsRequest.MissingValueInterpretation.DEFAULT_VALUE) + .setRetrySettings(retrySettings) .build(); } From 46e2891674e4dc6fac6ee0ce7ce5d4c92bee1a8a Mon Sep 17 00:00:00 2001 From: Evan Greco Date: Tue, 27 Feb 2024 17:14:53 +0000 Subject: [PATCH 2/4] Add RetrySettings to the rest of samples. Also move manual retry out of default sample. --- .../bigquery/storage/v1/JsonStreamWriter.java | 2 +- .../bigquerystorage/JsonWriterStreamCdc.java | 18 +++++++- .../ParallelWriteCommittedStream.java | 20 +++++++-- .../bigquerystorage/WriteBufferedStream.java | 4 ++ .../bigquerystorage/WriteCommittedStream.java | 4 ++ .../bigquerystorage/WritePendingStream.java | 4 ++ .../bigquerystorage/WriteToDefaultStream.java | 41 ++++--------------- 7 files changed, 54 insertions(+), 39 deletions(-) diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java index 0e8d669764..b507934b41 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java @@ -362,7 +362,7 @@ public Builder setCompressorName(String compressorName) { * Enable client lib automatic retries on request level errors. * *
-     * Immeidate Retry code:
+     * Immediate Retry code:
      * ABORTED, UNAVAILABLE, CANCELLED, INTERNAL, DEADLINE_EXCEEDED
      * Backoff Retry code:
      * RESOURCE_EXHAUSTED
diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/JsonWriterStreamCdc.java b/samples/snippets/src/main/java/com/example/bigquerystorage/JsonWriterStreamCdc.java
index fef48095a2..6b9edb9477 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/JsonWriterStreamCdc.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/JsonWriterStreamCdc.java
@@ -19,6 +19,7 @@
 import com.google.api.core.ApiFuture;
 import com.google.api.core.ApiFutureCallback;
 import com.google.api.core.ApiFutures;
+import com.google.api.gax.retrying.RetrySettings;
 import com.google.cloud.bigquery.BigQuery;
 import com.google.cloud.bigquery.BigQueryException;
 import com.google.cloud.bigquery.BigQueryOptions;
@@ -37,6 +38,7 @@
 import java.io.IOException;
 import org.json.JSONArray;
 import org.json.JSONObject;
+import org.threeten.bp.Duration;
 
 public class JsonWriterStreamCdc {
 
@@ -108,6 +110,18 @@ private static void query(String query) {
   public static void writeToDefaultStream(
       String projectId, String datasetName, String tableName, JSONArray data)
       throws DescriptorValidationException, InterruptedException, IOException {
+    // Configure in-stream automatic retry settings.
+    // Error codes that are immediately retried:
+    // * ABORTED, UNAVAILABLE, CANCELLED, INTERNAL, DEADLINE_EXCEEDED
+    // Error codes that are retried with exponential backoff:
+    // * RESOURCE_EXHAUSTED
+    RetrySettings retrySettings =
+        RetrySettings.newBuilder()
+            .setInitialRetryDelay(Duration.ofMillis(500))
+            .setRetryDelayMultiplier(1.1)
+            .setMaxAttempts(5)
+            .setMaxRetryDelay(Duration.ofMinutes(1))
+            .build();
     // To use the UPSERT functionality, the table schema needs to be padded with an additional
     // column "_change_type".
     TableSchema tableSchema =
@@ -159,7 +173,8 @@ public static void writeToDefaultStream(
     // Use the JSON stream writer to send records in JSON format.
     TableName parentTable = TableName.of(projectId, datasetName, tableName);
     try (JsonStreamWriter writer =
-        JsonStreamWriter.newBuilder(parentTable.toString(), tableSchema).build()) {
+        JsonStreamWriter.newBuilder(parentTable.toString(), tableSchema)
+            .setRetrySettings(retrySettings).build()) {
 
       ApiFuture future = writer.append(data);
       // The append method is asynchronous. Rather than waiting for the method to complete,
@@ -184,6 +199,7 @@ public static JSONArray getRecordsFromDataFile(String dataFile)
   }
 
   static class AppendCompleteCallback implements ApiFutureCallback {
+
     private static final Object lock = new Object();
     private static int batchCount = 0;
 
diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/ParallelWriteCommittedStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/ParallelWriteCommittedStream.java
index d7949e38cd..43c2aa8ce3 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/ParallelWriteCommittedStream.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/ParallelWriteCommittedStream.java
@@ -20,6 +20,7 @@
 import com.google.api.core.ApiFuture;
 import com.google.api.core.ApiFutureCallback;
 import com.google.api.core.ApiFutures;
+import com.google.api.gax.retrying.RetrySettings;
 import com.google.cloud.bigquery.storage.v1.AppendRowsResponse;
 import com.google.cloud.bigquery.storage.v1.BQTableSchemaToProtoDescriptor;
 import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient;
@@ -36,12 +37,12 @@
 import com.google.protobuf.Descriptors.DescriptorValidationException;
 import com.google.protobuf.Message;
 import java.io.IOException;
-import java.time.Duration;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.logging.Logger;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.GuardedBy;
 import org.json.JSONObject;
+import org.threeten.bp.Duration;
 
 public class ParallelWriteCommittedStream {
 
@@ -157,6 +158,18 @@ private void writeToStream(
       lastMetricsSuccessCount = 0;
       lastMetricsFailureCount = 0;
     }
+    // Configure in-stream automatic retry settings.
+    // Error codes that are immediately retried:
+    // * ABORTED, UNAVAILABLE, CANCELLED, INTERNAL, DEADLINE_EXCEEDED
+    // Error codes that are retried with exponential backoff:
+    // * RESOURCE_EXHAUSTED
+    RetrySettings retrySettings =
+        RetrySettings.newBuilder()
+            .setInitialRetryDelay(Duration.ofMillis(500))
+            .setRetryDelayMultiplier(1.1)
+            .setMaxAttempts(5)
+            .setMaxRetryDelay(Duration.ofMinutes(1))
+            .build();
     Descriptor descriptor =
         BQTableSchemaToProtoDescriptor.convertBQTableSchemaToProtoDescriptor(
             writeStream.getTableSchema());
@@ -164,6 +177,7 @@ private void writeToStream(
     try (StreamWriter writer =
         StreamWriter.newBuilder(writeStream.getName())
             .setWriterSchema(protoSchema)
+            .setRetrySettings(retrySettings)
             .setTraceId("SAMPLE:parallel_append")
             .build()) {
       while (System.currentTimeMillis() < deadlineMillis) {
@@ -255,8 +269,8 @@ public void onSuccess(@Nullable AppendRowsResponse response) {
                   + metricsTimeMillis
                   + "ms. Successful MB Per Second: "
                   + (double) (successCountInIteration * BATCH_SIZE * ROW_SIZE)
-                      / metricsTimeMillis
-                      / 1000
+                  / metricsTimeMillis
+                  / 1000
                   + " Current inflight: "
                   + parent.inflightCount);
           parent.lastMetricsTimeMillis = System.currentTimeMillis();
diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteBufferedStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteBufferedStream.java
index 3aad2d6b33..749af8d718 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteBufferedStream.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteBufferedStream.java
@@ -65,6 +65,10 @@ public static void writeBufferedStream(String projectId, String datasetName, Str
       WriteStream writeStream = client.createWriteStream(createWriteStreamRequest);
 
       // Configure in-stream automatic retry settings.
+      // Error codes that are immediately retried:
+      // * ABORTED, UNAVAILABLE, CANCELLED, INTERNAL, DEADLINE_EXCEEDED
+      // Error codes that are retried with exponential backoff:
+      // * RESOURCE_EXHAUSTED
       RetrySettings retrySettings =
           RetrySettings.newBuilder()
               .setInitialRetryDelay(Duration.ofMillis(500))
diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteCommittedStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteCommittedStream.java
index b510a4b5f1..bc82613933 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteCommittedStream.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteCommittedStream.java
@@ -117,6 +117,10 @@ void initialize(TableName parentTable, BigQueryWriteClient client)
       WriteStream writeStream = client.createWriteStream(createWriteStreamRequest);
 
       // Configure in-stream automatic retry settings.
+      // Error codes that are immediately retried:
+      // * ABORTED, UNAVAILABLE, CANCELLED, INTERNAL, DEADLINE_EXCEEDED
+      // Error codes that are retried with exponential backoff:
+      // * RESOURCE_EXHAUSTED
       RetrySettings retrySettings =
           RetrySettings.newBuilder()
               .setInitialRetryDelay(Duration.ofMillis(500))
diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java
index 3a74f1558a..2569784963 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java
@@ -132,6 +132,10 @@ void initialize(TableName parentTable, BigQueryWriteClient client)
       WriteStream stream = WriteStream.newBuilder().setType(WriteStream.Type.PENDING).build();
 
       // Configure in-stream automatic retry settings.
+      // Error codes that are immediately retried:
+      // * ABORTED, UNAVAILABLE, CANCELLED, INTERNAL, DEADLINE_EXCEEDED
+      // Error codes that are retried with exponential backoff:
+      // * RESOURCE_EXHAUSTED
       RetrySettings retrySettings =
           RetrySettings.newBuilder()
               .setInitialRetryDelay(Duration.ofMillis(500))
diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java
index a368a9d546..f82526105f 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java
@@ -99,7 +99,7 @@ public static void writeToDefaultStream(String projectId, String datasetName, St
         jsonArr.put(record);
       }
 
-      writer.append(new AppendContext(jsonArr, 0));
+      writer.append(new AppendContext(jsonArr));
     }
 
     // Final cleanup for the stream during worker teardown.
@@ -132,26 +132,15 @@ private static void verifyExpectedRowCount(TableName parentTable, int expectedRo
   private static class AppendContext {
 
     JSONArray data;
-    int retryCount = 0;
 
-    AppendContext(JSONArray data, int retryCount) {
+    AppendContext(JSONArray data) {
       this.data = data;
-      this.retryCount = retryCount;
     }
   }
 
   private static class DataWriter {
 
-    private static final int MAX_RETRY_COUNT = 3;
     private static final int MAX_RECREATE_COUNT = 3;
-    private static final ImmutableList RETRIABLE_ERROR_CODES =
-        ImmutableList.of(
-            Code.INTERNAL,
-            Code.ABORTED,
-            Code.CANCELLED,
-            Code.FAILED_PRECONDITION,
-            Code.DEADLINE_EXCEEDED,
-            Code.UNAVAILABLE);
 
     // Track the number of in-flight requests to wait for all responses before shutting down.
     private final Phaser inflightRequestCount = new Phaser(1);
@@ -166,6 +155,10 @@ private static class DataWriter {
     public void initialize(TableName parentTable)
         throws DescriptorValidationException, IOException, InterruptedException {
       // Configure in-stream automatic retry settings.
+      // Error codes that are immediately retried:
+      // * ABORTED, UNAVAILABLE, CANCELLED, INTERNAL, DEADLINE_EXCEEDED
+      // Error codes that are retried with exponential backoff:
+      // * RESOURCE_EXHAUSTED
       RetrySettings retrySettings =
           RetrySettings.newBuilder()
               .setInitialRetryDelay(Duration.ofMillis(500))
@@ -256,26 +249,6 @@ public void onSuccess(AppendRowsResponse response) {
       }
 
       public void onFailure(Throwable throwable) {
-        // If the wrapped exception is a StatusRuntimeException, check the state of the operation.
-        // If the state is INTERNAL, CANCELLED, or ABORTED, you can retry. For more information,
-        // see: https://grpc.github.io/grpc-java/javadoc/io/grpc/StatusRuntimeException.html
-        Status status = Status.fromThrowable(throwable);
-        if (appendContext.retryCount < MAX_RETRY_COUNT
-            && RETRIABLE_ERROR_CODES.contains(status.getCode())) {
-          appendContext.retryCount++;
-          try {
-            // Since default stream appends are not ordered, we can simply retry the appends.
-            // Retrying with exclusive streams requires more careful consideration.
-            this.parent.append(appendContext);
-            // Mark the existing attempt as done since it's being retried.
-            done();
-            return;
-          } catch (Exception e) {
-            // Fall through to return error.
-            System.out.format("Failed to retry append: %s\n", e);
-          }
-        }
-
         if (throwable instanceof AppendSerializationError) {
           AppendSerializationError ase = (AppendSerializationError) throwable;
           Map rowIndexToErrorMessage = ase.getRowIndexToErrorMessage();
@@ -294,7 +267,7 @@ public void onFailure(Throwable throwable) {
             // avoid potentially blocking while we are in a callback.
             if (dataNew.length() > 0) {
               try {
-                this.parent.append(new AppendContext(dataNew, 0));
+                this.parent.append(new AppendContext(dataNew));
               } catch (DescriptorValidationException e) {
                 throw new RuntimeException(e);
               } catch (IOException e) {

From bc5da15219e112bcd0ef5b340220518cc1174169 Mon Sep 17 00:00:00 2001
From: Evan Greco 
Date: Tue, 27 Feb 2024 17:20:54 +0000
Subject: [PATCH 3/4] Cleanup overzealous auto formatting

---
 .../java/com/example/bigquerystorage/JsonWriterStreamCdc.java | 1 -
 .../example/bigquerystorage/ParallelWriteCommittedStream.java | 4 ++--
 .../java/com/example/bigquerystorage/WriteBufferedStream.java | 1 -
 .../com/example/bigquerystorage/WriteCommittedStream.java     | 1 -
 .../java/com/example/bigquerystorage/WritePendingStream.java  | 1 -
 .../com/example/bigquerystorage/WriteToDefaultStream.java     | 1 -
 6 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/JsonWriterStreamCdc.java b/samples/snippets/src/main/java/com/example/bigquerystorage/JsonWriterStreamCdc.java
index 6b9edb9477..f7b2ed50c3 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/JsonWriterStreamCdc.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/JsonWriterStreamCdc.java
@@ -199,7 +199,6 @@ public static JSONArray getRecordsFromDataFile(String dataFile)
   }
 
   static class AppendCompleteCallback implements ApiFutureCallback {
-
     private static final Object lock = new Object();
     private static int batchCount = 0;
 
diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/ParallelWriteCommittedStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/ParallelWriteCommittedStream.java
index 43c2aa8ce3..3680e43307 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/ParallelWriteCommittedStream.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/ParallelWriteCommittedStream.java
@@ -269,8 +269,8 @@ public void onSuccess(@Nullable AppendRowsResponse response) {
                   + metricsTimeMillis
                   + "ms. Successful MB Per Second: "
                   + (double) (successCountInIteration * BATCH_SIZE * ROW_SIZE)
-                  / metricsTimeMillis
-                  / 1000
+                      / metricsTimeMillis
+                      / 1000
                   + " Current inflight: "
                   + parent.inflightCount);
           parent.lastMetricsTimeMillis = System.currentTimeMillis();
diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteBufferedStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteBufferedStream.java
index 749af8d718..718b5373d6 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteBufferedStream.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteBufferedStream.java
@@ -17,7 +17,6 @@
 package com.example.bigquerystorage;
 
 // [START bigquerystorage_jsonstreamwriter_buffered]
-
 import com.google.api.core.ApiFuture;
 import com.google.api.gax.retrying.RetrySettings;
 import com.google.cloud.bigquery.storage.v1.AppendRowsResponse;
diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteCommittedStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteCommittedStream.java
index bc82613933..b2dfe21b00 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteCommittedStream.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteCommittedStream.java
@@ -17,7 +17,6 @@
 package com.example.bigquerystorage;
 
 // [START bigquerystorage_jsonstreamwriter_committed]
-
 import com.google.api.core.ApiFuture;
 import com.google.api.core.ApiFutureCallback;
 import com.google.api.core.ApiFutures;
diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java
index 2569784963..42179f93f2 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java
@@ -17,7 +17,6 @@
 package com.example.bigquerystorage;
 
 // [START bigquerystorage_jsonstreamwriter_pending]
-
 import com.google.api.core.ApiFuture;
 import com.google.api.core.ApiFutureCallback;
 import com.google.api.core.ApiFutures;
diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java
index f82526105f..9307208bc3 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java
@@ -17,7 +17,6 @@
 package com.example.bigquerystorage;
 
 // [START bigquerystorage_jsonstreamwriter_default]
-
 import com.google.api.core.ApiFuture;
 import com.google.api.core.ApiFutureCallback;
 import com.google.api.core.ApiFutures;

From 322cdbffc3b4b6c428994fa5e1b805a446c55194 Mon Sep 17 00:00:00 2001
From: Owl Bot 
Date: Tue, 27 Feb 2024 19:34:54 +0000
Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?=
 =?UTF-8?q?st-processor?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
---
 .../com/example/bigquerystorage/JsonWriterStreamCdc.java     | 3 ++-
 .../java/com/example/bigquerystorage/WritePendingStream.java | 3 ++-
 .../com/example/bigquerystorage/WriteToDefaultStream.java    | 5 +----
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/JsonWriterStreamCdc.java b/samples/snippets/src/main/java/com/example/bigquerystorage/JsonWriterStreamCdc.java
index f7b2ed50c3..0ba37ba13d 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/JsonWriterStreamCdc.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/JsonWriterStreamCdc.java
@@ -174,7 +174,8 @@ public static void writeToDefaultStream(
     TableName parentTable = TableName.of(projectId, datasetName, tableName);
     try (JsonStreamWriter writer =
         JsonStreamWriter.newBuilder(parentTable.toString(), tableSchema)
-            .setRetrySettings(retrySettings).build()) {
+            .setRetrySettings(retrySettings)
+            .build()) {
 
       ApiFuture future = writer.append(data);
       // The append method is asynchronous. Rather than waiting for the method to complete,
diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java
index 42179f93f2..e8de163ed5 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WritePendingStream.java
@@ -155,7 +155,8 @@ void initialize(TableName parentTable, BigQueryWriteClient client)
       // https://googleapis.dev/java/google-cloud-bigquerystorage/latest/com/google/cloud/bigquery/storage/v1beta2/JsonStreamWriter.html
       streamWriter =
           JsonStreamWriter.newBuilder(writeStream.getName(), writeStream.getTableSchema())
-              .setRetrySettings(retrySettings).build();
+              .setRetrySettings(retrySettings)
+              .build();
     }
 
     public void append(JSONArray data, long offset)
diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java
index 9307208bc3..6c35f06018 100644
--- a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java
+++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java
@@ -35,12 +35,9 @@
 import com.google.cloud.bigquery.storage.v1.Exceptions.StorageException;
 import com.google.cloud.bigquery.storage.v1.JsonStreamWriter;
 import com.google.cloud.bigquery.storage.v1.TableName;
-import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.MoreExecutors;
 import com.google.protobuf.ByteString;
 import com.google.protobuf.Descriptors.DescriptorValidationException;
-import io.grpc.Status;
-import io.grpc.Status.Code;
 import java.io.IOException;
 import java.util.Map;
 import java.util.concurrent.Executors;
@@ -63,7 +60,7 @@ public static void runWriteToDefaultStream()
   }
 
   private static ByteString buildByteString() {
-    byte[] bytes = new byte[]{1, 2, 3, 4, 5};
+    byte[] bytes = new byte[] {1, 2, 3, 4, 5};
     return ByteString.copyFrom(bytes);
   }