This is an automated email from the ASF dual-hosted git repository.

dataroaring pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 58640caa735 [feat](cloud) change the type to optional in the alter 
storage vault command (#54394)
58640caa735 is described below

commit 58640caa735d6b5438668a9ab1592c987e27e5df
Author: lw112 <[email protected]>
AuthorDate: Fri Aug 8 09:57:25 2025 +0800

    [feat](cloud) change the type to optional in the alter storage vault 
command (#54394)
    
    ### What problem does this PR solve?
    
    change the type to optional in the alter storage vault command
    before
    ```
    ALTER STORAGE VAULT vault_name
    PROPERTIES (
      "type"="S3",
      "s3.access_key" = "new_ak"
    );
    ```
    now
    ```
    ALTER STORAGE VAULT vault_name
    PROPERTIES (
      "s3.access_key" = "new_ak"
    );
    ```
---
 .../org/apache/doris/catalog/StorageVaultMgr.java  | 21 +++++++++++++++++++
 .../plans/commands/AlterStorageVaultCommand.java   | 22 +++++++++++++++++---
 .../vault_p0/alter/test_alter_vault_type.groovy    | 24 ++++++++++++++++++++++
 3 files changed, 64 insertions(+), 3 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/catalog/StorageVaultMgr.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/StorageVaultMgr.java
index 76266356df4..6be61aabda6 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/StorageVaultMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/StorageVaultMgr.java
@@ -291,6 +291,27 @@ public class StorageVaultMgr {
         }
     }
 
+    public StorageVaultType getStorageVaultTypeByName(String vaultName) throws 
DdlException {
+        try {
+            Cloud.GetObjStoreInfoResponse resp = MetaServiceProxy.getInstance()
+                    
.getObjStoreInfo(Cloud.GetObjStoreInfoRequest.newBuilder().build());
+
+            for (Cloud.StorageVaultPB vault : resp.getStorageVaultList()) {
+                if (vault.getName().equals(vaultName)) {
+                    if (vault.hasHdfsInfo()) {
+                        return StorageVaultType.HDFS;
+                    } else if (vault.hasObjInfo()) {
+                        return StorageVaultType.S3;
+                    }
+                }
+            }
+            return StorageVaultType.UNKNOWN;
+        } catch (RpcException e) {
+            LOG.warn("failed to get storage vault type due to RpcException: 
{}", e);
+            throw new DdlException(e.getMessage());
+        }
+    }
+
     @VisibleForTesting
     public void createHdfsVault(StorageVault vault) throws Exception {
         Cloud.StorageVaultPB.Builder alterHdfsInfoBuilder = 
buildAlterStorageVaultRequest(vault);
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterStorageVaultCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterStorageVaultCommand.java
index f877ef0da14..ac428935934 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterStorageVaultCommand.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterStorageVaultCommand.java
@@ -21,6 +21,7 @@ import org.apache.doris.catalog.Env;
 import org.apache.doris.catalog.StorageVault;
 import org.apache.doris.catalog.StorageVault.StorageVaultType;
 import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.DdlException;
 import org.apache.doris.common.ErrorCode;
 import org.apache.doris.common.ErrorReport;
 import org.apache.doris.common.FeNameFormat;
@@ -55,9 +56,24 @@ public class AlterStorageVaultCommand extends Command 
implements ForwardWithSync
         if 
(!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.ADMIN)) {
             
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, 
"ADMIN");
         }
-        StorageVault.StorageVaultType vaultType = 
StorageVaultType.fromString(properties.get(TYPE));
-        if (vaultType == StorageVault.StorageVaultType.UNKNOWN) {
-            throw new AnalysisException("Unsupported Storage Vault type: " + 
type);
+
+        StorageVault.StorageVaultType vaultType;
+        if (properties.containsKey(TYPE)) {
+            vaultType = StorageVaultType.fromString(properties.get(TYPE));
+            if (vaultType == StorageVaultType.UNKNOWN) {
+                throw new AnalysisException("Unsupported Storage Vault type: " 
+ type);
+            }
+        } else {
+            // auto-detect
+            try {
+                vaultType = 
Env.getCurrentEnv().getStorageVaultMgr().getStorageVaultTypeByName(name);
+                if (vaultType == StorageVaultType.UNKNOWN) {
+                    throw new AnalysisException("Storage vault '" + name + "' 
does not exist or has unknown type. "
+                            + "You can use `SHOW STORAGE VAULT` to get all 
available vaults.");
+                }
+            } catch (DdlException e) {
+                throw new AnalysisException("Failed to get storage vault type: 
" + e.getMessage());
+            }
         }
 
         FeNameFormat.checkStorageVaultName(name);
diff --git a/regression-test/suites/vault_p0/alter/test_alter_vault_type.groovy 
b/regression-test/suites/vault_p0/alter/test_alter_vault_type.groovy
index a57207712e9..7babbeb4fe7 100644
--- a/regression-test/suites/vault_p0/alter/test_alter_vault_type.groovy
+++ b/regression-test/suites/vault_p0/alter/test_alter_vault_type.groovy
@@ -95,4 +95,28 @@ suite("test_alter_vault_type", "nonConcurrent") {
     } catch (Exception e) {
         assertTrue(e.getMessage().contains("Access denied for user"), 
e.getMessage())
     }
+
+    sql """
+        ALTER STORAGE VAULT ${s3VaultName}
+        PROPERTIES (
+            "s3.access_key" = "${getS3AK()}",
+            "s3.secret_key" = "${getS3SK()}"
+        );
+    """
+
+    sql """
+        ALTER STORAGE VAULT ${hdfsVaultName}
+        PROPERTIES (
+            "hadoop.username" = "${getHmsUser()}"
+        );
+    """
+
+    expectExceptionLike({
+        sql """
+            ALTER STORAGE VAULT non_existent_vault_${randomStr}
+            PROPERTIES (
+                "s3.access_key" = "test_ak"
+            );
+        """
+    }, "does not exist")
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to