Improve LocalProxyTransaction.doExists()
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / LeaderFrontendState.java
index 295dbdc0058a129193bb83464f3b40a9b9dc852e..e086e51a66f706d103168bbe36db50841e3c68eb 100644 (file)
@@ -14,6 +14,7 @@ import com.google.common.base.MoreObjects.ToStringHelper;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.controller.cluster.access.commands.CreateLocalHistoryRequest;
 import org.opendaylight.controller.cluster.access.commands.DeadHistoryException;
@@ -31,7 +32,7 @@ import org.opendaylight.controller.cluster.access.concepts.RequestEnvelope;
 import org.opendaylight.controller.cluster.access.concepts.RequestException;
 import org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException;
 import org.opendaylight.controller.cluster.datastore.ShardDataTreeCohort.State;
-import org.opendaylight.controller.cluster.datastore.utils.UnsignedLongRangeSet;
+import org.opendaylight.controller.cluster.datastore.utils.MutableUnsignedLongSet;
 import org.opendaylight.yangtools.concepts.Identifiable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -65,8 +66,8 @@ abstract class LeaderFrontendState implements Identifiable<ClientIdentifier> {
         // Histories which have not been purged
         private final Map<LocalHistoryIdentifier, LocalFrontendHistory> localHistories;
 
-        // RangeSet performs automatic merging, hence we keep minimal state tracking information
-        private final UnsignedLongRangeSet purgedHistories;
+        // UnsignedLongSet performs automatic merging, hence we keep minimal state tracking information
+        private final MutableUnsignedLongSet purgedHistories;
 
         // Used for all standalone transactions
         private final AbstractFrontendHistory standaloneHistory;
@@ -75,12 +76,12 @@ abstract class LeaderFrontendState implements Identifiable<ClientIdentifier> {
         private Long lastSeenHistory = null;
 
         Enabled(final String persistenceId, final ClientIdentifier clientId, final ShardDataTree tree) {
-            this(persistenceId, clientId, tree, UnsignedLongRangeSet.create(),
+            this(persistenceId, clientId, tree, MutableUnsignedLongSet.of(),
                 StandaloneFrontendHistory.create(persistenceId, clientId, tree), new HashMap<>());
         }
 
         Enabled(final String persistenceId, final ClientIdentifier clientId, final ShardDataTree tree,
-                final UnsignedLongRangeSet purgedHistories, final AbstractFrontendHistory standaloneHistory,
+                final MutableUnsignedLongSet purgedHistories, final AbstractFrontendHistory standaloneHistory,
                 final Map<LocalHistoryIdentifier, LocalFrontendHistory> localHistories) {
             super(persistenceId, clientId, tree);
             this.purgedHistories = requireNonNull(purgedHistories);
@@ -99,7 +100,7 @@ abstract class LeaderFrontendState implements Identifiable<ClientIdentifier> {
                 } else if (request instanceof DestroyLocalHistoryRequest) {
                     return handleDestroyHistory((DestroyLocalHistoryRequest) request, envelope, now);
                 } else if (request instanceof PurgeLocalHistoryRequest) {
-                    return handlePurgeHistory((PurgeLocalHistoryRequest)request, envelope, now);
+                    return handlePurgeHistory((PurgeLocalHistoryRequest) request, envelope, now);
                 } else {
                     LOG.warn("{}: rejecting unsupported request {}", persistenceId(), request);
                     throw new UnsupportedRequestException(request);
@@ -123,7 +124,7 @@ abstract class LeaderFrontendState implements Identifiable<ClientIdentifier> {
                     if (history == null) {
                         if (purgedHistories.contains(lhId.getHistoryId())) {
                             LOG.warn("{}: rejecting request {} to purged history", persistenceId(), request);
-                            throw new DeadHistoryException(purgedHistories.toImmutable());
+                            throw new DeadHistoryException(purgedHistories.toRangeSet());
                         }
 
                         LOG.warn("{}: rejecting unknown history request {}", persistenceId(), request);
@@ -174,7 +175,7 @@ abstract class LeaderFrontendState implements Identifiable<ClientIdentifier> {
             // not end up resurrecting a purged history.
             if (purgedHistories.contains(historyId.getHistoryId())) {
                 LOG.debug("{}: rejecting purged request {}", persistenceId(), request);
-                throw new DeadHistoryException(purgedHistories.toImmutable());
+                throw new DeadHistoryException(purgedHistories.toRangeSet());
             }
 
             // Update last history we have seen
@@ -236,9 +237,9 @@ abstract class LeaderFrontendState implements Identifiable<ClientIdentifier> {
 
     private static final Logger LOG = LoggerFactory.getLogger(LeaderFrontendState.class);
 
-    private final ShardDataTree tree;
-    private final ClientIdentifier clientId;
-    private final String persistenceId;
+    private final @NonNull ClientIdentifier clientId;
+    private final @NonNull String persistenceId;
+    private final @NonNull ShardDataTree tree;
 
     private long lastConnectTicks;
     private long lastSeenTicks;
@@ -256,7 +257,7 @@ abstract class LeaderFrontendState implements Identifiable<ClientIdentifier> {
         this.persistenceId = requireNonNull(persistenceId);
         this.clientId = requireNonNull(clientId);
         this.tree = requireNonNull(tree);
-        this.lastSeenTicks = tree.readTime();
+        lastSeenTicks = tree.readTime();
     }
 
     @Override
@@ -281,7 +282,7 @@ abstract class LeaderFrontendState implements Identifiable<ClientIdentifier> {
     }
 
     final void touch() {
-        this.lastSeenTicks = tree.readTime();
+        lastSeenTicks = tree.readTime();
     }
 
     abstract @Nullable LocalHistorySuccess handleLocalHistoryRequest(LocalHistoryRequest<?> request,