Skip to content

Commit

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

[sc-46727]

---
TYPE: NO_HISTORY
DESC: Migrate APIs out of StorageManager: store_group_detail.
  • Loading branch information
bekadavis9 authored May 16, 2024
1 parent c28e084 commit 342edda
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 55 deletions.
35 changes: 34 additions & 1 deletion tiledb/sm/group/group_details.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<shared_ptr<GroupDetails>> GroupDetails::deserialize(
Deserializer& deserializer, const URI& group_uri) {
uint32_t version = 0;
Expand Down
25 changes: 20 additions & 5 deletions tiledb/sm/group/group_details.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -131,6 +131,21 @@ class GroupDetails {
*/
void delete_member(const shared_ptr<GroupMember> 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.
*
Expand Down Expand Up @@ -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
36 changes: 2 additions & 34 deletions tiledb/sm/storage_manager/storage_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<GroupDetails> 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<ArraySchema>& array_schema,
const EncryptionKey& encryption_key) {
Expand Down
15 changes: 0 additions & 15 deletions tiledb/sm/storage_manager/storage_manager_canonical.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<GroupDetails> group,
const EncryptionKey& encryption_key);

/**
* Creates a TileDB array storing its schema.
*
Expand Down

0 comments on commit 342edda

Please sign in to comment.