Murtadha Hubail has uploaded a new change for review.

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

Change subject: [ASTERIXDB-2229][OTR] Restore Thread Names in Thread Pool
......................................................................

[ASTERIXDB-2229][OTR] Restore Thread Names in Thread Pool

- user model changes: no
- storage format changes: no
- interface changes: no

- Restore thread names to their original names
  before returning them to the pool of the NC
  app.

Change-Id: I3bda1b65e7aefd35d2b8cfa814f73369c3bf5a18
---
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java
A 
hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MaintainedThreadNameExecutorService.java
2 files changed, 58 insertions(+), 2 deletions(-)


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

diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java
index c724952..288e5f2 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java
@@ -28,7 +28,6 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 import java.util.stream.Collectors;
 
 import org.apache.asterix.active.ActiveManager;
@@ -102,6 +101,7 @@
 import org.apache.hyracks.storage.common.file.FileMapManager;
 import org.apache.hyracks.storage.common.file.ILocalResourceRepositoryFactory;
 import org.apache.hyracks.storage.common.file.IResourceIdFactory;
+import org.apache.hyracks.util.MaintainedThreadNameExecutorService;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -171,7 +171,8 @@
     @Override
     public void initialize(boolean initialRun) throws IOException, 
ACIDException {
         ioManager = getServiceContext().getIoManager();
-        threadExecutor = 
Executors.newCachedThreadPool(getServiceContext().getThreadFactory());
+        threadExecutor =
+                
MaintainedThreadNameExecutorService.newCachedThreadPool(getServiceContext().getThreadFactory());
         ICacheMemoryAllocator allocator = new HeapBufferAllocator();
         IPageCleanerPolicy pcp = new DelayPageCleanerPolicy(600000);
         IPageReplacementStrategy prs = new 
ClockPageReplacementStrategy(allocator,
diff --git 
a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MaintainedThreadNameExecutorService.java
 
b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MaintainedThreadNameExecutorService.java
new file mode 100644
index 0000000..e141758
--- /dev/null
+++ 
b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MaintainedThreadNameExecutorService.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hyracks.util;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+public class MaintainedThreadNameExecutorService extends ThreadPoolExecutor {
+
+    private final Map<Thread, String> threadNames = new HashMap<>();
+
+    private MaintainedThreadNameExecutorService(ThreadFactory threadFactory) {
+        super(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new 
SynchronousQueue<>(), threadFactory);
+    }
+
+    public static ExecutorService newCachedThreadPool(ThreadFactory 
threadFactory) {
+        return new MaintainedThreadNameExecutorService(threadFactory);
+    }
+
+    @Override
+    protected void beforeExecute(Thread t, Runnable r) {
+        threadNames.put(t, t.getName());
+        super.beforeExecute(t, r);
+    }
+
+    @Override
+    protected void afterExecute(Runnable r, Throwable t) {
+        final String threadName = threadNames.remove(Thread.currentThread());
+        if (threadName != null) {
+            Thread.currentThread().setName(threadName);
+        }
+        super.afterExecute(r, t);
+    }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3bda1b65e7aefd35d2b8cfa814f73369c3bf5a18
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Murtadha Hubail <mhub...@apache.org>

Reply via email to