Forward CloseTransactionChain messages to the leader 15/78215/4
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 27 Nov 2018 16:03:21 +0000 (17:03 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 27 Nov 2018 21:05:13 +0000 (22:05 +0100)
The frontend broadcasts this message to all shards leaders,
but it may end up being misrouted. Make sure we forward the
request to the current leader.

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

index dbcbd3d02eff96f393e389d6b92ee5487b83ce18..c69b839bea8595acc6f63a2ff80b0e1b7cdf80f3 100644 (file)
@@ -788,9 +788,16 @@ public class Shard extends RaftActor {
     }
 
     private void closeTransactionChain(final CloseTransactionChain closeTransactionChain) {
-        final LocalHistoryIdentifier id = closeTransactionChain.getIdentifier();
-        store.closeTransactionChain(id, null);
-        store.purgeTransactionChain(id, null);
+        if (isLeader()) {
+            final LocalHistoryIdentifier id = closeTransactionChain.getIdentifier();
+            // FIXME: CONTROLLER-1628: stage purge once no transactions are present
+            store.closeTransactionChain(id, null);
+            store.purgeTransactionChain(id, null);
+        } else if (getLeader() != null) {
+            getLeader().forward(closeTransactionChain, getContext());
+        } else {
+            LOG.warn("{}: Could not close transaction {}", persistenceId(), closeTransactionChain.getIdentifier());
+        }
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")