Skip to content

Commit 69d2a62

Browse files
authored
Create file array_operations.cc for I/O-oriented Array functions. (#5200)
Create file `array_operations.cc` for I/O-oriented `Array` functions. Migrate `OpenedArray::load_delete_and_update_conditions` from `array.cc` into `array_operations.cc`. [sc-51376] --- TYPE: NO_HISTORY DESC: Create file `array_operations.cc` for I/O-oriented `Array` functions.
1 parent ea0a866 commit 69d2a62

File tree

10 files changed

+234
-89
lines changed

10 files changed

+234
-89
lines changed

test/src/unit-cppapi-deletes.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "tiledb/api/c_api/context/context_api_internal.h"
3838
#include "tiledb/common/stdx_string.h"
3939
#include "tiledb/sm/array/array_directory.h"
40+
#include "tiledb/sm/array/array_operations.h"
4041
#include "tiledb/sm/c_api/tiledb_struct_def.h"
4142
#include "tiledb/sm/cpp_api/group.h"
4243
#include "tiledb/sm/cpp_api/tiledb"
@@ -436,15 +437,14 @@ void DeletesFx::check_delete_conditions(
436437
auto array_ptr = array->ptr()->array_;
437438

438439
// Load delete conditions.
439-
auto&& [st, delete_conditions, update_values] =
440-
array_ptr->opened_array()->load_delete_and_update_conditions();
441-
REQUIRE(st.ok());
442-
REQUIRE(delete_conditions->size() == qcs.size());
440+
auto&& [delete_conditions, update_values] = load_delete_and_update_conditions(
441+
ctx_.ptr().get()->resources(), *array_ptr->opened_array().get());
442+
REQUIRE(delete_conditions.size() == qcs.size());
443443

444444
for (uint64_t i = 0; i < qcs.size(); i++) {
445445
// Compare to negated condition.
446446
auto cmp = qcs[i].ptr()->query_condition_->negated_condition();
447-
CHECK(tiledb::test::ast_equal(delete_conditions->at(i).ast(), cmp.ast()));
447+
CHECK(tiledb::test::ast_equal(delete_conditions.at(i).ast(), cmp.ast()));
448448
}
449449

450450
array->close();

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "test/support/src/helpers.h"
3636
#include "tiledb/api/c_api/context/context_api_internal.h"
3737
#include "tiledb/sm/array/array_directory.h"
38+
#include "tiledb/sm/array/array_operations.h"
3839
#include "tiledb/sm/c_api/tiledb_struct_def.h"
3940
#include "tiledb/sm/cpp_api/tiledb"
4041
#include "tiledb/sm/cpp_api/tiledb_experimental"
@@ -205,16 +206,15 @@ void UpdatesFx::check_update_conditions(
205206
auto array_ptr = array->ptr()->array_;
206207

207208
// Load delete conditions.
208-
auto&& [st, conditions, update_values] =
209-
array_ptr->opened_array()->load_delete_and_update_conditions();
210-
REQUIRE(st.ok());
211-
REQUIRE(conditions->size() == qcs.size());
209+
auto&& [conditions, update_values] = load_delete_and_update_conditions(
210+
ctx_.ptr().get()->resources(), *array_ptr->opened_array().get());
211+
REQUIRE(conditions.size() == qcs.size());
212212

213213
for (uint64_t i = 0; i < qcs.size(); i++) {
214214
// Compare to negated condition.
215215
auto cmp = qcs[i].ptr()->query_condition_->negated_condition();
216-
CHECK(tiledb::test::ast_equal(conditions->at(i).ast(), cmp.ast()));
217-
auto& loaded_update_values = update_values->at(i);
216+
CHECK(tiledb::test::ast_equal(conditions.at(i).ast(), cmp.ast()));
217+
auto& loaded_update_values = update_values.at(i);
218218
for (uint64_t j = 0; j < uvs[i].size(); j++) {
219219
CHECK(uvs[i][j].field_name() == loaded_update_values[j].field_name());
220220
}

tiledb/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ set(TILEDB_CORE_SOURCES
144144
${TILEDB_CORE_INCLUDE_DIR}/tiledb/platform/cert_file.cc
145145
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/array/array.cc
146146
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/array/array_directory.cc
147+
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/array/array_operations.cc
147148
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/array/consistency.cc
148149
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/array_schema/array_schema.cc
149150
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/array_schema/array_schema_evolution.cc

tiledb/sm/array/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,32 @@
2727
include(common NO_POLICY_SCOPE)
2828
include(object_library)
2929

30+
#
31+
# The data- and I/O-oriented operations of class `Array` have been
32+
# intentionally separated to support two _future_ standalone object libraries:
33+
# - `array`: data-oriented
34+
# - `array_operations`: I/O-oriented
35+
#
36+
# This design eliminates cyclic dependencies in the build, as each module has
37+
# its own dependency chain.
38+
#
39+
# Note that neither object library has been implemented at present. Rather,
40+
# class `Array` is getting segregated by functionality to prepare for this
41+
# future work.
42+
#
43+
# Though there is currently an object library named `array`, it will soon be
44+
# aptly renamed `array_directory`.
45+
#
46+
# The `array` object library will be added in the near future.
47+
#
48+
# The `array_operations` object library is very specifically blocked by
49+
# `StrategyBase::throw_if_cancelled`. At present, this function relies on
50+
# `StorageManagerCanonical`, which is slated for removal. The `Query` class is
51+
# undergoing maintenance to remove all dependencies on class `StorageManager`.
52+
# Once `StorageManager` is removed and a standalone `StrategyBase` object
53+
# library can be added, so should the `array_operations` object library.
54+
#
55+
3056
#
3157
# `array` object library
3258
#

tiledb/sm/array/array.cc

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
*
2828
* @section DESCRIPTION
2929
*
30-
* This file implements class Array.
30+
* This file implements the data-oriented operations on class Array.
31+
*
3132
*/
3233

3334
#include "tiledb/common/common.h"
3435

3536
#include "tiledb/common/logger.h"
3637
#include "tiledb/common/memory_tracker.h"
37-
#include "tiledb/common/stdx_string.h"
3838
#include "tiledb/sm/array/array.h"
3939
#include "tiledb/sm/array_schema/array_schema.h"
4040
#include "tiledb/sm/array_schema/array_schema_evolution.h"
@@ -54,7 +54,6 @@
5454
#include "tiledb/sm/misc/tdb_time.h"
5555
#include "tiledb/sm/object/object.h"
5656
#include "tiledb/sm/object/object_mutex.h"
57-
#include "tiledb/sm/query/deletes_and_updates/serialization.h"
5857
#include "tiledb/sm/query/update_value.h"
5958
#include "tiledb/sm/rest/rest_client.h"
6059
#include "tiledb/sm/tile/generic_tile_io.h"
@@ -109,60 +108,6 @@ Array::Array(
109108
/* API */
110109
/* ********************************* */
111110

112-
tuple<
113-
Status,
114-
optional<std::vector<QueryCondition>>,
115-
optional<std::vector<std::vector<UpdateValue>>>>
116-
OpenedArray::load_delete_and_update_conditions() {
117-
auto& locations = array_directory().delete_and_update_tiles_location();
118-
auto conditions = std::vector<QueryCondition>(locations.size());
119-
auto update_values = std::vector<std::vector<UpdateValue>>(locations.size());
120-
121-
auto status = parallel_for(
122-
&resources_.compute_tp(), 0, locations.size(), [&](size_t i) {
123-
// Get condition marker.
124-
auto& uri = locations[i].uri();
125-
126-
// Read the condition from storage.
127-
auto tile = GenericTileIO::load(
128-
resources_,
129-
uri,
130-
locations[i].offset(),
131-
*(encryption_key()),
132-
resources_.ephemeral_memory_tracker());
133-
134-
if (tiledb::sm::utils::parse::ends_with(
135-
locations[i].condition_marker(),
136-
tiledb::sm::constants::delete_file_suffix)) {
137-
conditions[i] = tiledb::sm::deletes_and_updates::serialization::
138-
deserialize_condition(
139-
i,
140-
locations[i].condition_marker(),
141-
tile->data(),
142-
tile->size());
143-
} else if (tiledb::sm::utils::parse::ends_with(
144-
locations[i].condition_marker(),
145-
tiledb::sm::constants::update_file_suffix)) {
146-
auto&& [cond, uvs] = tiledb::sm::deletes_and_updates::serialization::
147-
deserialize_update_condition_and_values(
148-
i,
149-
locations[i].condition_marker(),
150-
tile->data(),
151-
tile->size());
152-
conditions[i] = std::move(cond);
153-
update_values[i] = std::move(uvs);
154-
} else {
155-
throw ArrayException("Unknown condition marker extension");
156-
}
157-
158-
throw_if_not_ok(conditions[i].check(array_schema_latest()));
159-
return Status::Ok();
160-
});
161-
throw_if_not_ok(status);
162-
163-
return {Status::Ok(), conditions, update_values};
164-
}
165-
166111
void Array::evolve_array_schema(
167112
ContextResources& resources,
168113
const URI& array_uri,

tiledb/sm/array/array.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ class ArraySchemaEvolution;
5555
class SchemaEvolution;
5656
class FragmentMetadata;
5757
class MemoryTracker;
58-
class UpdateValue;
59-
class QueryCondition;
6058
enum class QueryType : uint8_t;
6159

6260
/**
@@ -215,17 +213,6 @@ class OpenedArray {
215213
return is_remote_;
216214
}
217215

218-
/**
219-
* Loads the delete and update conditions from storage.
220-
*
221-
* @return Status, vector of the conditions, vector of the update values.
222-
*/
223-
tuple<
224-
Status,
225-
optional<std::vector<QueryCondition>>,
226-
optional<std::vector<std::vector<UpdateValue>>>>
227-
load_delete_and_update_conditions();
228-
229216
private:
230217
/** The context resources. */
231218
ContextResources& resources_;
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/**
2+
* @file array_operations.cc
3+
*
4+
* @section LICENSE
5+
*
6+
* The MIT License
7+
*
8+
* @copyright Copyright (c) 2024 TileDB, Inc.
9+
*
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* of this software and associated documentation files (the "Software"), to deal
12+
* in the Software without restriction, including without limitation the rights
13+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* copies of the Software, and to permit persons to whom the Software is
15+
* furnished to do so, subject to the following conditions:
16+
*
17+
* The above copyright notice and this permission notice shall be included in
18+
* all copies or substantial portions of the Software.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26+
* THE SOFTWARE.
27+
*
28+
* @section DESCRIPTION
29+
*
30+
* This file implements I/O operations which support class `Array`.
31+
*
32+
* Note that these functions are _non-members_ of class `Array`, and therefore
33+
* do not need access to class member variables.
34+
*
35+
* These operations have been intentionally segregated from class `Array`
36+
* to support a future standalone object library, `array_operations`,
37+
* eliminating cyclic dependendencies in the build.
38+
*
39+
* This object library cannot yet be added, however, due to a dependence
40+
* of `load_delete_and_update_conditions` on `StrategyBase::throw_if_cancelled`.
41+
* This function relies on `StorageManagerCanonical`, which is slated for
42+
* removal. Once all `Query` code is overhauled to remove this dependence,
43+
* the `array_operations` module can be created.
44+
*
45+
*/
46+
47+
#include "tiledb/sm/array/array_operations.h"
48+
#include "tiledb/common/stdx_string.h"
49+
#include "tiledb/sm/array/array.h"
50+
#include "tiledb/sm/array/array_directory.h"
51+
#include "tiledb/sm/crypto/encryption_key.h"
52+
#include "tiledb/sm/misc/parallel_functions.h"
53+
#include "tiledb/sm/query/deletes_and_updates/serialization.h"
54+
#include "tiledb/sm/tile/generic_tile_io.h"
55+
56+
namespace tiledb::sm {
57+
58+
class ArrayOperationsException : public StatusException {
59+
public:
60+
explicit ArrayOperationsException(const std::string& message)
61+
: StatusException("ArrayOperations", message) {
62+
}
63+
};
64+
65+
/* ********************************* */
66+
/* API */
67+
/* ********************************* */
68+
69+
tuple<std::vector<QueryCondition>, std::vector<std::vector<UpdateValue>>>
70+
load_delete_and_update_conditions(
71+
ContextResources& resources, const OpenedArray& opened_array) {
72+
auto& locations =
73+
opened_array.array_directory().delete_and_update_tiles_location();
74+
auto conditions = std::vector<QueryCondition>(locations.size());
75+
auto update_values = std::vector<std::vector<UpdateValue>>(locations.size());
76+
77+
auto status =
78+
parallel_for(&resources.compute_tp(), 0, locations.size(), [&](size_t i) {
79+
// Get condition marker.
80+
auto& uri = locations[i].uri();
81+
82+
// Read the condition from storage.
83+
auto tile = GenericTileIO::load(
84+
resources,
85+
uri,
86+
locations[i].offset(),
87+
*(opened_array.encryption_key()),
88+
resources.ephemeral_memory_tracker());
89+
90+
if (tiledb::sm::utils::parse::ends_with(
91+
locations[i].condition_marker(),
92+
tiledb::sm::constants::delete_file_suffix)) {
93+
conditions[i] = tiledb::sm::deletes_and_updates::serialization::
94+
deserialize_condition(
95+
i,
96+
locations[i].condition_marker(),
97+
tile->data(),
98+
tile->size());
99+
} else if (tiledb::sm::utils::parse::ends_with(
100+
locations[i].condition_marker(),
101+
tiledb::sm::constants::update_file_suffix)) {
102+
auto&& [cond, uvs] = tiledb::sm::deletes_and_updates::serialization::
103+
deserialize_update_condition_and_values(
104+
i,
105+
locations[i].condition_marker(),
106+
tile->data(),
107+
tile->size());
108+
conditions[i] = std::move(cond);
109+
update_values[i] = std::move(uvs);
110+
} else {
111+
throw ArrayOperationsException("Unknown condition marker extension");
112+
}
113+
114+
throw_if_not_ok(
115+
conditions[i].check(opened_array.array_schema_latest()));
116+
return Status::Ok();
117+
});
118+
throw_if_not_ok(status);
119+
120+
return {conditions, update_values};
121+
}
122+
123+
} // namespace tiledb::sm

tiledb/sm/array/array_operations.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* @file array_operations.h
3+
*
4+
* @section LICENSE
5+
*
6+
* The MIT License
7+
*
8+
* @copyright Copyright (c) 2024 TileDB, Inc.
9+
*
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* of this software and associated documentation files (the "Software"), to deal
12+
* in the Software without restriction, including without limitation the rights
13+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* copies of the Software, and to permit persons to whom the Software is
15+
* furnished to do so, subject to the following conditions:
16+
*
17+
* The above copyright notice and this permission notice shall be included in
18+
* all copies or substantial portions of the Software.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26+
* THE SOFTWARE.
27+
*
28+
* @section DESCRIPTION
29+
*
30+
* This file defines I/O operations which support class Array.
31+
*
32+
*/
33+
34+
#ifndef TILEDB_ARRAY_OPERATIONS_H
35+
#define TILEDB_ARRAY_OPERATIONS_H
36+
37+
#include <vector>
38+
39+
#include "tiledb/common/common.h"
40+
41+
using namespace tiledb::common;
42+
43+
namespace tiledb::sm {
44+
45+
class ContextResources;
46+
class OpenedArray;
47+
class QueryCondition;
48+
class UpdateValue;
49+
50+
/**
51+
* Loads the delete and update conditions from storage.
52+
*
53+
* @param resources The context resources.
54+
* @param opened_array The opened array whose conditions are getting loaded.
55+
* @return vector of the conditions, vector of the update values.
56+
*/
57+
tuple<std::vector<QueryCondition>, std::vector<std::vector<UpdateValue>>>
58+
load_delete_and_update_conditions(
59+
ContextResources& resources, const OpenedArray& opened_array);
60+
61+
} // namespace tiledb::sm
62+
63+
#endif // TILEDB_ARRAY_OPERATIONS_H

0 commit comments

Comments
 (0)