Centralize StandaloneFrontendHistory identifier 97/114297/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 2 Nov 2024 09:42:57 +0000 (10:42 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 2 Nov 2024 09:44:04 +0000 (10:44 +0100)
We have three callsites using historyId == 0. Centralize this assumption
in a dedicated method.

JIRA: CONTROLLER-2131
Change-Id: I36a02be078c6e9ad96fef44eee13283d00322562
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendClientMetadataBuilder.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/StandaloneFrontendHistory.java

index 5377351ee5d6204e98447d659434f3056821f52c..e2b5130c905f5d310c28105971cd0d588502b309 100644 (file)
@@ -42,7 +42,7 @@ final class FrontendClientMetadataBuilder {
         purgedHistories = MutableUnsignedLongSet.of();
 
         // History for stand-alone transactions is always present
-        standaloneId = new LocalHistoryIdentifier(clientId, 0);
+        standaloneId = StandaloneFrontendHistory.identifierForClient(clientId);
         currentHistories.put(standaloneId, new FrontendHistoryMetadataBuilder(standaloneId));
     }
 
@@ -57,7 +57,7 @@ final class FrontendClientMetadataBuilder {
         }
 
         // Sanity check and recovery
-        standaloneId = new LocalHistoryIdentifier(clientId, 0);
+        standaloneId = StandaloneFrontendHistory.identifierForClient(clientId);
         currentHistories.computeIfAbsent(standaloneId, missingId -> {
             LOG.warn("{}: Client {} recovered histories {} do not contain stand-alone history, attempting recovery",
                 shardName, clientId, currentHistories);
index 57c680da2a6f0d673b7ee1861eaecd05e6c07eba..32a8fac74847b7f925b0ac3a4f8e93271cddfaff 100644 (file)
@@ -25,8 +25,6 @@ import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
 /**
  * Standalone transaction specialization of {@link AbstractFrontendHistory}. There can be multiple open transactions
  * and they are submitted in any order.
- *
- * @author Robert Varga
  */
 final class StandaloneFrontendHistory extends AbstractFrontendHistory {
     private final @NonNull LocalHistoryIdentifier identifier;
@@ -36,8 +34,12 @@ final class StandaloneFrontendHistory extends AbstractFrontendHistory {
             final ShardDataTree tree, final Map<UnsignedLong, Boolean> closedTransactions,
             final MutableUnsignedLongSet purgedTransactions) {
         super(persistenceId, tree, closedTransactions, purgedTransactions);
-        identifier = new LocalHistoryIdentifier(clientId, 0);
         this.tree = requireNonNull(tree);
+        identifier = identifierForClient(clientId);
+    }
+
+    static @NonNull LocalHistoryIdentifier identifierForClient(final ClientIdentifier clientId) {
+        return new LocalHistoryIdentifier(clientId, 0);
     }
 
     static @NonNull StandaloneFrontendHistory create(final String persistenceId, final ClientIdentifier clientId,