You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by ni...@apache.org on 2019/08/15 08:48:04 UTC

[kylin] branch master updated: KYLIN-4131 Fix Broadcaster memory leak

This is an automated email from the ASF dual-hosted git repository.

nic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kylin.git


The following commit(s) were added to refs/heads/master by this push:
     new 1942729  KYLIN-4131 Fix Broadcaster memory leak
1942729 is described below

commit 194272986e6dec96a78f1228d27e0208a68a268b
Author: chao long <wa...@qq.com>
AuthorDate: Mon Aug 12 23:15:11 2019 +0800

    KYLIN-4131 Fix Broadcaster memory leak
---
 .../java/org/apache/kylin/common/Closeable.java    | 23 ++++++++++++++++++++++
 .../java/org/apache/kylin/common/KylinConfig.java  | 15 ++++++++++++++
 .../kylin/metadata/cachesync/Broadcaster.java      | 12 ++++++++---
 3 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/core-common/src/main/java/org/apache/kylin/common/Closeable.java b/core-common/src/main/java/org/apache/kylin/common/Closeable.java
new file mode 100644
index 0000000..e5e3de6
--- /dev/null
+++ b/core-common/src/main/java/org/apache/kylin/common/Closeable.java
@@ -0,0 +1,23 @@
+/*
+ * 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.kylin.common;
+
+public interface Closeable {
+    void close();
+}
diff --git a/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java b/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java
index f7c6033..ffa666f 100644
--- a/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java
+++ b/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java
@@ -479,7 +479,22 @@ public class KylinConfig extends KylinConfigBase {
             return;
         }
 
+        Map<Class, Closeable> closableManagers = new ConcurrentHashMap<>();
+
+        managersCache.forEach((key, value) -> {
+            if (value instanceof Closeable) {
+                closableManagers.put(key, (Closeable) value);
+            }
+        });
+
         managersCache.clear();
+
+        if (closableManagers.size() > 0) {
+            closableManagers.forEach((key, value) -> {
+                logger.info("Close manager {}", key.getSimpleName());
+                value.close();
+            });
+        }
     }
 
     public Properties exportToProperties() {
diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/cachesync/Broadcaster.java b/core-metadata/src/main/java/org/apache/kylin/metadata/cachesync/Broadcaster.java
index 834401c..7e6ee7c 100644
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/cachesync/Broadcaster.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/cachesync/Broadcaster.java
@@ -33,6 +33,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.kylin.common.Closeable;
 import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.common.restclient.RestClient;
 import org.apache.kylin.common.util.ClassUtil;
@@ -57,7 +58,7 @@ import com.google.common.collect.Maps;
  * - on all servers, model listener is invoked, reload the model, and notify a "project_schema" update event
  * - all listeners respond to the "project_schema" update -- reload cube desc, clear project L2 cache, clear calcite data source etc
  */
-public class Broadcaster {
+public class Broadcaster implements Closeable {
 
     private static final Logger logger = LoggerFactory.getLogger(Broadcaster.class);
 
@@ -153,6 +154,11 @@ public class Broadcaster {
         });
     }
 
+    @Override
+    public void close() {
+        stopAnnounce();
+    }
+
     private SyncErrorHandler getSyncErrorHandler(KylinConfig config) {
         String clzName = config.getCacheSyncErrorHandler();
         if (StringUtils.isEmpty(clzName)) {
@@ -166,8 +172,8 @@ public class Broadcaster {
     }
     
     public void stopAnnounce() {
-        announceThreadPool.shutdown();
-        announceMainLoop.shutdown();
+        announceThreadPool.shutdownNow();
+        announceMainLoop.shutdownNow();
     }
 
     // static listener survives cache wipe and goes after normal listeners