Skip to content

feat: add standalone binlog-to-page correlation API#203

Merged
ringo380 merged 3 commits intomasterfrom
feat/binlog-page-correlation-api
Mar 28, 2026
Merged

feat: add standalone binlog-to-page correlation API#203
ringo380 merged 3 commits intomasterfrom
feat/binlog-page-correlation-api

Conversation

@ringo380
Copy link
Copy Markdown
Owner

Summary

  • Add correlate_events() API in new src/binlog/correlate.rs — maps binlog row events (INSERT/UPDATE/DELETE) to tablespace pages via B+Tree PK lookup
  • Refactor timeline.rs::correlate_binlog_pages() to use shared helpers (build_column_meta, convert_pk_values), eliminating ~50 lines of duplication
  • Add correlate_binlog_events() WASM export for web UI consumption

Closes #178

New API

pub fn correlate_events(
    binlog: &mut BinlogFile,
    ts: &mut Tablespace,
) -> Result<Vec<CorrelatedEvent>, IdbError>

CorrelatedEvent includes: binlog_pos, event_type (Insert/Update/Delete), database, table, page_no, space_id, page_lsn, pk_values, timestamp.

Test plan

  • Unit tests for RowEventType, convert_pk_values, build_column_meta
  • Integration test: correlate_events returns empty vec for tablespace without SDI
  • cargo clippy -- -D warnings — zero warnings
  • cargo check --target wasm32-unknown-unknown --no-default-features — WASM compiles
  • Full test suite passes

Add `correlate_events()` in new `src/binlog/correlate.rs` module that
maps binlog row events to tablespace pages via B+Tree PK lookup.
Refactor `timeline.rs` to reuse shared helpers, add WASM export.

Closes #178
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@ringo380
Copy link
Copy Markdown
Owner Author

Code review

Found 1 issue:

  1. Bare numeric event type codes (19, 30, 31, 32) used instead of named constants from src/binlog/constants.rs (CLAUDE.md says "Binlog constants in src/binlog/constants.rs match MySQL binlog_event.h names; other binlog submodules import from there (no local duplicates)")

RowEventType::from_type_code uses raw literals 30, 31, 32, and correlate_events checks type_code == 19 directly. These should import and use TABLE_MAP_EVENT, WRITE_ROWS_EVENT, UPDATE_ROWS_EVENT, DELETE_ROWS_EVENT from crate::binlog::constants.

match code {
30 => Some(RowEventType::Insert), // WRITE_ROWS_EVENT_V2
31 => Some(RowEventType::Update), // UPDATE_ROWS_EVENT_V2
32 => Some(RowEventType::Delete), // DELETE_ROWS_EVENT_V2
_ => None,
}
}
}
impl std::fmt::Display for RowEventType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
RowEventType::Insert => write!(f, "INSERT"),

let space_id = match FilHeader::parse(&page0) {
Some(h) => h.space_id,
None => return Ok(vec![]),
};

CLAUDE.md reference: https://github.com/ringo380/idb-utils/blob/420352cb081ae8f04e75424f90e73da968bc1adf/CLAUDE.md#L167

- Replace bare numeric event type codes (19, 30, 31, 32) with named
  constants from binlog/constants.rs (TABLE_MAP_EVENT, WRITE_ROWS_EVENT,
  UPDATE_ROWS_EVENT, DELETE_ROWS_EVENT)
- Fix build_column_meta to match PK columns by name against DDL-ordered
  column names instead of assuming PK columns are first in TABLE_MAP
  order (TABLE_MAP uses DDL order, not InnoDB's PK-first physical order)
- Add extract_ddl_column_names helper to read DDL-ordered column names
  from tablespace SDI metadata
- Use public re-export path in WASM binding
@ringo380 ringo380 force-pushed the feat/binlog-page-correlation-api branch from e9e479d to b6acfb5 Compare March 28, 2026 21:06
@ringo380 ringo380 merged commit fbbe618 into master Mar 28, 2026
8 of 15 checks passed
@ringo380 ringo380 deleted the feat/binlog-page-correlation-api branch March 28, 2026 21:08
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.

Map binlog row events to specific tablespace pages — which SQL changed which pages

1 participant