w41ter commented on code in PR #25943:
URL: https://github.com/apache/doris/pull/25943#discussion_r1372797261


##########
fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java:
##########
@@ -3331,4 +3338,174 @@ public TCreatePartitionResult 
createPartition(TCreatePartitionRequest request) t
         LOG.debug("send create partition result: {}", result);
         return result;
     }
+
+    public TGetMetaResult getMeta(TGetMetaRequest request) throws TException {
+        String clientAddr = getClientAddrAsString();
+        LOG.debug("receive get meta request: {}", request);
+
+        TGetMetaResult result = new TGetMetaResult();
+        TStatus status = new TStatus(TStatusCode.OK);
+        result.setStatus(status);
+        try {
+            result = getMetaImpl(request, clientAddr);
+        } catch (UserException e) {
+            LOG.warn("failed to get meta: {}", e.getMessage());
+            status.setStatusCode(TStatusCode.ANALYSIS_ERROR);
+            status.addToErrorMsgs(e.getMessage());
+        } catch (Throwable e) {
+            LOG.warn("catch unknown result.", e);
+            status.setStatusCode(TStatusCode.INTERNAL_ERROR);
+            status.addToErrorMsgs(Strings.nullToEmpty(e.getMessage()));
+            return result;

Review Comment:
   ```suggestion
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java:
##########
@@ -3331,4 +3338,174 @@ public TCreatePartitionResult 
createPartition(TCreatePartitionRequest request) t
         LOG.debug("send create partition result: {}", result);
         return result;
     }
+
+    public TGetMetaResult getMeta(TGetMetaRequest request) throws TException {
+        String clientAddr = getClientAddrAsString();
+        LOG.debug("receive get meta request: {}", request);
+
+        TGetMetaResult result = new TGetMetaResult();
+        TStatus status = new TStatus(TStatusCode.OK);
+        result.setStatus(status);
+        try {
+            result = getMetaImpl(request, clientAddr);
+        } catch (UserException e) {
+            LOG.warn("failed to get meta: {}", e.getMessage());
+            status.setStatusCode(TStatusCode.ANALYSIS_ERROR);
+            status.addToErrorMsgs(e.getMessage());
+        } catch (Throwable e) {
+            LOG.warn("catch unknown result.", e);
+            status.setStatusCode(TStatusCode.INTERNAL_ERROR);
+            status.addToErrorMsgs(Strings.nullToEmpty(e.getMessage()));
+            return result;
+        }
+        return result;
+    }
+
+    private TGetMetaResult getMetaImpl(TGetMetaRequest request, String 
clientIp)
+            throws Exception {
+        //  Step 1: check fields
+        if (!request.isSetUser()) {
+            throw new UserException("user is not set");
+        }
+        if (!request.isSetPasswd()) {
+            throw new UserException("passwd is not set");
+        }
+        if (!request.isSetDb()) {
+            throw new UserException("db is not set");
+        }
+
+        // Step 2: check auth
+        TGetMetaResult result = new TGetMetaResult();
+        result.setStatus(new TStatus(TStatusCode.OK));
+        Database db = null;
+        List<Table> tables = null;
+
+        String cluster = request.getCluster();
+        if (Strings.isNullOrEmpty(cluster)) {
+            cluster = SystemInfoService.DEFAULT_CLUSTER;
+        }
+        if (Strings.isNullOrEmpty(request.getToken())) {
+            TGetMetaDB getMetaDb = request.getDb();
+
+            if (getMetaDb.isSetId()) {
+                db = 
Env.getCurrentInternalCatalog().getDbNullable(getMetaDb.getId());
+            } else if (getMetaDb.isSetName()) {
+                db = 
Env.getCurrentInternalCatalog().getDbNullable(getMetaDb.getName());
+            }
+
+            if (db == null) {
+                LOG.warn("db not found {}", getMetaDb);
+                return result;
+            }
+
+            if (getMetaDb.isSetTables()) {
+                tables = Lists.newArrayList();
+                List<TGetMetaTable> getMetaTables = getMetaDb.getTables();
+                for (TGetMetaTable getMetaTable : getMetaTables) {
+                    Table table = null;
+                    if (getMetaTable.isSetId()) {
+                        table = db.getTableNullable(getMetaTable.getId());
+                    } else {
+                        table = db.getTableNullable(getMetaTable.getName());
+                    }
+
+                    if (table == null) {
+                        LOG.warn("table not found {}", getMetaTable);
+                        continue;
+                    }
+
+                    tables.add(table);
+                }
+            }
+
+            if (tables == null) {
+                checkDbPasswordAndPrivs(cluster, request.getUser(), 
request.getPasswd(), db.getFullName(), clientIp,
+                        PrivPredicate.SELECT);
+            } else {
+                List<String> tableList = Lists.newArrayList();
+                for (Table table : tables) {
+                    tableList.add(table.getName());
+                }
+                checkPasswordAndPrivs(cluster, request.getUser(), 
request.getPasswd(), db.getFullName(), tableList,
+                        clientIp,
+                        PrivPredicate.SELECT);
+            }
+        }
+
+        // Step 3: get meta
+        try {
+            result = Env.getMeta(db, tables);
+            return result;
+        } catch (Throwable e) {
+            throw e;
+        }

Review Comment:
   Just `return Env.getMeta(db, tables);`   ?



##########
fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java:
##########
@@ -3331,4 +3338,174 @@ public TCreatePartitionResult 
createPartition(TCreatePartitionRequest request) t
         LOG.debug("send create partition result: {}", result);
         return result;
     }
+
+    public TGetMetaResult getMeta(TGetMetaRequest request) throws TException {
+        String clientAddr = getClientAddrAsString();
+        LOG.debug("receive get meta request: {}", request);
+
+        TGetMetaResult result = new TGetMetaResult();
+        TStatus status = new TStatus(TStatusCode.OK);
+        result.setStatus(status);
+        try {
+            result = getMetaImpl(request, clientAddr);
+        } catch (UserException e) {
+            LOG.warn("failed to get meta: {}", e.getMessage());
+            status.setStatusCode(TStatusCode.ANALYSIS_ERROR);
+            status.addToErrorMsgs(e.getMessage());
+        } catch (Throwable e) {
+            LOG.warn("catch unknown result.", e);
+            status.setStatusCode(TStatusCode.INTERNAL_ERROR);
+            status.addToErrorMsgs(Strings.nullToEmpty(e.getMessage()));
+            return result;
+        }
+        return result;
+    }
+
+    private TGetMetaResult getMetaImpl(TGetMetaRequest request, String 
clientIp)
+            throws Exception {
+        //  Step 1: check fields
+        if (!request.isSetUser()) {
+            throw new UserException("user is not set");
+        }
+        if (!request.isSetPasswd()) {
+            throw new UserException("passwd is not set");
+        }
+        if (!request.isSetDb()) {
+            throw new UserException("db is not set");
+        }
+
+        // Step 2: check auth
+        TGetMetaResult result = new TGetMetaResult();
+        result.setStatus(new TStatus(TStatusCode.OK));
+        Database db = null;
+        List<Table> tables = null;
+
+        String cluster = request.getCluster();
+        if (Strings.isNullOrEmpty(cluster)) {
+            cluster = SystemInfoService.DEFAULT_CLUSTER;
+        }
+        if (Strings.isNullOrEmpty(request.getToken())) {
+            TGetMetaDB getMetaDb = request.getDb();
+
+            if (getMetaDb.isSetId()) {
+                db = 
Env.getCurrentInternalCatalog().getDbNullable(getMetaDb.getId());
+            } else if (getMetaDb.isSetName()) {
+                db = 
Env.getCurrentInternalCatalog().getDbNullable(getMetaDb.getName());
+            }
+
+            if (db == null) {
+                LOG.warn("db not found {}", getMetaDb);
+                return result;
+            }
+
+            if (getMetaDb.isSetTables()) {
+                tables = Lists.newArrayList();
+                List<TGetMetaTable> getMetaTables = getMetaDb.getTables();
+                for (TGetMetaTable getMetaTable : getMetaTables) {
+                    Table table = null;
+                    if (getMetaTable.isSetId()) {
+                        table = db.getTableNullable(getMetaTable.getId());
+                    } else {
+                        table = db.getTableNullable(getMetaTable.getName());
+                    }
+
+                    if (table == null) {
+                        LOG.warn("table not found {}", getMetaTable);
+                        continue;
+                    }
+
+                    tables.add(table);
+                }
+            }
+
+            if (tables == null) {
+                checkDbPasswordAndPrivs(cluster, request.getUser(), 
request.getPasswd(), db.getFullName(), clientIp,
+                        PrivPredicate.SELECT);
+            } else {
+                List<String> tableList = Lists.newArrayList();
+                for (Table table : tables) {
+                    tableList.add(table.getName());
+                }
+                checkPasswordAndPrivs(cluster, request.getUser(), 
request.getPasswd(), db.getFullName(), tableList,
+                        clientIp,
+                        PrivPredicate.SELECT);
+            }
+        }
+
+        // Step 3: get meta
+        try {
+            result = Env.getMeta(db, tables);
+            return result;
+        } catch (Throwable e) {
+            throw e;
+        }
+    }
+
+    public TGetBackendMetaResult getBackendMeta(TGetBackendMetaRequest 
request) throws TException {
+        String clientAddr = getClientAddrAsString();
+        LOG.debug("receive get backend meta request: {}", request);
+
+        TGetBackendMetaResult result = new TGetBackendMetaResult();
+        TStatus status = new TStatus(TStatusCode.OK);
+        result.setStatus(status);
+        try {
+            result = getBackendMetaImpl(request, clientAddr);
+        } catch (UserException e) {
+            LOG.warn("failed to get backend meta: {}", e.getMessage());
+            status.setStatusCode(TStatusCode.ANALYSIS_ERROR);
+            status.addToErrorMsgs(e.getMessage());
+        } catch (Throwable e) {
+            LOG.warn("catch unknown result.", e);
+            status.setStatusCode(TStatusCode.INTERNAL_ERROR);
+            status.addToErrorMsgs(Strings.nullToEmpty(e.getMessage()));
+            return result;

Review Comment:
   ```suggestion
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java:
##########
@@ -3331,4 +3338,174 @@ public TCreatePartitionResult 
createPartition(TCreatePartitionRequest request) t
         LOG.debug("send create partition result: {}", result);
         return result;
     }
+
+    public TGetMetaResult getMeta(TGetMetaRequest request) throws TException {
+        String clientAddr = getClientAddrAsString();
+        LOG.debug("receive get meta request: {}", request);
+
+        TGetMetaResult result = new TGetMetaResult();
+        TStatus status = new TStatus(TStatusCode.OK);
+        result.setStatus(status);
+        try {
+            result = getMetaImpl(request, clientAddr);
+        } catch (UserException e) {
+            LOG.warn("failed to get meta: {}", e.getMessage());
+            status.setStatusCode(TStatusCode.ANALYSIS_ERROR);
+            status.addToErrorMsgs(e.getMessage());
+        } catch (Throwable e) {
+            LOG.warn("catch unknown result.", e);
+            status.setStatusCode(TStatusCode.INTERNAL_ERROR);
+            status.addToErrorMsgs(Strings.nullToEmpty(e.getMessage()));
+            return result;
+        }
+        return result;
+    }
+
+    private TGetMetaResult getMetaImpl(TGetMetaRequest request, String 
clientIp)
+            throws Exception {
+        //  Step 1: check fields
+        if (!request.isSetUser()) {
+            throw new UserException("user is not set");
+        }
+        if (!request.isSetPasswd()) {
+            throw new UserException("passwd is not set");
+        }
+        if (!request.isSetDb()) {
+            throw new UserException("db is not set");
+        }
+
+        // Step 2: check auth
+        TGetMetaResult result = new TGetMetaResult();
+        result.setStatus(new TStatus(TStatusCode.OK));
+        Database db = null;
+        List<Table> tables = null;
+
+        String cluster = request.getCluster();
+        if (Strings.isNullOrEmpty(cluster)) {
+            cluster = SystemInfoService.DEFAULT_CLUSTER;
+        }
+        if (Strings.isNullOrEmpty(request.getToken())) {
+            TGetMetaDB getMetaDb = request.getDb();
+
+            if (getMetaDb.isSetId()) {
+                db = 
Env.getCurrentInternalCatalog().getDbNullable(getMetaDb.getId());
+            } else if (getMetaDb.isSetName()) {
+                db = 
Env.getCurrentInternalCatalog().getDbNullable(getMetaDb.getName());
+            }
+
+            if (db == null) {
+                LOG.warn("db not found {}", getMetaDb);
+                return result;

Review Comment:
   Is returns OK if db does not exist by design?



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java:
##########
@@ -5614,6 +5623,89 @@ public static boolean isTableNamesCaseInsensitive() {
         return GlobalVariable.lowerCaseTableNames == 2;
     }
 
+    private static void getTableMeta(OlapTable olapTable, TGetMetaDBMeta 
dbMeta) {
+        LOG.debug("get table meta. table: {}", olapTable.getName());
+
+        TGetMetaTableMeta tableMeta = new TGetMetaTableMeta();
+        olapTable.readLock();
+        try {
+            tableMeta.setId(olapTable.getId());
+            tableMeta.setName(olapTable.getName());
+
+            PartitionInfo tblPartitionInfo = olapTable.getPartitionInfo();
+
+            Collection<Partition> partitions = olapTable.getAllPartitions();
+            for (Partition partition : partitions) {
+                TGetMetaPartitionMeta partitionMeta = new 
TGetMetaPartitionMeta();
+                long partitionId = partition.getId();
+                partitionMeta.setId(partitionId);
+                partitionMeta.setName(partition.getName());
+                String partitionRange = "";
+                if (tblPartitionInfo.getType() == PartitionType.RANGE
+                        || tblPartitionInfo.getType() == PartitionType.LIST) {
+                    partitionRange = 
tblPartitionInfo.getItem(partitionId).getItems().toString();
+                }
+                partitionMeta.setRange(partitionRange);
+                partitionMeta.setVisibleVersion(partition.getVisibleVersion());
+                // partitionMeta.setTemp(partition.isTemp());

Review Comment:
   Isn't it needed here anymore?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to