Skip to content

Commit

Permalink
Migrate APIs out of StorageManager: array_get_encryption. (#4950)
Browse files Browse the repository at this point in the history
Migrate APIs out of `StorageManager`: `array_get_encryption`.

---
[sc-44995]

---
TYPE: NO_HISTORY
DESC: Migrate APIs out of StorageManager: array_get_encryption.
  • Loading branch information
bekadavis9 authored May 9, 2024
1 parent 6e3dacc commit 474fc1e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 44 deletions.
30 changes: 30 additions & 0 deletions tiledb/sm/array/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,36 @@ void Array::delete_fragments_list(const std::vector<URI>& fragment_uris) {
}
}

Status Array::encryption_type(
ContextResources& resources,
const URI& uri,
EncryptionType* encryption_type) {
if (uri.is_invalid()) {
throw ArrayException("[encryption_type] Invalid array URI");
}

if (uri.is_tiledb()) {
throw std::invalid_argument(
"Getting the encryption type of remote arrays is not supported.");
}

// Load URIs from the array directory
optional<tiledb::sm::ArrayDirectory> array_dir;
array_dir.emplace(
resources,
uri,
0,
UINT64_MAX,
tiledb::sm::ArrayDirectoryMode::SCHEMA_ONLY);

// Read tile header
auto&& header = GenericTileIO::read_generic_tile_header(
resources, array_dir->latest_array_schema_uri(), 0);
*encryption_type = static_cast<EncryptionType>(header.encryption_type);

return Status::Ok();
}

shared_ptr<const Enumeration> Array::get_enumeration(
const std::string& enumeration_name) {
return get_enumerations({enumeration_name})[0];
Expand Down
13 changes: 13 additions & 0 deletions tiledb/sm/array/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,19 @@ class Array {
opened_array_->fragment_metadata() = fragment_metadata;
}

/**
* Retrieves the encryption type.
*
* @param resources The context resources.
* @param uri The URI of the array.
* @param encryption_type Set to the encryption type.
* @return Status
*/
static Status encryption_type(
ContextResources& resources,
const URI& uri,
EncryptionType* encryption_type);

/**
* Get the enumeration for the given name.
*
Expand Down
8 changes: 4 additions & 4 deletions tiledb/sm/c_api/tiledb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2934,14 +2934,14 @@ int32_t tiledb_array_encryption_type(
const char* array_uri,
tiledb_encryption_type_t* encryption_type) {
// Sanity checks
if (array_uri == nullptr || encryption_type == nullptr)
if (array_uri == nullptr || encryption_type == nullptr) {
return TILEDB_ERR;
}

auto uri = tiledb::sm::URI(array_uri);
// Get encryption type
tiledb::sm::EncryptionType enc;
throw_if_not_ok(ctx->storage_manager()->array_get_encryption(uri, &enc));

throw_if_not_ok(sm::Array::encryption_type(
ctx->resources(), tiledb::sm::URI(array_uri), &enc));
*encryption_type = static_cast<tiledb_encryption_type_t>(enc);

return TILEDB_OK;
Expand Down
31 changes: 0 additions & 31 deletions tiledb/sm/storage_manager/storage_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -492,37 +492,6 @@ Status StorageManagerCanonical::array_upgrade_version(
return Status::Ok();
}

Status StorageManagerCanonical::array_get_encryption(
const URI& uri, EncryptionType* encryption_type) {
if (uri.is_invalid()) {
return logger_->status(Status_StorageManagerError(
"Cannot get array encryption; Invalid array URI"));
}

if (uri.is_tiledb()) {
throw std::invalid_argument(
"Getting the encryption type of remote arrays is not supported.");
}

// Load URIs from the array directory
optional<tiledb::sm::ArrayDirectory> array_dir;
array_dir.emplace(
resources_,
uri,
0,
UINT64_MAX,
tiledb::sm::ArrayDirectoryMode::SCHEMA_ONLY);

const URI& schema_uri = array_dir->latest_array_schema_uri();

// Read tile header
auto&& header =
GenericTileIO::read_generic_tile_header(resources_, schema_uri, 0);
*encryption_type = static_cast<EncryptionType>(header.encryption_type);

return Status::Ok();
}

Status StorageManagerCanonical::async_push_query(Query* query) {
cancelable_tasks_.execute(
compute_tp(),
Expand Down
9 changes: 0 additions & 9 deletions tiledb/sm/storage_manager/storage_manager_canonical.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,6 @@ class StorageManagerCanonical {
*/
Status array_upgrade_version(const URI& uri, const Config& config);

/**
* Retrieves the encryption type from an array.
*
* @param uri The URI of the array.
* @param encryption_type Set to the encryption type of the array.
* @return Status
*/
Status array_get_encryption(const URI& uri, EncryptionType* encryption_type);

/**
* Pushes an async query to the queue.
*
Expand Down

0 comments on commit 474fc1e

Please sign in to comment.