Access historyId only once 82/105182/3
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 3 Apr 2023 15:26:04 +0000 (17:26 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 3 Apr 2023 17:11:36 +0000 (19:11 +0200)
This is a simple improvement, improving access a bit.

Change-Id: I42dbd91a0a8d5ce75cd99b36d786d446eac69501
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java

index 65511017ae6448be582ef96152f9b0f60ca60097..7ad721fc905b0c48353121f664b7a2d520309334 100644 (file)
@@ -621,22 +621,21 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
     final ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(final TransactionIdentifier txId) {
         shard.getShardMBean().incrementReadOnlyTransactionCount();
 
-        if (txId.getHistoryId().getHistoryId() == 0) {
+        final var historyId = txId.getHistoryId();
+        if (historyId.getHistoryId() == 0) {
             return new ReadOnlyShardDataTreeTransaction(this, txId, dataTree.takeSnapshot());
         }
-
-        return ensureTransactionChain(txId.getHistoryId(), null).newReadOnlyTransaction(txId);
+        return ensureTransactionChain(historyId, null).newReadOnlyTransaction(txId);
     }
 
     final ReadWriteShardDataTreeTransaction newReadWriteTransaction(final TransactionIdentifier txId) {
         shard.getShardMBean().incrementReadWriteTransactionCount();
 
-        if (txId.getHistoryId().getHistoryId() == 0) {
-            return new ReadWriteShardDataTreeTransaction(ShardDataTree.this, txId, dataTree.takeSnapshot()
-                    .newModification());
+        final var historyId = txId.getHistoryId();
+        if (historyId.getHistoryId() == 0) {
+            return new ReadWriteShardDataTreeTransaction(this, txId, dataTree.takeSnapshot().newModification());
         }
-
-        return ensureTransactionChain(txId.getHistoryId(), null).newReadWriteTransaction(txId);
+        return ensureTransactionChain(historyId, null).newReadWriteTransaction(txId);
     }
 
     @VisibleForTesting
@@ -1184,11 +1183,11 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
     // the newReadWriteTransaction()
     final ShardDataTreeCohort newReadyCohort(final TransactionIdentifier txId, final DataTreeModification mod,
             final Optional<SortedSet<String>> participatingShardNames) {
-        if (txId.getHistoryId().getHistoryId() == 0) {
+        final var historyId = txId.getHistoryId();
+        if (historyId.getHistoryId() == 0) {
             return createReadyCohort(txId, mod, participatingShardNames);
         }
-
-        return ensureTransactionChain(txId.getHistoryId(), null).createReadyCohort(txId, mod, participatingShardNames);
+        return ensureTransactionChain(historyId, null).createReadyCohort(txId, mod, participatingShardNames);
     }
 
     @SuppressFBWarnings(value = "DB_DUPLICATE_SWITCH_CLAUSES", justification = "See inline comments below.")