Skip to content

Commit

Permalink
Changes from PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
davisp committed Feb 8, 2024
1 parent 2b124b5 commit 3d380f0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 30 deletions.
20 changes: 13 additions & 7 deletions tiledb/common/memory_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,34 @@ bool MemoryTrackerResource::do_is_equal(
}

MemoryTracker::~MemoryTracker() {
// TODO: Make this spit out some loud log noise if we've not
// properly deallocated all our things.
assert(
total_counter_.fetch_add(0) == 0 &&
"MemoryTracker destructed with outstanding allocations.");
}

tdb::pmr::memory_resource* MemoryTracker::get_resource(MemoryType type) {
std::lock_guard<std::mutex> lg(mutex_);
auto iter = resources_.find(type);

// If we've already created an instance for this type, return it.
auto iter = resources_.find(type);
if (iter != resources_.end()) {
return iter->second.get();
}

if (counters_.find(type) != counters_.end() && counters_[type] != 0) {
throw MemoryTrackerException("Invalid internal state");
// Add a new counter if it doesn't exist.
if (counters_.find(type) == counters_.end()) {
counters_.emplace(type, 0);
} else {
// There's no outstanding memory resource for this type, so it must be zero.
assert(counters_[type] == 0 && "Invalid memory tracking state.");
}

counters_.emplace(type, 0);

// Create and track a shared_ptr to the new memory resource.
auto ret = make_shared<MemoryTrackerResource>(
HERE(), upstream_, total_counter_, counters_[type]);
resources_.emplace(type, ret);

// Return the raw memory resource pointer for use by pmr containers.
return ret.get();
}

Expand Down
10 changes: 0 additions & 10 deletions tiledb/common/pmr.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@
#ifndef TILEDB_COMMON_PMR_H
#define TILEDB_COMMON_PMR_H

// Currently, this is fairly broken when building with XCode 15 on macOS 13.x.
// For now I'm just going to default to using Pablo Halpern's implementation
// rather than spend time fighting compiler detection and build chains.
//
// #if __has_include(<memory_resource>)
// #include <memory_resource>
// #else
// #error Missing memory_resources header.
// #endif

#include <vector>

#include <boost/container/pmr/memory_resource.hpp>
Expand Down
10 changes: 2 additions & 8 deletions tiledb/sm/fragment/fragment_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,14 @@ class FragmentMetadataStatusException : public StatusException {
}
};

// Temporary until these changes are verified.
inline shared_ptr<MemoryTracker> verify_tracker(shared_ptr<MemoryTracker> mt) {
assert(mt != nullptr);
return mt;
}

/* ****************************** */
/* CONSTRUCTORS & DESTRUCTORS */
/* ****************************** */

FragmentMetadata::FragmentMetadata(
ContextResources* resources, shared_ptr<MemoryTracker> memory_tracker)
: resources_(resources)
, memory_tracker_(verify_tracker(memory_tracker))
, memory_tracker_(memory_tracker)
, tile_offsets_(memory_tracker_->get_resource(MemoryType::TILE_OFFSETS))
, tile_var_offsets_(memory_tracker_->get_resource(MemoryType::TILE_OFFSETS))
, tile_var_sizes_(memory_tracker_->get_resource(MemoryType::TILE_OFFSETS))
Expand All @@ -113,7 +107,7 @@ FragmentMetadata::FragmentMetadata(
bool has_timestamps,
bool has_deletes_meta)
: resources_(resources)
, memory_tracker_(verify_tracker(memory_tracker))
, memory_tracker_(memory_tracker)
, array_schema_(array_schema)
, dense_(dense)
, footer_size_(0)
Expand Down
6 changes: 1 addition & 5 deletions tiledb/sm/query/strategy_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class StrategyParams {
/* API */
/* ********************************* */

/** Return the array memory tracker. */
inline shared_ptr<MemoryTracker> array_memory_tracker() {
return array_memory_tracker_;
}
Expand Down Expand Up @@ -205,11 +206,6 @@ class StrategyBase {
/* API */
/* ********************************* */

/** Returns `memory_tracker_`. */
inline shared_ptr<MemoryTracker> array_memory_tracker() const {
return array_memory_tracker_;
}

/** Returns `stats_`. */
inline stats::Stats* stats() const {
return stats_;
Expand Down
1 change: 1 addition & 0 deletions tiledb/sm/query/writers/writer_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class WriterBase : public StrategyBase, public IQueryStrategy {
/* PROTECTED METHODS */
/* ********************************* */

/** Utility function for constructing new FragmentMetadata instances. */
shared_ptr<FragmentMetadata> create_fragment_metadata();

/** Adss a fragment to `written_fragment_info_`. */
Expand Down

0 comments on commit 3d380f0

Please sign in to comment.