GetUpdatesSince: Fix assert when polling an empty DB#14865
Conversation
✅ clang-tidy: No findings on changed linesCompleted in 36.8s. |
9ca6b75 to
f59cce7
Compare
TransactionLogIterator supports polling the end of the WAL e.g. db_log_iter_test.cc test TransactionLogIteratorStallAtLastRecord. To poll, we need to call Next() on an iterator that is at the end (iter->Valid() == false). However, if the iterator is created when there are no WAL files (e.g. an empty DB), the call to Next() hits an assert in NextImpl: assert(current_log_reader_); To fix this, make an iterator without files return a TryAgain status code instead. This should not affect any existing applications, since if they are doing this, they will crash. transaction_log_impl.cc: * TransactionLogIteratorImpl::NextImpl: Check for no files and return TryAgain. * db.h: GetUpdatesSince doc comment: Reference the documentation on TransactionLogIterator. * transaction_log.h: Clarify how to use TransactionLogIterator. db_log_iter_test: * OpenTransactionLogIter: Remove EXPECT_TRUE(iter->Valid()): this is not true if the database is empty. * TransactionLogIteratorPollNoWALFiles: Test polling the iterator in two cases: the database is empty, and all WAL files were purged. These previously triggered an assertion in Next().
f59cce7 to
294124c
Compare
🟡 Codex Code ReviewAuto-triggered after CI passed — reviewing commit 294124c ❌ Codex review failed before producing findings. ℹ️ About this responseGenerated by Codex CLI. Limitations:
Commands:
|
✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 294124c SummaryClean, minimal fix for a real crash (assertion failure when polling an empty-DB TransactionLogIterator). The approach is correct: returning High-severity findings (0): No high-severity findings. Full review (click to expand)Findings🔴 HIGHNone. 🟡 MEDIUMM1. Removing
|
TransactionLogIterator supports polling the end of the WAL e.g. db_log_iter_test.cc test TransactionLogIteratorStallAtLastRecord. To poll, we need to call Next() on an iterator that is at the end (iter->Valid() == false). However, if the iterator is created when there are no WAL files (e.g. an empty DB), the call to Next() hits an assert in NextImpl:
To fix this, make an iterator without files return a TryAgain status code instead. This should not affect any existing applications, since if they are doing this, they will crash.
transaction_log_impl.cc:TransactionLogIteratorImpl::NextImpl: Check for no files and return TryAgain.db.h: GetUpdatesSince doc comment: Reference the documentation on TransactionLogIterator.transaction_log.h: Clarify how to use TransactionLogIterator.db_log_iter_test: