Skip to content

Commit

Permalink
document throws and extend metadata sync timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiitk committed Jan 11, 2022
1 parent 9661035 commit b3a3914
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions xds/src/main/java/io/grpc/xds/ClientXdsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -163,8 +164,8 @@ final class ClientXdsClient extends XdsClient implements XdsResponseHandler, Res
static boolean enableRouteLookup =
!Strings.isNullOrEmpty(System.getenv("GRPC_EXPERIMENTAL_XDS_RLS_LB"))
&& Boolean.parseBoolean(System.getenv("GRPC_EXPERIMENTAL_XDS_RLS_LB"));

private static final long METADATA_SYNC_TIMEOUT_SEC = 1;
// Normally this shouldn't take long, but add some slack for cases like a cold JVM.
private static final long METADATA_SYNC_TIMEOUT_SEC = 20;
private static final String TYPE_URL_HTTP_CONNECTION_MANAGER_V2 =
"type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2"
+ ".HttpConnectionManager";
Expand Down Expand Up @@ -2062,7 +2063,7 @@ public void run() {
return future.get(METADATA_SYNC_TIMEOUT_SEC, TimeUnit.SECONDS);
} catch (ExecutionException e) {
throw new UncheckedExecutionException(e.getCause());
} catch (TimeoutException e) {
} catch (TimeoutException | CancellationException e) {
throw new UncheckedExecutionException(e);
} catch (InterruptedException e) {
logger.log(XdsLogLevel.DEBUG, "Interrupted while preparing subscribed resources snapshot", e);
Expand Down
6 changes: 6 additions & 0 deletions xds/src/main/java/io/grpc/xds/XdsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,12 @@ TlsContextManager getTlsContextManager() {
/**
* Returns a map from the "resource type" to a map ("resource name": "resource metadata")
* containing the snapshot of the subscribed resources as they are at the moment of the call.
*
* @throws com.google.common.util.concurrent.UncheckedExecutionException
* if couldn't retrieve the snapshot of the subscribed resources in a synchronous manner
* because the task failed, cancelled, or timed out.
* TODO(sergiitk): when migrated to Java 8, throw CompletionException instead.
* @throws InterruptedException if the current thread was interrupted while waiting.
*/
// Must be synchronized.
Map<ResourceType, Map<String, ResourceMetadata>> getSubscribedResourcesMetadataSnapshot()
Expand Down

0 comments on commit b3a3914

Please sign in to comment.