Fix write transaction shard stats 89/82189/3
authorTomas Cere <tomas.cere@pantheon.tech>
Tue, 21 May 2019 11:42:47 +0000 (13:42 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 24 May 2019 15:27:53 +0000 (15:27 +0000)
With the changes in ask protocol due to to tell based
integration, shards stats had incorrectly reported
write transaction counts. Since backend doesnt care
about the difference between write-only and read-write
transactions and all are read-write from backend point of view
we can safely remove writeOnly counter.

Change-Id: I18046ad3b229755bbd0daa788a3fe62f59e4140d
Signed-off-by: Tomas Cere <tomas.cere@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransactionActorFactory.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardStats.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardStatsMXBean.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java

index d22e028..8a3140b 100644 (file)
@@ -547,6 +547,8 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
     }
 
     ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(final TransactionIdentifier txId) {
+        shard.getShardMBean().incrementReadOnlyTransactionCount();
+
         if (txId.getHistoryId().getHistoryId() == 0) {
             return new ReadOnlyShardDataTreeTransaction(this, txId, dataTree.takeSnapshot());
         }
@@ -555,6 +557,8 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
     }
 
     ReadWriteShardDataTreeTransaction newReadWriteTransaction(final TransactionIdentifier txId) {
+        shard.getShardMBean().incrementReadWriteTransactionCount();
+
         if (txId.getHistoryId().getHistoryId() == 0) {
             return new ReadWriteShardDataTreeTransaction(ShardDataTree.this, txId, dataTree.takeSnapshot()
                     .newModification());
index 3cd09ab..26c4086 100644 (file)
@@ -68,15 +68,10 @@ class ShardTransactionActorFactory {
         switch (type) {
             case READ_ONLY:
                 transaction = dataTree.newReadOnlyTransaction(transactionID);
-                shardMBean.incrementReadOnlyTransactionCount();
                 break;
             case READ_WRITE:
-                transaction = dataTree.newReadWriteTransaction(transactionID);
-                shardMBean.incrementReadWriteTransactionCount();
-                break;
             case WRITE_ONLY:
                 transaction = dataTree.newReadWriteTransaction(transactionID);
-                shardMBean.incrementWriteOnlyTransactionCount();
                 break;
             default:
                 throw new IllegalArgumentException("Unsupported transaction type " + type);
index 7f81370..954032a 100644 (file)
@@ -44,8 +44,6 @@ public class ShardStats extends AbstractMXBean implements ShardStatsMXBean {
 
     private long readOnlyTransactionCount;
 
-    private long writeOnlyTransactionCount;
-
     private long readWriteTransactionCount;
 
     private long lastCommittedTransactionTime;
@@ -113,11 +111,6 @@ public class ShardStats extends AbstractMXBean implements ShardStatsMXBean {
         return readOnlyTransactionCount;
     }
 
-    @Override
-    public long getWriteOnlyTransactionCount() {
-        return writeOnlyTransactionCount;
-    }
-
     @Override
     public long getReadWriteTransactionCount() {
         return readWriteTransactionCount;
@@ -221,10 +214,6 @@ public class ShardStats extends AbstractMXBean implements ShardStatsMXBean {
         return ++readOnlyTransactionCount;
     }
 
-    public long incrementWriteOnlyTransactionCount() {
-        return ++writeOnlyTransactionCount;
-    }
-
     public long incrementReadWriteTransactionCount() {
         return ++readWriteTransactionCount;
     }
@@ -264,8 +253,6 @@ public class ShardStats extends AbstractMXBean implements ShardStatsMXBean {
 
         readOnlyTransactionCount = 0;
 
-        writeOnlyTransactionCount = 0;
-
         readWriteTransactionCount = 0;
 
         lastCommittedTransactionTime = 0;
index 3943e7e..0fb3a41 100644 (file)
@@ -843,7 +843,7 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest {
         readWriteTx.write(CarsModel.newCarPath("car" + carIndex), cars.getLast());
 
         IntegrationTestKit.verifyShardStats(leaderDistributedDataStore, "cars",
-            stats -> assertEquals("getReadWriteTransactionCount", 1, stats.getReadWriteTransactionCount()));
+            stats -> assertEquals("getReadWriteTransactionCount", 5, stats.getReadWriteTransactionCount()));
 
         // Disable elections on the leader so it switches to follower.
 
index 65ca16a..2eec393 100644 (file)
@@ -7,12 +7,15 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 import akka.actor.ActorRef;
 import akka.actor.Props;
 import akka.testkit.TestActorRef;
 import java.util.concurrent.TimeUnit;
+import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Mockito;
 import org.opendaylight.controller.cluster.access.concepts.MemberName;
 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
@@ -37,7 +40,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest {
     private static final TransactionType RO = TransactionType.READ_ONLY;
     private static final TransactionType RW = TransactionType.READ_WRITE;
 
-    private static final Shard MOCK_SHARD = Mockito.mock(Shard.class);
+    private static final Shard MOCK_SHARD = mock(Shard.class);
 
     private static final ShardDataTree STORE = new ShardDataTree(MOCK_SHARD, TEST_SCHEMA_CONTEXT, TreeType.OPERATIONAL);
 
@@ -55,6 +58,12 @@ public class ShardTransactionFailureTest extends AbstractActorTest {
         return shard;
     }
 
+    @Before
+    public void setup() {
+        ShardStats stats = mock(ShardStats.class);
+        when(MOCK_SHARD.getShardMBean()).thenReturn(stats);
+    }
+
     @Test(expected = ReadFailedException.class)
     public void testNegativeReadWithReadOnlyTransactionClosed() throws Exception {
 

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.