Skip to content

Commit

Permalink
Fix test issue, open between timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
bekadavis9 authored and KiterLuc committed Sep 29, 2023
1 parent 64823c3 commit 971a762
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 52 deletions.
98 changes: 51 additions & 47 deletions test/src/unit-capi-array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void ArrayFx::create_dense_array(const std::string& path) {

void ArrayFx::write_fragment(tiledb_array_t* array, uint64_t timestamp) {
// Open the array at the given timestamp
int rc = tiledb_array_set_open_timestamp_start(ctx_, array, timestamp);
int rc = tiledb_array_set_open_timestamp_end(ctx_, array, timestamp);
REQUIRE(rc == TILEDB_OK);
rc = tiledb_array_open(ctx_, array, TILEDB_WRITE);
REQUIRE(rc == TILEDB_OK);
Expand Down Expand Up @@ -2686,63 +2686,67 @@ TEST_CASE_METHOD(
CHECK(tiledb::test::num_commits(array_name) == 2);
CHECK(tiledb::test::num_fragments(array_name) == 2);

// Serialize fragment timestamp and deserialize using C API
// ALlocate buffer
tiledb_buffer_t* buff;
rc = tiledb_buffer_alloc(ctx_, &buff);
REQUIRE(rc == TILEDB_OK);
tiledb::sm::serialization::fragments_timestamps_serialize(
array_name,
start_timestamp,
end_timestamp,
tiledb::sm::SerializationType::CAPNP,
&buff->buffer());
rc = tiledb_deserialize_array_delete_fragments_timestamps_request(
ctx_,
(tiledb_serialization_type_t)tiledb::sm::SerializationType::CAPNP,
buff);
REQUIRE(rc == TILEDB_OK);
// #TODO Update test once cloud-side endpoint is added
// CHECK(tiledb::test::num_commits(array_name) == 0);
// CHECK(tiledb::test::num_fragments(array_name) == 0);

// Get the fragment info object
tiledb_fragment_info_t* fragment_info = nullptr;
rc = tiledb_fragment_info_alloc(ctx_, array_name.c_str(), &fragment_info);
REQUIRE(rc == TILEDB_OK);
rc = tiledb_fragment_info_load(ctx_, fragment_info);
REQUIRE(rc == TILEDB_OK);
SECTION("delete_fragments") {
// Serialize fragment timestamps and deserialize delete request
tiledb::sm::serialization::fragments_timestamps_serialize(
array_name,
start_timestamp,
end_timestamp,
tiledb::sm::SerializationType::CAPNP,
&buff->buffer());
rc = tiledb_deserialize_array_delete_fragments_timestamps_request(
ctx_,
(tiledb_serialization_type_t)tiledb::sm::SerializationType::CAPNP,
buff);
REQUIRE(rc == TILEDB_OK);
CHECK(tiledb::test::num_commits(array_name) == 0);
CHECK(tiledb::test::num_fragments(array_name) == 0);
}

// Get the fragment URIs
const char* uri1;
rc = tiledb_fragment_info_get_fragment_uri(ctx_, fragment_info, 0, &uri1);
REQUIRE(rc == TILEDB_OK);
const char* uri2;
rc = tiledb_fragment_info_get_fragment_uri(ctx_, fragment_info, 1, &uri2);
REQUIRE(rc == TILEDB_OK);
SECTION("delete_fragments_list") {
// Get the fragment info object
tiledb_fragment_info_t* fragment_info = nullptr;
rc = tiledb_fragment_info_alloc(ctx_, array_name.c_str(), &fragment_info);
REQUIRE(rc == TILEDB_OK);
rc = tiledb_fragment_info_load(ctx_, fragment_info);
REQUIRE(rc == TILEDB_OK);

std::vector<URI> fragments;
fragments.emplace_back(URI(uri1));
fragments.emplace_back(URI(uri2));
// Get the fragment URIs
const char* uri1;
rc = tiledb_fragment_info_get_fragment_uri(ctx_, fragment_info, 0, &uri1);
REQUIRE(rc == TILEDB_OK);
const char* uri2;
rc = tiledb_fragment_info_get_fragment_uri(ctx_, fragment_info, 1, &uri2);
REQUIRE(rc == TILEDB_OK);

// Serialize fragments list and deserialize using C API
tiledb::sm::serialization::fragments_list_serialize(
array_name,
fragments,
tiledb::sm::SerializationType::CAPNP,
&buff->buffer());
rc = tiledb_deserialize_array_delete_fragments_list_request(
ctx_,
(tiledb_serialization_type_t)tiledb::sm::SerializationType::CAPNP,
buff);
REQUIRE(rc == TILEDB_OK);
// #TODO Update test once cloud-side endpoint is added
// CHECK(tiledb::test::num_commits(array_name) == 0);
// CHECK(tiledb::test::num_fragments(array_name) == 0);
std::vector<URI> fragments;
fragments.emplace_back(URI(uri1));
fragments.emplace_back(URI(uri2));

// Serialize fragments list and deserialize delete request
tiledb::sm::serialization::fragments_list_serialize(
array_name,
fragments,
tiledb::sm::SerializationType::CAPNP,
&buff->buffer());
rc = tiledb_deserialize_array_delete_fragments_list_request(
ctx_,
(tiledb_serialization_type_t)tiledb::sm::SerializationType::CAPNP,
buff);
REQUIRE(rc == TILEDB_OK);
CHECK(tiledb::test::num_commits(array_name) == 0);
CHECK(tiledb::test::num_fragments(array_name) == 0);
tiledb_fragment_info_free(&fragment_info);
}

// Clean up
tiledb_array_free(&array);
tiledb_buffer_free(&buff);
tiledb_fragment_info_free(&fragment_info);
remove_temp_dir(local_fs.file_prefix() + local_fs.temp_dir());
#endif
}
4 changes: 2 additions & 2 deletions test/src/unit-cppapi-deletes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,7 @@ TEST_CASE_METHOD(

// Delete fragments
SECTION("delete fragments by timestamps") {
Array::delete_fragments_v2(ctx_, SPARSE_ARRAY_NAME, 2, 6);
Array::delete_fragments(ctx_, SPARSE_ARRAY_NAME, 2, 6);
}

SECTION("delete fragments by uris") {
Expand Down Expand Up @@ -1912,7 +1912,7 @@ TEST_CASE_METHOD(
CHECK(tiledb::test::num_fragments(SPARSE_ARRAY_NAME) == num_fragments);

// Delete fragments at timestamps 2 - 4
Array::delete_fragments_v2(ctx_, SPARSE_ARRAY_NAME, 2, 4);
Array::delete_fragments(ctx_, SPARSE_ARRAY_NAME, 2, 4);
if (!vacuum) {
// Vacuum after deletion
auto config = ctx_.config();
Expand Down
8 changes: 8 additions & 0 deletions tiledb/sm/c_api/tiledb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2391,6 +2391,10 @@ capi_return_t tiledb_array_delete_fragments_v2(
throw api::CAPIStatusException("Failed to create array");
}

// Set array open timestamps
array->array_->set_timestamp_start(timestamp_start);
array->array_->set_timestamp_end(timestamp_end);

// Open the array for exclusive modification
throw_if_not_ok(array->array_->open(
static_cast<tiledb::sm::QueryType>(TILEDB_MODIFY_EXCLUSIVE),
Expand Down Expand Up @@ -4076,6 +4080,10 @@ capi_return_t tiledb_deserialize_array_delete_fragments_timestamps_request(
throw api::CAPIStatusException("Failed to create array");
}

// Set array open timestamps
array->array_->set_timestamp_start(timestamp_start);
array->array_->set_timestamp_end(timestamp_end);

// Open the array for exclusive modification
throw_if_not_ok(array->array_->open(
static_cast<tiledb::sm::QueryType>(TILEDB_MODIFY_EXCLUSIVE),
Expand Down
6 changes: 3 additions & 3 deletions tiledb/sm/cpp_api/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ class Array {
uint64_t timestamp_start,
uint64_t timestamp_end) const {
throw std::logic_error(
"Array::delete_fragments is deprecated. Please use "
"Array::delete_fragments_v2 instead.");
"This method is deprecated. Please use "
"Array::delete_fragments(ctx, uri, timestamp_start, timestamp_end)");
auto& ctx = ctx_.get();
ctx.handle_error(tiledb_array_delete_fragments_v2(
ctx.ptr().get(), uri.c_str(), timestamp_start, timestamp_end));
Expand All @@ -377,7 +377,7 @@ class Array {
* @param timestamp_end The epoch end timestamp in milliseconds. Use
* UINT64_MAX for the current timestamp.
*/
static void delete_fragments_v2(
static void delete_fragments(
const Context& ctx,
const std::string& uri,
uint64_t timestamp_start,
Expand Down

0 comments on commit 971a762

Please sign in to comment.