Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect xDS deletions #971

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions d2/src/main/java/com/linkedin/d2/xds/XdsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,22 @@ interface ResourceWatcher
interface NodeResourceWatcher extends ResourceWatcher
{
void onChanged(NodeUpdate update);

void onDelete(String resourceName);
}

interface SymlinkNodeResourceWatcher extends ResourceWatcher
{
void onChanged(String resourceName, NodeUpdate update);

void onDelete(String resourceName);
}

interface D2URIMapResourceWatcher extends ResourceWatcher
{
void onChanged(D2URIMapUpdate update);

void onDelete(String resourceName);
}

interface ResourceUpdate
Expand Down
11 changes: 9 additions & 2 deletions d2/src/main/java/com/linkedin/d2/xds/XdsClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -443,19 +443,21 @@ private static final class DiscoveryResponseData
{
private final ResourceType _resourceType;
private final List<Resource> _resources;
private final List<String> _removedResources;
private final String _nonce;

DiscoveryResponseData(ResourceType resourceType, List<Resource> resources, String nonce)
DiscoveryResponseData(ResourceType resourceType, List<Resource> resources, List<String> removedResources, String nonce)
{
_resourceType = resourceType;
_resources = resources;
_removedResources = removedResources;
_nonce = nonce;
}

static DiscoveryResponseData fromEnvoyProto(DeltaDiscoveryResponse proto)
{
return new DiscoveryResponseData(ResourceType.fromTypeUrl(proto.getTypeUrl()), proto.getResourcesList(),
proto.getNonce());
proto.getRemovedResourcesList(), proto.getNonce());
}

ResourceType getResourceType()
Expand All @@ -468,6 +470,11 @@ List<Resource> getResourcesList()
return _resources;
}

List<String> getRemovedResources()
{
return _removedResources;
}

String getNonce()
{
return _nonce;
Expand Down
46 changes: 41 additions & 5 deletions d2/src/main/java/com/linkedin/d2/xds/XdsToD2PropertiesAdaptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -225,6 +224,12 @@ public void onChanged(XdsClient.NodeUpdate update)
}
}

@Override
public void onDelete(String name)
{
_serviceEventBus.publishRemove(name);
}

@Override
public void onError(Status error)
{
Expand Down Expand Up @@ -286,6 +291,12 @@ private void publishClusterData(String clusterName, ClusterProperties properties
}
}

@Override
public void onDelete(String name)
{
_clusterEventBus.publishRemove(name);
}

@Override
public void onError(Status error)
{
Expand Down Expand Up @@ -325,6 +336,13 @@ public void onChanged(String resourceName, XdsClient.NodeUpdate update)
listenToUris(actualNodeName);
}

@Override
public void onDelete(String resourceName)
{
// TODO: Is this all we need to do here?
removeSymlink(symlinkName);
}

@Override
public void onError(Status error)
{
Expand All @@ -339,14 +357,26 @@ public void onReconnect()
};
}

private void updateSymlinkAndActualNodeMap(String symlinkName, String actualNodeName) {
synchronized (_symlinkAndActualNodeLock) {
private void updateSymlinkAndActualNodeMap(String symlinkName, String actualNodeName)
{
synchronized (_symlinkAndActualNodeLock)
{
_symlinkAndActualNode.put(symlinkName, actualNodeName);
}
}

private String getSymlink(String actualNodeName) {
synchronized (_symlinkAndActualNodeLock) {
private String removeSymlink(String symlinkName)
{
synchronized (_symlinkAndActualNodeLock)
{
return _symlinkAndActualNode.remove(symlinkName);
}
}

private String getSymlink(String actualNodeName)
{
synchronized (_symlinkAndActualNodeLock)
{
return _symlinkAndActualNode.inverse().get(actualNodeName);
}
}
Expand Down Expand Up @@ -486,6 +516,12 @@ private void mergeAndPublishUris(String clusterName)
}
}

@Override
public void onDelete(String resourceName)
{
_uriEventBus.publishRemove(resourceName);
}

@Override
public void onError(Status error)
{
Expand Down
Loading