This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 621d394a5e0 [enhance](Backup) Do connectivity check when creating
repository (#38350) (#39538)
621d394a5e0 is described below
commit 621d394a5e00582ef2e44721ccf200a9e81fc9fd
Author: Gavin Chou <[email protected]>
AuthorDate: Mon Aug 19 22:16:02 2024 +0800
[enhance](Backup) Do connectivity check when creating repository (#38350)
(#39538)
Previously when creating repository, FE would not do connectivity check.
It might result in confusing error when using backup restore.
pick #38350
Co-authored-by: AlexYue <[email protected]>
---
.../org/apache/doris/backup/BackupHandler.java | 5 ++-
.../java/org/apache/doris/backup/Repository.java | 3 ++
.../org/apache/doris/backup/BackupHandlerTest.java | 1 +
.../test_backup_connectivity_failed.groovy | 40 ++++++++++++++++++++++
4 files changed, 48 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java
b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java
index 4db8994107f..5feeb8005bd 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupHandler.java
@@ -91,7 +91,6 @@ public class BackupHandler extends MasterDaemon implements
Writable {
public static final int SIGNATURE_VERSION = 1;
public static final Path BACKUP_ROOT_DIR = Paths.get(Config.tmp_dir,
"backup").normalize();
public static final Path RESTORE_ROOT_DIR = Paths.get(Config.tmp_dir,
"restore").normalize();
-
private RepositoryMgr repoMgr = new RepositoryMgr();
// this lock is used for updating dbIdToBackupOrRestoreJobs
@@ -220,6 +219,10 @@ public class BackupHandler extends MasterDaemon implements
Writable {
ErrorReport.reportDdlException(ErrorCode.ERR_COMMON_ERROR,
"Failed to create repository: " +
st.getErrMsg());
}
+ if (!repo.ping()) {
+ ErrorReport.reportDdlException(ErrorCode.ERR_COMMON_ERROR,
+ "Failed to create repository: failed to connect to the
repo");
+ }
}
public void alterRepository(AlterRepositoryStmt stmt) throws DdlException {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/backup/Repository.java
b/fe/fe-core/src/main/java/org/apache/doris/backup/Repository.java
index 879f248f6a1..04b93ab6a2f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/backup/Repository.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/backup/Repository.java
@@ -368,6 +368,9 @@ public class Repository implements Writable {
// Check if this repo is available.
// If failed to connect this repo, set errMsg and return false.
public boolean ping() {
+ if (FeConstants.runningUnitTest) {
+ return true;
+ }
// for s3 sdk, the headObject() method does not support list "dir",
// so we check FILE_REPO_INFO instead.
String path = location + "/" + joinPrefix(PREFIX_REPO, name) + "/" +
FILE_REPO_INFO;
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/backup/BackupHandlerTest.java
b/fe/fe-core/src/test/java/org/apache/doris/backup/BackupHandlerTest.java
index 97e689b6972..ba564599029 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/backup/BackupHandlerTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/backup/BackupHandlerTest.java
@@ -105,6 +105,7 @@ public class BackupHandlerTest {
Config.tmp_dir = tmpPath;
rootDir = new File(Config.tmp_dir);
rootDir.mkdirs();
+ FeConstants.runningUnitTest = true;
new Expectations() {
{
diff --git
a/regression-test/suites/backup_restore/test_backup_connectivity_failed.groovy
b/regression-test/suites/backup_restore/test_backup_connectivity_failed.groovy
new file mode 100644
index 00000000000..1b18032aaca
--- /dev/null
+++
b/regression-test/suites/backup_restore/test_backup_connectivity_failed.groovy
@@ -0,0 +1,40 @@
+// 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", "connectivity_failed") {
+ def name = "test_name"
+ def bucket = "useless_bucket"
+ def prefix = "useless_prefix"
+ def endpoint = getS3Endpoint()
+ def region = getS3Region()
+ def ak = getS3AK()
+ def sk = getS3SK()
+ expectExceptionLike({
+ sql """
+ CREATE REPOSITORY `${name}`
+ WITH S3
+ ON LOCATION "s3://${bucket}/${prefix}/${name}"
+ PROPERTIES
+ (
+ "s3.endpoint" = "http://${endpoint}",
+ "s3.region" = "${region}",
+ "s3.access_key" = "${ak}",
+ "s3.secret_key" = "${sk}"
+ )
+ """
+ }, "Failed to create repository")
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]