Skip to content

Add reliable UDP air-gap transport for Pipe - #19357

Open
Caideyipi wants to merge 5 commits into
masterfrom
codex/udp-sta-origin-pr-20261122
Open

Caideyipi wants to merge 5 commits into
masterfrom
codex/udp-sta-origin-pr-20261122

Conversation

@Caideyipi

@Caideyipi Caideyipi commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add strictly unidirectional UDP Pipe transfer with bounded request slicing/reassembly, acknowledgements, retries, and receiver-side deduplication.
  • Make the receiver's maximum pending UDP slice-request count configurable (pipe_air_gap_receiver_udp_max_pending_request_count, default 32); the least-recently-used incomplete request is evicted at the limit.
  • Set the default UDP send interval to 1 ms; retain the default of 2 request copies. Copies are duplicate datagrams, not acknowledgement retries.

Example

For a strict one-way UDP connector, use:

connector.air-gap.strict-unidirectional=true
connector.air-gap.udp.packet-size-bytes=1400
connector.air-gap.udp.send-interval-ms=1
connector.air-gap.udp.request-copy-count=2

This sends two copies of each datagram at a 1 ms interval, with a configured packet limit of 1400 bytes; it does not wait for acknowledgements in strict one-way mode.

Two-host replay results

A fixed, preloaded 8,000,000-row historical dataset was replayed between two independent open-source 1C1D clusters. Each candidate used one concurrent Pipe, strict unidirectional UDP, 1400-byte packets, no external writes during measurement, and the same dataset. The reported sender byte rates and send counts are from the sender; receive counts and final SQL row counts are from the receiver.

Interval / copies / reorder limit Trials Sent / received datagrams per trial Lost datagrams Sender bytes/s Active seconds Final rows
1 ms / 2 / 32 4 210,904 / 210,904 0 in all trials 9,650,463; 9,621,506; 9,613,593; 9,611,237 28.020; 28.105; 28.128; 28.135 8,000,000 in all trials
1 ms / 1 / 32 3 105,452 / 105,437; 105,452; 105,452 15 (0.014224%) in the first repeat; 0 in the other two 9,495,524; 9,591,911; 9,633,893 14.239; 14.096; 14.035 7,983,616 (16,384 missing); 8,000,000; 8,000,000
5 ms / 1 / 32 1 105,452 / 105,452 0 1,987,473 68.028 8,000,000

The 1 ms / 2 copies / reorder 32 setting completed the initial run and three repeats with no observed datagram loss and all rows present. The 5 ms result used one copy, so it is not a copy-for-copy comparison with the recommended default. A matching 5 ms / 2-copy trial was not run.

The receiver UDP request queue capacity was 4,096 datagrams / 32 MiB, sampled once per second. It recorded 0/29 full samples in each 1 ms / 2-copy trial; the longest run of full samples was zero. Historical replay was treated as sender backlog for this workload, but the sender's shared outbound queue occupancy was not independently sampled. These results therefore do not establish behavior with a continuously full receiver request queue, and one-second samples do not prove continuous occupancy between samples.

Validation

  • PipeDescriptorTest and PipeTransferSliceReqBuilderTest: 19 tests passed, 0 failures or errors.

@Caideyipi
Caideyipi marked this pull request as draft November 23, 2026 02:06
@Caideyipi
Caideyipi marked this pull request as ready for review November 23, 2026 02:23
@Caideyipi

Copy link
Copy Markdown
Collaborator Author

CI Fix and Verification

The CI failure came from a test double intercepting only the legacy two-argument sendBytes method while production invokes the rate-limited overload. The test double now intercepts the active overload and invokes its rate-limit callback. The request-ID assertion tolerates a randomized initial ID, and strict-unidirectional cases explicitly use one request copy.

The focused sink test and Spotless check passed locally. For end-to-end verification, a temporary test-only adapter selected UDP and ran IoTDBPipeProtocolIT.testAirGapUdpConnectorUseNodeUrls against two independently started local clusters: 1 test passed, 0 failures, 0 errors, 0 skipped. The adapter was removed before publication; no integration-test changes are included in this PR.

Current local and remote head: 4da2ff5a638c5eca0ec6f6c63fadd3b1d2288f24.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.27634% with 64 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.58%. Comparing base (dd450f7) to head (a2e5c9d).
⚠️ Report is 26 commits behind head on master.

