You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2018/10/29 03:25:45 UTC

[kylin] branch 2.5.x updated: KYLIN-3651 JDBCResourceStore doesn't list all resources

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

shaofengshi pushed a commit to branch 2.5.x
in repository https://gitbox.apache.org/repos/asf/kylin.git


The following commit(s) were added to refs/heads/2.5.x by this push:
     new d1d8706  KYLIN-3651 JDBCResourceStore doesn't list all resources
d1d8706 is described below

commit d1d87065de99e1bf8a3927165a899ab32122d9da
Author: shaofengshi <sh...@apache.org>
AuthorDate: Mon Oct 29 08:36:29 2018 +0800

    KYLIN-3651 JDBCResourceStore doesn't list all resources
---
 .../kylin/common/persistence/JDBCResourceDAO.java  | 49 +++++++++++++++++-----
 1 file changed, 38 insertions(+), 11 deletions(-)

diff --git a/core-common/src/main/java/org/apache/kylin/common/persistence/JDBCResourceDAO.java b/core-common/src/main/java/org/apache/kylin/common/persistence/JDBCResourceDAO.java
index ddb8f4b..5ad484a 100644
--- a/core-common/src/main/java/org/apache/kylin/common/persistence/JDBCResourceDAO.java
+++ b/core-common/src/main/java/org/apache/kylin/common/persistence/JDBCResourceDAO.java
@@ -149,10 +149,21 @@ public class JDBCResourceDAO {
     //fetch primary key only
     public TreeSet<String> listAllResource(final String folderPath, final boolean recursive) throws SQLException {
         final TreeSet<String> allResourceName = new TreeSet<>();
+        if (isRootPath(folderPath)) {
+            for (int i = 0; i < tableNames.length; i++) {
+                final String tableName = tableNames[i];
+                listResource(tableName, folderPath, allResourceName, recursive);
+            }
+        } else {
+            listResource(getMetaTableName(folderPath), folderPath, allResourceName, recursive);
+        }
+        return allResourceName;
+    }
+
+    private void listResource(final String tableName, final String folderPath, final TreeSet<String> allResourceName, final boolean recursive) throws SQLException {
         executeSql(new SqlOperation() {
             @Override
             public void execute(Connection connection) throws SQLException {
-                String tableName = getMetaTableName(folderPath);
                 pstat = connection.prepareStatement(getListResourceSqlString(tableName));
                 pstat.setString(1, folderPath + "%");
                 rs = pstat.executeQuery();
@@ -169,7 +180,6 @@ public class JDBCResourceDAO {
                 }
             }
         });
-        return allResourceName;
     }
 
     public List<JDBCResource> getAllResource(final String folderPath, final long timeStart, final long timeEndExclusive,
@@ -224,28 +234,37 @@ public class JDBCResourceDAO {
     }
 
     public void deleteResource(final String resourcePath) throws SQLException {
+        if (isRootPath(resourcePath)) {
+            for (int i = 0; i < tableNames.length; i++) {
+                final String tableName = tableNames[i];
+                deleteResourceFromTable(tableName, resourcePath);
+            }
+        } else {
+            String tableName = getMetaTableName(resourcePath);
+            deleteResourceFromTable(tableName, resourcePath);
+        }
 
         boolean skipHdfs = isJsonMetadata(resourcePath);
+        if (!skipHdfs) {
+            try {
+                deleteHDFSResourceIfExist(resourcePath);
+            } catch (Throwable e) {
+                throw new SQLException(e);
+            }
+        }
+    }
 
+    private void deleteResourceFromTable(final String tableName, final String resourcePath) throws SQLException {
         executeSql(new SqlOperation() {
             @Override
             public void execute(Connection connection) throws SQLException {
-                String tableName = getMetaTableName(resourcePath);
                 pstat = connection.prepareStatement(getDeletePstatSql(tableName));
                 pstat.setString(1, resourcePath);
                 pstat.executeUpdate();
             }
         });
 
-        if (!skipHdfs) {
-            try {
-                deleteHDFSResourceIfExist(resourcePath);
-            } catch (Throwable e) {
-                throw new SQLException(e);
-            }
-        }
     }
-
     private void deleteHDFSResourceIfExist(String resourcePath) throws IOException {
         Path redirectPath = bigCellHDFSPath(resourcePath);
         if (redirectFileSystem.exists(redirectPath)) {
@@ -678,6 +697,10 @@ public class JDBCResourceDAO {
      * @return the table name
      */
     public String getMetaTableName(String resPath) {
+        if (isRootPath(resPath)) {
+            throw new IllegalArgumentException("Not supported");
+        }
+
         if (resPath.startsWith(ResourceStore.BAD_QUERY_RESOURCE_ROOT)
                 || resPath.startsWith(ResourceStore.EXECUTE_OUTPUT_RESOURCE_ROOT)
                 || resPath.startsWith(ResourceStore.TEMP_STATMENT_RESOURCE_ROOT)) {
@@ -687,4 +710,8 @@ public class JDBCResourceDAO {
         }
     }
 
+    public boolean isRootPath(String path) {
+        return "/".equals(path);
+    }
+
 }
\ No newline at end of file