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

Move StorageManager::store_data_to_generic_tile to GenericTileIO. #4743

Merged
merged 4 commits into from
Feb 27, 2024
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
8 changes: 6 additions & 2 deletions tiledb/sm/query/deletes_and_updates/deletes_and_updates.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "tiledb/sm/fragment/fragment_identifier.h"
#include "tiledb/sm/query/deletes_and_updates/serialization.h"
#include "tiledb/sm/storage_manager/storage_manager.h"
#include "tiledb/sm/tile/generic_tile_io.h"
#include "tiledb/storage_format/uri/generate_uri.h"

using namespace tiledb;
Expand Down Expand Up @@ -161,8 +162,11 @@ Status DeletesAndUpdates::dowork() {
constants::update_file_suffix;

auto uri = commit_uri.join_path(new_fragment_str);
RETURN_NOT_OK(storage_manager_->store_data_to_generic_tile(
serialized_condition, uri, *array_->encryption_key()));
GenericTileIO::store_data(
storage_manager_->resources(),
uri,
serialized_condition,
*array_->encryption_key());

return Status::Ok();
}
Expand Down
18 changes: 4 additions & 14 deletions tiledb/sm/storage_manager/storage_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1278,8 +1278,7 @@ Status StorageManagerCanonical::store_group_detail(
if (!group_detail_dir_exists)
RETURN_NOT_OK(vfs()->create_dir(group_detail_folder_uri));

RETURN_NOT_OK(
store_data_to_generic_tile(tile, group_detail_uri, encryption_key));
GenericTileIO::store_data(resources_, group_detail_uri, tile, encryption_key);

return Status::Ok();
}
Expand Down Expand Up @@ -1315,7 +1314,7 @@ Status StorageManagerCanonical::store_array_schema(
if (!schema_dir_exists)
RETURN_NOT_OK(vfs()->create_dir(array_schema_dir_uri));

RETURN_NOT_OK(store_data_to_generic_tile(tile, schema_uri, encryption_key));
GenericTileIO::store_data(resources_, schema_uri, tile, encryption_key);

// Create the `__enumerations` directory under `__schema` if it doesn't
// exist. This might happen if someone tries to add an enumeration to an
Expand Down Expand Up @@ -1347,8 +1346,7 @@ Status StorageManagerCanonical::store_array_schema(
enmr->serialize(serializer);

auto abs_enmr_uri = array_enumerations_dir_uri.join_path(enmr->path_name());
RETURN_NOT_OK(
store_data_to_generic_tile(tile, abs_enmr_uri, encryption_key));
GenericTileIO::store_data(resources_, abs_enmr_uri, tile, encryption_key);
}

return Status::Ok();
Expand Down Expand Up @@ -1380,19 +1378,11 @@ Status StorageManagerCanonical::store_metadata(
// Create a metadata file name
URI metadata_uri = metadata->get_uri(uri);

RETURN_NOT_OK(store_data_to_generic_tile(tile, metadata_uri, encryption_key));
GenericTileIO::store_data(resources_, metadata_uri, tile, encryption_key);

return Status::Ok();
}

Status StorageManagerCanonical::store_data_to_generic_tile(
WriterTile& tile, const URI& uri, const EncryptionKey& encryption_key) {
GenericTileIO tile_io(resources_, uri);
uint64_t nbytes = 0;
tile_io.write_generic(&tile, encryption_key, &nbytes);
return vfs()->close_file(uri);
}

void StorageManagerCanonical::wait_for_zero_in_progress() {
std::unique_lock<std::mutex> lck(queries_in_progress_mtx_);
queries_in_progress_cv_.wait(
Expand Down
11 changes: 0 additions & 11 deletions tiledb/sm/storage_manager/storage_manager_canonical.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,17 +591,6 @@ class StorageManagerCanonical {
Status store_metadata(
const URI& uri, const EncryptionKey& encryption_key, Metadata* metadata);

/**
* Stores data into persistent storage.
*
* @param tile Tile to store.
* @param uri The object URI.
* @param encryption_key The encryption key to use.
* @return Status
*/
Status store_data_to_generic_tile(
WriterTile& tile, const URI& uri, const EncryptionKey& encryption_key);

[[nodiscard]] inline ContextResources& resources() const {
return resources_;
}
Expand Down
11 changes: 11 additions & 0 deletions tiledb/sm/tile/generic_tile_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ GenericTileIO::GenericTileHeader GenericTileIO::read_generic_tile_header(
return header;
}

void GenericTileIO::store_data(
ContextResources& resources,
const URI& uri,
WriterTile& tile,
const EncryptionKey& encryption_key) {
GenericTileIO tile_io(resources, uri);
uint64_t nbytes = 0;
tile_io.write_generic(&tile, encryption_key, &nbytes);
throw_if_not_ok(resources.vfs().close_file(uri));
}

void GenericTileIO::write_generic(
WriterTile* tile, const EncryptionKey& encryption_key, uint64_t* nbytes) {
// Create a header
Expand Down
23 changes: 17 additions & 6 deletions tiledb/sm/tile/generic_tile_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class GenericTileIO {
* @param uri The object URI.
* @param offset The offset into the file to read from.
* @param encryption_key The encryption key to use.
* @return Status, Tile with the data.
* @return Tile with the data.
*/
static Tile load(
ContextResources& resources,
Expand All @@ -141,7 +141,7 @@ class GenericTileIO {
* @param file_offset The offset in the file to read from.
* @param encryption_key The encryption key to use.
* @param config The storage manager's config.
* @return Status, Tile
* @return Tile
*/
Tile read_generic(
uint64_t file_offset,
Expand All @@ -154,13 +154,25 @@ class GenericTileIO {
* @param resources The ContextResources instance to use for reading.
* @param uri The URI of the generic tile.
* @param file_offset The offset where the header read will begin.
* @param encryption_key If the array is encrypted, the private encryption
* key. For unencrypted arrays, pass `nullptr`.
* @return Status, Header
* @return Header
*/
static GenericTileHeader read_generic_tile_header(
ContextResources& resources, const URI& uri, uint64_t file_offset);

/**
* Writes a generic tile to a file.
*
* @param resources The ContextResources instance to use for writing.
* @param uri The URI of the generic tile.
* @param tile The tile to write.
* @param encryption_key The encryption key to use.
*/
static void store_data(
ContextResources& resources,
const URI& uri,
WriterTile& tile,
const EncryptionKey& encryption_key);

/**
* Writes a tile generically to the file. This means that a header will be
* prepended to the file before writing the tile contents. The reason is
Expand All @@ -170,7 +182,6 @@ class GenericTileIO {
* @param tile The tile to be written.
* @param encryption_key The encryption key to use.
* @param nbytes The total number of bytes written to the file.
* @return Status
*/
void write_generic(
WriterTile* tile, const EncryptionKey& encryption_key, uint64_t* nbytes);
Expand Down
Loading