From 55e860c337fc5f04145688969392f06de237787a Mon Sep 17 00:00:00 2001 From: Wojtek Date: Fri, 21 Nov 2025 21:42:33 +0100 Subject: [PATCH] suppress CacheException from destructors --- src/dbzero/core/memory/CacheRecycler.cpp | 6 +++--- src/dbzero/core/memory/config.hpp | 7 ++++--- src/dbzero/object_model/index/Index.cpp | 8 ++++++-- src/dbzero/object_model/tags/TagIndex.cpp | 2 +- src/dbzero/workspace/Fixture.cpp | 12 ++++++------ 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/dbzero/core/memory/CacheRecycler.cpp b/src/dbzero/core/memory/CacheRecycler.cpp index 4b21ebc7..1b845593 100644 --- a/src/dbzero/core/memory/CacheRecycler.cpp +++ b/src/dbzero/core/memory/CacheRecycler.cpp @@ -133,9 +133,9 @@ namespace db0 updateSize(lock, m_capacity - flush_size); flushed = true; flush_result = m_current_size[priority] <= (m_capacity - flush_size); - if(getCurrentSize() >= m_capacity && !m_suppress_dist_overflow_error){ - THROWF(db0::CacheException) << "DIST Memory Overflow. Too many Python objects" << THROWF_END; - } + if (getCurrentSize() >= m_capacity && !m_suppress_dist_overflow_error) { + THROWF(db0::CacheException) << "DIST Memory Overflow. Too many Python objects"; + } } // resize is a costly operation but cannot be avoided if the number of locked // resources exceeds the assumed limit diff --git a/src/dbzero/core/memory/config.hpp b/src/dbzero/core/memory/config.hpp index 39182fa4..7f33a8eb 100644 --- a/src/dbzero/core/memory/config.hpp +++ b/src/dbzero/core/memory/config.hpp @@ -15,12 +15,13 @@ namespace db0 // Currently we use uint32_t as the state number which allows enumerating 4B sequential transactions // assuming 1s per transaction that gives us 136 years of continuous operation until the state number wraps using StateNumType = std::uint32_t; - - struct Settings + + class Settings { + public: #ifndef NDEBUG static bool __dbg_logs; #endif }; - + } diff --git a/src/dbzero/object_model/index/Index.cpp b/src/dbzero/object_model/index/Index.cpp index 2dd16bbd..de4ae54f 100644 --- a/src/dbzero/object_model/index/Index.cpp +++ b/src/dbzero/object_model/index/Index.cpp @@ -72,8 +72,12 @@ namespace db0::object_model // after unregister object might still have unflushed data, we need to flush them if (hasInstance() && isDirty()) { - _flush(); - } + try { + _flush(); + } catch (CacheException &) { + // suppress cache exception, other exceptions will terminate + } + } } Index::Builder::Builder(Index &index) diff --git a/src/dbzero/object_model/tags/TagIndex.cpp b/src/dbzero/object_model/tags/TagIndex.cpp index be8a6191..2b5627a9 100644 --- a/src/dbzero/object_model/tags/TagIndex.cpp +++ b/src/dbzero/object_model/tags/TagIndex.cpp @@ -164,7 +164,7 @@ namespace db0::object_model m_batch_op_types.empty() && "TagIndex::flush() or close() must be called before destruction"); } - + void TagIndex::addTags(ObjectPtr memo_ptr, ObjectPtr const *args, std::size_t nargs) { using TypeId = db0::bindings::TypeId; diff --git a/src/dbzero/workspace/Fixture.cpp b/src/dbzero/workspace/Fixture.cpp index 1214ae27..2f28beb5 100644 --- a/src/dbzero/workspace/Fixture.cpp +++ b/src/dbzero/workspace/Fixture.cpp @@ -182,6 +182,12 @@ namespace db0 timer = std::make_unique("Fixture::close", timer_ptr); } + // flush to prepare objects which require it (e.g. Index) for commit + // NOTE: flush must NOT lock the fixture's shared mutex + if (m_gc0_ptr) { + getGC0().flushAllOf(Memspace::getForFlush()); + } + // clear cache to destroy object instances supported by the cache // this has to be done before commit (to not commit unrefereced objects) m_lang_cache.clear(true, as_defunct); @@ -191,12 +197,6 @@ namespace db0 // prevents commit on a closed fixture std::unique_lock lock(m_close_mutex); if (!Memspace::isClosed()) { - // flush to prepare objects which require it (e.g. Index) for commit - // NOTE: flush must NOT lock the fixture's shared mutex - if (m_gc0_ptr) { - getGC0().flushAllOf(Memspace::getForFlush()); - } - // clear lang cache again since flush might've released some Python instances m_lang_cache.clear(true);