FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: handling of totalTimeout on sql plan refresh by jackdingilian · Pull Request #2541 · googleapis/java-bigtable · GitHub

This repository was archived by the owner on May 8, 2026. It is now read-only.
/ java-bigtable Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.cloud.bigtable.data.v2.models.sql.PreparedStatementRefreshTimeoutException;
import com.google.cloud.bigtable.data.v2.models.sql.ResultSetMetadata;
import com.google.cloud.bigtable.data.v2.stub.SafeResponseObserver;
import com.google.common.annotations.VisibleForTesting;
import com.google.rpc.PreconditionFailure;
import com.google.rpc.PreconditionFailure.Violation;
import io.grpc.Deadline;
Expand Down Expand Up @@ -104,7 +105,8 @@ public void call(

// Checks for an attempt timeout first, then a total timeout. If found, converts the timeout
// to an absolute deadline. Adjusts totalTimeout based on the time since startTimeOfOverallRequest
private static @Nullable Deadline getDeadline(
@VisibleForTesting
static @Nullable Deadline getDeadline(
GrpcCallContext grpcCallContext, Instant startTimeOfOverallRequest) {
Optional<Deadline> attemptDeadline =
Optional.ofNullable(grpcCallContext)
Expand All @@ -123,7 +125,7 @@ public void call(
Duration elapsedTime = Duration.between(startTimeOfOverallRequest, Instant.now());
Duration remaining = d.minus(elapsedTime);
// zero is treated as no deadline, so if full deadline is elapsed pass 1 nano
long adjusted = Math.max(remaining.getNano(), 1);
long adjusted = Math.max(remaining.toNanos(), 1);
return Deadline.after(adjusted, TimeUnit.NANOSECONDS);
})
.orElse(null);
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import io.grpc.Deadline;
import io.grpc.Status.Code;
import java.time.Duration;
import java.time.Instant;
import java.util.Collections;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -282,4 +283,47 @@ public void planRefreshDelayIsFactoredIntoExecuteTimeout() throws InterruptedExc
Deadline executeDeadline = grpcCallContext.getCallOptions().getDeadline();
assertThat(executeDeadline.isBefore(paddedDeadlineAtStartOfCall)).isTrue();
}

@Test
public void testGetDeadlineWithAttemptTimeout() {
GrpcCallContext callContext =
GrpcCallContext.createDefault().withTimeoutDuration(Duration.ofMinutes(1));
// startTimeOfOverallRequest doesn't matter here
Deadline deadline = PlanRefreshingCallable.getDeadline(callContext, Instant.now());
long millisRemaining = deadline.timeRemaining(TimeUnit.MILLISECONDS);
assertThat(millisRemaining).isLessThan((60 * 1000) + 1);
// Give some padding in case tests are very slow
assertThat(millisRemaining).isGreaterThan(58 * 1000);
}

@Test
public void testGetDeadlineWithTotalTimeout() {
GrpcCallContext callContext =
GrpcCallContext.createDefault()
.withRetrySettings(
RetrySettings.newBuilder()
.setTotalTimeout(org.threeten.bp.Duration.ofMinutes(1))
.build());
Deadline deadline = PlanRefreshingCallable.getDeadline(callContext, Instant.now());
long millisRemaining = deadline.timeRemaining(TimeUnit.MILLISECONDS);
assertThat(millisRemaining).isLessThan((60 * 1000) + 1);
// Give some padding in case tests are very slow
assertThat(millisRemaining).isGreaterThan(58 * 1000);
}

@Test
public void testAttemptTimeoutUsedOverTotalTimeout() {
GrpcCallContext callContext =
GrpcCallContext.createDefault()
.withTimeoutDuration(Duration.ofMinutes(1))
.withRetrySettings(
RetrySettings.newBuilder()
.setTotalTimeout(org.threeten.bp.Duration.ofHours(1))
.build());
Deadline deadline = PlanRefreshingCallable.getDeadline(callContext, Instant.now());
long millisRemaining = deadline.timeRemaining(TimeUnit.MILLISECONDS);
assertThat(millisRemaining).isLessThan((60 * 1000) + 1);
// Give some padding in case tests are very slow
assertThat(millisRemaining).isGreaterThan(58 * 1000);
}
}

Back | FazBrowse Home | New Git URL