Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate std::prm memory tracking for class ArraySchemaEvolution. #4736

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/src/unit-cppapi-schema-evolution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,8 @@ TEST_CASE(
TEST_CASE(
"SchemaEvolution Error Handling Tests",
"[cppapi][schema][evolution][errors]") {
auto ase = make_shared<tiledb::sm::ArraySchemaEvolution>(HERE());
auto ase = make_shared<tiledb::sm::ArraySchemaEvolution>(
HERE(), tiledb::test::create_test_memory_tracker());
REQUIRE_THROWS(ase->evolve_schema(nullptr));
REQUIRE_THROWS(ase->add_attribute(nullptr));

Expand Down
51 changes: 26 additions & 25 deletions test/src/unit-enumerations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ TEST_CASE_METHOD(
array->load_all_enumerations();

auto orig_schema = array->array_schema_latest_ptr();
auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);
auto attr3 = make_shared<Attribute>(HERE(), "attr3", Datatype::UINT32);
ase->add_attribute(attr3);
CHECK_NOTHROW(ase->evolve_schema(orig_schema));
Expand All @@ -1588,7 +1588,7 @@ TEST_CASE_METHOD(
"[enumeration][array-schema-evolution][simple]") {
create_array();
auto orig_schema = get_array_schema_latest();
auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);

std::vector<uint64_t> values{0, 1, 2, 3, 4, 1000};
auto enmr = create_enumeration(values);
Expand All @@ -1609,7 +1609,7 @@ TEST_CASE_METHOD(
"[enumeration][array-schema-evolution][drop-add]") {
create_array();
auto orig_schema = get_array_schema_latest();
auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);

std::vector<uint64_t> values{0, 1, 2, 3, 4, 1000};
auto enmr = create_enumeration(values);
Expand All @@ -1630,7 +1630,7 @@ TEST_CASE_METHOD(
create_array();
auto orig_schema = get_array_schema_latest();

auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);

std::vector<uint64_t> values{0, 1, 2, 3, 4, 1000};
auto enmr = create_enumeration(values);
Expand All @@ -1649,7 +1649,7 @@ TEST_CASE_METHOD(
"[enumeration][array-schema-evolution][enmr-to-add]") {
create_array();
auto orig_schema = get_array_schema_latest();
auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);

std::vector<uint64_t> values{0, 1, 2, 3, 4, 1000};
auto enmr1 = create_enumeration(values);
Expand All @@ -1675,7 +1675,7 @@ TEST_CASE_METHOD(
REQUIRE(old_enmr != nullptr);
auto new_enmr = extend_enumeration(old_enmr, values_to_add);

auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);
ase->extend_enumeration(new_enmr);
CHECK_NOTHROW(ase->evolve_schema(orig_schema));
}
Expand All @@ -1684,7 +1684,7 @@ TEST_CASE_METHOD(
EnumerationFx,
"ArraySchemaEvolution - Drop Enumeration",
"[enumeration][array-schema-evolution][enmr-to-drop]") {
auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);
CHECK_NOTHROW(ase->drop_enumeration("test_enmr"));
}

Expand All @@ -1694,15 +1694,15 @@ TEST_CASE_METHOD(
"[enumeration][array-schema-evolution][enmr-to-drop]") {
create_array();
auto orig_schema = get_array_schema_latest();
auto ase1 = make_shared<ArraySchemaEvolution>(HERE());
auto ase1 = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);

std::vector<uint64_t> values{0, 1, 2, 3, 4, 1000};
auto enmr1 = create_enumeration(values, false, Datatype::UINT64, "enmr");
ase1->add_enumeration(enmr1);

auto new_schema = ase1->evolve_schema(orig_schema);

auto ase2 = make_shared<ArraySchemaEvolution>(HERE());
auto ase2 = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);
ase2->drop_enumeration("enmr");

