[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 <yj976240184@gmail.com>
This commit is contained in:
Gavin Chou
2024-08-19 22:16:02 +08:00
committed by GitHub
parent 3922fdddb6
commit 621d394a5e
4 changed files with 48 additions and 1 deletions

View File

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

View File

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