Skip to content

Commit

Permalink
Validate open array paths for TILEDB_EXPERIMENTAL
Browse files Browse the repository at this point in the history
- Fix syntax error
- Use constexpr to check if experimental features are enabled
- Syntax changes
  • Loading branch information
bekadavis9 authored and ihnorton committed Jun 22, 2022
1 parent 8387d97 commit 9bdd9b7
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
4 changes: 4 additions & 0 deletions test/src/unit-backwards_compat.cc
Expand Up @@ -684,6 +684,10 @@ TEST_CASE(
TEST_CASE(
"Backwards compatibility: Write to an array of older version",
"[backwards-compat][write-to-older-version]") {
if constexpr (is_experimental_build) {
return;
}

std::string old_array_name(arrays_dir + "/non_split_coords_v1_4_0");
Context ctx;
std::string fragment_uri;
Expand Down
4 changes: 4 additions & 0 deletions test/src/unit-capi-consolidation.cc
Expand Up @@ -6737,6 +6737,10 @@ TEST_CASE_METHOD(
ConsolidationFx,
"C API: Test consolidation, sparse, commits, mixed versions",
"[capi][consolidation][commits][mixed-versions]") {
if constexpr (is_experimental_build) {
return;
}

remove_sparse_array();

// Get the v11 sparse array.
Expand Down
4 changes: 4 additions & 0 deletions test/src/unit-cppapi-consolidation-with-timestamps.cc
Expand Up @@ -518,6 +518,10 @@ TEST_CASE_METHOD(
"CPP API: Test consolidation with timestamps, check directory contents of "
"old array",
"[cppapi][consolidation-with-timestamps][sparse-unordered-with-dups]") {
if constexpr (is_experimental_build) {
return;
}

remove_sparse_array();
create_sparse_array_v11();
// Write first fragment.
Expand Down
10 changes: 9 additions & 1 deletion tiledb/common/common.h
Expand Up @@ -54,7 +54,6 @@ namespace tdb = tiledb::common;
using std::shared_ptr;
using tiledb::common::allocator;
using tiledb::common::make_shared;
// using tiledb::common::make_unique;

/*
* Exception
Expand All @@ -65,4 +64,13 @@ using tiledb::common::make_shared;
using tiledb::common::StatusException;
using tiledb::common::throw_if_not_ok;

/*
* Experimental build
*/
#ifdef TILEDB_EXPERIMENTAL_FEATURES
constexpr bool is_experimental_build = true;
#else
constexpr bool is_experimental_build = false;
#endif // TILEDB_EXPERIMENTAL_FEATURES

#endif // TILEDB_COMMON_COMMON_H
49 changes: 48 additions & 1 deletion tiledb/sm/storage_manager/storage_manager.cc
Expand Up @@ -251,6 +251,23 @@ StorageManager::array_open_for_reads(Array* array) {
*array->encryption_key());
RETURN_NOT_OK_TUPLE(st, nullopt, nullopt, nullopt);

// If building experimentally, this library should not be able to
// read from newer-versioned arrays
if constexpr (is_experimental_build) {
auto version = array_schema_latest.value()->version();
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 << ")";
return {logger_->status(Status_StorageManagerError(err.str())),
nullopt,
nullopt,
nullopt};
}
}

// Mark the array as open
std::lock_guard<std::mutex> lock{open_arrays_mtx_};
open_arrays_.insert(array);
Expand All @@ -272,6 +289,22 @@ StorageManager::array_open_for_reads_without_fragments(Array* array) {
load_array_schemas(array->array_directory(), *array->encryption_key());
RETURN_NOT_OK_TUPLE(st_schemas, nullopt, nullopt);

// If building experimentally, this library should not be able to
// read from newer-versioned arrays
if constexpr (is_experimental_build) {
auto version = array_schema_latest.value()->version();
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 << ")";
return {logger_->status(Status_StorageManagerError(err.str())),
nullopt,
nullopt};
}
}

// Mark the array as now open
std::lock_guard<std::mutex> lock{open_arrays_mtx_};
open_arrays_.insert(array);
Expand All @@ -296,9 +329,23 @@ StorageManager::array_open_for_writes(Array* array) {
load_array_schemas(array->array_directory(), *array->encryption_key());
RETURN_NOT_OK_TUPLE(st_schemas, nullopt, nullopt);

// This library should not be able to write to newer-versioned arrays
// If building experimentally, this library should not be able to
// write to newer-versioned or older-versioned arrays
// Else, this library should not be able to write to newer-versioned arrays
// (but it is ok to write to older arrays)
auto version = array_schema_latest.value()->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 {logger_->status(Status_StorageManagerError(err.str())),
nullopt,
nullopt};
}
}
if (version > constants::format_version) {
std::stringstream err;
err << "Cannot open array for writes; Array format version (";
Expand Down

0 comments on commit 9bdd9b7

Please sign in to comment.