Add LeadershipChangeCount to ShardStats 81/17981/2
authorTom Pantelis <tpanteli@brocade.com>
Wed, 8 Apr 2015 18:09:46 +0000 (14:09 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Fri, 10 Apr 2015 20:02:34 +0000 (16:02 -0400)
It's useful to see how many shard leadership changes have occurred so I
added a LeadershipChangeCount stat to the ShardStats mbean. This helps
to determine if spurious leadership changes are occurring. I also added
LastLeadershipChangeTime.

Change-Id: I33ddbcd96d6fa93fbfa9887393a2f5a40027d9f3
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.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

index 81449c5..7110adc 100644 (file)
@@ -701,6 +701,11 @@ public class Shard extends RaftActor {
         }
     }
 
+    @Override
+    protected void onLeaderChanged(String oldLeader, String newLeader) {
+        shardMBean.incrementLeadershipChangeCount();
+    }
+
     @Override
     public String persistenceId() {
         return this.name;
index fb59b76..e3c8ced 100644 (file)
@@ -77,6 +77,10 @@ public class ShardStats extends AbstractMXBean implements ShardStatsMXBean {
 
     private String statRetrievalTime;
 
+    private long leadershipChangeCount;
+
+    private long lastLeadershipChangeTime;
+
     public ShardStats(final String shardName, final String mxBeanType) {
         super(shardName, mxBeanType, JMX_CATEGORY_SHARD);
     }
@@ -366,4 +370,19 @@ public class ShardStats extends AbstractMXBean implements ShardStatsMXBean {
         getOnDemandRaftState();
         return statRetrievalError;
     }
+
+    @Override
+    public long getLeadershipChangeCount() {
+        return leadershipChangeCount;
+    }
+
+    public void incrementLeadershipChangeCount() {
+        leadershipChangeCount++;
+        lastLeadershipChangeTime = System.currentTimeMillis();
+    }
+
+    @Override
+    public String getLastLeadershipChangeTime() {
+        return DATE_FORMAT.format(new Date(lastLeadershipChangeTime));
+    }
 }

©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.