Skip to content

Pipe: Reject async loads when target disk is low - #19534

Open
Caideyipi wants to merge 3 commits into
apache:masterfrom
Caideyipi:pipe-async-load-disk-threshold
Open

Caideyipi wants to merge 3 commits into
apache:masterfrom
Caideyipi:pipe-async-load-disk-threshold

Conversation

@Caideyipi

Copy link
Copy Markdown
Collaborator

Summary

  • Apply a five-percentage-point safety margin above disk_space_warning_threshold to Pipe async loads.
  • Check the selected target disk and reject before transfer with DISK_SPACE_INSUFFICIENT, leaving source files intact for retry.

Example

With the default disk_space_warning_threshold = 0.05 (5% free), the kernel cutoff is 5% free. The async-load guard rejects a selected disk at or below 10% free (for example, 8%) and accepts one with 20% free.

Tests

  • LoadUtilTest and IoTDBDataNodeReceiverTest (37 tests passed)

sourceFile.getAbsolutePath()));
}
}
if (JVMCommonUtils.getDiskFreeRatio(targetFilePath.getAbsolutePath())

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/storageengine/load/util/LoadUtil.java:258 — Pipe async load aborts on a low selected disk without trying other listening dirs

The margin is enforced after selection instead of during it, so the selection still accepts a dir with freeRatio in (disk_space_warning_threshold, threshold+0.05]. With the default MIN_IO_FIRST strategy, MinIOSelector.selectTargetDirectory deterministically returns the listening dir on the source's mount point (no space check at all), so every sender retry of the same seal re-selects the same low disk and loadFilesToActiveDir throws again, even when another configured load_active_listening_dirs entry has ample space. The pipe async load then stalls indefinitely while the node is not read-only, and each retry forces a full TsFile re-transfer.

Fix: Make the disk selector margin-aware (e.g., extend the hasSpace predicate used by SequenceStrategy/MinIOSelector with the 0.05 margin, or loop over the configured listening dirs and skip those below the margin) so a low dir is not selected/thrown on while a healthier dir exists.

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.

Implemented in commit c8d73be5800. Async disk selection now applies the warning threshold plus the safety margin before choosing a target. When the source-mount directory is below that limit, the selector tries the configured listening directories and uses a healthy one instead. LoadUtilTest.testPipeAsyncLoadUsesSelectedDiskThresholdAcrossMultipleDisks covers this fallback.

if (!LoadUtil.loadFilesToActiveDir(loadAttributes, absolutePaths, true)) {
throw new PipeException(DataNodePipeMessages.LOAD_ACTIVE_LISTENING_PIPE_DIR_IS_NOT);
}
} catch (final DiskSpaceInsufficientException e) {

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.

minor iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/thrift/IoTDBDataNodeReceiver.java:919 — New DISK_SPACE_INSUFFICIENT mapping in loadTsFileAsync is untested

The added catch that converts DiskSpaceInsufficientException into RpcUtils.getStatus(e.getErrorCode(), e.getMessage()) has no test: IoTDBDataNodeReceiverTest contains no DISK_SPACE_INSUFFICIENT/DiskSpaceInsufficient assertion and no test stubs LoadUtil.loadFilesToActiveDir to throw. A regression here (wrong status code, unmarked retryable task, or lost staging file) would pass CI, since the retry/keep-files behaviour depends on the returned code being in StatusUtils.NEED_RETRY.

Fix: Add a test that stubs LoadUtil.loadFilesToActiveDir to throw DiskSpaceInsufficientException and asserts the seal response code is TSStatusCode.DISK_SPACE_INSUFFICIENT and that the retryable task keeps its staged files.

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.

Implemented in commit c8d73be5800. Added a receiver regression test that drives a V2 seal request while stubbing LoadUtil.loadFilesToActiveDir to throw DiskSpaceInsufficientException. It asserts the response code, retry classification, paused task state, and retained staged file. Both targeted test classes pass (14 tests total).

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Review-comment updates for PR #19534

Findings: the async-load disk margin was checked only after directory selection, and the insufficient-space status mapping lacked receiver retry/staging coverage. The selector now skips low-space candidates and falls back to a healthy configured listening directory. Added receiver seal coverage for DISK_SPACE_INSUFFICIENT, retry classification, paused task state, and staging-file retention.

Verification: mvn spotless:apply -P with-integration-tests -pl iotdb-core/datanode; targeted LoadUtilTest and IoTDBDataNodeReceiverDiskSpaceTest passed (14 tests, 0 failures).

Reviewed PR head: e76d1f961642ec3ffed484637219b831accde3b4
Final local SHA: c8d73be580012448f49497b1f728f98fba4dbd6e
Confirmed remote PR head: c8d73be580012448f49497b1f728f98fba4dbd6e

return new File(finalFolderManager.getNextFolder());
}
for (int i = 0; i < dirs.length; i++) {
final String folder = finalFolderManager.getNextFolder();

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.

minor iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/util/LoadUtil.java:507 — Margin scan samples a shared unsynchronized folder cursor, so a healthy listening dir can be skipped

The new selection loop probes candidates through finalFolderManager.getNextFolder(), i.e. SequenceStrategy.nextFolderIndex()'s plain (non-volatile, unsynchronized) currentIndex read-modify-write on a FolderManager instance shared by all callers of the static loadDiskSelector (multiple IoTDBDataNodeReceiver instances via loadTsFileAsync, plus loadTsFilesToActiveDir from query threads). A concurrent nextFolderIndex() between two iterations makes the loop read one folder twice and never sample another, so the dirs.length iterations are not distinct and a dir above the margin can be missed: DiskSpaceInsufficientException is thrown although a healthy listening dir exists, costing a full TsFile re-transfer per retry.

Fix: Iterate the captured dirs array directly (skipping unavailable folders) instead of sampling the shared round-robin cursor, or synchronize the scan on the FolderManager.

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.

Fixed in 60bcd129795. The margin-aware scan now iterates the captured dirs array directly and uses an independent atomic round-robin index for its starting point. Concurrent calls no longer share the mutable FolderManager cursor during a candidate scan, so each invocation checks every configured directory once.


try {
Assert.assertTrue(
LoadUtil.loadFilesToActiveDir(

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.

minor iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/load/util/LoadUtilTest.java:178 — No test covers the rejection branch when every listening dir is below the margin

testPipeAsyncLoadUsesSelectedDiskThresholdAcrossMultipleDisks is the only test that drives the real selector with a margin, and it only stubs one healthy plus one low dir and asserts success (LoadUtil.java:506-511). Nothing asserts the throw new DiskSpaceInsufficientException(Arrays.asList(dirs)) fallback nor the post-selection guard at LoadUtil.java:262, and the receiver test stubs LoadUtil.loadFilesToActiveDir wholesale. Flipping the > comparison or dropping either guard keeps CI green while the feature stops rejecting low disks.

Fix: Add a case where every configured listening dir returns a free ratio <= warningThreshold+0.05 and assert DiskSpaceInsufficientException is thrown and the source TsFile still exists in the receiver dir.

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.

Added testPipeAsyncLoadRejectsWhenAllListeningDisksAreBelowThreshold. It sets one directory exactly at the warning threshold plus the safety margin and a second below it; the test verifies DiskSpaceInsufficientException and confirms the source TsFile remains. LoadUtilTest passes (14 tests).

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Review-comment update for PR #19534

Findings: Fixed the shared-cursor race in threshold-aware disk selection and added rejection-path coverage for the all-low-space case.

Changes: The scan now checks each configured directory using a separate atomic round-robin starting index, so concurrent use of the shared FolderManager cursor cannot skip candidates. Added testPipeAsyncLoadRejectsWhenAllListeningDisksAreBelowThreshold, which verifies rejection at/below the threshold and preserves the source TsFile.

Verification: mvn spotless:apply -P with-integration-tests -pl iotdb-core/datanode passed. Targeted LoadUtilTest passed (14 tests, 0 failures).

Reviewed PR head: c8d73be580012448f49497b1f728f98fba4dbd6e
Final local SHA: 60bcd129795524c8d777b955a91703bd18e050d9
Confirmed remote PR head: 60bcd129795524c8d777b955a91703bd18e050d9

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