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/16 05:43:45 UTC
[kylin] branch master updated: KYLIN-4137 Accelerate metadata
reloading
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 dfb8488 KYLIN-4137 Accelerate metadata reloading
dfb8488 is described below
commit dfb848844f9e6c9e9984f99a347d4e70f44c4249
Author: Temple Zhou <db...@gmail.com>
AuthorDate: Wed Aug 14 15:34:23 2019 +0800
KYLIN-4137 Accelerate metadata reloading
---
.../kylin/common/persistence/ResourceStore.java | 28 ++++++++++++++++++
.../kylin/metadata/cachesync/CachedCrudAssist.java | 33 +++++++++++++++++++---
2 files changed, 57 insertions(+), 4 deletions(-)
diff --git a/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceStore.java b/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceStore.java
index 20a9b0a..097b4e5 100644
--- a/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceStore.java
+++ b/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceStore.java
@@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.NavigableSet;
import java.util.TreeSet;
import java.util.UUID;
@@ -243,6 +244,33 @@ abstract public class ResourceStore {
}
/**
+ * Read all resources under a folder having last modified time between given range. Return empty map if folder not exist.
+ *
+ * NOTE: Different from the getAllResources, this return value will contain the resource path.
+ */
+ final public <T extends RootPersistentEntity> Map<String, T> getAllResourcesMap(final String folderPath,
+ final boolean recursive, final VisitFilter filter, final ContentReader<T> reader) throws IOException {
+
+ return new ExponentialBackoffRetry(this).doWithRetry(() -> {
+ final LinkedHashMap<String, T> collector = new LinkedHashMap<>();
+ visitFolderAndContent(folderPath, recursive, filter, new Visitor() {
+ @Override
+ public void visit(RawResource resource) throws IOException {
+ try {
+ T entity = reader.readContent(resource);
+ if (entity != null) {
+ collector.put(resource.path(), entity);
+ }
+ } catch (Exception ex) {
+ logger.error("Error reading resource " + resource.path(), ex);
+ }
+ }
+ });
+ return collector;
+ });
+ }
+
+ /**
* Return true if a resource exists, return false in case of folder or non-exist
*/
final public boolean exists(String resPath) throws IOException {
diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/cachesync/CachedCrudAssist.java b/core-metadata/src/main/java/org/apache/kylin/metadata/cachesync/CachedCrudAssist.java
index bb1b374..0305cad 100644
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/cachesync/CachedCrudAssist.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/cachesync/CachedCrudAssist.java
@@ -25,7 +25,9 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import org.apache.kylin.common.persistence.ContentReader;
import org.apache.kylin.common.persistence.JsonSerializer;
import org.apache.kylin.common.persistence.ResourceStore;
import org.apache.kylin.common.persistence.RootPersistentEntity;
@@ -122,12 +124,35 @@ abstract public class CachedCrudAssist<T extends RootPersistentEntity> {
cache.clear();
loadErrors.clear();
- List<String> paths = store.collectResourceRecursively(resRootPath, resPathSuffix);
- for (String path : paths) {
- reloadQuietlyAt(path);
+ Map<String, T> entities = store.getAllResourcesMap(resRootPath, true, null, new ContentReader(serializer));
+ for (Map.Entry<String,T> entitySet: entities.entrySet()) {
+ String path = entitySet.getKey();
+ if (!path.endsWith(resPathSuffix)) {
+ continue;
+ }
+
+ T entity = entitySet.getValue();
+ try {
+ if (entity == null) {
+ logger.warn("No " + entityType.getSimpleName() + " found at " + path + ", returning null");
+ cache.removeLocal(resourceName(path));
+ continue;
+ }
+
+ // mark cached object
+ entity.setCachedAndShared(true);
+ entity = initEntityAfterReload(entity, resourceName(path));
+
+ if (path.equals(resourcePath(entity.resourceName()))) {
+ cache.putLocal(entity.resourceName(), entity);
+ }
+ } catch (Exception ex) {
+ logger.error("Error loading " + entityType.getSimpleName() + " at " + path, ex);
+ loadErrors.add(path);
+ }
}
- logger.debug("Loaded " + cache.size() + " " + entityType.getSimpleName() + "(s) out of " + paths.size()
+ logger.debug("Loaded " + cache.size() + " " + entityType.getSimpleName() + "(s) out of " + entities.size()
+ " resource with " + loadErrors.size() + " errors");
}