X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FFrontendMetadata.java;h=efb0fdc04beb351845e6a4465298a705f5ba8156;hp=6a04674b6ca2919c32b63a28e1b699a037d73cc1;hb=bdce894fa73714aa9f68eadad3524cfc94dc71d2;hpb=4bbbd57c8f96e864d4353c1bdbce0dc068a6a57b diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendMetadata.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendMetadata.java index 6a04674b6c..efb0fdc04b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendMetadata.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendMetadata.java @@ -7,10 +7,14 @@ */ package org.opendaylight.controller.cluster.datastore; +import static com.google.common.base.Verify.verify; + +import com.google.common.base.Preconditions; import com.google.common.collect.Collections2; +import com.google.common.collect.Maps; import java.util.HashMap; import java.util.Map; -import javax.annotation.concurrent.NotThreadSafe; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; @@ -23,15 +27,19 @@ import org.slf4j.LoggerFactory; /** * Frontend state as observed by a shard follower. This class is responsible for maintaining metadata state * so that this can be used to seed {@link LeaderFrontendState} with proper state so that the frontend/backend - * conversation can continue where it left off. + * conversation can continue where it left off. This class is NOT thread-safe. * * @author Robert Varga */ -@NotThreadSafe final class FrontendMetadata extends ShardDataTreeMetadata { private static final Logger LOG = LoggerFactory.getLogger(FrontendMetadata.class); private final Map clients = new HashMap<>(); + private final String shardName; + + FrontendMetadata(final String shardName) { + this.shardName = Preconditions.checkNotNull(shardName); + } @Override Class getSupportedType() { @@ -40,15 +48,22 @@ final class FrontendMetadata extends ShardDataTreeMetadata toLeaderState(final @NonNull Shard shard) { + return new HashMap<>(Maps.transformValues(clients, meta -> meta.toLeaderState(shard))); + } + + void disableTracking(final ClientIdentifier clientId) { + final FrontendIdentifier frontendId = clientId.getFrontendId(); + final FrontendClientMetadataBuilder client = clients.get(frontendId); + if (client == null) { + // When we havent seen the client before, we still need to disable tracking for him since this only gets + // triggered once. + LOG.debug("{}: disableTracking {} does not match any client, pre-disabling client.", shardName, clientId); + clients.put(frontendId, new FrontendClientMetadataBuilder.Disabled(shardName, clientId)); + return; + } + if (!clientId.equals(client.getIdentifier())) { + LOG.debug("{}: disableTracking {} does not match client {}, ignoring", shardName, clientId, client); + return; + } + if (client instanceof FrontendClientMetadataBuilder.Disabled) { + LOG.debug("{}: client {} is has already disabled tracking", shardName, client); + return; + } + + verify(clients.replace(frontendId, client, new FrontendClientMetadataBuilder.Disabled(shardName, clientId))); + } }