Files with missing lines Patch % Lines
...oad/thrift/common/PipeTransferSliceReqHandler.java 85.41% 21 Missing ⚠️
...iver/protocol/airgap/IoTDBAirGapReceiverAgent.java 86.31% 13 Missing ⚠️
...eceiver/protocol/thrift/IoTDBDataNodeReceiver.java 85.05% 13 Missing ⚠️
...db/commons/pipe/sink/protocol/IoTDBAirGapSink.java 90.90% 8 Missing ⚠️
.../receiver/protocol/airgap/IoTDBAirGapReceiver.java 81.08% 7 Missing ⚠️
...g/apache/iotdb/commons/pipe/config/PipeConfig.java 33.33% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #19357      +/-   ##
============================================
+ Coverage     49.44%   50.58%   +1.14%     
+ Complexity      718      129     -589     
============================================
  Files          5656     5786     +130     
  Lines        418222   426060    +7838     
  Branches      55296    56535    +1239     
============================================
+ Hits         206769   215519    +8750     
+ Misses       211453   210541     -912     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Caideyipi
Caideyipi marked this pull request as draft November 24, 2026 00:50
@Caideyipi
Caideyipi marked this pull request as ready for review November 24, 2026 01:33

ReadWriteIOUtils.write(sliceReq.sliceIndex, outputStream);
ReadWriteIOUtils.write(sliceReq.sliceCount, outputStream);
final int orderIdHighBits = (int) (orderId >>> Integer.SIZE);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

major iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/sink/payload/thrift/request/PipeTransferSliceReq.java:131 — UDP slice order id high bits collide with legacy 32-bit order id after sender restart

The high 32 bits of the UDP slice order id are appended after the legacy 32-bit order id, and getOrderId() truncates to (int) orderId. nextUdpSliceOrderId() derives the id from udpRequestIdGenerator, which is seeded randomly per sink instance, so after a sender restart a new request can share the low 32 bits with an id already in retiredUdpResults. receiveSliceWithReordering then returns the retired STALE/DROPPED result, the receiver answers SUCCESS, and the new request's slices are
…[truncated]

Fix: Key retiredUdpResults (and the pending map) on the full 64-bit order id only, or make the retired-result lookup also compare the full id; do not let a truncated 32-bit match suppress a new request.

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.

