Skip to content

Commit

Permalink
Make DiscoveryServer stream ID global
Browse files Browse the repository at this point in the history
When surfacing V2 and V3 streams alongside each other in envoy-control,
DiscoveryServerCallbacks are unable to differentiate between V2 & V3 ADS
upon onStreamClose(), onStreamCloseWithError().

This means that any DiscoveryServerCallback that keeps state cannot pivot
on stream IDs, since there will be duplicate between V2 & V3. This change
creates a global StreamCounter, which ensures stream IDs will be unique
across V2 & V3 streams.

Signed-off-by: Stephanie Tilden <[email protected]>
  • Loading branch information
Stephanie Tilden committed Dec 16, 2020
1 parent ff834cb commit 91da9e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -21,7 +20,6 @@ public abstract class DiscoveryServer<T, U> {
final ConfigWatcher configWatcher;
final ProtoResourcesSerializer protoResourcesSerializer;
private final ExecutorGroup executorGroup;
private final AtomicLong streamCount = new AtomicLong();

/**
* Creates the server.
Expand Down Expand Up @@ -59,7 +57,7 @@ StreamObserver<T> createRequestHandler(
boolean ads,
String defaultTypeUrl) {

long streamId = streamCount.getAndIncrement();
long streamId = StreamCounter.getAndIncrement();
Executor executor = executorGroup.next();

LOGGER.debug("[{}] open stream from {}", streamId, defaultTypeUrl);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.envoyproxy.controlplane.server;

import java.util.concurrent.atomic.AtomicLong;

public final class StreamCounter {
private static final AtomicLong streamCount = new AtomicLong();

public static long getAndIncrement() {
return streamCount.getAndIncrement();
}
}

0 comments on commit 91da9e9

Please sign in to comment.