BUG-5280: make sure we have metadata for standalone history 88/54088/3
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 30 Mar 2017 08:45:50 +0000 (10:45 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Fri, 31 Mar 2017 10:58:54 +0000 (10:58 +0000)
With metadata propagation in place, we get a ton of warnings
in the form of:

Unknown history for aborted transaction member-2-datastore-config-fe-0-txn-1261-0, ignoring

which is indicative of our failure to populate metadata builder
with the history for standalone transactions. This patch fixes
that and adds recovery for the case when we fail to find the
history in recovered journal.

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

index 8a0ce605dfd18bb7bcd205c8cdebce9b6691f356..ec2cdb6daa209a9f7ad2b2474ccf454166f9da57 100644 (file)
@@ -39,6 +39,10 @@ final class FrontendClientMetadataBuilder implements Builder<FrontendClientMetad
     FrontendClientMetadataBuilder(final ClientIdentifier identifier) {
         this.identifier = Preconditions.checkNotNull(identifier);
         purgedHistories = TreeRangeSet.create();
     FrontendClientMetadataBuilder(final ClientIdentifier identifier) {
         this.identifier = Preconditions.checkNotNull(identifier);
         purgedHistories = TreeRangeSet.create();
+
+        // History for stand-alone transactions is always present
+        final LocalHistoryIdentifier standaloneId = standaloneHistoryId();
+        currentHistories.put(standaloneId, new FrontendHistoryMetadataBuilder(standaloneId));
     }
 
     FrontendClientMetadataBuilder(final FrontendClientMetadata meta) {
     }
 
     FrontendClientMetadataBuilder(final FrontendClientMetadata meta) {
@@ -49,6 +53,18 @@ final class FrontendClientMetadataBuilder implements Builder<FrontendClientMetad
             final FrontendHistoryMetadataBuilder b = new FrontendHistoryMetadataBuilder(identifier, h);
             currentHistories.put(b.getIdentifier(), b);
         }
             final FrontendHistoryMetadataBuilder b = new FrontendHistoryMetadataBuilder(identifier, h);
             currentHistories.put(b.getIdentifier(), b);
         }
+
+        // Sanity check and recovery
+        final LocalHistoryIdentifier standaloneId = standaloneHistoryId();
+        if (!currentHistories.containsKey(standaloneId)) {
+            LOG.warn("Client {} recovered histories {} do not contain stand-alone history, attempting recovery",
+                identifier, currentHistories);
+            currentHistories.put(standaloneId, new FrontendHistoryMetadataBuilder(standaloneId));
+        }
+    }
+
+    private LocalHistoryIdentifier standaloneHistoryId() {
+        return new LocalHistoryIdentifier(identifier, 0);
     }
 
     @Override
     }
 
     @Override