Fix: Java agent: update ref count in enabledLoggers
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 7 Apr 2015 18:26:35 +0000 (14:26 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 4 Aug 2015 19:02:15 +0000 (15:02 -0400)
Integer objects are immutable in Java, so

    Integer refcount = enabledLoggers.get(name);
    refcount--;

does not update the value in enabledLoggers.

However, this bug "fixes" a bug in the session daemon
(LTTng-tools) which sends multiple _disable event_
commands for the same event name (one when the event is
disabled manually, and another one when the session is
destroyed). Therefore we use the registration done
command's version to know if the Java agent is connected to
a fixed or non-fixed session daemon, using the old
behaviour if connected to a non-fixed one.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust-java-agent/java/org/lttng/ust/agent/LTTngTCPSessiondClient.java
liblttng-ust-java-agent/java/org/lttng/ust/agent/LogFramework.java
liblttng-ust-java-agent/java/org/lttng/ust/agent/LogFrameworkSkeleton.java

index db4e1f70c75d31b861d26b9d39c91628ccbf01a5..76e8426b2344cad4f67b8b9e39386f2d493ad343 100644 (file)
@@ -185,6 +185,22 @@ class LTTngTCPSessiondClient implements Runnable {
                        switch (headerCmd.cmd) {
                                case CMD_REG_DONE:
                                {
+                                       /*
+                                        * Check command version:
+                                        *
+                                        *   * 0:  Connected to a non-fixed session daemon,
+                                        *         which could send multiple disable
+                                        *         event commands: do not decrement
+                                        *         reference count on disable event command
+                                        *         (original behaviour).
+                                        *   * >0: Connected to a fixed session daemon:
+                                        *         do decrement reference count on disable
+                                        *         event command.
+                                        */
+                                       if (headerCmd.cmd_version > 0) {
+                                               this.log.setEnableRefCountDecrement(true);
+                                       }
+
                                        /*
                                         * Release semaphore so meaning registration is done and we
                                         * can proceed to continue tracing.
index 0dd7c9827c058fdb88daaa524c018346cdb63824..692a820254155f0b212ea51b06aec8ea6969c808 100644 (file)
@@ -26,4 +26,5 @@ interface LogFramework {
        Iterator<String> listLoggers();
        Boolean isRoot();
        void reset();
+       void setEnableRefCountDecrement(boolean enableRefCountDecrement);
 }
index 4ad981e9375b59596ce5bcb21dfd3a13733ca6c4..6775827a07ba3ccb8a368fde285506553d6d1ae3 100644 (file)
@@ -27,6 +27,19 @@ public abstract class LogFrameworkSkeleton implements LogFramework {
        /* A map of event name and reference count */
        private Map<String, Integer> enabledLoggers;
 
+       /*
+        * If the following attribute is false, the internal ref count is
+        * never decremented when disabling a logger. This was the original
+        * behaviour of this agent, and this bug worked in concert with a
+        * bug in the session daemon which would send multiple disable
+        * commands for the same event name (manual disable + another
+        * disable on session destroy). The following attribute is needed
+        * because this version of the agent could be connected to a
+        * fixed session daemon, or a non-fixed session daemon, and it needs
+        * to work in both situations.
+        */
+       private boolean enableRefCountDecrement = false;
+
        public LogFrameworkSkeleton() {
                this.enabledLoggers = new HashMap<String, Integer>();
        }
@@ -68,6 +81,11 @@ public abstract class LogFrameworkSkeleton implements LogFramework {
                refcount--;
                assert (refcount >= 0);
 
+               if (enableRefCountDecrement) {
+                       /* Effectively decrement reference count. */
+                       enabledLoggers.put(name, refcount);
+               }
+
                if (refcount == 0) {
                        /* Event is not used anymore, remove it from the map */
                        Integer oldval = enabledLoggers.remove(name);
@@ -91,4 +109,8 @@ public abstract class LogFrameworkSkeleton implements LogFramework {
        protected Integer getEventCount() {
                return enabledLoggers.size();
        }
+
+       public void setEnableRefCountDecrement(boolean enableRefCountDecrement) {
+               this.enableRefCountDecrement = enableRefCountDecrement;
+       }
 }
This page took 0.02605 seconds and 4 git commands to generate.