From b1d8be74477d42f5670421a8176f2735903bace4 Mon Sep 17 00:00:00 2001 From: Ypatia Tsavliri Date: Wed, 18 Dec 2024 15:26:16 +0200 Subject: [PATCH] Try to fix ASAN error --- tiledb/sm/query/readers/result_tile.cc | 40 ++++++++++++++++++++++++-- tiledb/sm/query/readers/result_tile.h | 15 +++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/tiledb/sm/query/readers/result_tile.cc b/tiledb/sm/query/readers/result_tile.cc index d65f1afca09..c5901e40d15 100644 --- a/tiledb/sm/query/readers/result_tile.cc +++ b/tiledb/sm/query/readers/result_tile.cc @@ -91,6 +91,16 @@ ResultTile::ResultTile( coord_func_ = &ResultTile::zipped_coord; } +ResultTile::~ResultTile() { + try { + // Wait for all tasks to be done + wait_all_attrs(); + wait_all_coords(); + } catch (...) { + return; + } +} + /* ****************************** */ /* API */ /* ****************************** */ @@ -130,7 +140,7 @@ void ResultTile::erase_tile(const std::string& name) { // Handle attribute tile for (auto& at : attr_tiles_) { - if (at.first == name) { + if (at.second.has_value() && at.first == name) { at.second.reset(); return; } @@ -262,8 +272,32 @@ ResultTile::TileTuple* ResultTile::tile_tuple(const std::string& name) { } void ResultTile::wait_all_coords() const { - for (auto& coord_tile : coord_tiles_) { - coord_tile.second->fixed_tile().data_as(); + for (auto& at : coord_tiles_) { + auto& tile_tuple = at.second; + if (tile_tuple.has_value()) { + tile_tuple.value().fixed_tile().data(); + if (tile_tuple.value().var_tile_opt().has_value()) { + tile_tuple.value().var_tile_opt().value().data(); + } + if (tile_tuple.value().validity_tile_opt().has_value()) { + tile_tuple.value().validity_tile_opt().value().data(); + } + } + } +} + +void ResultTile::wait_all_attrs() const { + for (auto& at : attr_tiles_) { + const auto& tile_tuple = at.second; + if (tile_tuple.has_value()) { + tile_tuple.value().fixed_tile().data(); + if (tile_tuple.value().var_tile_opt().has_value()) { + tile_tuple.value().var_tile_opt().value().data(); + } + if (tile_tuple.value().validity_tile_opt().has_value()) { + tile_tuple.value().validity_tile_opt().value().data(); + } + } } } diff --git a/tiledb/sm/query/readers/result_tile.h b/tiledb/sm/query/readers/result_tile.h index a375e855c47..c236269b1b1 100644 --- a/tiledb/sm/query/readers/result_tile.h +++ b/tiledb/sm/query/readers/result_tile.h @@ -396,6 +396,16 @@ class ResultTile { return validity_tile_.value(); } + /** @returns Var tile. */ + const std::optional& var_tile_opt() const { + return var_tile_; + } + + /** @returns Validity tile. */ + const std::optional& validity_tile_opt() const { + return validity_tile_; + } + /** @returns Fixed tile. */ const Tile& fixed_tile() const { return fixed_tile_; @@ -457,7 +467,7 @@ class ResultTile { DISABLE_MOVE_AND_MOVE_ASSIGN(ResultTile); /** Default destructor. */ - ~ResultTile() = default; + virtual ~ResultTile(); /* ********************************* */ /* API */ @@ -746,6 +756,9 @@ class ResultTile { /* Waits for all coord tiles results to be available */ void wait_all_coords() const; + /* Waits for all attr tiles results to be available */ + void wait_all_attrs() const; + protected: /* ********************************* */ /* PROTECTED ATTRIBUTES */