Skip to content

Commit

Permalink
[opt](storage vault) Check s3.root.path cannot be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
SWJTU-ZhangLei committed Jan 16, 2025
1 parent 90d307c commit 318071b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cloud/src/meta-service/meta_service_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,8 @@ void MetaServiceImpl::alter_obj_store_info(google::protobuf::RpcController* cont
return;
}
// ATTN: prefix may be empty
if (ak.empty() || sk.empty() || bucket.empty() || endpoint.empty() || region.empty()) {
if (ak.empty() || sk.empty() || bucket.empty() || endpoint.empty() || region.empty() ||
prefix.empty()) {
code = MetaServiceCode::INVALID_ARGUMENT;
msg = "s3 conf info err, please check it";
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ public static Cloud.ObjectStoreInfoPB.Builder getObjStoreInfoPB(Map<String, Stri
builder.setSk(properties.get(S3Properties.SECRET_KEY));
}
if (properties.containsKey(S3Properties.ROOT_PATH)) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(properties.get(S3Properties.ROOT_PATH)),
"%s cannot be empty", S3Properties.ROOT_PATH);
builder.setPrefix(properties.get(S3Properties.ROOT_PATH));
}
if (properties.containsKey(S3Properties.BUCKET)) {
Expand Down
63 changes: 63 additions & 0 deletions regression-test/suites/vault_p0/create/test_create_vault.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.

import java.util.stream.Collectors;
import java.util.stream.Stream;

suite("test_create_vault", "nonConcurrent") {
def suiteName = name;
if (!isCloudMode()) {
Expand All @@ -31,6 +34,48 @@ suite("test_create_vault", "nonConcurrent") {
def s3VaultName = "s3_" + randomStr
def hdfsVaultName = "hdfs_" + randomStr

def length64Str = Stream.generate(() -> String.valueOf('a'))
.limit(32)
.collect(Collectors.joining()) + randomStr

def exceed64LengthStr = length64Str + "a"

// test long length storage vault
expectExceptionLike({
sql """
CREATE STORAGE VAULT ${exceed64LengthStr}
PROPERTIES (
"type"="S3",
"fs.defaultFS"="${getHmsHdfsFs()}",
"path_prefix" = "${exceed64LengthStr}",
"hadoop.username" = "${getHmsUser()}"
);
"""
}, "Incorrect vault name")

sql """
CREATE STORAGE VAULT ${length64Str}
PROPERTIES (
"type"="HDFS",
"fs.defaultFS"="${getHmsHdfsFs()}",
"path_prefix" = "${length64Str}",
"hadoop.username" = "${getHmsUser()}"
);
"""

expectExceptionLike({
sql """
CREATE STORAGE VAULT ${s3VaultName}
PROPERTIES (
"type"="S3",
"fs.defaultFS"="${getHmsHdfsFs()}",
"path_prefix" = "${s3VaultName}",
"hadoop.username" = "${getHmsUser()}"
);
"""
}, "Missing [s3.endpoint] in properties")


expectExceptionLike({
sql """
CREATE STORAGE VAULT ${s3VaultName}
Expand Down Expand Up @@ -63,6 +108,24 @@ suite("test_create_vault", "nonConcurrent") {
"""
}, "Storage vault 'not_exist_vault' does not exist")

// test s3.root.path cannot be empty
expectExceptionLike({
sql """
CREATE STORAGE VAULT ${s3VaultName}
PROPERTIES (
"type"="S3",
"s3.endpoint"="${getS3Endpoint()}",
"s3.region" = "${getS3Region()}",
"s3.access_key" = "${getS3AK()}",
"s3.secret_key" = "${getS3SK()}",
"s3.root.path" = "",
"s3.bucket" = "${getS3BucketName()}",
"s3.external_endpoint" = "",
"provider" = "${getS3Provider()}",
"use_path_style" = "false"
);
"""
}, "cannot be empty")

// test `if not exist` and dup name s3 vault
sql """
Expand Down

0 comments on commit 318071b

Please sign in to comment.