diff --git a/tiledb/sm/group/group_details.cc b/tiledb/sm/group/group_details.cc index a777732e729..8853775ca33 100644 --- a/tiledb/sm/group/group_details.cc +++ b/tiledb/sm/group/group_details.cc @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2022-2023 TileDB, Inc. + * @copyright Copyright (c) 2022-2024 TileDB, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -44,6 +44,7 @@ #include "tiledb/sm/metadata/metadata.h" #include "tiledb/sm/misc/tdb_time.h" #include "tiledb/sm/rest/rest_client.h" +#include "tiledb/sm/tile/generic_tile_io.h" using namespace tiledb::common; @@ -202,6 +203,38 @@ GroupDetails::members() const { return members_; } +Status GroupDetails::store( + ContextResources& resources, + const URI& group_detail_folder_uri, + const URI& group_detail_uri, + const EncryptionKey& encryption_key) { + // Serialize + auto members = members_to_serialize(); + SizeComputationSerializer size_computation_serializer; + serialize(members, size_computation_serializer); + + auto tile{WriterTile::from_generic( + size_computation_serializer.size(), + resources.ephemeral_memory_tracker())}; + + Serializer serializer(tile->data(), tile->size()); + serialize(members, serializer); + resources.stats().add_counter("write_group_size", tile->size()); + + // Check if the array schema directory exists + // If not create it, this is caused by a pre-v10 array + bool group_detail_dir_exists = false; + auto& vfs = resources.vfs(); + throw_if_not_ok( + vfs.is_dir(group_detail_folder_uri, &group_detail_dir_exists)); + if (!group_detail_dir_exists) { + throw_if_not_ok(vfs.create_dir(group_detail_folder_uri)); + } + GenericTileIO::store_data(resources, group_detail_uri, tile, encryption_key); + + return Status::Ok(); +} + std::optional> GroupDetails::deserialize( Deserializer& deserializer, const URI& group_uri) { uint32_t version = 0; diff --git a/tiledb/sm/group/group_details.h b/tiledb/sm/group/group_details.h index 9e28bf8822d..88fec9599d4 100644 --- a/tiledb/sm/group/group_details.h +++ b/tiledb/sm/group/group_details.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2022 TileDB, Inc. + * @copyright Copyright (c) 2022-2024 TileDB, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -41,12 +41,12 @@ #include "tiledb/sm/group/group_directory.h" #include "tiledb/sm/group/group_member.h" #include "tiledb/sm/metadata/metadata.h" +#include "tiledb/sm/storage_manager/context_resources.h" #include "tiledb/sm/storage_manager/storage_manager_declaration.h" using namespace tiledb::common; -namespace tiledb { -namespace sm { +namespace tiledb::sm { class GroupDetails { public: @@ -131,6 +131,21 @@ class GroupDetails { */ void delete_member(const shared_ptr group_member); + /** + * Store the group details + * + * @param resources the context resources + * @param group_detail_folder_uri group details folder + * @param group_detail_uri uri for detail file to write + * @param encryption_key encryption key for at-rest encryption + * @return status + */ + Status store( + ContextResources& resources, + const URI& group_detail_folder_uri, + const URI& group_detail_uri, + const EncryptionKey& encryption_key); + /** * Serializes the object members into a binary buffer. * @@ -264,7 +279,7 @@ class GroupDetails { /** Invalidate the built lookup tables. */ void invalidate_lookups(); }; -} // namespace sm -} // namespace tiledb + +} // namespace tiledb::sm #endif // TILEDB_GROUP_DETAILS_H diff --git a/tiledb/sm/storage_manager/storage_manager.cc b/tiledb/sm/storage_manager/storage_manager.cc index ab860153346..ec515fab511 100644 --- a/tiledb/sm/storage_manager/storage_manager.cc +++ b/tiledb/sm/storage_manager/storage_manager.cc @@ -142,10 +142,10 @@ Status StorageManagerCanonical::group_close_for_writes(Group* group) { if (group->group_details()->is_modified()) { const URI& group_detail_folder_uri = group->group_detail_uri(); auto group_detail_uri = group->generate_detail_uri(); - RETURN_NOT_OK(store_group_detail( + throw_if_not_ok(group->group_details()->store( + resources_, group_detail_folder_uri, group_detail_uri, - group->group_details(), *group->encryption_key())); } return Status::Ok(); @@ -856,38 +856,6 @@ Status StorageManagerCanonical::set_tag( return Status::Ok(); } -Status StorageManagerCanonical::store_group_detail( - const URI& group_detail_folder_uri, - const URI& group_detail_uri, - tdb_shared_ptr group, - const EncryptionKey& encryption_key) { - // Serialize - auto members = group->members_to_serialize(); - SizeComputationSerializer size_computation_serializer; - group->serialize(members, size_computation_serializer); - - auto tile{WriterTile::from_generic( - size_computation_serializer.size(), - resources_.ephemeral_memory_tracker())}; - - Serializer serializer(tile->data(), tile->size()); - group->serialize(members, serializer); - - stats()->add_counter("write_group_size", tile->size()); - - // Check if the array schema directory exists - // If not create it, this is caused by a pre-v10 array - bool group_detail_dir_exists = false; - RETURN_NOT_OK( - vfs()->is_dir(group_detail_folder_uri, &group_detail_dir_exists)); - if (!group_detail_dir_exists) - RETURN_NOT_OK(vfs()->create_dir(group_detail_folder_uri)); - - GenericTileIO::store_data(resources_, group_detail_uri, tile, encryption_key); - - return Status::Ok(); -} - Status StorageManagerCanonical::store_array_schema( const shared_ptr& array_schema, const EncryptionKey& encryption_key) { diff --git a/tiledb/sm/storage_manager/storage_manager_canonical.h b/tiledb/sm/storage_manager/storage_manager_canonical.h index 948a79e406a..b012174c14c 100644 --- a/tiledb/sm/storage_manager/storage_manager_canonical.h +++ b/tiledb/sm/storage_manager/storage_manager_canonical.h @@ -156,21 +156,6 @@ class StorageManagerCanonical { */ Status group_close_for_writes(tiledb::sm::Group* group); - /** - * Store the group details - * - * @param group_detail_folder_uri group details folder - * @param group_detail_uri uri for detail file to write - * @param group to serialize and store - * @param encryption_key encryption key for at-rest encryption - * @return status - */ - Status store_group_detail( - const URI& group_detail_folder_uri, - const URI& group_detail_uri, - tdb_shared_ptr group, - const EncryptionKey& encryption_key); - /** * Creates a TileDB array storing its schema. *