Fix a couple of issues with replication
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / Shard.java
index a7089a7f75c9cd01a5c336a5f400a71c30a605fd..46f09217d04a3119f97b4ae25b66737a22690caa 100644 (file)
@@ -157,10 +157,23 @@ public class Shard extends RaftActor {
             modificationToCohort.remove(serialized);
         if (cohort == null) {
             LOG.error(
-                "Could not find cohort for modification : " + modification);
+                "Could not find cohort for modification : {}", modification);
             LOG.info("Writing modification using a new transaction");
-            modification.apply(store.newReadWriteTransaction());
-            return;
+            DOMStoreReadWriteTransaction transaction =
+                store.newReadWriteTransaction();
+            modification.apply(transaction);
+            DOMStoreThreePhaseCommitCohort commitCohort = transaction.ready();
+            ListenableFuture<Void> future =
+                commitCohort.preCommit();
+            try {
+                future.get();
+                future = commitCohort.commit();
+                future.get();
+            } catch (InterruptedException e) {
+                LOG.error("Failed to commit", e);
+            } catch (ExecutionException e) {
+                LOG.error("Failed to commit", e);
+            }
         }
 
         final ListenableFuture<Void> future = cohort.commit();
@@ -250,7 +263,14 @@ public class Shard extends RaftActor {
         if(data instanceof CompositeModificationPayload){
             Object modification =
                 ((CompositeModificationPayload) data).getModification();
-            commit(clientActor, modification);
+
+            if(modification != null){
+                commit(clientActor, modification);
+            } else {
+                LOG.error("modification is null - this is very unexpected");
+            }
+
+
         } else {
             LOG.error("Unknown state received {}", data);
         }