Propagate shard name to FrontendClientMetadataBuilder 73/57373/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 26 Apr 2017 13:24:37 +0000 (15:24 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 18 May 2017 15:26:33 +0000 (17:26 +0200)
Prefixing log message with shard name is useful to track things
down. Pass the shard name down from FrontendMetadata, so we can
emit such messages.

Change-Id: Ie6a2cd218e1a2686f8cc14f67574f245e3de914b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit cd6996f873c6d98b642a0f6f725babed67e211f1)

opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendClientMetadataBuilder.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendMetadata.java

index a13899c354b165526674469bbe02f8c9ad90cc12..b996ee45a73492cbac47cb611a331825736342a4 100644 (file)
@@ -36,8 +36,10 @@ final class FrontendClientMetadataBuilder implements Builder<FrontendClientMetad
     private final Map<LocalHistoryIdentifier, FrontendHistoryMetadataBuilder> currentHistories = new HashMap<>();
     private final RangeSet<UnsignedLong> purgedHistories;
     private final ClientIdentifier identifier;
+    private final String shardName;
 
-    FrontendClientMetadataBuilder(final ClientIdentifier identifier) {
+    FrontendClientMetadataBuilder(final String shardName, final ClientIdentifier identifier) {
+        this.shardName = Preconditions.checkNotNull(shardName);
         this.identifier = Preconditions.checkNotNull(identifier);
         purgedHistories = TreeRangeSet.create();
 
@@ -46,7 +48,8 @@ final class FrontendClientMetadataBuilder implements Builder<FrontendClientMetad
         currentHistories.put(standaloneId, new FrontendHistoryMetadataBuilder(standaloneId));
     }
 
-    FrontendClientMetadataBuilder(final FrontendClientMetadata meta) {
+    FrontendClientMetadataBuilder(final String shardName, final FrontendClientMetadata meta) {
+        this.shardName = Preconditions.checkNotNull(shardName);
         this.identifier = Preconditions.checkNotNull(meta.getIdentifier());
         purgedHistories = TreeRangeSet.create(meta.getPurgedHistories());
 
@@ -58,8 +61,8 @@ final class FrontendClientMetadataBuilder implements Builder<FrontendClientMetad
         // 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);
+            LOG.warn("{}: Client {} recovered histories {} do not contain stand-alone history, attempting recovery",
+                shardName, identifier, currentHistories);
             currentHistories.put(standaloneId, new FrontendHistoryMetadataBuilder(standaloneId));
         }
     }
@@ -84,9 +87,9 @@ final class FrontendClientMetadataBuilder implements Builder<FrontendClientMetad
         final FrontendHistoryMetadataBuilder oldMeta = currentHistories.putIfAbsent(historyId, newMeta);
         if (oldMeta != null) {
             // This should not be happening, warn about it
-            LOG.warn("Reused local history {}", historyId);
+            LOG.warn("{}: Reused local history {}", shardName, historyId);
         } else {
-            LOG.debug("Created local history {}", historyId);
+            LOG.debug("{}: Created local history {}", shardName, historyId);
         }
     }
 
@@ -94,30 +97,30 @@ final class FrontendClientMetadataBuilder implements Builder<FrontendClientMetad
         final FrontendHistoryMetadataBuilder builder = currentHistories.get(historyId);
         if (builder != null) {
             builder.onHistoryClosed();
-            LOG.debug("Closed history {}", historyId);
+            LOG.debug("{}: Closed history {}", shardName, historyId);
         } else {
-            LOG.warn("Closed unknown history {}, ignoring", historyId);
+            LOG.warn("{}: Closed unknown history {}, ignoring", shardName, historyId);
         }
     }
 
     void onHistoryPurged(final LocalHistoryIdentifier historyId) {
         final FrontendHistoryMetadataBuilder history = currentHistories.remove(historyId);
         if (history == null) {
-            LOG.warn("Purging unknown history {}", historyId);
+            LOG.warn("{}: Purging unknown history {}", shardName, historyId);
         }
 
         // XXX: do we need to account for cookies?
         purgedHistories.add(Range.singleton(UnsignedLong.fromLongBits(historyId.getHistoryId())));
-        LOG.debug("Purged history {}", historyId);
+        LOG.debug("{}: Purged history {}", historyId);
     }
 
     void onTransactionAborted(final TransactionIdentifier txId) {
         final FrontendHistoryMetadataBuilder history = getHistory(txId);
         if (history != null) {
             history.onTransactionAborted(txId);
-            LOG.debug("Committed transaction {}", txId);
+            LOG.debug("{}: Committed transaction {}", shardName, txId);
         } else {
-            LOG.warn("Unknown history for aborted transaction {}, ignoring", txId);
+            LOG.warn("{}: Unknown history for aborted transaction {}, ignoring", shardName, txId);
         }
     }
 
@@ -125,9 +128,9 @@ final class FrontendClientMetadataBuilder implements Builder<FrontendClientMetad
         final FrontendHistoryMetadataBuilder history = getHistory(txId);
         if (history != null) {
             history.onTransactionCommitted(txId);
-            LOG.debug("Aborted transaction {}", txId);
+            LOG.debug("{}: Aborted transaction {}", txId);
         } else {
-            LOG.warn("Unknown history for commited transaction {}, ignoring", txId);
+            LOG.warn("{}: Unknown history for commited transaction {}, ignoring", shardName, txId);
         }
     }
 
@@ -135,9 +138,9 @@ final class FrontendClientMetadataBuilder implements Builder<FrontendClientMetad
         final FrontendHistoryMetadataBuilder history = getHistory(txId);
         if (history != null) {
             history.onTransactionPurged(txId);
-            LOG.debug("Purged transaction {}", txId);
+            LOG.debug("{}: Purged transaction {}", txId);
         } else {
-            LOG.warn("Unknown history for purged transaction {}, ignoring", txId);
+            LOG.warn("{}: Unknown history for purged transaction {}, ignoring", shardName, txId);
         }
     }
 
index 39d04286c44ab5fff0337e58ee66312b37d9d9e5..d323b1026d5b8661b7bf5ac44690c9aa0294dd7d 100644 (file)
@@ -59,7 +59,7 @@ final class FrontendMetadata extends ShardDataTreeMetadata<FrontendShardDataTree
 
         for (FrontendClientMetadata m : snapshot.getClients()) {
             LOG.debug("{}: applying metadata {}", shardName, m);
-            final FrontendClientMetadataBuilder b = new FrontendClientMetadataBuilder(m);
+            final FrontendClientMetadataBuilder b = new FrontendClientMetadataBuilder(shardName, m);
             final FrontendIdentifier client = m.getIdentifier().getFrontendId();
 
             LOG.debug("{}: client {} updated to {}", shardName, client, b);
@@ -79,7 +79,7 @@ final class FrontendMetadata extends ShardDataTreeMetadata<FrontendShardDataTree
             return existing;
         }
 
-        final FrontendClientMetadataBuilder client = new FrontendClientMetadataBuilder(id);
+        final FrontendClientMetadataBuilder client = new FrontendClientMetadataBuilder(shardName, id);
         final FrontendClientMetadataBuilder previous = clients.put(id.getFrontendId(), client);
         if (previous != null) {
             LOG.debug("{}: Replaced client {} with {}", shardName, previous, client);