From ba65c8976f54d4da2467074235a12f5be0bd5ebc Mon Sep 17 00:00:00 2001 From: "Douglas B. Rumbaugh" Date: Sun, 22 Dec 2024 15:12:13 -0500 Subject: Continued development --- include/framework/structure/ExtensionStructure.h | 63 ++++++++++++++++++------ 1 file changed, 49 insertions(+), 14 deletions(-) (limited to 'include/framework/structure/ExtensionStructure.h') diff --git a/include/framework/structure/ExtensionStructure.h b/include/framework/structure/ExtensionStructure.h index 9b7ae87..3bb8a0b 100644 --- a/include/framework/structure/ExtensionStructure.h +++ b/include/framework/structure/ExtensionStructure.h @@ -147,14 +147,14 @@ public: inline void perform_reconstruction(ReconstructionTask task) { /* perform the reconstruction itself */ - std::vector shards; + std::vector shards; for (ShardID shid : task.sources) { - assert(shid.level_idx < m_levels.size()); + assert(shid.level_idx < (level_index) m_levels.size()); assert(shid.shard_idx >= -1); /* if unspecified, push all shards into the vector */ if (shid.shard_idx == all_shards_idx) { - for (size_t i = 0; i < m_levels[shid.level_idx].get_shard_count(); + for (size_t i = 0; i < m_levels[shid.level_idx]->get_shard_count(); i++) { if (m_levels[shid.level_idx]->get_shard(i)) { shards.push_back(m_levels[shid.level_idx]->get_shard(i)); @@ -165,7 +165,7 @@ public: } } - auto new_shard = Shard(shards); + auto new_shard = new ShardType(shards); /* * Remove all of the shards processed by the operation @@ -181,10 +181,11 @@ public: /* * Append the new shard to the target level */ - if (task.target < m_levels.size()) { - m_levels[task.target]->append_shard(new_shard); - } else { - m_levels.push_back(); + if (task.target < (level_index)m_levels.size()) { + m_levels[task.target]->append(std::shared_ptr(new_shard)); + } else { /* grow the structure if needed */ + m_levels.push_back(std::make_shared>(task.target)); + m_levels[task.target]->append(std::shared_ptr(new_shard)); } } @@ -197,12 +198,20 @@ public: * the buffer itself. Given that we're unlikely to actually use policies * like that, we'll leave this as low priority. */ - ShardType *buffer_shard = new ShardType(buffer); - if (task.type == ReconstructionType::Append) { - m_levels[0]->append(std::shared_ptr(buffer_shard)); + + /* insert the first level, if needed */ + if (m_levels.size() == 0) { + m_levels.push_back( + std::make_shared>(0)); + } + + ShardType *buffer_shard = new ShardType(std::move(buffer)); + if (task.type == ReconstructionType::Append || m_levels[0]->get_shard_count() == 0) { + m_levels[0]->append(std::shared_ptr(buffer_shard)); } else { - std::vector shards; - for (size_t i = 0; i < m_levels[0].size(); i++) { + std::vector shards; + for (level_index i = 0; i < (level_index)m_levels[0]->get_shard_count(); + i++) { if (m_levels[0]->get_shard(i)) { shards.push_back(m_levels[0]->get_shard(i)); } @@ -210,7 +219,7 @@ public: shards.push_back(buffer_shard); ShardType *new_shard = new ShardType(shards); m_levels[0]->truncate(); - m_levels[0]->append(std::shared_ptr(new_shard)); + m_levels[0]->append(std::shared_ptr(new_shard)); } } } @@ -243,6 +252,32 @@ public: LevelVector const &get_level_vector() const { return m_levels; } + + /* + * Validate that no level in the structure exceeds its maximum tombstone + * capacity. This is used to trigger preemptive compactions at the end of + * the reconstruction process. + */ + bool validate_tombstone_proportion(double max_delete_prop) const { + long double ts_prop; + for (size_t i = 0; i < m_levels.size(); i++) { + if (m_levels[i]) { + ts_prop = (long double)m_levels[i]->get_tombstone_count() / + (long double)m_levels[i]->get_record_count(); + if (ts_prop > (long double)max_delete_prop) { + return false; + } + } + } + + return true; + } + + bool validate_tombstone_proportion(level_index level, double max_delete_prop) const { + long double ts_prop = (long double) m_levels[level]->get_tombstone_count() / (long double) m_levels[level]->get_record_count(); + return ts_prop <= (long double) max_delete_prop; + } + private: std::atomic m_refcnt; LevelVector m_levels; -- cgit v1.2.3