Skip to content

Commit 45361ef

Browse files
KiterLucdavisp
andauthored
Keep opened array resources alive until query ends. (#4601)
This change moves all the opened array resources used in strategies to a class so that they can be acquired as a shared pointer when the strategy begins and kept alive until the strategy is done. [sc-38872] --- TYPE: IMPROVEMENT DESC: Keep opened array resources alive until query ends. --------- Co-authored-by: Paul J. Davis <[email protected]>
1 parent b8bc74a commit 45361ef

28 files changed

+678
-413
lines changed

test/src/unit-Reader.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,16 @@ TEST_CASE_METHOD(
165165
DefaultChannelAggregates default_channel_aggregates;
166166
auto params = StrategyParams(
167167
context.storage_manager(),
168-
&array,
168+
array.opened_array(),
169169
config,
170170
buffers,
171171
aggregate_buffers,
172172
subarray,
173173
Layout::ROW_MAJOR,
174174
condition,
175175
default_channel_aggregates,
176-
false);
176+
false,
177+
array.memory_tracker());
177178
Reader reader(&g_helper_stats, g_helper_logger(), params);
178179
unsigned dim_num = 2;
179180
auto size = 2 * sizeof(int32_t);

test/src/unit-capi-array.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2337,7 +2337,7 @@ TEST_CASE_METHOD(
23372337

23382338
// Check the retrieved non empty domain
23392339
auto non_empty_domain = new_array->array_->loaded_non_empty_domain();
2340-
CHECK(non_empty_domain->empty() == false);
2340+
CHECK(non_empty_domain.empty() == false);
23412341

23422342
// Check the retrieved metadata
23432343
Datatype type;

test/src/unit-capi-fragment_info.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,8 @@ TEST_CASE(
12791279
rc = tiledb_array_consolidate(ctx, array_name.c_str(), config);
12801280
CHECK(rc == TILEDB_OK);
12811281

1282+
tiledb_config_free(&config);
1283+
12821284
// Load fragment info
12831285
rc = tiledb_fragment_info_load(ctx, fragment_info);
12841286
CHECK(rc == TILEDB_OK);

test/src/unit-cppapi-array.cc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,3 +2088,52 @@ TEST_CASE(
20882088
vfs.remove_dir(get_commit_dir(array_read.uri()));
20892089
vfs.remove_dir(array_read.uri() + "/__schema");
20902090
}
2091+
2092+
TEST_CASE(
2093+
"C++ API: Close array with running query", "[cppapi][close-before-read]") {
2094+
const std::string array_name = "cpp_unit_array";
2095+
Context ctx;
2096+
VFS vfs(ctx);
2097+
2098+
if (vfs.is_dir(array_name))
2099+
vfs.remove_dir(array_name);
2100+
2101+
// Create
2102+
Domain domain(ctx);
2103+
domain.add_dimension(Dimension::create<int>(ctx, "rows", {{0, 3}}, 4))
2104+
.add_dimension(Dimension::create<int>(ctx, "cols", {{0, 3}}, 4));
2105+
ArraySchema schema(ctx, TILEDB_DENSE);
2106+
schema.set_domain(domain).set_order({{TILEDB_ROW_MAJOR, TILEDB_ROW_MAJOR}});
2107+
schema.add_attribute(Attribute::create<int>(ctx, "a"));
2108+
Array::create(array_name, schema);
2109+
2110+
// Write
2111+
std::vector<int> data_w = {
2112+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
2113+
Array array_w(ctx, array_name, TILEDB_WRITE);
2114+
Query query_w(ctx, array_w);
2115+
query_w.set_subarray(Subarray(ctx, array_w).set_subarray({0, 3, 0, 3}))
2116+
.set_layout(TILEDB_ROW_MAJOR)
2117+
.set_data_buffer("a", data_w);
2118+
query_w.submit();
2119+
array_w.close();
2120+
2121+
// Open for read.
2122+
Array array(ctx, array_name, TILEDB_READ);
2123+
std::vector<int> subarray_read = {0, 3, 0, 3};
2124+
std::vector<int> a_read(16);
2125+
2126+
Query query(ctx, array);
2127+
query.set_subarray(subarray_read)
2128+
.set_layout(TILEDB_ROW_MAJOR)
2129+
.set_data_buffer("a", a_read);
2130+
query.submit_async();
2131+
array.close();
2132+
2133+
uint64_t i = 0;
2134+
while (query.query_status() != Query::Status::COMPLETE) {
2135+
i++;
2136+
}
2137+
2138+
CHECK(i > 0);
2139+
}

test/src/unit-cppapi-deletes.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ void DeletesFx::check_delete_conditions(
458458

459459
// Load delete conditions.
460460
auto&& [st, delete_conditions, update_values] =
461-
sm_->load_delete_and_update_conditions(*array_ptr);
461+
sm_->load_delete_and_update_conditions(*(array_ptr->opened_array()));
462462
REQUIRE(st.ok());
463463
REQUIRE(delete_conditions->size() == qcs.size());
464464

test/src/unit-cppapi-subarray.cc

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -415,32 +415,6 @@ TEST_CASE("C++ API: Test subarray (dense)", "[cppapi][dense][subarray]") {
415415
// default expected to err.
416416
REQUIRE_THROWS(subarray.set_subarray({1, 4, -1, 3}));
417417
tiledb::Config config;
418-
// The config option should be ignored but we set anyway.
419-
config.set("sm.read_range_oob", "error");
420-
subarray.set_config(config);
421-
REQUIRE_THROWS(subarray.set_subarray({1, 4, -1, 3}));
422-
}
423-
424-
SECTION("- set_subarray Write ranges oob warn - Subarray-query") {
425-
tiledb::Array array(ctx, array_name, TILEDB_WRITE);
426-
tiledb::Query query(ctx, array);
427-
// default (dense) WRITE should always err/throw on oob
428-
REQUIRE_THROWS(query.set_subarray({1, 4, -1, 3}));
429-
tiledb::Config config;
430-
config.set("sm.read_range_oob", "warn");
431-
query.set_config(config);
432-
// (dense) WRITE should ignore sm.read_range_oob config option
433-
// and err/throw on oob
434-
REQUIRE_THROWS(query.set_subarray({1, 4, -1, 3}));
435-
}
436-
437-
SECTION("- set_subarray Write ranges oob warn - Subarray-cppapi") {
438-
tiledb::Array array(ctx, array_name, TILEDB_WRITE);
439-
tiledb::Subarray subarray(ctx, array);
440-
REQUIRE_THROWS(subarray.set_subarray({1, 4, -1, 3}));
441-
tiledb::Config config;
442-
config.set("sm.read_range_oob", "warn");
443-
subarray.set_config(config);
444418
REQUIRE_THROWS(subarray.set_subarray({1, 4, -1, 3}));
445419
}
446420

test/src/unit-cppapi-update-queries.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void UpdatesFx::check_update_conditions(
203203

204204
// Load delete conditions.
205205
auto&& [st, conditions, update_values] =
206-
sm_->load_delete_and_update_conditions(*array_ptr);
206+
sm_->load_delete_and_update_conditions(*(array_ptr->opened_array()));
207207
REQUIRE(st.ok());
208208
REQUIRE(conditions->size() == qcs.size());
209209

0 commit comments

Comments
 (0)