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 11:11:01 UTC

[GitHub] [incubator-doris] EmmyMiao87 opened a new pull request #5314: Support content, exclude and whole database in backup

EmmyMiao87 opened a new pull request #5314:
URL: https://github.com/apache/incubator-doris/pull/5314


   ## Proposed changes
   This PR support following functions:
   1. Support content properties in backup stmt. It means user can backup only metadata or meta+data which use content [METADATA_ONLY| ALL]attribute to distinguish.
   2. Support exclude some tables in backup and restore stmt. This means that some very large and unimportant tables can be excluded when the entire database is backed up.
   3. Support backup and restore whole database instead of declaring each table name in the backup and restore statement.
   
   The backup and restore api has changed as following:
   ```
   BACKUP SNAPSHOT [db_name].{snapshot_name}
   TO 'repo_name'
   [ON|EXCLUDE (
       'table_name' [partition (p1,...)]
   )]
   [properties (
       "content" = "metadata_only|all"
   )]
   
   RESTORE SNAPSHOT [db_name].{snapshot_name}
   TO 'repo_name'
   [EXCLUDE|ON (
       'table_name' [partition (p1,...)]
   )]
   [properties (
   )]
   ```
   
   ## Types of changes
   
   What types of changes does your code introduce to Doris?
   _Put an `x` in the boxes that apply_
   
   - [] Bugfix (non-breaking change which fixes an issue)
   - [x] New feature (non-breaking change which adds functionality)
   - [] Breaking change (fix or feature that would cause existing functionality to not work as expected)
   - [] Documentation Update (if none of the other choices apply)
   - [] Code refactor (Modify the code structure, format the code, etc...)
   
   ## Checklist
   
   _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._
   
   - [] I have created an issue on (Fix #5298 ) and described the bug/feature there in detail
   - [x] Compiling and unit tests pass locally with my changes
   - [x] I have added tests that prove my fix is effective or that my feature works
   - [TODO] If these changes need document changes, I have updated the document
   - [] Any dependent changes have been merged
   
   ## Further comments
   
   I will continue to update the documentation, please review my code first.
   


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


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

Posted by GitBox <gi...@apache.org>.
morningman merged pull request #5314:
URL: https://github.com/apache/incubator-doris/pull/5314


   


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


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

Posted by GitBox <gi...@apache.org>.
EmmyMiao87 commented on a change in pull request #5314:
URL: https://github.com/apache/incubator-doris/pull/5314#discussion_r566528366



##########
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:
       I think it can be checked but it is not necessary to report an error.Just write a log.




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


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

Posted by GitBox <gi...@apache.org>.
EmmyMiao87 commented on a change in pull request #5314:
URL: https://github.com/apache/incubator-doris/pull/5314#discussion_r566541272



##########
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, it will be serialized by default, but some serialized names and attribute names are different.




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


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

Posted by GitBox <gi...@apache.org>.
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