abdullah alamoudi has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/2364

Change subject: DEBUG: Print out openers who didn't close an index
......................................................................

DEBUG: Print out openers who didn't close an index

Change-Id: Idb8ce0284ecdbd67adf28082f2081309259194a4
---
M 
asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/DatasetLifecycleManager.java
M 
asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/Info.java
2 files changed, 36 insertions(+), 0 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/64/2364/1

diff --git 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/DatasetLifecycleManager.java
 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/DatasetLifecycleManager.java
index 1a61b8f..9204680 100644
--- 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/DatasetLifecycleManager.java
+++ 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/DatasetLifecycleManager.java
@@ -21,10 +21,12 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.asterix.common.api.IDatasetLifecycleManager;
@@ -148,6 +150,12 @@
                         resourcePath, iInfo.getReferenceCount(), 
opTracker.getNumActiveOperations());
                 LOGGER.error(logMsg);
             }
+            int refCount = iInfo.getReferenceCount();
+            LOGGER.error("The index " + resourcePath + " was opened but not 
closed from " + refCount + " place(s)");
+            for (Entry<Long, StackTraceElement[]> entry : 
iInfo.getCallers().entrySet()) {
+                LOGGER.error("The index " + resourcePath + " was opened but 
not closed from "
+                        + Arrays.toString(entry.getValue()));
+            }
             throw 
HyracksDataException.create(ErrorCode.CANNOT_DROP_IN_USE_INDEX,
                     StoragePathUtil.getIndexNameFromPath(resourcePath));
         }
diff --git 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/Info.java
 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/Info.java
index 8afae0d..a625af5 100644
--- 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/Info.java
+++ 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/Info.java
@@ -18,9 +18,19 @@
  */
 package org.apache.asterix.common.context;
 
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
 public abstract class Info {
+    private static final Logger LOGGER = LogManager.getLogger();
     private int referenceCount;
     private boolean isOpen;
+    private final Map<Long, StackTraceElement[]> callers = new HashMap<>();
 
     public Info() {
         referenceCount = 0;
@@ -28,10 +38,24 @@
     }
 
     public void touch() {
+        long tid = Thread.currentThread().getId();
+        if (callers.containsKey(tid)) {
+            LOGGER.log(Level.WARN,
+                    "\"Double touch of a resource by thread:" + tid + ". 
Previous call was from: "
+                            + Arrays.toString(callers.get(tid)) + ". This call 
is from: "
+                            + Arrays.toString(new 
Throwable().getStackTrace()));
+            throw new RuntimeException("Double touch of a resource by thread: 
" + tid);
+        }
+        callers.put(tid, new Throwable().getStackTrace());
         ++referenceCount;
     }
 
     public void untouch() {
+        long tid = Thread.currentThread().getId();
+        StackTraceElement[] caller = callers.remove(tid);
+        if (caller == null) {
+            throw new RuntimeException("Untouch of an untouched resource by 
thread: " + tid);
+        }
         --referenceCount;
     }
 
@@ -46,4 +70,8 @@
     public void setOpen(boolean isOpen) {
         this.isOpen = isOpen;
     }
+
+    public Map<Long, StackTraceElement[]> getCallers() {
+        return callers;
+    }
 }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/2364
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idb8ce0284ecdbd67adf28082f2081309259194a4
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: abdullah alamoudi <[email protected]>

Reply via email to