Skip to content

feat(#106): integrate BlockState machine into PersistMemoryManager#107

Merged
netkeep80 merged 4 commits intonetkeep80:mainfrom
konard:issue-106-c1784c062b06
Mar 7, 2026
Merged

feat(#106): integrate BlockState machine into PersistMemoryManager#107
netkeep80 merged 4 commits intonetkeep80:mainfrom
konard:issue-106-c1784c062b06

Conversation

@konard
Copy link
Copy Markdown
Contributor

@konard konard commented Mar 7, 2026

Summary

Fixes #106: Integration of BlockState Machine and full migration to its use in PersistMemoryManager.

What changed

  • allocator_policy.h (v0.3): Complete rewrite using BlockState machine transitions from block_state.h instead of direct field assignments to BlockHeader:

    • allocate_from_block(): FreeBlock → remove_from_avl → FreeBlockRemovedAVL → [split] SplittingBlock/finalize_split or mark_as_allocated → AllocatedBlock
    • coalesce(): FreeBlockNotInAVL → begin_coalescing → CoalescingBlock → coalesce_with_next/prev → finalize_coalesce → FreeBlock
    • rebuild_free_tree(): calls recover_block_state<A>() per block (Issue интеграция BlockState Machine и полный переход на её использование в PersistMemoryManager #106 requirement)
    • recompute_counters() / repair_linked_list(): use Block<A> field names (weight instead of size)
    • Signature changed: allocate_from_block(base, hdr, uint32_t blk_idx, user_size) and coalesce(base, hdr, uint32_t blk_idx) now accept granule index instead of BlockHeader*
  • free_block_tree.h (v1.1): Rewrite AvlFreeTree to use Block<AddressTraitsT>* (BlockT) instead of BlockHeader*, updating all AVL field accesses to Block<A> byte positions (next_offset at byte 4, left_offset at byte 8, etc.)

  • types.h (v2.1): Added Block<A>* utilities:

    • block_at_block(), block_idx(Block<A>*), block_total_granules(Block<A>*)
    • is_valid_block(): uses weight (byte 24) instead of size (byte 0)
    • header_from_ptr(): returns Block<A>*, checks weight == 0
    • user_ptr(Block<A>*) overload
  • abstract_pmm.h (v0.4): Updated to new API:

    • allocate(): passes idx (uint32_t) to allocate_from_block instead of BlockHeader*
    • deallocate(): uses AllocatedBlock::mark_as_free() state transition
    • init_layout(), do_expand(): use Block<A> fields throughout (no more BlockHeader* direct access)
  • tests/test_issue106_block_state_integration.cpp (new): 10 integration test suites verifying state machine transitions in full PMM lifecycle (weight field, allocate/deallocate transitions, coalescing, recover_block_state, detect_block_state, split path)

  • docs/atomic_writes.md: Updated to reflect Block<A> layout (weight field), BlockState machine API in state transition diagrams

Binary layout change

The internal block format changed from BlockHeader (size at byte 0) to Block<A> (weight at byte 24). Both are 32 bytes. This is not backward-compatible with existing PMM images created with older versions.

Acceptance criteria

  • ✅ No direct assignments to size and root_offset fields in allocator_policy.h (uses state machine methods)
  • ✅ All 28 existing tests pass
  • ✅ New integration tests added: test_issue106_block_state_integration (10 test suites)

Test plan

  • Build with no warnings
  • 28 original tests pass
  • 1 new test (test_issue106_block_state_integration) passes with 10 test suites:

🤖 Generated with Claude Code

konard and others added 2 commits March 7, 2026 21:58
Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: netkeep80#106
…anager

Migrate all allocator internals from legacy BlockHeader layout to Block<A>
(LinkedListNode<A> + TreeNode<A>) layout, and use BlockState machine
methods from block_state.h throughout:

- allocator_policy.h: Complete rewrite using state machine transitions:
  * allocate_from_block: FreeBlock → remove_from_avl → FreeBlockRemovedAVL
    → begin_splitting/finalize_split or mark_as_allocated → AllocatedBlock
  * coalesce: FreeBlockNotInAVL → begin_coalescing → CoalescingBlock
    → coalesce_with_next/coalesce_with_prev → finalize_coalesce → FreeBlock
  * rebuild_free_tree: uses recover_block_state<A>() per block
  * recompute_counters/repair_linked_list: use Block<A> field names (weight)

- free_block_tree.h: Rewrite AvlFreeTree to use Block<A>* (BlockT) instead
  of BlockHeader*, updating all field accesses to Block<A> byte positions

- types.h: Add Block<A>* utilities alongside legacy BlockHeader* ones:
  * block_at_block(), block_idx(Block<A>*), block_total_granules(Block<A>*)
  * is_valid_block(): use weight (byte 24) instead of size (byte 0)
  * header_from_ptr(): returns Block<A>*, checks weight == 0
  * user_ptr(Block<A>*) overload

- abstract_pmm.h: Update to new API:
  * allocate(): pass idx (uint32_t) to allocate_from_block instead of BlockHeader*
  * deallocate(): use AllocatedBlock::mark_as_free() state transition
  * init_layout(), do_expand(): use Block<A> fields throughout
  * Add #include block.h and block_state.h

- tests/test_issue106_block_state_integration.cpp: New integration test
  verifying state machine transitions in full PMM lifecycle (10 test suites)

- docs/atomic_writes.md: Update to reflect Block<A> layout, weight field,
  and BlockState machine API in state transition diagrams

All 29 tests pass (28 original + 1 new).

Acceptance criteria met:
- No direct assignments to legacy size/root_offset fields in allocator_policy.h
- All existing tests pass
- New state machine integration tests added

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard changed the title [WIP] интеграция BlockState Machine и полный переход на её использование в PersistMemoryManager feat(#106): integrate BlockState machine into PersistMemoryManager Mar 7, 2026
@konard konard marked this pull request as ready for review March 7, 2026 22:23
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 7, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $6.689186
  • Calculated by Anthropic: $5.302331 USD
  • Difference: $-1.386855 (-20.73%)
    📎 Log file uploaded as Gist (3851KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 7, 2026

🔄 Auto-restart triggered (attempt 1)

Reason: CI failures detected

Starting new session to address the issues.


Auto-restart-until-mergeable mode is active. Will continue until PR becomes mergeable.

Fix clang-format violations in files added as part of issue netkeep80#106
implementation. The CI clang-format check was failing due to misaligned
consecutive declarations and assignments in include/pmm/*.h and
tests/test_issue106_block_state_integration.cpp.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 7, 2026

🔄 Auto-restart-until-mergeable Log (iteration 1)

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $1.339556
  • Calculated by Anthropic: $1.237382 USD
  • Difference: $-0.102174 (-7.63%)
    📎 Log file uploaded as Gist (5287KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 7, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@netkeep80 netkeep80 merged commit dfe68bf into netkeep80:main Mar 7, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

интеграция BlockState Machine и полный переход на её использование в PersistMemoryManager

2 participants