Skip to content

Fix ListOfABAFreeId::add() dropping new id after GC - #3776

Merged
chenBright merged 2 commits into
apache:masterfrom
aschenmaker:fix-abalist-gc-insert
Nov 26, 2026
Merged

chenBright merged 2 commits into
apache:masterfrom
aschenmaker:fix-abalist-gc-insert

Conversation

@aschenmaker

Copy link
Copy Markdown
Contributor

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 calls gc() and directly returns rc (0) without inserting the pending id into the newly compacted list. Because gc() only migrates existing live IDs, the newly added id is silently dropped even though add() reports success.

For Socket::_id_wait_list (bthread_id_list_t), this causes Socket::NotifyOnFailed() to skip both list registration and the rc != 0 fallback bthread_id_error(). If the socket subsequently fails, the omitted RPC ID will never be notified by bthread_id_list_reset2_pthreadsafe().

What is changed and the side effects?

Changed:

  • src/bthread/list_of_abafree_id.h: After gc() succeeds (rc == 0), write id into _cur_block->ids[_cur_index] and call forward_index() before returning 0. At the end of gc(), add_to_temp_list() guarantees _cur_block->ids[_cur_index] is an initialized empty slot (ID_INIT).
  • test/abalist_unittest.cc: Added AbaListTest.TestGcPreservesAddedIds, which verifies after every add() returning 0 that apply() 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:

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

Comment thread test/abalist_unittest.cc
int rc = aba_list.add(id);
if (rc != 0) {
TestIdTraits::id_set.erase(id);
continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@aschenmaker

This comment was marked as duplicate.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active issues remain, and the change addresses pending-ID loss during garbage collection with regression coverage for retention and churn scenarios.

No open issues 🎉

Review effort: Lite

@chenBright chenBright left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chenBright
chenBright merged commit e20a3e0 into apache:master Nov 26, 2026
29 checks passed
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.

ListOfABAFreeId::add() returns 0 without inserting new id when GC triggers

3 participants