diff --git a/test/src/unit-cppapi-deletes.cc b/test/src/unit-cppapi-deletes.cc index f4a4253b59d..0033000f29c 100644 --- a/test/src/unit-cppapi-deletes.cc +++ b/test/src/unit-cppapi-deletes.cc @@ -1774,8 +1774,7 @@ TEST_CASE_METHOD( REQUIRE_THROWS_WITH( Array::delete_fragments_list( ctx_, SPARSE_ARRAY_NAME, extraneous_fragments, 1), - Catch::Matchers::ContainsSubstring( - "is not a fragment of the ArrayDirectory")); + Catch::Matchers::ContainsSubstring("Failed to delete fragments_list")); CHECK(tiledb::test::num_fragments(SPARSE_ARRAY_NAME) == 2); remove_sparse_array(); diff --git a/tiledb/sm/array/array.cc b/tiledb/sm/array/array.cc index d89f1d42b36..5d1bacb8c17 100644 --- a/tiledb/sm/array/array.cc +++ b/tiledb/sm/array/array.cc @@ -552,8 +552,18 @@ void Array::delete_fragments( ensure_array_is_valid_for_delete(uri); // Delete fragments - storage_manager_->delete_fragments( - uri.c_str(), timestamp_start, timestamp_end); + if (remote_) { + auto rest_client = resources_.rest_client(); + if (rest_client == nullptr) { + throw ArrayException( + "[delete_fragments] Remote array with no REST client."); + } + rest_client->delete_fragments_from_rest( + uri, timestamp_start, timestamp_end); + } else { + storage_manager_->delete_fragments( + uri.c_str(), timestamp_start, timestamp_end); + } } void Array::delete_fragments_list( @@ -562,9 +572,18 @@ void Array::delete_fragments_list( ensure_array_is_valid_for_delete(uri); // Delete fragments_list - auto array_dir = - ArrayDirectory(resources_, uri, 0, std::numeric_limits::max()); - array_dir.delete_fragments_list(fragment_uris); + if (remote_) { + auto rest_client = resources_.rest_client(); + if (rest_client == nullptr) { + throw ArrayException( + "[delete_fragments_list] Remote array with no REST client."); + } + rest_client->delete_fragments_list_from_rest(uri, fragment_uris); + } else { + auto array_dir = ArrayDirectory( + resources_, uri, 0, std::numeric_limits::max()); + array_dir.delete_fragments_list(fragment_uris); + } } shared_ptr Array::get_enumeration( diff --git a/tiledb/sm/c_api/tiledb.cc b/tiledb/sm/c_api/tiledb.cc index 3967dcf3c2c..cc47f5b2e11 100644 --- a/tiledb/sm/c_api/tiledb.cc +++ b/tiledb/sm/c_api/tiledb.cc @@ -2380,55 +2380,39 @@ capi_return_t tiledb_array_delete_fragments_v2( "Failed to delete fragments; Invalid input uri"); } - if (uri.is_tiledb()) { - // Check REST client - auto rest_client = ctx->storage_manager()->rest_client(); - if (rest_client == nullptr) { - auto st = Status_Error( - "Failed to delete fragments; remote array with no REST client."); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_ERR; - } - - rest_client->delete_fragments_from_rest( - uri, timestamp_start, timestamp_end); - } else { - // Allocate an array object - tiledb_array_t* array = new (std::nothrow) tiledb_array_t; - try { - array->array_ = - make_shared(HERE(), uri, ctx->storage_manager()); - } catch (std::bad_alloc&) { - auto st = Status_Error( - "Failed to create TileDB array object; Memory allocation error"); - delete array; - array = nullptr; - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_OOM; - } - - // Open the array for exclusive modification - throw_if_not_ok(array->array_->open( - static_cast(TILEDB_MODIFY_EXCLUSIVE), - static_cast(TILEDB_NO_ENCRYPTION), - nullptr, - 0)); + // Allocate an array object + tiledb_array_t* array = new (std::nothrow) tiledb_array_t; + try { + array->array_ = + make_shared(HERE(), uri, ctx->storage_manager()); + } catch (...) { + delete array; + array = nullptr; + throw api::CAPIStatusException("Failed to create array"); + } - try { - array->array_->delete_fragments(uri, timestamp_start, timestamp_end); - } catch (std::exception& e) { - auto st = Status_ArrayError(e.what()); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_ERR; - } + // Open the array for exclusive modification + throw_if_not_ok(array->array_->open( + static_cast(TILEDB_MODIFY_EXCLUSIVE), + static_cast(TILEDB_NO_ENCRYPTION), + nullptr, + 0)); - // Close the array + // Delete fragments + try { + array->array_->delete_fragments(uri, timestamp_start, timestamp_end); + } catch (...) { throw_if_not_ok(array->array_->close()); + delete array; + array = nullptr; + throw api::CAPIStatusException("Failed to delete fragments"); } + // Close and delete the array + throw_if_not_ok(array->array_->close()); + delete array; + array = nullptr; + return TILEDB_OK; } @@ -2462,54 +2446,39 @@ capi_return_t tiledb_array_delete_fragments_list( uris.emplace_back(tiledb::sm::URI(fragment_uris[i])); } - if (uri.is_tiledb()) { - // Check REST client - auto rest_client = ctx->storage_manager()->rest_client(); - if (rest_client == nullptr) { - auto st = Status_Error( - "Failed to delete fragments; remote array with no REST client."); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_ERR; - } - rest_client->delete_fragments_list_from_rest(uri, uris); - } else { - // Allocate an array object - tiledb_array_t* array = new (std::nothrow) tiledb_array_t; - try { - array->array_ = - make_shared(HERE(), uri, ctx->storage_manager()); - } catch (std::bad_alloc&) { - auto st = Status_Error( - "Failed to create TileDB array object; Memory allocation error"); - delete array; - array = nullptr; - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_OOM; - } - - // Open the array for exclusive modification - throw_if_not_ok(array->array_->open( - static_cast(TILEDB_MODIFY_EXCLUSIVE), - static_cast(TILEDB_NO_ENCRYPTION), - nullptr, - 0)); + // Allocate an array object + tiledb_array_t* array = new (std::nothrow) tiledb_array_t; + try { + array->array_ = + make_shared(HERE(), uri, ctx->storage_manager()); + } catch (...) { + delete array; + array = nullptr; + throw api::CAPIStatusException("Failed to create array"); + } - try { - array->array_->delete_fragments_list(uri, uris); - } catch (std::exception& e) { - throw_if_not_ok(array->array_->close()); - auto st = Status_ArrayError(e.what()); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_ERR; - } + // Open the array for exclusive modification + throw_if_not_ok(array->array_->open( + static_cast(TILEDB_MODIFY_EXCLUSIVE), + static_cast(TILEDB_NO_ENCRYPTION), + nullptr, + 0)); - // Close the array + // Delete fragments list + try { + array->array_->delete_fragments_list(uri, uris); + } catch (...) { throw_if_not_ok(array->array_->close()); + delete array; + array = nullptr; + throw api::CAPIStatusException("Failed to delete fragments_list"); } + // Close the array + throw_if_not_ok(array->array_->close()); + delete array; + array = nullptr; + return TILEDB_OK; } @@ -4096,55 +4065,39 @@ capi_return_t tiledb_deserialize_array_delete_fragments_timestamps_request( "Failed to delete fragments; Invalid input uri"); } - // Delete fragments - if (uri.is_tiledb()) { - // Check REST client - auto rest_client = ctx->storage_manager()->rest_client(); - if (rest_client == nullptr) { - auto st = Status_Error( - "Failed to delete fragments; remote array with no REST client."); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_ERR; - } - rest_client->delete_fragments_from_rest( - uri, timestamp_start, timestamp_end); - } else { - // Allocate an array object - tiledb_array_t* array = new (std::nothrow) tiledb_array_t; - try { - array->array_ = - make_shared(HERE(), uri, ctx->storage_manager()); - } catch (std::bad_alloc&) { - auto st = Status_Error( - "Failed to create TileDB array object; Memory allocation error"); - delete array; - array = nullptr; - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_OOM; - } - - // Open the array for exclusive modification - throw_if_not_ok(array->array_->open( - static_cast(TILEDB_MODIFY_EXCLUSIVE), - static_cast(TILEDB_NO_ENCRYPTION), - nullptr, - 0)); + // Allocate an array object + tiledb_array_t* array = new (std::nothrow) tiledb_array_t; + try { + array->array_ = + make_shared(HERE(), uri, ctx->storage_manager()); + } catch (...) { + delete array; + array = nullptr; + throw api::CAPIStatusException("Failed to create array"); + } - try { - array->array_->delete_fragments(uri, timestamp_start, timestamp_end); - } catch (std::exception& e) { - auto st = Status_ArrayError(e.what()); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_ERR; - } + // Open the array for exclusive modification + throw_if_not_ok(array->array_->open( + static_cast(TILEDB_MODIFY_EXCLUSIVE), + static_cast(TILEDB_NO_ENCRYPTION), + nullptr, + 0)); - // Close the array + // Delete fragments + try { + array->array_->delete_fragments(uri, timestamp_start, timestamp_end); + } catch (...) { throw_if_not_ok(array->array_->close()); + delete array; + array = nullptr; + throw api::CAPIStatusException("Failed to delete fragments"); } + // Close and delete the array + throw_if_not_ok(array->array_->close()); + delete array; + array = nullptr; + return TILEDB_OK; } @@ -4164,55 +4117,39 @@ capi_return_t tiledb_deserialize_array_delete_fragments_list_request( "Failed to delete_fragments_list; Invalid input uri"); } - // Delete fragments list - if (uri.is_tiledb()) { - // Check REST client - auto rest_client = ctx->storage_manager()->rest_client(); - if (rest_client == nullptr) { - auto st = Status_Error( - "Failed to delete fragments; remote array with no REST client."); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_ERR; - } - rest_client->delete_fragments_list_from_rest(uri, uris); - } else { - // Allocate an array object - tiledb_array_t* array = new (std::nothrow) tiledb_array_t; - try { - array->array_ = - make_shared(HERE(), uri, ctx->storage_manager()); - } catch (std::bad_alloc&) { - auto st = Status_Error( - "Failed to create TileDB array object; Memory allocation error"); - delete array; - array = nullptr; - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_OOM; - } - - // Open the array for exclusive modification - throw_if_not_ok(array->array_->open( - static_cast(TILEDB_MODIFY_EXCLUSIVE), - static_cast(TILEDB_NO_ENCRYPTION), - nullptr, - 0)); + // Allocate an array object + tiledb_array_t* array = new (std::nothrow) tiledb_array_t; + try { + array->array_ = + make_shared(HERE(), uri, ctx->storage_manager()); + } catch (...) { + delete array; + array = nullptr; + throw api::CAPIStatusException("Failed to create array"); + } - try { - array->array_->delete_fragments_list(uri, uris); - } catch (std::exception& e) { - throw_if_not_ok(array->array_->close()); - auto st = Status_ArrayError(e.what()); - LOG_STATUS_NO_RETURN_VALUE(st); - save_error(ctx, st); - return TILEDB_ERR; - } + // Open the array for exclusive modification + throw_if_not_ok(array->array_->open( + static_cast(TILEDB_MODIFY_EXCLUSIVE), + static_cast(TILEDB_NO_ENCRYPTION), + nullptr, + 0)); - // Close the array + // Delete fragments list + try { + array->array_->delete_fragments_list(uri, uris); + } catch (...) { throw_if_not_ok(array->array_->close()); + delete array; + array = nullptr; + throw api::CAPIStatusException("Failed to delete fragments_list"); } + // Close and delete the array + throw_if_not_ok(array->array_->close()); + delete array; + array = nullptr; + return TILEDB_OK; }