Skip to content

Commit d3dfb6c

Browse files
shaunrd0ihnorton
andcommitted
Add configuration parameter to load enumerations on all schemas. (#5379)
This adds a new config parameter `rest.load_enumerations_on_array_open_all_schemas` to control loading enumerations on all array schemas. The previously existing `rest.load_enumerations_on_array_open` config parameter is used to control loading enumerations on the latest schema only. --- TYPE: FEATURE DESC: Add `rest.load_enumerations_on_array_open_all_schemas` config parameter. --------- Co-authored-by: Isaiah Norton <[email protected]>
1 parent 545d2cb commit d3dfb6c

File tree

13 files changed

+430
-63
lines changed

13 files changed

+430
-63
lines changed

test/src/unit-capi-config.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ void check_save_to_file() {
233233
ss << "rest.curl.verbose false\n";
234234
ss << "rest.http_compressor any\n";
235235
ss << "rest.load_enumerations_on_array_open false\n";
236+
ss << "rest.load_enumerations_on_array_open_all_schemas false\n";
236237
ss << "rest.load_metadata_on_array_open true\n";
237238
ss << "rest.load_non_empty_domain_on_array_open true\n";
238239
ss << "rest.retry_count 25\n";
@@ -617,6 +618,8 @@ TEST_CASE("C API: Test config iter", "[capi][config]") {
617618
all_param_values["rest.load_metadata_on_array_open"] = "false";
618619
all_param_values["rest.load_non_empty_domain_on_array_open"] = "false";
619620
all_param_values["rest.load_enumerations_on_array_open"] = "false";
621+
all_param_values["rest.load_enumerations_on_array_open_all_schemas"] =
622+
"false";
620623
all_param_values["rest.use_refactored_array_open"] = "false";
621624
all_param_values["rest.use_refactored_array_open_and_query_submit"] = "false";
622625
all_param_values["rest.payer_namespace"] = "";

test/src/unit-cppapi-enumerations.cc

Lines changed: 346 additions & 11 deletions
Large diffs are not rendered by default.

test/src/unit-enumerations.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2488,7 +2488,7 @@ TEST_CASE_METHOD(
24882488
REQUIRE(a1->serialize_enumerations() == (do_load == "true"));
24892489
REQUIRE(
24902490
a1->array_schema_latest_ptr()->get_loaded_enumeration_names().size() ==
2491-
(do_load == "true" ? 2 : 0));
2491+
0);
24922492

24932493
auto a2 = make_shared<Array>(HERE(), ctx.resources(), uri_);
24942494

test/src/unit-rest-enumerations.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ TEST_CASE_METHOD(
164164

165165
create_array(uri_);
166166
Array opened_array(ctx_, uri_, TILEDB_READ);
167+
if (!vfs_test_setup_.is_rest() && load_enmrs) {
168+
if (opened_array.ptr()->array()->use_refactored_array_open()) {
169+
CHECK_NOTHROW(
170+
ArrayExperimental::load_enumerations_all_schemas(ctx_, opened_array));
171+
} else {
172+
CHECK_NOTHROW(
173+
ArrayExperimental::load_all_enumerations(ctx_, opened_array));
174+
}
175+
}
167176
auto array = opened_array.ptr()->array();
168177
auto schema = array->array_schema_latest_ptr();
169178
REQUIRE(schema->is_enumeration_loaded("my_enum") == load_enmrs);
@@ -218,6 +227,9 @@ TEST_CASE_METHOD(
218227
CHECK_NOTHROW(sm::Array::evolve_array_schema(
219228
ctx_.ptr()->resources(), uri, ase.get(), array->get_encryption_key()));
220229
CHECK(array->reopen().ok());
230+
if (load_enmrs && !vfs_test_setup_.is_rest()) {
231+
array->load_all_enumerations(array->use_refactored_array_open());
232+
}
221233
schema = array->array_schema_latest_ptr();
222234
std::string schema_name_2 = schema->name();
223235
REQUIRE(schema->is_enumeration_loaded("my_enum") == load_enmrs);
@@ -227,6 +239,9 @@ TEST_CASE_METHOD(
227239
expected_enmrs[schema_name_2] = {enmr1, enmr2, var_enmr.ptr()->enumeration()};
228240
actual_enmrs = array->get_enumerations_all_schemas();
229241
if (!load_enmrs) {
242+
if (!vfs_test_setup_.is_rest()) {
243+
array->load_all_enumerations(array->use_refactored_array_open());
244+
}
230245
REQUIRE(schema->is_enumeration_loaded("my_enum") == true);
231246
REQUIRE(schema->is_enumeration_loaded("fruit") == true);
232247
REQUIRE(schema->is_enumeration_loaded("ase_var_enmr") == true);
@@ -242,6 +257,9 @@ TEST_CASE_METHOD(
242257
CHECK_NOTHROW(sm::Array::evolve_array_schema(
243258
ctx_.ptr()->resources(), uri, ase.get(), array->get_encryption_key()));
244259
CHECK(array->reopen().ok());
260+
if (load_enmrs && !vfs_test_setup_.is_rest()) {
261+
array->load_all_enumerations(array->use_refactored_array_open());
262+
}
245263
schema = array->array_schema_latest_ptr();
246264
std::string schema_name_3 = schema->name();
247265
REQUIRE_THROWS_WITH(
@@ -253,6 +271,9 @@ TEST_CASE_METHOD(
253271
expected_enmrs[schema_name_3] = {enmr2, var_enmr.ptr()->enumeration()};
254272
actual_enmrs = array->get_enumerations_all_schemas();
255273
if (!load_enmrs) {
274+
if (!vfs_test_setup_.is_rest()) {
275+
array->load_all_enumerations(array->use_refactored_array_open());
276+
}
256277
REQUIRE_THROWS_WITH(
257278
schema->is_enumeration_loaded("my_enum"),
258279
Catch::Matchers::ContainsSubstring("unknown enumeration"));

tiledb/sm/array/array.cc

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,7 @@ Status Array::open(
502502
rest_client->get_array_schema_from_rest(array_uri_);
503503
throw_if_not_ok(st);
504504
set_array_schema_latest(array_schema_latest.value());
505-
if (config_.get<bool>(
506-
"rest.load_enumerations_on_array_open", Config::must_find)) {
505+
if (serialize_enumerations()) {
507506
// The route for array open v1 does not currently support loading
508507
// enumerations. Once #5359 is merged and deployed to REST this will
509508
// not be the case.
@@ -596,17 +595,6 @@ Status Array::open(
596595
return LOG_STATUS(Status_ArrayError(e.what()));
597596
}
598597

599-
// Handle any array open config options for local arrays.
600-
if (!remote_) {
601-
// For fetching remote enumerations REST calls
602-
// tiledb_handle_load_enumerations_request which loads enumerations. For
603-
// local arrays we don't call this method.
604-
if (config_.get<bool>(
605-
"rest.load_enumerations_on_array_open", Config::must_find)) {
606-
load_all_enumerations(use_refactored_array_open());
607-
}
608-
}
609-
610598
is_opening_or_closing_ = false;
611599
return Status::Ok();
612600
}
@@ -904,32 +892,24 @@ Array::get_enumerations_all_schemas() {
904892
}
905893

906894
// Store the loaded enumerations into the schemas.
907-
auto latest_schema = opened_array_->array_schema_latest_ptr();
908-
for (const auto& schema_enmrs : ret) {
895+
for (const auto& [schema_name, enmrs] : ret) {
909896
// This case will only be hit for remote arrays if the client evolves the
910897
// schema and does not reopen the array before loading all enumerations.
911-
if (!array_schemas_all().contains(schema_enmrs.first)) {
898+
if (!array_schemas_all().contains(schema_name)) {
912899
throw ArrayException(
913900
"Array opened using timestamp range (" +
914901
std::to_string(array_dir_timestamp_start_) + ", " +
915902
std::to_string(array_dir_timestamp_end_) +
916-
") has no loaded schema named '" + schema_enmrs.first +
903+
") has no loaded schema named '" + schema_name +
917904
"'; If the array was recently evolved be sure to reopen it after "
918905
"applying the evolution.");
919906
}
920907

921-
auto schema = array_schemas_all().at(schema_enmrs.first);
922-
for (const auto& enmr : schema_enmrs.second) {
908+
auto schema = array_schemas_all().at(schema_name);
909+
for (const auto& enmr : enmrs) {
923910
if (!schema->is_enumeration_loaded(enmr->name())) {
924911
schema->store_enumeration(enmr);
925912
}
926-
// Also store enumerations into the latest schema when we encounter
927-
// it.
928-
if (schema_enmrs.first == latest_schema->name()) {
929-
if (!latest_schema->is_enumeration_loaded(enmr->name())) {
930-
latest_schema->store_enumeration(enmr);
931-
}
932-
}
933913
}
934914
}
935915

@@ -989,9 +969,12 @@ std::vector<shared_ptr<const Enumeration>> Array::get_enumerations(
989969
paths_to_load, *encryption_key(), memory_tracker_);
990970
}
991971

992-
// Store the loaded enumerations in the schema
972+
// Store the loaded enumerations in the latest schema
973+
auto schema = opened_array_->array_schema_latest_ptr();
993974
for (auto& enmr : loaded) {
994-
opened_array_->array_schema_latest_ptr()->store_enumeration(enmr);
975+
if (!schema->is_enumeration_loaded(enmr->name())) {
976+
schema->store_enumeration(enmr);
977+
}
995978
}
996979
}
997980

@@ -1147,11 +1130,6 @@ Status Array::reopen(uint64_t timestamp_start, uint64_t timestamp_end) {
11471130
set_array_schemas_all(std::move(array_schemas_all));
11481131
set_fragment_metadata(std::move(fragment_metadata));
11491132

1150-
if (config_.get<bool>(
1151-
"rest.load_enumerations_on_array_open", Config::must_find)) {
1152-
load_all_enumerations(use_refactored_array_open());
1153-
}
1154-
11551133
return Status::Ok();
11561134
}
11571135

@@ -1615,13 +1593,11 @@ bool Array::serialize_non_empty_domain() const {
16151593
}
16161594

16171595
bool Array::serialize_enumerations() const {
1618-
auto serialize = config_.get<bool>("rest.load_enumerations_on_array_open");
1619-
if (!serialize.has_value()) {
1620-
throw std::runtime_error(
1621-
"Cannot get rest.load_enumerations_on_array_open configuration option "
1622-
"from config");
1623-
}
1624-
return serialize.value();
1596+
return config_.get<bool>(
1597+
"rest.load_enumerations_on_array_open", Config::must_find) ||
1598+
config_.get<bool>(
1599+
"rest.load_enumerations_on_array_open_all_schemas",
1600+
Config::must_find);
16251601
}
16261602

16271603
bool Array::serialize_metadata() const {

tiledb/sm/array/array.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ class OpenedArray {
142142
inline void set_array_schema_latest(
143143
const shared_ptr<ArraySchema>& array_schema) {
144144
array_schema_latest_ = array_schema;
145+
// Update the latest schema in the map of all array schemas.
146+
array_schemas_all_[array_schema->name()] = array_schema;
145147
}
146148

147149
/** Returns all array schemas. */
@@ -985,7 +987,11 @@ class Array {
985987
bool serialize_non_empty_domain() const;
986988

987989
/**
988-
* Checks the config to se if enumerations should be serialized on array open.
990+
* Checks the config to see if enumerations should be serialized on array
991+
* open.
992+
*
993+
* @return True if either `rest.load_enumerations_on_array_open` or
994+
* `rest.load_enumerations_on_array_open_all_schemas` is set, else False.
989995
*/
990996
bool serialize_enumerations() const;
991997

tiledb/sm/c_api/tiledb.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2155,7 +2155,7 @@ capi_return_t tiledb_handle_load_array_schema_request(
21552155
static_cast<tiledb::sm::SerializationType>(serialization_type),
21562156
request->buffer());
21572157

2158-
if (load_schema_req.include_enumerations()) {
2158+
if (load_schema_req.include_enumerations_latest_schema()) {
21592159
array->load_all_enumerations();
21602160
}
21612161

tiledb/sm/config/config.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ const std::string Config::REST_CURL_VERBOSE = "false";
9494
const std::string Config::REST_CURL_TCP_KEEPALIVE = "true";
9595
const std::string Config::REST_CURL_RETRY_ERRORS = "true";
9696
const std::string Config::REST_LOAD_ENUMERATIONS_ON_ARRAY_OPEN = "false";
97+
const std::string Config::REST_LOAD_ENUMERATIONS_ON_ARRAY_OPEN_ALL_SCHEMAS =
98+
"false";
9799
const std::string Config::REST_LOAD_METADATA_ON_ARRAY_OPEN = "true";
98100
const std::string Config::REST_LOAD_NON_EMPTY_DOMAIN_ON_ARRAY_OPEN = "true";
99101
const std::string Config::REST_USE_REFACTORED_ARRAY_OPEN = "true";
@@ -264,6 +266,9 @@ const std::map<std::string, std::string> default_config_values = {
264266
std::make_pair(
265267
"rest.load_enumerations_on_array_open",
266268
Config::REST_LOAD_ENUMERATIONS_ON_ARRAY_OPEN),
269+
std::make_pair(
270+
"rest.load_enumerations_on_array_open_all_schemas",
271+
Config::REST_LOAD_ENUMERATIONS_ON_ARRAY_OPEN_ALL_SCHEMAS),
267272
std::make_pair(
268273
"rest.load_metadata_on_array_open",
269274
Config::REST_LOAD_METADATA_ON_ARRAY_OPEN),

tiledb/sm/config/config.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,18 @@ class Config {
116116
/** If we should retry Curl errors in requests to REST. */
117117
static const std::string REST_CURL_RETRY_ERRORS;
118118

119-
/** If the array enumerations should be loaded on array open */
119+
/**
120+
* If the array enumerations should be loaded on array open for the latest
121+
* array schema only.
122+
*/
120123
static const std::string REST_LOAD_ENUMERATIONS_ON_ARRAY_OPEN;
121124

125+
/**
126+
* If the array enumerations should be loaded on array open for all array
127+
* schemas.
128+
*/
129+
static const std::string REST_LOAD_ENUMERATIONS_ON_ARRAY_OPEN_ALL_SCHEMAS;
130+
122131
/** If the array metadata should be loaded on array open */
123132
static const std::string REST_LOAD_METADATA_ON_ARRAY_OPEN;
124133

tiledb/sm/cpp_api/config.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,8 +928,12 @@ class Config {
928928
* together with the open array <br>
929929
* **Default**: true
930930
* - `rest.load_enumerations_on_array_open` <br>
931-
* If true, enumerations will be loaded and sent to server together with
932-
* the open array.
931+
* If true, enumerations will be loaded for the latest array schema on
932+
* array open.
933+
* **Default**: false
934+
* - `rest.load_enumerations_on_array_open_all_schemas` <br>
935+
* If true, enumerations will be loaded for all array schemas on array
936+
* open.
933937
* **Default**: false
934938
* - `rest.use_refactored_array_open` <br>
935939
* If true, the new REST routes and APIs for opening an array will be used

0 commit comments

Comments
 (0)