Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

branch-3.0: [opt](storage vault) Check s3.root.path cannot be empty #47078 #47196

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading