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%2FFrontendClientMetadataBuilder.java;h=7e6eced779bdf4026dca36134b2b13e7509f1bbb;hp=475d2e62f2faeaf8a8b52b58b8ddaa878e5d7181;hb=HEAD;hpb=535d499672a88b772ca0b296fa40882f8fd0cf03 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendClientMetadataBuilder.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendClientMetadataBuilder.java index 475d2e62f2..c89627800f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendClientMetadataBuilder.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendClientMetadataBuilder.java @@ -7,17 +7,13 @@ */ package org.opendaylight.controller.cluster.datastore; -import static com.google.common.base.Verify.verify; import static java.util.Objects.requireNonNull; import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.base.VerifyException; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableRangeSet; -import com.google.common.collect.RangeSet; -import com.google.common.primitives.UnsignedLong; -import java.util.Collection; import java.util.HashMap; import java.util.Map; import org.eclipse.jdt.annotation.NonNull; @@ -25,26 +21,23 @@ import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.persisted.FrontendClientMetadata; -import org.opendaylight.controller.cluster.datastore.persisted.FrontendHistoryMetadata; -import org.opendaylight.controller.cluster.datastore.utils.UnsignedLongRangeSet; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.concepts.Identifiable; +import org.opendaylight.controller.cluster.datastore.utils.ImmutableUnsignedLongSet; +import org.opendaylight.controller.cluster.datastore.utils.MutableUnsignedLongSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * This class is NOT thread-safe. */ -abstract class FrontendClientMetadataBuilder implements Builder, - Identifiable { +abstract sealed class FrontendClientMetadataBuilder { static final class Disabled extends FrontendClientMetadataBuilder { - Disabled(final String shardName, final ClientIdentifier identifier) { - super(shardName, identifier); + Disabled(final String shardName, final ClientIdentifier clientId) { + super(shardName, clientId); } @Override - public FrontendClientMetadata build() { - return new FrontendClientMetadata(getIdentifier(), ImmutableRangeSet.of(), ImmutableList.of()); + FrontendClientMetadata build() { + return new FrontendClientMetadata(clientId(), ImmutableUnsignedLongSet.of(), ImmutableList.of()); } @Override @@ -77,22 +70,26 @@ abstract class FrontendClientMetadataBuilder implements Builder currentHistories = new HashMap<>(); - private final UnsignedLongRangeSet purgedHistories; + private final MutableUnsignedLongSet purgedHistories; private final LocalHistoryIdentifier standaloneId; - Enabled(final String shardName, final ClientIdentifier identifier) { - super(shardName, identifier); + Enabled(final String shardName, final ClientIdentifier clientId) { + super(shardName, clientId); - purgedHistories = UnsignedLongRangeSet.create(); + purgedHistories = MutableUnsignedLongSet.of(); // History for stand-alone transactions is always present standaloneId = standaloneHistoryId(); @@ -100,33 +97,33 @@ abstract class FrontendClientMetadataBuilder implements Builder histories = new HashMap<>(); - for (FrontendHistoryMetadataBuilder e : currentHistories.values()) { - if (e.getIdentifier().getHistoryId() != 0) { - final AbstractFrontendHistory state = e.toLeaderState(shard); - verify(state instanceof LocalFrontendHistory, "Unexpected state %s", state); - histories.put(e.getIdentifier(), (LocalFrontendHistory) state); + final var histories = new HashMap(); + for (var historyMetaBuilder : currentHistories.values()) { + final var historyId = historyMetaBuilder.getIdentifier(); + if (historyId.getHistoryId() != 0) { + final var state = historyMetaBuilder.toLeaderState(shard); + if (state instanceof LocalFrontendHistory localState) { + histories.put(historyId, localState); + } else { + throw new VerifyException("Unexpected state " + state); + } } } final AbstractFrontendHistory singleHistory; - final FrontendHistoryMetadataBuilder singleHistoryMeta = currentHistories.get( - new LocalHistoryIdentifier(getIdentifier(), 0)); + final var singleHistoryMeta = currentHistories.get(new LocalHistoryIdentifier(clientId(), 0)); if (singleHistoryMeta == null) { - final ShardDataTree tree = shard.getDataStore(); - singleHistory = StandaloneFrontendHistory.create(shard.persistenceId(), getIdentifier(), tree); + final var tree = shard.getDataStore(); + singleHistory = StandaloneFrontendHistory.create(shard.persistenceId(), clientId(), tree); } else { singleHistory = singleHistoryMeta.toLeaderState(shard); } - return new LeaderFrontendState.Enabled(shard.persistenceId(), getIdentifier(), shard.getDataStore(), - purgedHistories.copy(), singleHistory, histories); + return new LeaderFrontendState.Enabled(shard.persistenceId(), clientId(), shard.getDataStore(), + purgedHistories.mutableCopy(), singleHistory, histories); } @Override @@ -229,51 +240,55 @@ abstract class FrontendClientMetadataBuilder implements Builder current = meta.getCurrentHistories(); - final RangeSet purged = meta.getPurgedHistories(); - // Completely empty histories imply disabled state, as otherwise we'd have a record of the single history -- // either purged or active - return current.isEmpty() && purged.isEmpty() ? new Disabled(shardName, meta.getIdentifier()) - : new Enabled(shardName, meta); + return meta.getCurrentHistories().isEmpty() && meta.getPurgedHistories().isEmpty() + ? new Disabled(shardName, meta.clientId()) : new Enabled(shardName, meta); } - @Override - public final ClientIdentifier getIdentifier() { - return identifier; + final ClientIdentifier clientId() { + return clientId; } final String shardName() { return shardName; } + abstract FrontendClientMetadata build(); + abstract void onHistoryCreated(LocalHistoryIdentifier historyId); abstract void onHistoryClosed(LocalHistoryIdentifier historyId); @@ -286,6 +301,8 @@ abstract class FrontendClientMetadataBuilder implements Builder