From 3412a022f41a2df16666a9fad512a14041f439b1 Mon Sep 17 00:00:00 2001 From: yuxuan-luo <119841515+yuxuan-luo@users.noreply.github.com> Date: Tue, 5 Dec 2023 10:55:28 +0800 Subject: [PATCH] =?UTF-8?q?[fix](restore)=20fix=20Restore=20from=20=5F=5Fk?= =?UTF-8?q?eep=5Fon=5Flocal=5F=5F=20throws=20null=20pointer=E2=80=A6=20(#2?= =?UTF-8?q?6943)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: walter Co-authored-by: hugoluo Co-authored-by: walter --- .../apache/doris/analysis/RestoreStmt.java | 4 + .../test_backup_restore_keep_on_local.groovy | 78 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 regression-test/suites/backup_restore/test_backup_restore_keep_on_local.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/RestoreStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/RestoreStmt.java index 3b5f46a37c..9f5f6ee725 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/RestoreStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/RestoreStmt.java @@ -112,6 +112,10 @@ public class RestoreStmt extends AbstractBackupStmt { public void analyze(Analyzer analyzer) throws UserException { if (repoName.equals(Repository.KEEP_ON_LOCAL_REPO_NAME)) { isLocal = true; + if (jobInfo == null) { + ErrorReport.reportDdlException(ErrorCode.ERR_COMMON_ERROR, + "restore from the local repo via SQL call is not supported"); + } } super.analyze(analyzer); } diff --git a/regression-test/suites/backup_restore/test_backup_restore_keep_on_local.groovy b/regression-test/suites/backup_restore/test_backup_restore_keep_on_local.groovy new file mode 100644 index 0000000000..d18006c101 --- /dev/null +++ b/regression-test/suites/backup_restore/test_backup_restore_keep_on_local.groovy @@ -0,0 +1,78 @@ +// 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. + +suite("test_backup_restore_keep_on_local", "backup_restore") { + String repoName = "__keep_on_local__" + String dbName = "backup_restore_keep_on_local_db" + String tableName = "test_backup_restore_table" + + def syncer = getSyncer() + + sql "CREATE DATABASE IF NOT EXISTS ${dbName}" + sql "DROP TABLE IF EXISTS ${dbName}.${tableName}" + sql """ + CREATE TABLE ${dbName}.${tableName} ( + `id` LARGEINT NOT NULL, + `count` LARGEINT SUM DEFAULT "0") + AGGREGATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 2 + PROPERTIES + ( + "replication_num" = "1" + ) + """ + + List values = [] + for (int i = 1; i <= 10; ++i) { + values.add("(${i}, ${i})") + } + sql "INSERT INTO ${dbName}.${tableName} VALUES ${values.join(",")}" + def result = sql "SELECT * FROM ${dbName}.${tableName}" + assertEquals(result.size(), values.size()); + + String snapshotName = "test_backup_restore_snapshot" + sql """ + BACKUP SNAPSHOT ${dbName}.${snapshotName} + TO `${repoName}` + ON (${tableName}) + """ + + while (!syncer.checkSnapshotFinish(dbName)) { + Thread.sleep(3000) + } + + sql "TRUNCATE TABLE ${dbName}.${tableName}" + + try { + sql """ + RESTORE SNAPSHOT ${dbName}.${snapshotName} + FROM `${repoName}` + ON ( `${tableName}`) + PROPERTIES + ( + "replication_num" = "1" + ) + """ + } catch (Exception e) { + // Check the error message + assertTrue(e.message.contains("not supported")) + } + + sql "DROP TABLE ${dbName}.${tableName} FORCE" + sql "DROP DATABASE ${dbName} FORCE" +} +