Repository navigation
Fix ListOfABAFreeId::add() dropping new id after GC - #3776
Conversation
a64b235 to
8681b81
Compare
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported, and the change directly addresses the garbage-collection ID-retention bug with targeted regression coverage.
No open issues 🎉
What changed in this PR
Fixes ListOfABAFreeId::add() so an ID submitted during garbage collection is retained after successful compaction instead of being silently dropped.
Changes:
- Inserts the pending ID after successful
gc()and advances the insertion cursor. - Adds regression coverage for all-live and identifier-churn scenarios.
| File | Description |
|---|---|
| test/abalist_unittest.cc | Adds regression tests verifying that accepted live IDs remain discoverable through apply() after garbage collection. |
| src/bthread/list_of_abafree_id.h | Preserves the ID being added when the garbage-collection path succeeds. |
Review effort: Lite
| int rc = aba_list.add(id); | ||
| if (rc != 0) { | ||
| TestIdTraits::id_set.erase(id); | ||
| continue; |
There was a problem hiding this comment.
This skips all insertion errors. In the all-live scenario, there are only 112 slots when GC is first triggered, below the 1000 limit. If this insertion returns EAGAIN, the ID being added is removed from the expected set, and the test can still pass. Consider recording the capacity before add() and skipping the check only if it already exceeds MAX_ENTRIES before the call and the call returns EAGAIN.
There was a problem hiding this comment.
Addressed @chenBright's review comment in 25e1f9c: recorded before_cap via get_sizes() before add(), only skipping when before_cap > TestIdTraits::MAX_ENTRIES && rc == EAGAIN, and asserting rc == 0 otherwise (also asserting max_cap > INIT_GC_SIZE).
What problem does this PR solve?
Issue Number: resolve #3775
Problem Summary:
When
ListOfABAFreeId<Id, IdTraits>::add(Id id)triggers GC (_nblock * IdTraits::BLOCK_SIZE > _next_gc_size), it callsgc()and directly returnsrc(0) without inserting the pendingidinto the newly compacted list. Becausegc()only migrates existing live IDs, the newly addedidis silently dropped even thoughadd()reports success.For
Socket::_id_wait_list(bthread_id_list_t), this causesSocket::NotifyOnFailed()to skip both list registration and therc != 0fallbackbthread_id_error(). If the socket subsequently fails, the omitted RPC ID will never be notified bybthread_id_list_reset2_pthreadsafe().What is changed and the side effects?
Changed:
src/bthread/list_of_abafree_id.h: Aftergc()succeeds (rc == 0), writeidinto_cur_block->ids[_cur_index]and callforward_index()before returning0. At the end ofgc(),add_to_temp_list()guarantees_cur_block->ids[_cur_index]is an initialized empty slot (ID_INIT).test/abalist_unittest.cc: AddedAbaListTest.TestGcPreservesAddedIds, which verifies after everyadd()returning0thatapply()visits every live accepted ID (both all-live and churn scenarios).Side effects:
Performance effects: None (only one slot assignment and index advance after GC).
Breaking backward compatibility: None.
Check List: