Skip to content

Add async save path, pinned-pool coalescing, and Python bindings for KVortexEngine#1

Open
fantasy520 wants to merge 1 commit into
mainfrom
codex/analyze-this-codebase
Open

Add async save path, pinned-pool coalescing, and Python bindings for KVortexEngine#1
fantasy520 wants to merge 1 commit into
mainfrom
codex/analyze-this-codebase

Conversation

@fantasy520
Copy link
Copy Markdown
Owner

Motivation

  • Expose a safe Python API for KVortex and make block/hasher conversions convenient for bindings using pybind11.
  • Add asynchronous save support to avoid blocking callers and provide handles to wait on background saves via save_blocks_async/wait.
  • Improve PinnedHostPool free-list handling by supporting coalescing to avoid fragmentation regressions.

Description

  • Added Python bindings in bindings.cpp to expose KVortexConfig, CacheStats, KVortexEngine, and BlockHasher, including helpers to convert BlockID to/from py::bytes and map KVortexError to std::runtime_error exceptions, and provided alias attributes Config and Stats for backwards compatibility.
  • Implemented a real async save mechanism in KVortexEngine (include/kvortex/api/kvortex.hpp and src/api/kvortex.cpp) with AsyncSaveTask, an async worker thread (async_worker_loop), queuing (async_queue_), result tracking (async_results_), save_blocks_async that copies payloads into task buffers, and a blocking wait that returns errors from background work; the worker is started in create and joined on shutdown.
  • Disabled move semantics for KVortexEngine by deleting the move ctor/assignment to avoid thread/ownership issues introduced by the background worker thread.
  • Implemented PinnedHostPool improvements in include/kvortex/memory/pool.hpp and src/memory/pool.cpp: maintain free_blocks_by_offset_ to allow coalescing, added helper methods insert_free_block/remove_free_block, and perform coalescing on deallocate; updated allocation/deallocation logic to use the helpers.
  • Minor includes and utility helpers added (<cstring>, <mutex>, <thread>, <condition_variable>) where needed.

Testing

  • Ran the unit/integration test suite with GoogleTest targeting memory and integration scenarios: tests/test_memory.cpp (including PinnedHostPool.CoalescingRegression) and tests/test_integration.cpp (including Integration.SaveBlocksAsyncWait), and all tests passed.
  • Verified that the new Python bindings build (CI-style compilation) and the async path correctly reports background errors via wait in the added integration test.

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6f566ba1e2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

std::multimap<size_t, size_t> free_blocks_;

// Free blocks by offset (for coalescing)
std::map<size_t, size_t> free_blocks_by_offset_;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Move coalescing index when moving PinnedHostPool

The new free_blocks_by_offset_ map is now required for deallocate coalescing, but the existing move constructor/assignment in src/memory/pool.cpp still only transfer free_blocks_ and allocated_blocks_. Because moves are public on PinnedHostPool, moving a pool leaves this offset index out of sync/empty in the destination object, so adjacent free regions stop coalescing and long-running workloads can hit avoidable fragmentation and out-of-memory errors after a move.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant