|
| 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 |
0 commit comments