Repository navigation
Pipe: Reject async loads when target disk is low #19534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Caideyipi
wants to merge
3
commits into
apache:master
Choose a base branch
from
Caideyipi:pipe-async-load-disk-threshold
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...org/apache/iotdb/db/pipe/receiver/protocol/thrift/IoTDBDataNodeReceiverDiskSpaceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.iotdb.db.pipe.receiver.protocol.thrift; | ||
|
|
||
| import org.apache.iotdb.commons.exception.DiskSpaceInsufficientException; | ||
| import org.apache.iotdb.commons.utils.StatusUtils; | ||
| import org.apache.iotdb.db.conf.IoTDBConfig; | ||
| import org.apache.iotdb.db.conf.IoTDBDescriptor; | ||
| import org.apache.iotdb.db.pipe.sink.payload.evolvable.request.PipeTransferTsFilePieceWithModReq; | ||
| import org.apache.iotdb.db.pipe.sink.payload.evolvable.request.PipeTransferTsFileSealWithModReq; | ||
| import org.apache.iotdb.db.storageengine.load.converter.PipeTsFileConversionTaskManager; | ||
| import org.apache.iotdb.db.storageengine.load.util.LoadUtil; | ||
| import org.apache.iotdb.rpc.TSStatusCode; | ||
| import org.apache.iotdb.service.rpc.thrift.TPipeTransferResp; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.TemporaryFolder; | ||
| import org.junit.runner.RunWith; | ||
| import org.powermock.api.mockito.PowerMockito; | ||
| import org.powermock.core.classloader.annotations.PowerMockIgnore; | ||
| import org.powermock.core.classloader.annotations.PrepareForTest; | ||
| import org.powermock.modules.junit4.PowerMockRunner; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
| import java.util.UUID; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.anyList; | ||
| import static org.mockito.ArgumentMatchers.anyMap; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
|
|
||
| @RunWith(PowerMockRunner.class) | ||
| @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) | ||
| @PrepareForTest(LoadUtil.class) | ||
| public class IoTDBDataNodeReceiverDiskSpaceTest { | ||
|
|
||
| @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
|
||
| @Test | ||
| public void testSealKeepsStagedFileWhenAsyncLoadHasInsufficientDiskSpace() throws Exception { | ||
| final File receiverDir = temporaryFolder.newFolder("receiver"); | ||
| final TestReceiver receiver = new TestReceiver(receiverDir); | ||
| final String fileName = "disk-space.tsfile"; | ||
| final byte[] fileContent = new byte[] {1, 2, 3}; | ||
| final String taskId = UUID.randomUUID().toString(); | ||
| final IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig(); | ||
| final boolean originalRequireUserIdentity = config.isPipeReceiverRequireUserIdentity(); | ||
| final DiskSpaceInsufficientException exception = | ||
| new DiskSpaceInsufficientException(Collections.singletonList("load-dir")); | ||
|
|
||
| config.setPipeReceiverRequireUserIdentity(false); | ||
| try { | ||
| Assert.assertEquals( | ||
| TSStatusCode.SUCCESS_STATUS.getStatusCode(), | ||
| receiver.writeFilePiece(fileName, fileContent).getStatus().getCode()); | ||
| final File stagedFile = new File(receiverDir, fileName); | ||
| final PipeTransferTsFileSealWithModReq request = | ||
| PipeTransferTsFileSealWithModReq.toTPipeTransferReq( | ||
| fileName, fileContent.length, "root.db") | ||
| .setConversionTaskInfo(taskId, false); | ||
|
|
||
| PowerMockito.mockStatic(LoadUtil.class); | ||
| PowerMockito.when(LoadUtil.loadFilesToActiveDir(anyMap(), anyList(), eq(true))) | ||
| .thenThrow(exception); | ||
|
|
||
| final TPipeTransferResp response = receiver.seal(request); | ||
|
|
||
| Assert.assertEquals( | ||
| TSStatusCode.DISK_SPACE_INSUFFICIENT.getStatusCode(), response.getStatus().getCode()); | ||
| Assert.assertTrue(StatusUtils.needRetry(response.getStatus())); | ||
| Assert.assertEquals( | ||
| PipeTsFileConversionTaskManager.State.PAUSED, | ||
| PipeTsFileConversionTaskManager.get(taskId).getState()); | ||
| Assert.assertTrue(stagedFile.isFile()); | ||
| } finally { | ||
| config.setPipeReceiverRequireUserIdentity(originalRequireUserIdentity); | ||
| PipeTsFileConversionTaskManager.markSuccess(taskId); | ||
| receiver.handleExit(); | ||
| } | ||
| } | ||
|
|
||
| private static final class TestReceiver extends IoTDBDataNodeReceiver { | ||
|
|
||
| private TestReceiver(final File receiverDir) { | ||
| receiverFileDirWithIdSuffix.set(receiverDir); | ||
| isUsingAsyncLoadTsFileStrategy.set(true); | ||
| } | ||
|
|
||
| private TPipeTransferResp writeFilePiece(final String fileName, final byte[] fileContent) | ||
| throws IOException { | ||
| return handleTransferFilePiece( | ||
| PipeTransferTsFilePieceWithModReq.toTPipeTransferReq(fileName, 0, fileContent), | ||
| false, | ||
| true); | ||
| } | ||
|
|
||
| private TPipeTransferResp seal(final PipeTransferTsFileSealWithModReq request) { | ||
| return handleTransferFileSealV2(request); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 untestedThe added catch that converts
DiskSpaceInsufficientExceptionintoRpcUtils.getStatus(e.getErrorCode(), e.getMessage())has no test:IoTDBDataNodeReceiverTestcontains noDISK_SPACE_INSUFFICIENT/DiskSpaceInsufficientassertion and no test stubsLoadUtil.loadFilesToActiveDirto 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 inStatusUtils.NEED_RETRY.Fix: Add a test that stubs
LoadUtil.loadFilesToActiveDirto throwDiskSpaceInsufficientExceptionand asserts the seal response code isTSStatusCode.DISK_SPACE_INSUFFICIENTand that the retryable task keeps its staged files.There was a problem hiding this comment.
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 stubbingLoadUtil.loadFilesToActiveDirto throwDiskSpaceInsufficientException. It asserts the response code, retry classification, paused task state, and retained staged file. Both targeted test classes pass (14 tests total).