CHECK_NOTHROW(ase2->evolve_schema(new_schema));
Expand All @@ -1712,7 +1712,7 @@ TEST_CASE_METHOD(
EnumerationFx,
"ArraySchemaEvolution - Drop Enumeration Repeated",
"[enumeration][array-schema-evolution][enmr-to-drop-repeated]") {
auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);
CHECK_NOTHROW(ase->drop_enumeration("test_enmr"));
CHECK_NOTHROW(ase->drop_enumeration("test_enmr"));
}
Expand All @@ -1721,7 +1721,7 @@ TEST_CASE_METHOD(
EnumerationFx,
"ArraySchemaEvolution - Drop Enumeration After Add",
"[enumeration][array-schema-evolution][enmr-add-drop]") {
auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);

std::vector<uint64_t> values{0, 1, 2, 3, 4, 1000};
auto enmr = create_enumeration(values, false, Datatype::UINT64, "enmr");
Expand All @@ -1736,7 +1736,7 @@ TEST_CASE_METHOD(
"ArraySchemaEvolution - Enumeration to Add - nullptr",
"[enumeration][array-schema-evolution][enmr-nullptr]") {
create_array();
auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);
REQUIRE_THROWS(ase->add_enumeration(nullptr));
}

Expand All @@ -1745,7 +1745,7 @@ TEST_CASE_METHOD(
"ArraySchemaEvolution - Enumeration to Add - Already Added",
"[enumeration][array-schema-evolution][enmr-already-added]") {
create_array();
auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);

std::vector<uint64_t> values{0, 1, 2, 3, 4, 1000};
auto enmr1 = create_enumeration(values, false, Datatype::UINT64, "enmr");
Expand All @@ -1759,7 +1759,7 @@ TEST_CASE_METHOD(
"ArraySchemaEvolution - Enumeration to Add - Missing Name",
"[enumeration][array-schema-evolution][missing-name]") {
create_array();
auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);
REQUIRE(ase->enumeration_to_add("foo") == nullptr);
}

Expand All @@ -1769,7 +1769,7 @@ TEST_CASE_METHOD(
"[enumeration][array-schema-evolution][enmr-still-in-use]") {
create_array();
auto orig_schema = get_array_schema_latest();
auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);
ase->drop_enumeration("test_enmr");

REQUIRE_THROWS(ase->evolve_schema(orig_schema));
Expand All @@ -1784,7 +1784,7 @@ TEST_CASE_METHOD(
auto attr3 = make_shared<Attribute>(HERE(), "attr3", Datatype::UINT32);
attr3->set_enumeration_name("test_enmr");

auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);
ase->add_attribute(attr3);

auto orig_schema = get_array_schema_latest();
Expand All @@ -1805,7 +1805,7 @@ TEST_CASE_METHOD(
auto attr3 = make_shared<Attribute>(HERE(), "attr3", Datatype::INT8);
attr3->set_enumeration_name("big_enmr");

auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);
ase->add_enumeration(enmr);
ase->add_attribute(attr3);

Expand All @@ -1827,7 +1827,7 @@ TEST_CASE_METHOD(
auto attr3 = make_shared<Attribute>(HERE(), "attr3", Datatype::UINT8);
attr3->set_enumeration_name("big_enmr");

auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);
ase->add_enumeration(enmr);
ase->add_attribute(attr3);

