Skip to content

Commit

Permalink
chore: Give methods in CloudSqlInstance names that better reflect the…
Browse files Browse the repository at this point in the history
…ir new async roles.
  • Loading branch information
hessjcg committed Sep 8, 2023
1 parent 86f06c8 commit 8519aff
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions core/src/main/java/com/google/cloud/sql/core/CloudSqlInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ class CloudSqlInstance {
}

synchronized (instanceDataGuard) {
this.currentInstanceData = this.performRefresh();
this.currentInstanceData = this.startRefreshAttempt();
this.nextInstanceData = currentInstanceData;
}
}

/**
* Returns the current data related to the instance from {@link #performRefresh()}. May block if
* no valid data is currently available.
* Returns the current data related to the instance from {@link #startRefreshAttempt()}. May block
* if no valid data is currently available.
*/
private InstanceData getInstanceData() {
ListenableFuture<InstanceData> instanceDataFuture;
Expand Down Expand Up @@ -187,7 +187,7 @@ void forceRefresh() {
"[%s] Force Refresh: the next refresh operation was cancelled."
+ " Scheduling new refresh operation immediately.",
instanceName));
currentInstanceData = this.performRefresh();
currentInstanceData = this.startRefreshAttempt();
nextInstanceData = currentInstanceData;
}
}
Expand All @@ -198,10 +198,10 @@ void forceRefresh() {
* futures that will 1. Acquire a rate limiter. 2. Attempt to fetch instance data. 3. Schedule the
* next attempt to get instance data based on the success/failure of this attempt.
*
* @see com.google.cloud.sql.core.CloudSqlInstance#rescheduleAfterGetInstanceData(
* @see com.google.cloud.sql.core.CloudSqlInstance#handleRefreshResult(
* com.google.common.util.concurrent.ListenableFuture)
*/
private ListenableFuture<InstanceData> performRefresh() {
private ListenableFuture<InstanceData> startRefreshAttempt() {

// To avoid unreasonable SQL Admin API usage, use a rate limit to throttle our usage.
ListenableFuture rateLimit =
Expand Down Expand Up @@ -234,13 +234,13 @@ private ListenableFuture<InstanceData> performRefresh() {
// Finally, reschedule refresh after getInstanceData is complete.
ListenableFuture<InstanceData> rescheduleFuture =
Futures.whenAllComplete(dataFuture)
.callAsync(() -> rescheduleAfterGetInstanceData(dataFuture), executor);
.callAsync(() -> handleRefreshResult(dataFuture), executor);

return rescheduleFuture;
}

private ListenableFuture<InstanceData> rescheduleAfterGetInstanceData(
ListenableFuture<InstanceData> dataFuture) throws ExecutionException, InterruptedException {
private ListenableFuture<InstanceData> handleRefreshResult(
ListenableFuture<InstanceData> dataFuture) {
try {
// This does not block, because it only gets called when dataFuture has completed.
// This will throw an exception if the refresh attempt has failed.
Expand Down Expand Up @@ -274,7 +274,7 @@ private ListenableFuture<InstanceData> rescheduleAfterGetInstanceData(
ListenableFuture scheduleDelay =
executor.schedule(() -> {}, secondsToRefresh, TimeUnit.SECONDS);
nextInstanceData =
Futures.whenAllComplete(scheduleDelay).callAsync(this::performRefresh, executor);
Futures.whenAllComplete(scheduleDelay).callAsync(this::startRefreshAttempt, executor);

// Resolves to an InstanceData immediately
return currentInstanceData;
Expand All @@ -289,7 +289,7 @@ private ListenableFuture<InstanceData> rescheduleAfterGetInstanceData(
e);
synchronized (instanceDataGuard) {
currentRefreshFailure = e;
nextInstanceData = this.performRefresh();
nextInstanceData = this.startRefreshAttempt();

// Resolves after the next successful refresh attempt.
return nextInstanceData;
Expand Down

0 comments on commit 8519aff

Please sign in to comment.