Refactor: Extract ReplicationEngine to eliminate code duplication
LocalReplicator and ReplicationHandler had ~640 lines of duplicated
prepare/commit/abort logic. This refactoring:
- Extracts common replication logic into ReplicationEngine (477 lines)
- Reduces LocalReplicator from 414 → 84 lines (80% reduction)
- Reduces ReplicationHandler from 1104 → 635 lines (42% reduction)
- Adds comprehensive test coverage (775 lines, 13 tests)
Fixes included:
- DDL schema version tracking: Check for DDL before commit (transaction
removed after commit, breaking version increments on followers)
- GC race condition: Add closed checks in PebbleMetaStore cleanup methods
- Refactor monolithic Prepare() into focused private methods
- Remove broken error handling in WriteIntent (string-matching SQLite
errors when MetaStore is PebbleDB - dead code that never executed)
All tests passing. No behavioral changes to replication protocol.
???? Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <
[email protected]>