Expand All @@ -1839,7 +1839,7 @@ TEST_CASE_METHOD(
EnumerationFx,
"ArraySchemaEvolution - Extend Enumeration nullptr",
"[enumeration][array-schema-evolution][extend][error]") {
auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);
auto matcher = Catch::Matchers::ContainsSubstring(
"Cannot extend enumeration; Input enumeration is null");
REQUIRE_THROWS_WITH(ase->extend_enumeration(nullptr), matcher);
Expand All @@ -1849,7 +1849,7 @@ TEST_CASE_METHOD(
EnumerationFx,
"ArraySchemaEvolution - Extend Enumeration Already Extended",
"[enumeration][array-schema-evolution][extend][error]") {
auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);
std::vector<int> values = {1, 2, 3, 4, 5};
auto enmr = create_enumeration(values);
auto matcher = Catch::Matchers::ContainsSubstring(
Expand Down Expand Up @@ -1928,7 +1928,7 @@ TEST_CASE_METHOD(
auto old_enmr = schema->get_enumeration("test_enmr");
auto new_enmr = extend_enumeration(old_enmr, values_to_add);

auto ase = make_shared<ArraySchemaEvolution>(HERE());
auto ase = make_shared<ArraySchemaEvolution>(HERE(), memory_tracker_);
ase->extend_enumeration(new_enmr);
auto st = ctx_.storage_manager()->array_evolve_schema(
array->array_uri(), ase.get(), array->get_encryption_key());
Expand Down Expand Up @@ -2182,7 +2182,7 @@ TEST_CASE_METHOD(
auto attr = make_shared<Attribute>(HERE(), "ohai", Datatype::INT64);
attr->set_enumeration_name("enmr2");

ArraySchemaEvolution ase1;
ArraySchemaEvolution ase1(memory_tracker_);
ase1.add_attribute(attr);
ase1.add_enumeration(enmr1);
ase1.add_enumeration(enmr2);
Expand Down Expand Up @@ -2216,7 +2216,7 @@ TEST_CASE_METHOD(
std::vector<double> values2 = {1.0, 2.0, 3.0, 4.0, 5.0};
auto enmr2 = create_enumeration(values2, true, Datatype::FLOAT64, "enmr2");

ArraySchemaEvolution ase1;
ArraySchemaEvolution ase1(memory_tracker_);
ase1.extend_enumeration(enmr1);
ase1.extend_enumeration(enmr2);

Expand Down Expand Up @@ -2416,6 +2416,7 @@ EnumerationFx::EnumerationFx()
, memory_tracker_(tiledb::test::create_test_memory_tracker()) {
rm_array();
throw_if_not_ok(enc_key_.set_key(EncryptionType::NO_ENCRYPTION, nullptr, 0));
memory_tracker_ = tiledb::test::create_test_memory_tracker();
}

EnumerationFx::~EnumerationFx() {
Expand Down Expand Up @@ -2762,8 +2763,8 @@ shared_ptr<ArraySchemaEvolution> EnumerationFx::ser_des_array_schema_evolution(
ase, stype, &buf, client_side));

ArraySchemaEvolution* ret;
throw_if_not_ok(
serialization::array_schema_evolution_deserialize(&ret, stype, buf));
throw_if_not_ok(serialization::array_schema_evolution_deserialize(
&ret, stype, buf, memory_tracker_));

return shared_ptr<ArraySchemaEvolution>(ret);
}
Expand Down
18 changes: 18 additions & 0 deletions tiledb/common/memory_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ std::string memory_type_to_str(MemoryType type) {
return "TileMinVals";
case MemoryType::TILE_NULL_COUNTS:
return "TileNullCounts";
case MemoryType::ATTRIBUTES:
return "Attributes";
case MemoryType::DIMENSION_LABELS:
return "DimensionLabels";
case MemoryType::DIMENSIONS:
return "Dimensions";
case MemoryType::TILE_SUMS:
return "TileSums";
case MemoryType::TILE_WRITER_DATA:
Expand All @@ -82,16 +88,28 @@ std::string memory_tracker_type_to_str(MemoryTrackerType type) {
switch (type) {
case MemoryTrackerType::ANONYMOUS:
return "Anonymous";
case MemoryTrackerType::ARRAY_CREATE:
return "ArrayCreate";
case MemoryTrackerType::ARRAY_LOAD:
return "ArrayLoad";
case MemoryTrackerType::ARRAY_READ:
return "ArrayRead";
case MemoryTrackerType::ARRAY_WRITE:
return "ArrayWrite";
case MemoryTrackerType::FRAGMENT_INFO_LOAD:
return "FragmentInfoLoad";
case MemoryTrackerType::QUERY_READ:
return "QueryRead";
case MemoryTrackerType::QUERY_WRITE:
return "QueryWrite";
case MemoryTrackerType::CONSOLIDATOR:
return "Consolidator";
case MemoryTrackerType::REST_CLIENT:
return "RestClient";
case MemoryTrackerType::EPHEMERAL:
return "Ephemeral";
case MemoryTrackerType::SCHEMA_EVOLUTION:
return "SchemaEvolution";
default:
auto val = std::to_string(static_cast<uint32_t>(type));
throw std::logic_error("Invalid memory tracker type: " + val);
Expand Down
3 changes: 2 additions & 1 deletion tiledb/common/memory_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ enum class MemoryTrackerType {
QUERY_WRITE,
CONSOLIDATOR,
REST_CLIENT,
EPHEMERAL
EPHEMERAL,
SCHEMA_EVOLUTION
};

class MemoryTrackerResource : public tdb::pmr::memory_resource {
Expand Down
35 changes: 30 additions & 5 deletions tiledb/sm/array_schema/array_schema_evolution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "tiledb/common/common.h"
#include "tiledb/common/heap_memory.h"
#include "tiledb/common/logger.h"
#include "tiledb/common/memory_tracker.h"
#include "tiledb/common/status.h"
#include "tiledb/sm/array_schema/array_schema.h"
#include "tiledb/sm/array_schema/attribute.h"
Expand Down Expand Up @@ -71,7 +72,15 @@ class ArraySchemaEvolutionException : public StatusException {
/* CONSTRUCTORS & DESTRUCTORS */
/* ****************************** */

ArraySchemaEvolution::ArraySchemaEvolution() {
ArraySchemaEvolution::ArraySchemaEvolution(
shared_ptr<MemoryTracker> memory_tracker)
: memory_tracker_(memory_tracker)
, attributes_to_add_map_(
memory_tracker->get_resource(MemoryType::ATTRIBUTES))
, enumerations_to_add_map_(
memory_tracker_->get_resource(MemoryType::ENUMERATION))
, enumerations_to_extend_map_(
memory_tracker_->get_resource(MemoryType::ENUMERATION)) {
}

ArraySchemaEvolution::ArraySchemaEvolution(
Expand All @@ -81,13 +90,29 @@ ArraySchemaEvolution::ArraySchemaEvolution(
std::unordered_map<std::string, shared_ptr<const Enumeration>>
enmrs_to_extend,
std::unordered_set<std::string> enmrs_to_drop,
std::pair<uint64_t, uint64_t> timestamp_range)
: attributes_to_add_map_(attrs_to_add)
std::pair<uint64_t, uint64_t> timestamp_range,
shared_ptr<MemoryTracker> memory_tracker)
: memory_tracker_(memory_tracker)
, attributes_to_add_map_(
memory_tracker->get_resource(MemoryType::ATTRIBUTES))
, attributes_to_drop_(attrs_to_drop)
, enumerations_to_add_map_(enmrs_to_add)
, enumerations_to_extend_map_(enmrs_to_extend)
, enumerations_to_add_map_(
memory_tracker_->get_resource(MemoryType::ENUMERATION))
, enumerations_to_extend_map_(
memory_tracker_->get_resource(MemoryType::ENUMERATION))
, enumerations_to_drop_(enmrs_to_drop)
, timestamp_range_(timestamp_range) {
for (auto& elem : attrs_to_add) {
attributes_to_add_map_.insert(elem);
}

for (auto& elem : enmrs_to_add) {
enumerations_to_add_map_.insert(elem);
}

for (auto& elem : enmrs_to_extend) {
enumerations_to_extend_map_.insert(elem);
}
}

ArraySchemaEvolution::~ArraySchemaEvolution() {
Expand Down
Loading
Loading