Skip to content

Commit

Permalink
Remove Status_StorageManagerError and Migrate group_metadata_vacuum o…
Browse files Browse the repository at this point in the history
…ut of StorageManager. (#5034)

Remove `Status_StorageManagerError` and its occurrences.
Related subsequent fixes:
* Remove `Logger::status_no_return_value` and replace occurrences with
`Logger::error`.
* Remove `Status` and `std::optional` from returned tuple of
`Array::open_for_writes`.
* de-`Status` `Context::init_loggers`.
* Migrate `StorageManagerCanonical::group_metadata_vacuum` -> `static
Group::vacuum_metadata`.

[sc-48630]
[sc-48639]

---
TYPE: NO_HISTORY
DESC: Remove `Status_StorageManagerError` and Migrate
`group_metadata_vacuum` out of `StorageManager`.
  • Loading branch information
bekadavis9 authored Jun 7, 2024
1 parent bc4ec51 commit 1326ed4
Show file tree
Hide file tree
Showing 19 changed files with 115 additions and 150 deletions.
2 changes: 1 addition & 1 deletion tiledb/api/c_api/group/group_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ capi_return_t tiledb_group_vacuum_metadata(
ensure_group_uri_argument_is_valid(group_uri);

auto cfg = (config == nullptr) ? ctx->config() : config->config();
ctx->storage_manager()->group_metadata_vacuum(group_uri, cfg);
sm::Group::vacuum_metadata(ctx->resources(), group_uri, cfg);

return TILEDB_OK;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ class StorageManagerStub {
inline Status cancel_all_tasks() {
return Status{};
}
inline Status group_metadata_vacuum(const char*, const Config&) {
throw std::logic_error(
"StorageManagerStub does not support group metadata vacuum");
}
inline Status set_tag(const std::string&, const std::string&) {
return Status{};
}
Expand Down
12 changes: 3 additions & 9 deletions tiledb/common/exception/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* The BSD License
*
* @copyright Copyright (c) 2017-2022 TileDB, Inc.
* @copyright Copyright (c) 2017-2024 TileDB, Inc.
* Copyright (c) 2011 The LevelDB Authors. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -60,8 +60,7 @@
#include "tiledb/common/common-std.h"
#include "tiledb/common/heap_memory.h"

namespace tiledb {
namespace common {
namespace tiledb::common {

#define RETURN_NOT_OK(s) \
do { \
Expand Down Expand Up @@ -250,10 +249,6 @@ inline Status Status_Ok() {
inline Status Status_Error(const std::string& msg) {
return {"Error", msg};
};
/** Return a StorageManager error class Status with a given message **/
inline Status Status_StorageManagerError(const std::string& msg) {
return {"[TileDB::StorageManager] Error", msg};
}
/** Return a FragmentMetadata error class Status with a given message **/
inline Status Status_FragmentMetadataError(const std::string& msg) {
return {"[TileDB::FragmentMetadata] Error", msg};
Expand Down Expand Up @@ -433,7 +428,6 @@ inline Status Status_TaskError(const std::string& msg) {
inline Status Status_RangeError(const std::string& msg) {
return {"[TileDB::Range] Error", msg};
}
} // namespace common
} // namespace tiledb
} // namespace tiledb::common

#endif // TILEDB_STATUS_H
6 changes: 1 addition & 5 deletions tiledb/common/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* The MIT License
*
* @copyright Copyright (c) 2017-2021 TileDB, Inc.
* @copyright Copyright (c) 2017-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 @@ -147,10 +147,6 @@ Status Logger::status(const Status& st) {
return st;
}

void Logger::status_no_return_value(const Status& st) {
logger_->error(st.message());
}

void Logger::trace(const std::string& msg) {
logger_->trace(msg);
}
Expand Down
15 changes: 3 additions & 12 deletions tiledb/common/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* The MIT License
*
* @copyright Copyright (c) 2017-2021 TileDB, Inc.
* @copyright Copyright (c) 2017-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 @@ -48,8 +48,7 @@ namespace spdlog {
class logger;
}

namespace tiledb {
namespace common {
namespace tiledb::common {

/** Definition of class Logger. */
class Logger {
Expand Down Expand Up @@ -315,13 +314,6 @@ class Logger {
*/
Status status(const Status& st);

/**
* Log a message from a Status object without returning it.
*
* @param st The Status object to log
*/
void status_no_return_value(const Status& st);

/**
* Log an error and exit with a non-zero status.
*
Expand Down Expand Up @@ -457,8 +449,7 @@ inline Status logger_format_from_string(
return Status::Ok();
}

} // namespace common
} // namespace tiledb
} // namespace tiledb::common

// Also include the public-permissible logger functions here.
#include "tiledb/common/logger_public.h"
Expand Down
66 changes: 24 additions & 42 deletions tiledb/sm/array/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,11 @@ Status Array::open(
array_dir_timestamp_end_,
ArrayDirectoryMode::SCHEMA_ONLY));
}
auto&& [st, array_schema_latest, array_schemas] = open_for_writes();
throw_if_not_ok(st);

// Set schemas
set_array_schema_latest(array_schema_latest.value());
set_array_schemas_all(std::move(array_schemas.value()));
auto&& [array_schema_latest, array_schemas] = open_for_writes();
set_array_schema_latest(array_schema_latest);
set_array_schemas_all(std::move(array_schemas));

// Set the timestamp
opened_array_->metadata().reset(timestamp_end_opened_at());
Expand All @@ -606,12 +605,11 @@ Status Array::open(
array_dir_timestamp_end_,
ArrayDirectoryMode::READ));
}
auto&& [st, latest, array_schemas] = open_for_writes();
throw_if_not_ok(st);

// Set schemas
set_array_schema_latest(latest.value());
set_array_schemas_all(std::move(array_schemas.value()));
auto&& [latest, array_schemas] = open_for_writes();
set_array_schema_latest(latest);
set_array_schemas_all(std::move(array_schemas));

auto version = array_schema_latest().version();
if (query_type == QueryType::DELETE &&
Expand Down Expand Up @@ -1842,19 +1840,15 @@ Array::open_for_reads_without_fragments() {
}

tuple<
Status,
optional<shared_ptr<ArraySchema>>,
optional<std::unordered_map<std::string, shared_ptr<ArraySchema>>>>
shared_ptr<ArraySchema>,
std::unordered_map<std::string, shared_ptr<ArraySchema>>>
Array::open_for_writes() {
auto timer_se =
resources_.stats().start_timer("array_open_write_load_schemas");
// Checks
if (!resources_.vfs().supports_uri_scheme(array_uri_))
return {
resources_.logger()->status(Status_StorageManagerError(
"Cannot open array; URI scheme unsupported.")),
nullopt,
nullopt};
if (!resources_.vfs().supports_uri_scheme(array_uri_)) {
throw ArrayException("Cannot open array; URI scheme unsupported.");
}

// Load array schemas
auto&& [array_schema_latest, array_schemas_all] =
Expand All @@ -1867,31 +1861,21 @@ Array::open_for_writes() {
auto version = array_schema_latest->version();
if constexpr (is_experimental_build) {
if (version != constants::format_version) {
std::stringstream err;
err << "Cannot open array for writes; Array format version (";
err << version;
err << ") is not the library format version (";
err << constants::format_version << ")";
return {
resources_.logger()->status(Status_StorageManagerError(err.str())),
nullopt,
nullopt};
throw ArrayException(
"Cannot open array for writes; Array format version (" +
std::to_string(version) + ") is not the library format version (" +
std::to_string(constants::format_version) + ")");
}
} else {
if (version > constants::format_version) {
std::stringstream err;
err << "Cannot open array for writes; Array format version (";
err << version;
err << ") is newer than library format version (";
err << constants::format_version << ")";
return {
resources_.logger()->status(Status_StorageManagerError(err.str())),
nullopt,
nullopt};
throw ArrayException(
"Cannot open array for writes; Array format version (" +
std::to_string(version) + ") is newer than library format version (" +
std::to_string(constants::format_version) + ")");
}
}

return {Status::Ok(), array_schema_latest, array_schemas_all};
return {array_schema_latest, array_schemas_all};
}

void Array::clear_last_max_buffer_sizes() {
Expand Down Expand Up @@ -2326,12 +2310,10 @@ void Array::ensure_array_is_valid_for_delete(const URI& uri) {
void ensure_supported_schema_version_for_read(format_version_t version) {
// We do not allow reading from arrays written by newer version of TileDB
if (version > constants::format_version) {
std::stringstream err;
err << "Cannot open array for reads; Array format version (";
err << version;
err << ") is newer than library format version (";
err << constants::format_version << ")";
throw Status_StorageManagerError(err.str());
throw ArrayException(
"Cannot open array for reads; Array format version (" +
std::to_string(version) + ") is newer than library format version (" +
std::to_string(constants::format_version) + ")");
}
}

Expand Down
11 changes: 5 additions & 6 deletions tiledb/sm/array/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -1200,19 +1200,18 @@ class Array {
std::unordered_map<std::string, shared_ptr<ArraySchema>>>
open_for_reads_without_fragments();

/** Opens an array for writes.
/**
* Opens an array for writes.
*
* @param array The array to open.
* @return tuple of Status, latest ArraySchema and map of all array schemas
* Status Ok on success, else error
* @return tuple of latest ArraySchema and map of all array schemas
* ArraySchema The array schema to be retrieved after the
* array is opened.
* ArraySchemaMap Map of all array schemas found keyed by name
*/
tuple<
Status,
optional<shared_ptr<ArraySchema>>,
optional<std::unordered_map<std::string, shared_ptr<ArraySchema>>>>
shared_ptr<ArraySchema>,
std::unordered_map<std::string, shared_ptr<ArraySchema>>>
open_for_writes();

/** Clears the cached max buffer sizes and subarray. */
Expand Down
2 changes: 1 addition & 1 deletion tiledb/sm/consolidator/array_meta_consolidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Status ArrayMetaConsolidator::consolidate(

void ArrayMetaConsolidator::vacuum(const char* array_name) {
if (array_name == nullptr) {
throw Status_StorageManagerError(
throw std::invalid_argument(
"Cannot vacuum array metadata; Array name cannot be null");
}

Expand Down
2 changes: 1 addition & 1 deletion tiledb/sm/consolidator/commits_consolidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Status CommitsConsolidator::consolidate(

void CommitsConsolidator::vacuum(const char* array_name) {
if (array_name == nullptr) {
throw Status_StorageManagerError(
throw std::invalid_argument(
"Cannot vacuum array metadata; Array name cannot be null");
}

Expand Down
2 changes: 1 addition & 1 deletion tiledb/sm/consolidator/fragment_meta_consolidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Status FragmentMetaConsolidator::consolidate(

void FragmentMetaConsolidator::vacuum(const char* array_name) {
if (array_name == nullptr) {
throw Status_StorageManagerError(
throw std::invalid_argument(
"Cannot vacuum fragment metadata; Array name cannot be null");
}

Expand Down
2 changes: 1 addition & 1 deletion tiledb/sm/consolidator/group_meta_consolidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Status GroupMetaConsolidator::consolidate(

void GroupMetaConsolidator::vacuum(const char* group_name) {
if (group_name == nullptr) {
throw Status_StorageManagerError(
throw std::invalid_argument(
"Cannot vacuum group metadata; Group name cannot be null");
}

Expand Down
22 changes: 22 additions & 0 deletions tiledb/sm/group/group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,28 @@ Status Group::consolidate_metadata(
group_name, EncryptionType::NO_ENCRYPTION, nullptr, 0);
}

void Group::vacuum_metadata(
ContextResources& resources, const char* group_name, const Config& config) {
// Check group URI
URI group_uri(group_name);
if (group_uri.is_invalid()) {
throw GroupException("Cannot vacuum group metadata; Invalid URI");
}

// Check if group exists
ObjectType obj_type;
throw_if_not_ok(object_type(resources, group_uri, &obj_type));

if (obj_type != ObjectType::GROUP) {
throw GroupException("Cannot vacuum group metadata; Group does not exist");
}

StorageManager sm(resources, resources.logger(), config);
auto consolidator =
Consolidator::create(ConsolidationMode::GROUP_META, config, &sm);
consolidator->vacuum(group_name);
}

const EncryptionKey* Group::encryption_key() const {
return encryption_key_.get();
}
Expand Down
15 changes: 15 additions & 0 deletions tiledb/sm/group/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@ class Group {
const char* group_name,
const Config& config);

/**
* Vacuums the consolidated metadata files of a group.
*
* @param resources The context resources.
* @param group_name The name of the group whose metadata will be
* vacuumed.
* @param config Configuration parameters for vacuuming
* (`nullptr` means default, which will use the config associated with
* this instance).
*/
static void vacuum_metadata(
ContextResources& resources,
const char* group_name,
const Config& config);

/** Returns a constant pointer to the encryption key. */
const EncryptionKey* encryption_key() const;

Expand Down
2 changes: 1 addition & 1 deletion tiledb/sm/query/writers/unordered_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ Status UnorderedWriter::check_coord_dups() const {
return Status::Ok();
});

RETURN_NOT_OK_ELSE(status, logger_->status_no_return_value(status));
RETURN_NOT_OK_ELSE(status, logger_->error(status.message()));

return Status::Ok();
}
Expand Down
2 changes: 1 addition & 1 deletion tiledb/sm/query/writers/writer_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ Status WriterBase::calculate_hilbert_values(
return Status::Ok();
});

RETURN_NOT_OK_ELSE(status, logger_->status_no_return_value(status));
RETURN_NOT_OK_ELSE(status, logger_->error(status.message()));

return Status::Ok();
}
Expand Down
Loading

0 comments on commit 1326ed4

Please sign in to comment.