Skip to content

Reclaim idle server RPC buffers under memory pressure - #19333

Merged
jt2594838 merged 4 commits into
apache:masterfrom
Caideyipi:fix/rpc-idle-buffer-reclaim
Nov 26, 2026
Merged

jt2594838 merged 4 commits into
apache:masterfrom
Caideyipi:fix/rpc-idle-buffer-reclaim

Conversation

@Caideyipi

Copy link
Copy Markdown
Collaborator

Summary

Reclaim oversized reusable RPC buffers on idle synchronous server connections when a new allocation is denied by the configured RPC buffer memory limit. Connections with active requests remain protected, and the input/output transports for one socket share activity state.

For example, after connection A completes a large request and becomes idle, connection B can reclaim A's excess reusable capacity under memory pressure; A remains usable for later requests.

Validation

  • mvn spotless:apply -P with-integration-tests -pl iotdb-client/service-rpc,iotdb-core/node-commons -am
  • mvn clean test -pl iotdb-client/service-rpc,iotdb-core/node-commons -am -Dtest=AutoResizingBufferTest,TCompressedElasticFramedTransportTest,ThriftServerBufferReclamationTest -Dsurefire.failIfNoSpecifiedTests=false (38 tests passed)
  • The existing three-node failover scenario was not rerun.

@Caideyipi
Caideyipi marked this pull request as draft November 20, 2026 08:49
@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Review summary (initial self-review): No confirmed issues found in the reviewed working-tree diff against base 60972db. No fixes were needed during review. git diff --check passed; tests were not run. Final local commit and confirmed PR head: 49d6b62. A fresh independent review of this published head remains pending before the PR can return to open.

@Caideyipi
Caideyipi marked this pull request as ready for review November 20, 2026 08:57
Comment on lines +197 to +205
private static long reclaimOneIdleConnection(ServerBufferPool pool) {
if (!reclaimingServerBuffers.compareAndSet(false, true)) {
return 0;
}
try {
List<ServerConnectionCandidate> candidates = new ArrayList<>();
pool.collectCandidates(candidates, System.nanoTime());
candidates.sort(ServerConnectionCandidate.RECLAMATION_ORDER);
for (ServerConnectionCandidate candidate : candidates) {

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.

Reclaiming one connection seems to collect all candidates.
Is it possible that reclaiming n connections becomes n^2?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes. Repeated calls previously rebuilt and sorted the full candidate list, so reclaiming N idle connections could require O(N^2 log N) total work. For a stable candidate set, the pool now sorts once and advances a cached cursor; connection registration/removal, request-state changes, and other buffer reclamation invalidate the snapshot as needed. The added regression test covers snapshot refresh after connection changes. The focused service-rpc test run passed (38 tests).

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Review summary (comment handling): Addressed the performance concern: repeated one-connection calls previously recollected and sorted all candidates, which could take O(N^2 log N) across N stable idle connections. Per-pool snapshots now retain the ordered candidates and advance a cursor; connection/request changes or other buffer reclamation invalidate the snapshot. Added regression coverage for snapshot refresh after connection changes. Verification: mvn spotless:apply -P with-integration-tests -pl iotdb-client/service-rpc -am and the focused clean test run succeeded (38 tests); git diff --check passed. Reviewed source head: 49d6b62be883d46fac81d568a016afa56fad852b. Final local SHA: 968a2af3bc80981f4c543bfd0231150ff9e22e16. Confirmed remote PR head: 968a2af3bc80981f4c543bfd0231150ff9e22e16. The PR remains open and the discussion remains unresolved; a fresh independent review of the final head is pending.

@jt2594838 jt2594838 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.

The current implementation invalidate the snapshot after each reclaimation.

If there are n reclaimations, the total cost will still be very high.

We does not need all candidates for a reclaimation. Maybe we can remove the candidate from the candidates after reclaimation, reuse the candidates if possible, and update it when we have exhausted them?

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Review summary (comment handling)

Thanks for pointing out that rebuilding the candidate list after each reclamation could make repeated reclamation expensive. The allocation-pressure paths now advance and reuse ordered candidate snapshots for both the preferred pool and other pools; snapshots are invalidated when the candidate set changes, not merely because a candidate was reclaimed. The existing pool-priority ordering is preserved.

Added regression coverage verifies snapshot reuse across repeated reclamations in both paths.

Verification:

  • mvn spotless:apply -P with-integration-tests -pl iotdb-client/service-rpc,iotdb-core/node-commons -am (exit code 0)
  • mvn clean test -P with-integration-tests -pl iotdb-client/service-rpc,iotdb-core/node-commons -am -Dtest=AutoResizingBufferTest,TCompressedElasticFramedTransportTest,ThriftServerBufferReclamationTest -Dsurefire.failIfNoSpecifiedTests=false (51 tests passed)
  • git diff --check passed.

Reviewed source head: 968a2af3bc80981f4c543bfd0231150ff9e22e16.
Final local SHA: 7d1140c969d3dfef630d38c699973827c7113d1c.
Confirmed PR head: 7d1140c969d3dfef630d38c699973827c7113d1c.

The PR remains open and this discussion remains unresolved. A fresh independent review of the updated head is pending.

@jt2594838
jt2594838 merged commit cfa607e into apache:master Nov 26, 2026
38 of 39 checks passed
@jt2594838
jt2594838 deleted the fix/rpc-idle-buffer-reclaim branch November 26, 2026 06:06
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.

2 participants