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

Make sure metadata are deleted when they got added in the same operation. #4022

Merged
merged 3 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
53 changes: 53 additions & 0 deletions test/src/unit-capi-group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,59 @@ TEST_CASE_METHOD(
remove_temp_dir(temp_dir);
}

TEST_CASE_METHOD(
GroupFx,
"C API: Group Metadata, delete",
"[capi][group][metadata][delete]") {
// TODO: move this test to unit_metadata.cc.
std::string temp_dir = fs_vec_[0]->temp_dir();
create_temp_dir(temp_dir);

std::string group1_uri = temp_dir + "group1";
int rc = tiledb_group_create(ctx_, group1_uri.c_str());
REQUIRE(rc == TILEDB_OK);

tiledb_group_t* group;
rc = tiledb_group_alloc(ctx_, group1_uri.c_str(), &group);
REQUIRE(rc == TILEDB_OK);

int metadata_val = 1;
rc = tiledb_group_open(ctx_, group, TILEDB_WRITE);
CHECK(rc == TILEDB_OK);
rc = tiledb_group_put_metadata(
ctx_, group, "hello", TILEDB_INT32, 1, &metadata_val);
CHECK(rc == TILEDB_OK);
rc = tiledb_group_put_metadata(
ctx_, group, "goodbye", TILEDB_INT32, 1, &metadata_val);
CHECK(rc == TILEDB_OK);
rc = tiledb_group_delete_metadata(ctx_, group, "hello");
CHECK(rc == TILEDB_OK);
rc = tiledb_group_close(ctx_, group);
CHECK(rc == TILEDB_OK);

metadata_val = 2;
rc = tiledb_group_open(ctx_, group, TILEDB_WRITE);
CHECK(rc == TILEDB_OK);
rc = tiledb_group_put_metadata(
ctx_, group, "goodbye", TILEDB_INT32, 1, &metadata_val);
CHECK(rc == TILEDB_OK);
rc = tiledb_group_delete_metadata(ctx_, group, "goodbye");
CHECK(rc == TILEDB_OK);
rc = tiledb_group_close(ctx_, group);
CHECK(rc == TILEDB_OK);

rc = tiledb_group_open(ctx_, group, TILEDB_READ);
CHECK(rc == TILEDB_OK);
uint64_t metadata_num;
rc = tiledb_group_get_metadata_num(ctx_, group, &metadata_num);
CHECK(rc == TILEDB_OK);
CHECK(metadata_num == 0);
rc = tiledb_group_close(ctx_, group);
CHECK(rc == TILEDB_OK);

tiledb_group_free(&group);
}

TEST_CASE_METHOD(
GroupFx, "C API: Group, write/read", "[capi][group][metadata][read]") {
// Create and open group in write mode
Expand Down
4 changes: 3 additions & 1 deletion tiledb/sm/metadata/metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ Status Metadata::del(const char* key) {

MetadataValue value;
value.del_ = 1;
metadata_map_.emplace(std::make_pair(std::string(key), std::move(value)));
std::string key_str(key);
metadata_map_.erase(key_str);
metadata_map_.emplace(std::make_pair(key_str, std::move(value)));
teo-tsirpanis marked this conversation as resolved.
Show resolved Hide resolved
teo-tsirpanis marked this conversation as resolved.
Show resolved Hide resolved
build_metadata_index();

return Status::Ok();
Expand Down