Thanks for flagging this. Both pendingUdpRequests and retiredUdpResults are keyed by the full long UDP order ID, and the UDP receiver uses getUdpOrderId() for these lookups; the legacy getOrderId() value is not used as the map key. The existing testUdpSliceOrderUsesUpperBitsAcrossSenderRestarts uses IDs with identical low 32 bits and different high 32 bits, retires one, and verifies that the restarted ID is accepted while the retired ID remains stale. I could not reproduce the described collision in the current implementation, so no code change was needed for this comment.

}
final TPipeTransferResp response =
receiveNestedRequest(req.get(), strictUnidirectional, udp);
if (udp

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

major iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/thrift/IoTDBDataNodeReceiver.java:1301 — UDP slice memory blocks leak when nested request returns TEMPORARY_UNAVAILABLE

reserveUdpSliceMemory allocates a PipeMemoryBlock per accepted slice into allocatedUdpSliceMemoryBlocks, but when the nested request returns PIPE_RECEIVER_TEMPORARY_UNAVAILABLE_EXCEPTION the code deliberately skips completeUdpRequest/clearUdpSliceMemoryBlocks (line 1301-1307) so the request can be retried. The blocks are only freed by the 15-minute expireUdpRequests sweep or handleExit, so repeated temporary-unavailable responses accumulate receiver memory for the whole timeout w
…[truncated]

Fix: Free the per-order blocks on the temporary-unavailable path (the slices are already buffered in the handler and will be re-reserved on retry), or cap the retained blocks per order id.

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.

Thanks for raising the memory-accounting concern. The receiver retains the assembled slice state so it can retry the same UDP order after TEMPORARY_UNAVAILABLE; releasing only its PipeMemoryBlocks would leave retained slice arrays unaccounted, while discarding the slices would prevent that retry. Retention is bounded by pipe_air_gap_receiver_udp_max_pending_request_count (32 by default), slice allocations are charged to the receiver memory manager, idle pending orders are evicted after pipeSinkTransferTimeoutMs (15 minutes by default), and receiver exit releases any remaining blocks. Active retries refresh the order's activity time, so its memory remains accounted while that retryable request is still active. No code change was needed for this comment.

currentDatagramRequestId != null
&& udpRequestDeduplicator != null
&& req.type != PipeRequestType.TRANSFER_SLICE.getType();
final long requestFingerprint = deduplicate ? ByteBuffer.wrap(data).getLong() : 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

major iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/airgap/IoTDBAirGapReceiver.java:192 — ACK retry of a failed UDP request is deduplicated as already completed

sendOneDatagram retries the identical datagram (same requestId, same CRC fingerprint) up to udpRequestCount times. On the receiver, handleReq returning false (e.g. a non-retryable error status) still falls through to markCompleted only on success, but a request that succeeded on the receiver while its ACK was lost is fine; conversely a request whose first attempt returned a failure status is not marked, so retry works. However for TRANSFER_SLICE the dedup is skipped entirely and for
…[truncated]

Fix: Use the full datagram (request id + checksum + payload hash) as the dedup fingerprint, or include the request id in the fingerprint so distinct requests cannot collide.

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.

Thanks for the report. The completed-request cache now stores a SHA-256 digest of the full serialized request data, rather than comparing only its first eight bytes; the request ID remains the cache key. I added regression coverage for inputs with the same first eight bytes but different trailing data. Spotless and the focused IoTDBAirGapReceiverAgentTest run passed (10 tests).

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Review round for PR #19357, reviewed head 3b193e0fa36950a0c5478b4ec9d8fcaa2191ed6f: one actionable issue was confirmed in UDP request deduplication, which compared only the first eight request bytes. The cache now compares a SHA-256 digest of the full serialized request, with regression coverage for different payloads sharing the same first eight bytes. The slice-order concern is already handled by full 64-bit keys and the existing sender-restart collision test. TEMPORARY_UNAVAILABLE slice retention remains associated with retryable buffered data; pending orders are capped at 32 by default, their slice memory is receiver-accounted, idle orders expire after the 15-minute default transfer timeout, and remaining allocations are released on eviction or receiver exit. Verification: Spotless passed and IoTDBAirGapReceiverAgentTest passed (10 tests). Final commit: 7aabab8fa7214277421df04bc767f6a0bbe3bd7c; the source branch and PR head both match this SHA. The PR remains open and all discussions remain unresolved.

IntStream.rangeClosed(1, CONNECTOR_AIR_GAP_UDP_REQUEST_COPY_COUNT_MAX_VALUE)
.mapToObj(String::valueOf)
.toArray(String[]::new);
validator

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

major iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/sink/protocol/IoTDBAirGapSink.java:283 — request-copy-count attribute is always rejected by validateAttributeValueRange

validateAttributeValueRange first calls parameters.hasAttribute(key), which only matches the exact key or KeyReducer.shallowReduce/reduce(key) (e.g. air-gap.udp.request-copy-count), never the full connector.air-gap.udp.request-copy-count / sink.air-gap.udp.request-copy-count keys. Setting the documented connector.air-gap.udp.request-copy-count=2 therefore throws PipeParameterNotValidException ("parameter should be set") and the pipe cannot be created.

Fix: Validate with parameters.hasAnyAttributes(CONNECTOR_..., SINK_...) plus an explicit value check (like the sendIntervalMs/packetSize validators), or call validateAttributeValueRange with the reduced key air-gap.udp.request-copy-count.


receiverSocket.setSoTimeout(1000);
long firstRequestId = -1L;
for (int i = 0; i < 3; i++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

major iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/sink/protocol/airgap/IoTDBDataRegionAirGapSinkTest.java:202 — Strict-unidirectional UDP slice test expects 3 datagrams but default copy count sends 6

testStrictUnidirectionalUdpSendsAllSlicesWithoutAcknowledgements sets no request-copy-count, so udpRequestCopyCount defaults to 2 and sendBytesByUdp sends copyRounds * requestCount = 6 datagrams for the 2500-byte request. The loop still reads only 3 packets and asserts firstRequestId + i, so the test fails (and leaves 3 unread datagrams).

Fix: Set SINK_AIR_GAP_UDP_REQUEST_COPY_COUNT_KEY/CONNECTOR_... to 1 in this test, or read and assert all 6 datagrams (two identical rounds).

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