Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.rpc;

import java.io.IOException;

public final class AutoResizingBufferMemoryAllocationException extends IOException {

public AutoResizingBufferMemoryAllocationException(final String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private static void allocate(AutoResizingBufferMemoryControl memoryControl, long
}
}
memoryAllocationFailureCount.incrementAndGet();
throw new IOException(
throw new AutoResizingBufferMemoryAllocationException(
String.format(
RpcMessages.AUTO_RESIZING_BUFFER_ALLOCATE_FAILED,
sizeInBytes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public void testThrowIOExceptionWhenMemoryIsInsufficient() throws Exception {
try {
buffer.resizeIfNecessary(200);
Assert.fail("Expected IOException");
} catch (IOException e) {
} catch (AutoResizingBufferMemoryAllocationException e) {
Assert.assertTrue(e.getMessage().contains("100"));
Assert.assertTrue(e.getMessage().contains("5"));
} finally {
Expand All @@ -545,6 +545,30 @@ public void testThrowIOExceptionWhenMemoryIsInsufficient() throws Exception {
}
}

@Test
public void testInterruptedMemoryAllocationRemainsRegularIOException() {
memoryControl.setLimit(0);
AutoResizingBufferMemoryManager.setMemoryControl(memoryControl);
AutoResizingBufferMemoryManager.setMemoryAllocateRetryIntervalInMs(1);
final boolean wasInterrupted = Thread.interrupted();

try {
Thread.currentThread().interrupt();
new AutoResizingBuffer(100);
Assert.fail("Expected allocation interruption");
} catch (IOException e) {
Assert.assertFalse(e instanceof AutoResizingBufferMemoryAllocationException);
Assert.assertTrue(e.getCause() instanceof InterruptedException);
Assert.assertTrue(Thread.currentThread().isInterrupted());
} finally {
if (wasInterrupted) {
Thread.currentThread().interrupt();
} else {
Thread.interrupted();
}
}
}

@Test
public void testMemoryAllocationMetrics() throws Exception {
memoryControl.setLimit(120);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.iotdb.commons.exception.pipe.PipeRuntimeException;
import org.apache.iotdb.commons.exception.pipe.PipeRuntimeSinkCriticalException;
import org.apache.iotdb.commons.exception.pipe.PipeRuntimeSinkNonReportTimeConfigurableException;
import org.apache.iotdb.commons.exception.pipe.PipeRuntimeSinkResourceException;
import org.apache.iotdb.commons.pipe.agent.task.connection.UnboundedBlockingPendingQueue;
import org.apache.iotdb.commons.pipe.agent.task.progress.CommitterKey;
import org.apache.iotdb.commons.pipe.event.EnrichedEvent;
Expand All @@ -41,10 +42,13 @@
import org.apache.iotdb.pipe.api.exception.PipeException;

import com.google.common.util.concurrent.Uninterruptibles;
import org.apache.thrift.transport.TTransportException;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

import java.io.IOException;
import java.net.SocketException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -594,10 +598,125 @@ public void testClientBorrowFailureRetriesLocallyWithoutReportingCriticalExcepti
}
}

@Test
public void testBrokenPipeFromReceiverResourcePressureDoesNotReportCriticalException() {
final long originalSleepIntervalInitMs =
CommonDescriptor.getInstance().getConfig().getPipeSinkSubtaskSleepIntervalInitMs();
final long originalSleepIntervalMaxMs =
CommonDescriptor.getInstance().getConfig().getPipeSinkSubtaskSleepIntervalMaxMs();
CommonDescriptor.getInstance().getConfig().setPipeSinkSubtaskSleepIntervalInitMs(1);
CommonDescriptor.getInstance().getConfig().setPipeSinkSubtaskSleepIntervalMaxMs(2);

final PipeConnector connector = mock(PipeConnector.class);
final UnboundedBlockingPendingQueue<Event> pendingQueue =
mock(UnboundedBlockingPendingQueue.class);
final CapturingPipeSinkSubtask subtask = new CapturingPipeSinkSubtask(pendingQueue, connector);

try {
subtask.handleExceptionForTest(
mock(EnrichedEvent.class),
new PipeException("transfer failed", new IOException("Broken pipe")));

Assert.assertEquals(
PipeResourceFailureType.NETWORK_TIMEOUT, subtask.getReportedResourceFailureType());
Assert.assertNull(subtask.getReportedException());
} finally {
subtask.close();
CommonDescriptor.getInstance()
.getConfig()
.setPipeSinkSubtaskSleepIntervalInitMs(originalSleepIntervalInitMs);
CommonDescriptor.getInstance()
.getConfig()
.setPipeSinkSubtaskSleepIntervalMaxMs(originalSleepIntervalMaxMs);
}
}

@Test
public void testConnectionResetRetriesLocallyWhenConnectionRetryIsDisabled() throws Exception {
final long originalSleepIntervalInitMs =
CommonDescriptor.getInstance().getConfig().getPipeSinkSubtaskSleepIntervalInitMs();
final long originalSleepIntervalMaxMs =
CommonDescriptor.getInstance().getConfig().getPipeSinkSubtaskSleepIntervalMaxMs();
final boolean originalRetryLocallyForConnectionError =
CommonDescriptor.getInstance().getConfig().isPipeSinkRetryLocallyForConnectionError();
CommonDescriptor.getInstance().getConfig().setPipeSinkSubtaskSleepIntervalInitMs(1);
CommonDescriptor.getInstance().getConfig().setPipeSinkSubtaskSleepIntervalMaxMs(2);
CommonDescriptor.getInstance().getConfig().setPipeSinkRetryLocallyForConnectionError(false);

final PipeConnector connector = mock(PipeConnector.class);
doThrow(new IOException("handshake failed")).when(connector).handshake();
final UnboundedBlockingPendingQueue<Event> pendingQueue =
mock(UnboundedBlockingPendingQueue.class);
final CapturingPipeSinkSubtask subtask = new CapturingPipeSinkSubtask(pendingQueue, connector);
final EnrichedEvent event = mock(EnrichedEvent.class);
subtask.prepareFailure(event);
subtask.allowSubmittingSelf();

try {
subtask.onFailure(
new PipeConnectionException(
"transfer failed", new TTransportException(new SocketException("Connection reset"))));

Assert.assertEquals(
PipeResourceFailureType.NETWORK_TIMEOUT, subtask.getReportedResourceFailureType());
Assert.assertNull(subtask.getReportedException());
Assert.assertEquals(1, subtask.getRetrySubmissionCount());
verify(connector, never()).handshake();
} finally {
subtask.close();
CommonDescriptor.getInstance()
.getConfig()
.setPipeSinkSubtaskSleepIntervalInitMs(originalSleepIntervalInitMs);
CommonDescriptor.getInstance()
.getConfig()
.setPipeSinkSubtaskSleepIntervalMaxMs(originalSleepIntervalMaxMs);
CommonDescriptor.getInstance()
.getConfig()
.setPipeSinkRetryLocallyForConnectionError(originalRetryLocallyForConnectionError);
}
}

@Test
public void testForcedRetryQueueResourceFailureRetriesWithoutCriticalStop() {
final long originalSleepIntervalInitMs =
CommonDescriptor.getInstance().getConfig().getPipeSinkSubtaskSleepIntervalInitMs();
final long originalSleepIntervalMaxMs =
CommonDescriptor.getInstance().getConfig().getPipeSinkSubtaskSleepIntervalMaxMs();
CommonDescriptor.getInstance().getConfig().setPipeSinkSubtaskSleepIntervalInitMs(1);
CommonDescriptor.getInstance().getConfig().setPipeSinkSubtaskSleepIntervalMaxMs(2);

final PipeConnector connector = mock(PipeConnector.class);
final UnboundedBlockingPendingQueue<Event> pendingQueue =
mock(UnboundedBlockingPendingQueue.class);
final CapturingPipeSinkSubtask subtask = new CapturingPipeSinkSubtask(pendingQueue, connector);
final EnrichedEvent event = mock(EnrichedEvent.class);
subtask.prepareFailure(event);
subtask.allowSubmittingSelf();

try {
subtask.onFailure(
new PipeRuntimeSinkResourceException(
"retry queue resource failure", PipeResourceFailureType.NETWORK_TIMEOUT, true));

Assert.assertNull(subtask.getReportedException());
Assert.assertNull(subtask.getReportedResourceFailureType());
Assert.assertEquals(1, subtask.getRetrySubmissionCount());
} finally {
subtask.close();
CommonDescriptor.getInstance()
.getConfig()
.setPipeSinkSubtaskSleepIntervalInitMs(originalSleepIntervalInitMs);
CommonDescriptor.getInstance()
.getConfig()
.setPipeSinkSubtaskSleepIntervalMaxMs(originalSleepIntervalMaxMs);
}
}

private static class CapturingPipeSinkSubtask extends PipeSinkSubtask {

private PipeRuntimeException reportedException;
private PipeResourceFailureType reportedResourceFailureType;
private int retrySubmissionCount;

private CapturingPipeSinkSubtask(
final UnboundedBlockingPendingQueue<Event> pendingQueue, final PipeConnector connector) {
Expand Down Expand Up @@ -625,10 +744,22 @@ private PipeResourceFailureType getReportedResourceFailureType() {
return reportedResourceFailureType;
}

private int getRetrySubmissionCount() {
return retrySubmissionCount;
}

private void handleExceptionForTest(final EnrichedEvent event, final Exception exception) {
handleException(event, exception);
}

@Override
public void submitSelf() {
retrySubmissionCount++;
}

@Override
protected void sleepIfNoHighPriorityTask(final long sleepMillis) {}

@Override
protected void report(final EnrichedEvent event, final PipeRuntimeException exception) {
reportedException = exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,39 @@

package org.apache.iotdb.db.pipe.sink.protocol.thrift.async;

import org.apache.iotdb.commons.conf.CommonConfig;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.exception.pipe.PipeRuntimeSinkCriticalException;
import org.apache.iotdb.commons.exception.pipe.PipeRuntimeSinkResourceException;
import org.apache.iotdb.commons.pipe.resource.PipeResourceFailureType;
import org.apache.iotdb.db.pipe.event.common.heartbeat.PipeHeartbeatEvent;
import org.apache.iotdb.db.pipe.event.common.tablet.PipeRawTabletInsertionEvent;
import org.apache.iotdb.db.pipe.event.common.tsfile.PipeTsFileInsertionEvent;
import org.apache.iotdb.pipe.api.event.Event;
import org.apache.iotdb.pipe.api.exception.PipeConnectionException;
import org.apache.iotdb.pipe.api.exception.PipeException;

import org.apache.thrift.transport.TTransportException;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

import java.io.File;
import java.io.FileNotFoundException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.SocketException;
import java.util.Map;

public class IoTDBDataRegionAsyncSinkTest {

private static class UnbatchedIoTDBDataRegionAsyncSink extends IoTDBDataRegionAsyncSink {

private UnbatchedIoTDBDataRegionAsyncSink() {
isTabletBatchModeEnabled = false;
}
}

@Test
public void testRetryQueueFailureMessageIncludesRootCauseAndIsCleared() {
final IoTDBDataRegionAsyncSink sink = new IoTDBDataRegionAsyncSink();
Expand Down Expand Up @@ -71,6 +88,78 @@ public void testRetryQueueFailureMessageKeepsRootCauseTypeWhenMessageIsMissing()
Assert.assertEquals("java.lang.NullPointerException", sink.getLastRetryFailureMessage());
}

@Test
public void testConnectionResetIsRetainedAsResourceFailureInRetryQueue() throws Exception {
final IoTDBDataRegionAsyncSink sink = new IoTDBDataRegionAsyncSink();
final Event event = Mockito.mock(Event.class);
final PipeConnectionException failure =
new PipeConnectionException(
"transfer failed", new TTransportException(new SocketException("Connection reset")));

sink.addFailureEventToRetryQueue(event, failure);

final Method getRetryQueueResourceFailureType =
IoTDBDataRegionAsyncSink.class.getDeclaredMethod("getRetryQueueResourceFailureType");
getRetryQueueResourceFailureType.setAccessible(true);
Assert.assertEquals(
PipeResourceFailureType.NETWORK_TIMEOUT, getRetryQueueResourceFailureType.invoke(sink));
sink.clearRetryEventsReferenceCount();
}

@Test
public void testForcedRetryQueueThresholdPreservesTransportResourceFailure() throws Exception {
final CommonConfig config = CommonDescriptor.getInstance().getConfig();
final int originalTabletQueueSize = config.getPipeAsyncSinkForcedRetryTabletEventQueueSize();
final int originalTsFileQueueSize = config.getPipeAsyncSinkForcedRetryTsFileEventQueueSize();
final int originalTotalQueueSize = config.getPipeAsyncSinkForcedRetryTotalEventQueueSize();
final long originalRetryExecutionTimeMs =
config.getPipeAsyncSinkMaxRetryExecutionTimeMsPerCall();
final IoTDBDataRegionAsyncSink sink = new UnbatchedIoTDBDataRegionAsyncSink();
try {
config.setPipeAsyncSinkForcedRetryTabletEventQueueSize(2);
config.setPipeAsyncSinkForcedRetryTsFileEventQueueSize(1);
config.setPipeAsyncSinkForcedRetryTotalEventQueueSize(2);
config.setPipeAsyncSinkMaxRetryExecutionTimeMsPerCall(100);

final PipeRawTabletInsertionEvent blockedEvent =
Mockito.mock(PipeRawTabletInsertionEvent.class);
Mockito.when(blockedEvent.increaseReferenceCount(Mockito.anyString()))
.thenAnswer(
invocation -> {
Thread.sleep(150);
return false;
});
sink.addFailureEventToRetryQueue(blockedEvent, null);

final PipeRawTabletInsertionEvent resourceFailureEvent =
Mockito.mock(PipeRawTabletInsertionEvent.class);
sink.addFailureEventToRetryQueue(resourceFailureEvent, null);

final Field resourceFailureTypesField =
IoTDBDataRegionAsyncSink.class.getDeclaredField("retryEvent2ResourceFailureType");
resourceFailureTypesField.setAccessible(true);
@SuppressWarnings("unchecked")
final Map<Event, PipeResourceFailureType> resourceFailureTypes =
(Map<Event, PipeResourceFailureType>) resourceFailureTypesField.get(sink);
resourceFailureTypes.put(resourceFailureEvent, PipeResourceFailureType.NETWORK_TIMEOUT);

final PipeRuntimeSinkResourceException failure =
Assert.assertThrows(
PipeRuntimeSinkResourceException.class,
() -> sink.transfer(new PipeHeartbeatEvent(-1, false)));

Assert.assertEquals(PipeResourceFailureType.NETWORK_TIMEOUT, failure.getFailureType());
Assert.assertTrue(failure.isFailureRecorded());
} finally {
sink.clearRetryEventsReferenceCount();
sink.close();
config.setPipeAsyncSinkForcedRetryTabletEventQueueSize(originalTabletQueueSize);
config.setPipeAsyncSinkForcedRetryTsFileEventQueueSize(originalTsFileQueueSize);
config.setPipeAsyncSinkForcedRetryTotalEventQueueSize(originalTotalQueueSize);
config.setPipeAsyncSinkMaxRetryExecutionTimeMsPerCall(originalRetryExecutionTimeMs);
}
}

@Test
@SuppressWarnings("unchecked")
public void testMissingTsFileRetryLimitKeepsEventQueuedAndStopsSink() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ public void onFailure(final Throwable throwable) {
}
}

if (throwable instanceof Exception && !PipeStopStrategy.accept((Exception) throwable, null)) {

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/agent/task/subtask/PipeAbstractSinkSubtask.java:110 — Resource-failure short-circuit skips handshake for connection-reset PipeConnectionException

The new block at line 110 runs before the throwable instanceof PipeConnectionException branch. A PipeConnectionException wrapping TTransportException("Connection reset"/"Broken pipe") is now classified as NETWORK_TIMEOUT, so onPipeConnectionException()/handshakeOutputPipeSink() is never called and the broken client is never re-established; the subtask only resubmits itself and keeps failing on the same dead connection. The new test testConnectionResetRetriesLocallyWhenConnectionRetryIsDisabled
…[truncated]

Fix: Evaluate the PipeConnectionException branch (handshake/reconnect) before the resource-failure short-circuit, or exclude PipeConnectionException from the new block so reconnect still happens; update the test to assert handshake is attempted.

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. Fixed in 470f3958e8d9c31b951dd012d8ba264c9880088f: onFailure now attempts the PipeConnectionException handshake/reconnect before applying the transient resource-failure retry path.

The regression test now verifies that handshake() is attempted when local connection retry is disabled.

Validation passed: mvn spotless:apply -P with-integration-tests and mvn clean test -P with-integration-tests -pl iotdb-core/datanode -am -Dtest=PipeSinkSubtaskTest -Dsurefire.failIfNoSpecifiedTests=false (14 tests, 0 failures).

final Exception exception = (Exception) throwable;
final PipeResourceFailureType failureType =
PipeStopStrategy.getResourceFailureType(exception, null);
if (lastEvent instanceof EnrichedEvent
&& !PipeStopStrategy.isResourceFailureRecorded(exception)) {
reportResourceFailure((EnrichedEvent) lastEvent, failureType);
}
super.onFailure(
new PipeRuntimeSinkNonReportTimeConfigurableException(
throwable.getMessage(), Long.MAX_VALUE));
return;
}

if (throwable instanceof PipeConnectionException) {
// Retry to connect to the target system if the connection is broken. Do not hold the subtask
// lock here because handshaking with an external sink may block for a long time, while drop
Expand Down
Loading
Loading