Skip to content

Commit

Permalink
fix: remove teh 30 minutes wait trying to refresh schema. Customers s… (
Browse files Browse the repository at this point in the history
#2088)

* fix: remove teh 30 minutes wait trying to refresh schema. Customers should be ready to handle InvalidArgumentErrors, and removing the wait and retry can reduce their chance to get stuck

* .

* .

* .

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
yirutang and gcf-owl-bot[bot] committed Apr 26, 2023
1 parent f6651dc commit 3ec294f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ implementation 'com.google.cloud:google-cloud-bigquerystorage'
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-bigquerystorage:2.35.0'
implementation 'com.google.cloud:google-cloud-bigquerystorage:2.36.0'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-bigquerystorage" % "2.35.0"
libraryDependencies += "com.google.cloud" % "google-cloud-bigquerystorage" % "2.36.0"
```
<!-- {x-version-update-end} -->

Expand Down Expand Up @@ -220,7 +220,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigquerystorage/java11.html
[stability-image]: https://img.shields.io/badge/stability-stable-green
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-bigquerystorage.svg
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquerystorage/2.35.0
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquerystorage/2.36.0
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
*/
public class SchemaAwareStreamWriter<T> implements AutoCloseable {
private static final Logger LOG = Logger.getLogger(SchemaAwareStreamWriter.class.getName());
private static final long UPDATE_SCHEMA_RETRY_INTERVAL_MILLIS = 30100L;
private final BigQueryWriteClient client;
private final String streamName;
private final StreamWriter.Builder streamWriterBuilder;
Expand Down Expand Up @@ -126,9 +125,6 @@ private Message buildMessage(T item)
return this.toProtoConverter.convertToProtoMessage(
this.descriptor, this.tableSchema, item, ignoreUnknownFields);
} catch (Exceptions.DataHasUnknownFieldException ex) {
// Backend cache for GetWriteStream schema staleness can be 30 seconds, wait a bit before
// trying to get the table schema to increase the chance of succeed. This is to avoid
// client's invalid datfa caused storm of GetWriteStream.
LOG.warning(
"Saw unknown field "
+ ex.getFieldName()
Expand All @@ -141,21 +137,8 @@ private Message buildMessage(T item)
.build();
WriteStream writeStream = client.getWriteStream(writeStreamRequest);
refreshWriter(writeStream.getTableSchema());
try {
return this.toProtoConverter.convertToProtoMessage(
this.descriptor, this.tableSchema, item, ignoreUnknownFields);
} catch (Exceptions.DataHasUnknownFieldException exex) {
LOG.warning(
"First attempt failed, waiting for 30 seconds to retry, stream: " + this.streamName);
Thread.sleep(UPDATE_SCHEMA_RETRY_INTERVAL_MILLIS);
writeStream = client.getWriteStream(writeStreamRequest);
// TODO(yiru): We should let TableSchema return a timestamp so that we can simply
// compare the timestamp to see if the table schema is the same. If it is the
// same, we don't need to go refresh the writer again.
refreshWriter(writeStream.getTableSchema());
return this.toProtoConverter.convertToProtoMessage(
this.descriptor, this.tableSchema, item, ignoreUnknownFields);
}
return this.toProtoConverter.convertToProtoMessage(
this.descriptor, this.tableSchema, item, ignoreUnknownFields);
}
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,7 @@ public void testWithoutIgnoreUnknownFieldsUpdateSecondSuccess() throws Exception
.setType(TableFieldSchema.Type.STRING)
.setMode(Mode.NULLABLE))
.build();
// GetWriteStream is called twice and got the updated schema
testBigQueryWrite.addResponse(
WriteStream.newBuilder().setName(TEST_STREAM).setTableSchema(tableSchema).build());
// GetWriteStream is called once and got the updated schema
testBigQueryWrite.addResponse(
WriteStream.newBuilder().setName(TEST_STREAM).setTableSchema(updatedSchema).build());
testBigQueryWrite.addResponse(
Expand Down

0 comments on commit 3ec294f

Please sign in to comment.