brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/5] git commit: tidy up of logging for persistence and location management
Date Thu, 16 Oct 2014 16:44:21 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 3f699cf09 -> c91119d21


tidy up of logging for persistence and location management


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/752f1613
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/752f1613
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/752f1613

Branch: refs/heads/master
Commit: 752f1613aea1801d580289b3ba8e80ee30e4a65f
Parents: 3f699cf
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed Oct 8 18:29:38 2014 -0700
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Thu Oct 16 17:42:51 2014 +0100

----------------------------------------------------------------------
 .../rebind/PeriodicDeltaChangeListener.java     | 55 +++++++++++---------
 .../BrooklynMementoPersisterToObjectStore.java  | 11 ++--
 .../internal/LocalLocationManager.java          | 18 ++++---
 3 files changed, 45 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/752f1613/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java b/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java
index 7306444..0f516dc 100644
--- a/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java
+++ b/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java
@@ -19,6 +19,7 @@
 package brooklyn.entity.rebind;
 
 import java.util.Collection;
+import java.util.List;
 import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.Semaphore;
@@ -307,6 +308,7 @@ public class PeriodicDeltaChangeListener implements ChangeListener {
         try {
             persistingMutex.acquire();
             if (!isActive()) return;
+            
             // Atomically switch the delta, so subsequent modifications will be done in the
             // next scheduled persist
             DeltaCollector prevDeltaCollector;
@@ -314,8 +316,23 @@ public class PeriodicDeltaChangeListener implements ChangeListener {
                 prevDeltaCollector = deltaCollector;
                 deltaCollector = new DeltaCollector();
             }
-            addReferencedObjects(prevDeltaCollector);
             
+            if (LOG.isDebugEnabled()) LOG.debug("Persister delta as reported: "
+                    + "updating entities={}, locations={}, policies={}, enrichers={}, catalog
items={}; "
+                    + "removing entities={}, locations={}, policies={}, enrichers={}, catalog
items={}",
+                    new Object[] {
+                        limitedCountString(prevDeltaCollector.entities), limitedCountString(prevDeltaCollector.locations),
limitedCountString(prevDeltaCollector.policies), limitedCountString(prevDeltaCollector.enrichers),
limitedCountString(prevDeltaCollector.catalogItems), 
+                        limitedCountString(prevDeltaCollector.removedEntityIds), limitedCountString(prevDeltaCollector.removedLocationIds),
limitedCountString(prevDeltaCollector.removedPolicyIds), limitedCountString(prevDeltaCollector.removedEnricherIds),
limitedCountString(prevDeltaCollector.removedCatalogItemIds)});
+
+            addReferencedObjects(prevDeltaCollector);
+
+            if (LOG.isDebugEnabled()) LOG.debug("Persister delta with references: "
+                    + "updating {} entities, {} locations, {} policies, {} enrichers, {}
catalog items; "
+                    + "removing {} entities, {} locations, {} policies, {} enrichers, {}
catalog items",
+                    new Object[] {
+                        prevDeltaCollector.entities.size(), prevDeltaCollector.locations.size(),
prevDeltaCollector.policies.size(), prevDeltaCollector.enrichers.size(), prevDeltaCollector.catalogItems.size(),
+                        prevDeltaCollector.removedEntityIds.size(), prevDeltaCollector.removedLocationIds.size(),
prevDeltaCollector.removedPolicyIds.size(), prevDeltaCollector.removedEnricherIds.size(),
prevDeltaCollector.removedCatalogItemIds.size()});
+
             // Generate mementos for everything that has changed in this time period
             if (prevDeltaCollector.isEmpty()) {
                 if (LOG.isTraceEnabled()) LOG.trace("No changes to persist since last delta");
@@ -370,7 +387,6 @@ public class PeriodicDeltaChangeListener implements ChangeListener {
                 persisterDelta.removedFeedIds = prevDeltaCollector.removedFeedIds;
                 persisterDelta.removedCatalogItemIds = prevDeltaCollector.removedCatalogItemIds;
 
-                if (LOG.isDebugEnabled()) dumpDebugInfo(persisterDelta);
                 /*
                  * Need to guarantee "happens before", with any thread that subsequently
reads
                  * the mementos.
@@ -396,30 +412,17 @@ public class PeriodicDeltaChangeListener implements ChangeListener {
         }
     }
     
-    private void dumpDebugInfo(PersisterDeltaImpl delta) {
-        //copied from BrooklynMementoPersisterObjectStore - already logged there, but have
a unified for all stores for debugging
-        LOG.debug("Periodic delta updated summary {} entities, {} locations, " +
-            "{} policies, {} enrichers and {} catalog items; " +
-            "removing {} entities, {} locations, {} policies, {} enrichers and {} catalog
items",
-            new Object[] {
-                    delta.entities().size(), delta.locations().size(), delta.policies().size(),
delta.enrichers().size(), delta.catalogItems().size(),
-                    delta.removedEntityIds().size(), delta.removedLocationIds().size(), delta.removedPolicyIds().size(),
-                    delta.removedEnricherIds().size(), delta.removedCatalogItemIds().size()});
-
-        LOG.debug("Detailed period delta updated {} entities, {} locations, " +
-                "{} policies, {} enrichers and {} catalog items; " +
-                "removing {} entities, {} locations, {} policies, {} enrichers and {} catalog
items",
-                new Object[] {
-                        limitCnt(delta.entities()), limitCnt(delta.locations()),
-                        limitCnt(delta.policies()), limitCnt(delta.enrichers()),
-                        limitCnt(delta.catalogItems()), limitCnt(delta.removedEntityIds()),
-                        limitCnt(delta.removedLocationIds()), limitCnt(delta.removedPolicyIds()),
-                        limitCnt(delta.removedEnricherIds()), limitCnt(delta.removedCatalogItemIds())});
-
-    }
-
-    private <T> Collection<T> limitCnt(Collection<T> items) {
-        return Lists.newArrayList(Iterables.limit(items, 50));
+    private static String limitedCountString(Collection<?> items) {
+        if (items==null) return null;
+        int size = items.size();
+        if (size==0) return "[]";
+        
+        int MAX = 12;
+        
+        if (size<=MAX) return items.toString();
+        List<Object> itemsTruncated = Lists.newArrayList(Iterables.limit(items, MAX));
+        if (items.size()>itemsTruncated.size()) itemsTruncated.add("... ("+(size-MAX)+"
more)");
+        return itemsTruncated.toString();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/752f1613/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterToObjectStore.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterToObjectStore.java
b/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterToObjectStore.java
index a751ada..dfc0676 100644
--- a/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterToObjectStore.java
+++ b/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterToObjectStore.java
@@ -522,13 +522,12 @@ public class BrooklynMementoPersisterToObjectStore implements BrooklynMementoPer
 
         Stopwatch stopwatch = deltaImpl(delta, exceptionHandler);
         
-        if (LOG.isDebugEnabled()) LOG.debug("Checkpointed delta of memento in {}; updated
{} entities, {} locations, " +
-                        "{} policies, {} enrichers and {} catalog items; " +
-                        "removing {} entities, {} locations, {} policies, {} enrichers and
{} catalog items",
-                new Object[] {Time.makeTimeStringRounded(stopwatch),
+        if (LOG.isDebugEnabled()) LOG.debug("Checkpointed delta of memento in {}: "
+                + "updated {} entities, {} locations, {} policies, {} enrichers, {} catalog
items; "
+                + "removed {} entities, {} locations, {} policies, {} enrichers {} catalog
items",
+                    new Object[] {Time.makeTimeStringRounded(stopwatch),
                         delta.entities().size(), delta.locations().size(), delta.policies().size(),
delta.enrichers().size(), delta.catalogItems().size(),
-                        delta.removedEntityIds().size(), delta.removedLocationIds().size(),
delta.removedPolicyIds().size(),
-                        delta.removedEnricherIds().size(), delta.removedCatalogItemIds().size()});
+                        delta.removedEntityIds().size(), delta.removedLocationIds().size(),
delta.removedPolicyIds().size(), delta.removedEnricherIds().size(), delta.removedCatalogItemIds().size()});
     }
     
     /**

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/752f1613/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java b/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java
index 1e65360..59415fe 100644
--- a/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java
+++ b/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java
@@ -37,12 +37,12 @@ import brooklyn.location.LocationSpec;
 import brooklyn.location.basic.AbstractLocation;
 import brooklyn.location.basic.LocationInternal;
 import brooklyn.management.AccessController;
+import brooklyn.management.entitlement.Entitlements;
 import brooklyn.management.internal.ManagementTransitionInfo.ManagementTransitionMode;
 import brooklyn.util.config.ConfigBag;
 import brooklyn.util.exceptions.Exceptions;
 import brooklyn.util.exceptions.RuntimeInterruptedException;
 import brooklyn.util.task.Tasks;
-import brooklyn.util.text.Strings;
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.Preconditions;
@@ -70,7 +70,7 @@ public class LocalLocationManager implements LocationManagerInternal {
     private final BrooklynStorage storage;
     private Map<String, String> locationTypes;
 
-    private static AtomicLong LOCATION_CNT = new AtomicLong(1);
+    private static AtomicLong LOCATION_CNT = new AtomicLong(0);
     
     public LocalLocationManager(LocalManagementContext managementContext) {
         this.managementContext = checkNotNull(managementContext, "managementContext");
@@ -205,11 +205,15 @@ public class LocalLocationManager implements LocationManagerInternal
{
             throw new IllegalStateException("Access controller forbids management of "+loc+":
"+access.getMsg());
         }
 
-        String msg = "Managing location " + loc + ". initialMode=" + initialMode + ", context:
" + Strings.toString(Tasks.current());
-        if (LOCATION_CNT.getAndIncrement() % 100 == 0) {
-            log.debug(msg, new Exception("Stack Trace"));
-        } else {
-            log.debug(msg);
+        if (log.isDebugEnabled()) {
+            String msg = "Managing location " + loc + " ("+initialMode+"), from " + Tasks.current()+"
/ "+Entitlements.getEntitlementContext();
+            long count = LOCATION_CNT.incrementAndGet();
+            if (count % 100 == 0) {
+                // include trace periodically in case we get leaks or too much location management
+                log.debug(msg, new Exception("Informational stack trace of call to manage
location "+loc+" ("+count+" calls; "+getLocations().size()+" currently managed)"));
+            } else {
+                log.debug(msg);
+            }
         }
 
         recursively(loc, new Predicate<AbstractLocation>() { public boolean apply(AbstractLocation
it) {


Mime
View raw message