Skip to content

fix: advance trx id past commit xids when recovering MVCC transactions - #651

Open
sayanx64 wants to merge 1 commit into
oceanbase:mainfrom
sayanx64:issue_442
Open

sayanx64 wants to merge 1 commit into
oceanbase:mainfrom
sayanx64:issue_442

Conversation

@sayanx64

Copy link
Copy Markdown

What problem were solved in this pull request?

Issue Number: close #442

Problem:

MvccTrx::commit() takes its commit xid from the same counter as transaction ids (MvccTrxKit::next_trx_id()), and a committed record stores it as its begin_xid. During recovery the counter is only advanced with the trx ids in the log entry headers (MvccTrxKit::create_trx(log_handler, trx_id)); the commit_trx_id of a commit log entry is ignored.

If a transaction commits after another transaction has started, its commit xid is larger than every trx id in the log. After recovery a new transaction can get an id smaller than that commit xid, and MvccTrx::visit_record treats the committed record as invisible (trx_id_ >= begin_xid is false).

Example: trx 1 and trx 2 start, then commit with xids 3 and 4. After recovery the counter is 2, so a new transaction gets id 3 and cannot see the record committed with xid 4.

MvccTrxLog.wal_rollback_abnormal can hit this when, at the end of its concurrent run, two transactions commit after the last transaction started: one transaction's records are then invisible after recovery and the test counts 499 instead of 500, which is the failure reported in #442. It failed exactly this way on #650: https://github.com/oceanbase/miniob/actions/runs/38174840520/job/114575201900

What is changed and how it works?

  • Add MvccTrxKit::update_trx_id(), which raises the trx id counter to at least the given id.
  • When redoing a commit log entry, call it with the entry's commit_trx_id.
  • Add MvccTrxLog.wal_trx_id_after_recovery, a single-threaded test of the example above. It fails without this change (1 of 2 committed records visible) and passes with it.

Other information

  • Found while looking at the mvcc_trx_log_test failure on fix: return the constant instead of the first child when simplifying conjunctions #650.
  • Verified locally with a debug build with ASAN: the new test fails before and passes after this change. The existing concurrent MvccTrxLog tests abort on my machine (12 cores, GCC 15) with assertion / ASAN errors in the storage layer during their concurrent insert phase, both with and without this change, so I am relying on CI for them.

The commit xid of a transaction is allocated from the same counter as trx
ids, but log replay only advanced the counter with the trx ids in the log
entry headers. When a transaction commits after another transaction has
started, its commit xid is larger than every trx id in the log, so a
transaction started after recovery could get a smaller id and could not
see the records committed before the crash.

This can make MvccTrxLog.wal_rollback_abnormal count 499 visible records
instead of 500.

Fixes oceanbase#442

This branch has not been deployed

No deployments
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.

[BUG] mvcc_trx_log_test occasional failed

1 participant