Repository navigation
Conversation
…pre-compile regexes in BigQueryRetryAlgorithm
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary & Bottleneck
Every RPC invoked through
BigQueryRetryHelper.runWithRetriescallsBigQueryRetryAlgorithm.shouldRetry(Throwable, ResponseT, TimedAttemptSettings)(java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryRetryAlgorithm.java:L82-L90). On every retry check (including the initialcreateFirstAttempt()call wherenextAttemptSettings == nullon every single RPC),shouldRetryevaluatedshouldRetryBasedOnResult(previousThrowable, previousResponse)andshouldRetryBasedOnBigQueryRetryConfig(previousThrowable, previousResponse, bigQueryRetryConfig)before checkingnextAttemptSettings != null, AND then evaluated both predicates a second time inside thereturnstatement. Furthermore,matchRegEx(BigQueryRetryAlgorithm.java:L164-L176) calledPattern.compile(regEx, Pattern.CASE_INSENSITIVE)on every retry evaluation,matchErrorMessages(BigQueryRetryAlgorithm.java:L149-L162) called.toLowerCase()on every configured error message string on every retry check, andBigQueryImpl.create(JobInfo, JobOption...)(java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java:L458) compiledPattern.compile("Already Exists: Job (.+):(.+)\\.(.+)", Pattern.CASE_INSENSITIVE)inline.Changes
BigQueryRetryAlgorithm.shouldRetry(java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryRetryAlgorithm.java) to returnfalseimmediately whennextAttemptSettings == nulland evaluate the retry predicates once instead of twice.ImmutableSet<String> lowerCaseRetriableErrorMessagesandImmutableList<Pattern> compiledRetriableRegExesinsideBigQueryRetryConfig(java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryRetryConfig.java) at config construction time, and use them inBigQueryRetryAlgorithm.matchErrorMessagesandBigQueryRetryAlgorithm.matchRegEx.ALREADY_EXISTS_JOB_PATTERNas aprivate static final Patternconstant inBigQueryImpl(java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java).Expected Impact
Pattern.compile(...)and per-config-entryString.toLowerCase(...)allocations.Verification
mvn test -pl java-bigquery/google-cloud-bigquery -Dtest=BigQueryImplTest -Dclirr.skip=true -Denforcer.skip=true -Dcheckstyle.skip=true(151 tests passing).