You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2021/01/28 15:21:17 UTC

[GitHub] [incubator-doris] morningman commented on a change in pull request #5314: [Backup]Support content, exclude and whole database in backup

morningman commented on a change in pull request #5314:
URL: https://github.com/apache/incubator-doris/pull/5314#discussion_r566168484



##########
File path: fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java
##########
@@ -269,10 +271,30 @@ private void backup(Repository repository, Database db, BackupStmt stmt) throws
                     + " is read only");
         }
 
+        // Determine the tables to be backed up
+        Set<String> tableNames = Sets.newHashSet();
+        AbstractBackupTableRefClause abstractBackupTableRefClause = stmt.getAbstractBackupTableRefClause();
+        if (abstractBackupTableRefClause == null) {
+            tableNames = db.getTableNamesWithLock();
+        } else if (abstractBackupTableRefClause != null && abstractBackupTableRefClause.isExclude()) {

Review comment:
       ```suggestion
           } else if (abstractBackupTableRefClause.isExclude()) {
   ```

##########
File path: fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java
##########
@@ -269,10 +271,30 @@ private void backup(Repository repository, Database db, BackupStmt stmt) throws
                     + " is read only");
         }
 
+        // Determine the tables to be backed up
+        Set<String> tableNames = Sets.newHashSet();
+        AbstractBackupTableRefClause abstractBackupTableRefClause = stmt.getAbstractBackupTableRefClause();
+        if (abstractBackupTableRefClause == null) {
+            tableNames = db.getTableNamesWithLock();
+        } else if (abstractBackupTableRefClause != null && abstractBackupTableRefClause.isExclude()) {
+            tableNames = db.getTableNamesWithLock();
+            for (TableRef tableRef : abstractBackupTableRefClause.getTableRefList()) {
+                tableNames.remove(tableRef.getName().getTbl());
+            }
+        }
+        List<TableRef> tblRefs = Lists.newArrayList();
+        if (tableNames.isEmpty()) {

Review comment:
       There may be no table in database at all, and in this case, the `tableNames` is empty, and `abstractBackupTableRefClause` is null. So NPE will thrown.

##########
File path: fe/fe-core/src/main/java/org/apache/doris/backup/BackupJobInfo.java
##########
@@ -204,6 +278,7 @@ public String getOrginNameByAlias(String alias) {
         public String database;
         @SerializedName("backup_time")
         public long backupTime;
+        public BackupContent content;

Review comment:
       No need `@SerializedName`?

##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/AbstractBackupTableRefClause.java
##########
@@ -0,0 +1,87 @@
+// 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.doris.analysis;
+
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.UserException;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Maps;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+import java.util.Map;
+
+public class AbstractBackupTableRefClause implements ParseNode {
+    private static final Logger LOG = LogManager.getLogger(AbstractBackupTableRefClause.class);
+
+    private boolean isExclude;
+    private List<TableRef> tableRefList;
+
+    public AbstractBackupTableRefClause(boolean isExclude, List<TableRef> tableRefList) {
+        this.isExclude = isExclude;
+        this.tableRefList = tableRefList;
+    }
+
+    @Override
+    public void analyze(Analyzer analyzer) throws UserException {
+        // normalize
+        // table name => table ref
+        Map<String, TableRef> tblPartsMap = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
+        for (TableRef tblRef : tableRefList) {
+            String tblName = tblRef.getName().getTbl();
+            if (!tblPartsMap.containsKey(tblName)) {
+                tblPartsMap.put(tblName, tblRef);
+            } else {
+                throw new AnalysisException("Duplicated restore table: " + tblName);
+            }
+        }
+
+        // update table ref
+        tableRefList.clear();
+        for (TableRef tableRef : tblPartsMap.values()) {
+            tableRefList.add(tableRef);
+        }
+
+        LOG.debug("table refs after normalization: \n{}", Joiner.on("\n").join(tableRefList));

Review comment:
       do not use `\n`, for easy log greping.

##########
File path: fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java
##########
@@ -269,10 +271,30 @@ private void backup(Repository repository, Database db, BackupStmt stmt) throws
                     + " is read only");
         }
 
+        // Determine the tables to be backed up
+        Set<String> tableNames = Sets.newHashSet();
+        AbstractBackupTableRefClause abstractBackupTableRefClause = stmt.getAbstractBackupTableRefClause();
+        if (abstractBackupTableRefClause == null) {
+            tableNames = db.getTableNamesWithLock();
+        } else if (abstractBackupTableRefClause != null && abstractBackupTableRefClause.isExclude()) {
+            tableNames = db.getTableNamesWithLock();
+            for (TableRef tableRef : abstractBackupTableRefClause.getTableRefList()) {
+                tableNames.remove(tableRef.getName().getTbl());

Review comment:
       Do we need to check if there "excluded" tables exist in database?
   
   eg:
   ```suggestion
                   if (!tableNames.remove(tableRef.getName().getTbl())) {
                       throw exception()
                   }
   ```




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org