Skip to content

Commit

Permalink
fix: Add a timeout to getTopicPartitionCount (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpcollins-google committed Dec 9, 2021
1 parent b6fbe65 commit 0301d55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ If you are using Maven, add this to your pom.xml file:
If you are using Gradle without BOM, add this to your dependencies

```Groovy
implementation 'com.google.cloud:google-cloud-pubsublite:1.4.2'
implementation 'com.google.cloud:google-cloud-pubsublite:1.4.3'
```

If you are using SBT, add this to your dependencies

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-pubsublite" % "1.4.2"
libraryDependencies += "com.google.cloud" % "google-cloud-pubsublite" % "1.4.3"
```

## Authentication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
package com.google.cloud.pubsublite.internal.wire;

import static com.google.cloud.pubsublite.internal.ExtractStatus.toCanonical;
import static java.util.concurrent.TimeUnit.MINUTES;

import com.google.api.core.AbstractApiService;
import com.google.cloud.pubsublite.AdminClient;
import com.google.cloud.pubsublite.TopicPath;
import com.google.cloud.pubsublite.internal.AlarmFactory;
import com.google.common.flogger.GoogleLogger;
import java.util.Optional;
import java.util.concurrent.*;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;

public class PartitionCountWatcherImpl extends AbstractApiService implements PartitionCountWatcher {
Expand Down Expand Up @@ -76,10 +78,15 @@ private void onAlarm() {

private void pollTopicConfig() {
try {
long partitionCount = adminClient.getTopicPartitionCount(topicPath).get();
if (currentPartitionCount == partitionCount) return;
long partitionCount = adminClient.getTopicPartitionCount(topicPath).get(1, MINUTES);
if (currentPartitionCount == partitionCount) {
return;
}
currentPartitionCount = partitionCount;
partitionCountReceiver.accept(partitionCount);
} catch (TimeoutException e) {
log.atWarning().withCause(e).log(
"Timed out polling for partition count- see https://github.com/googleapis/gax-java/issues/1577");
} catch (Throwable t) {
throw toCanonical(t).underlying;
}
Expand Down

0 comments on commit 0301d55

Please sign in to comment.