This is an automated email from the ASF dual-hosted git repository.
jt2594838 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new dbbe38a6119 Retry Pipe sinks after transient resource failures (#19379)
dbbe38a6119 is described below
commit dbbe38a61197b6a680adcd803c189e2503964944
Author: Caideyipi <[email protected]>
AuthorDate: Wed Nov 25 10:53:51 2026 +0800
Retry Pipe sinks after transient resource failures (#19379)
* Retry Pipe sinks after transient resource failures
* Restore Pipe sink handshake on connection reset
---
...utoResizingBufferMemoryAllocationException.java | 29 +++++
.../iotdb/rpc/AutoResizingBufferMemoryManager.java | 2 +-
.../apache/iotdb/rpc/AutoResizingBufferTest.java | 26 ++++-
.../task/subtask/sink/PipeSinkSubtaskTest.java | 130 +++++++++++++++++++++
.../thrift/async/IoTDBDataRegionAsyncSinkTest.java | 89 ++++++++++++++
.../task/subtask/PipeAbstractSinkSubtask.java | 14 +++
.../commons/pipe/resource/PipeStopStrategy.java | 37 ++++++
.../pipe/resource/PipeStopStrategyTest.java | 124 ++++++++++++++++++++
8 files changed, 449 insertions(+), 2 deletions(-)
diff --git
a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/AutoResizingBufferMemoryAllocationException.java
b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/AutoResizingBufferMemoryAllocationException.java
new file mode 100644
index 00000000000..8364b7b30d4
--- /dev/null
+++
b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/AutoResizingBufferMemoryAllocationException.java
@@ -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);
+ }
+}
diff --git
a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/AutoResizingBufferMemoryManager.java
b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/AutoResizingBufferMemoryManager.java
index bbdbc8bda06..a8d7d4fe076 100644
---
a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/AutoResizingBufferMemoryManager.java
+++
b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/AutoResizingBufferMemoryManager.java
@@ -91,7 +91,7 @@ public final class AutoResizingBufferMemoryManager {
}
}
memoryAllocationFailureCount.incrementAndGet();
- throw new IOException(
+ throw new AutoResizingBufferMemoryAllocationException(
String.format(
RpcMessages.AUTO_RESIZING_BUFFER_ALLOCATE_FAILED,
sizeInBytes,
diff --git
a/iotdb-client/service-rpc/src/test/java/org/apache/iotdb/rpc/AutoResizingBufferTest.java
b/iotdb-client/service-rpc/src/test/java/org/apache/iotdb/rpc/AutoResizingBufferTest.java
index 3ffffda811b..8744d671170 100644
---
a/iotdb-client/service-rpc/src/test/java/org/apache/iotdb/rpc/AutoResizingBufferTest.java
+++
b/iotdb-client/service-rpc/src/test/java/org/apache/iotdb/rpc/AutoResizingBufferTest.java
@@ -534,7 +534,7 @@ public class AutoResizingBufferTest {
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 {
@@ -545,6 +545,30 @@ public class AutoResizingBufferTest {
}
}
+ @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);
diff --git
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/agent/task/subtask/sink/PipeSinkSubtaskTest.java
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/agent/task/subtask/sink/PipeSinkSubtaskTest.java
index 2016c79617e..162c11e6a94 100644
---
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/agent/task/subtask/sink/PipeSinkSubtaskTest.java
+++
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/agent/task/subtask/sink/PipeSinkSubtaskTest.java
@@ -24,6 +24,7 @@ import org.apache.iotdb.commons.conf.CommonDescriptor;
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;
@@ -41,10 +42,13 @@ import
org.apache.iotdb.pipe.api.exception.PipeConnectionException;
import org.apache.iotdb.pipe.api.exception.PipeException;
import
org.apache.ratis.thirdparty.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;
@@ -594,10 +598,124 @@ public class PipeSinkSubtaskTest {
}
}
+ @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);
+ 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).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) {
@@ -625,10 +743,22 @@ public class PipeSinkSubtaskTest {
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;
diff --git
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/async/IoTDBDataRegionAsyncSinkTest.java
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/async/IoTDBDataRegionAsyncSinkTest.java
index fb924b31e30..c7007db0d0d 100644
---
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/async/IoTDBDataRegionAsyncSinkTest.java
+++
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/sink/protocol/thrift/async/IoTDBDataRegionAsyncSinkTest.java
@@ -19,11 +19,19 @@
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;
@@ -31,10 +39,19 @@ 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();
@@ -71,6 +88,78 @@ public class IoTDBDataRegionAsyncSinkTest {
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 {
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/agent/task/subtask/PipeAbstractSinkSubtask.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/agent/task/subtask/PipeAbstractSinkSubtask.java
index 45cfa4bf86b..5245765526a 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/agent/task/subtask/PipeAbstractSinkSubtask.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/agent/task/subtask/PipeAbstractSinkSubtask.java
@@ -129,6 +129,20 @@ public abstract class PipeAbstractSinkSubtask extends
PipeReportableSubtask {
}
}
+ if (throwable instanceof Exception && !PipeStopStrategy.accept((Exception)
throwable, null)) {
+ 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;
+ }
+
synchronized (this) {
if (tryIgnoreFailure(throwable)) {
return;
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/resource/PipeStopStrategy.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/resource/PipeStopStrategy.java
index 4535bf57fe5..779fc1eeeb4 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/resource/PipeStopStrategy.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/resource/PipeStopStrategy.java
@@ -23,10 +23,16 @@ import org.apache.iotdb.common.rpc.thrift.TSStatus;
import org.apache.iotdb.commons.client.exception.ClientManagerException;
import
org.apache.iotdb.commons.exception.pipe.PipeRuntimeOutOfMemoryCriticalException;
import
org.apache.iotdb.commons.exception.pipe.PipeRuntimeSinkResourceException;
+import org.apache.iotdb.rpc.AutoResizingBufferMemoryAllocationException;
import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.thrift.transport.TTransportException;
+
import javax.annotation.Nullable;
+import java.io.IOException;
+import java.util.Locale;
+
public final class PipeStopStrategy {
private PipeStopStrategy() {}
@@ -50,9 +56,15 @@ public final class PipeStopStrategy {
if (current instanceof PipeRuntimeOutOfMemoryCriticalException) {
return PipeResourceFailureType.MEMORY_TIMEOUT;
}
+ if (current instanceof AutoResizingBufferMemoryAllocationException) {
+ return PipeResourceFailureType.MEMORY_TIMEOUT;
+ }
if (current instanceof ClientManagerException) {
return PipeResourceFailureType.NETWORK_TIMEOUT;
}
+ if (isPeerConnectionClosed(current)) {
+ return PipeResourceFailureType.NETWORK_TIMEOUT;
+ }
current = current.getCause();
}
@@ -63,6 +75,31 @@ public final class PipeStopStrategy {
: null;
}
+ private static boolean isPeerConnectionClosed(final Throwable throwable) {
+ if (throwable instanceof TTransportException
+ && ((TTransportException) throwable).getType() ==
TTransportException.END_OF_FILE) {
+ return true;
+ }
+
+ if (!(throwable instanceof IOException) && !(throwable instanceof
TTransportException)) {
+ return false;
+ }
+
+ final String message = throwable.getMessage();
+ if (message == null) {
+ return false;
+ }
+
+ final String normalizedMessage = message.toLowerCase(Locale.ROOT);
+ return normalizedMessage.contains("broken pipe")
+ || normalizedMessage.contains("connection reset")
+ || normalizedMessage.contains("connection was reset")
+ || normalizedMessage.contains("closed by peer")
+ || normalizedMessage.contains("read call frame size failed")
+ || normalizedMessage.contains("forcibly closed by the remote host")
+ || normalizedMessage.contains("connection was aborted");
+ }
+
public static boolean isResourceFailureRecorded(final @Nullable Exception
exception) {
Throwable current = exception;
while (current != null) {
diff --git
a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/pipe/resource/PipeStopStrategyTest.java
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/pipe/resource/PipeStopStrategyTest.java
index 5798ec192ff..04099910c3a 100644
---
a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/pipe/resource/PipeStopStrategyTest.java
+++
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/pipe/resource/PipeStopStrategyTest.java
@@ -24,12 +24,18 @@ import
org.apache.iotdb.commons.client.exception.ClientManagerException;
import
org.apache.iotdb.commons.exception.pipe.PipeRuntimeOutOfMemoryCriticalException;
import
org.apache.iotdb.commons.exception.pipe.PipeRuntimeSinkResourceException;
import
org.apache.iotdb.commons.exception.pipe.PipeRuntimeSinkRetryTimesConfigurableException;
+import org.apache.iotdb.rpc.AutoResizingBufferMemoryAllocationException;
+import org.apache.iotdb.rpc.TElasticFramedTransport;
import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.thrift.TConfiguration;
+import org.apache.thrift.transport.TTransport;
+import org.apache.thrift.transport.TTransportException;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
+import java.net.SocketException;
public class PipeStopStrategyTest {
@@ -64,6 +70,87 @@ public class PipeStopStrategyTest {
PipeStopStrategy.getResourceFailureType(null, status));
}
+ @Test
+ public void testAutoResizingBufferAllocationFailureDoesNotStopPipe() {
+ final Exception failure =
+ new TTransportException(
+ new AutoResizingBufferMemoryAllocationException("buffer allocation
failed"));
+
+ Assert.assertFalse(PipeStopStrategy.accept(failure, null));
+ Assert.assertEquals(
+ PipeResourceFailureType.MEMORY_TIMEOUT,
+ PipeStopStrategy.getResourceFailureType(failure, null));
+ }
+
+ @Test
+ public void testBrokenPipeFromReceiverResourcePressureDoesNotStopPipe() {
+ final Exception failure =
+ new PipeRuntimeSinkRetryTimesConfigurableException(
+ "transfer failed",
+ Integer.MAX_VALUE,
+ new TTransportException(new IOException("Broken pipe")));
+
+ Assert.assertFalse(PipeStopStrategy.accept(failure, null));
+ Assert.assertEquals(
+ PipeResourceFailureType.NETWORK_TIMEOUT,
+ PipeStopStrategy.getResourceFailureType(failure, null));
+ }
+
+ @Test
+ public void testPeerClosedTransportDoesNotStopPipe() {
+ final Exception failure =
+ new PipeRuntimeSinkRetryTimesConfigurableException(
+ "transfer failed",
+ Integer.MAX_VALUE,
+ new TTransportException(
+ TTransportException.END_OF_FILE, new IOException("Connection
reset")));
+
+ Assert.assertFalse(PipeStopStrategy.accept(failure, null));
+ Assert.assertEquals(
+ PipeResourceFailureType.NETWORK_TIMEOUT,
+ PipeStopStrategy.getResourceFailureType(failure, null));
+ }
+
+ @Test
+ public void testElasticFramedTransportResetRemainsRetryable() throws
Exception {
+ try (TElasticFramedTransport transport =
+ new TElasticFramedTransport(new ConnectionResetTransport(), 100, 1024,
true)) {
+ final TTransportException failure =
+ Assert.assertThrows(TTransportException.class, () ->
transport.read(new byte[1], 0, 1));
+
+ Assert.assertEquals(TTransportException.END_OF_FILE, failure.getType());
+ Assert.assertFalse(PipeStopStrategy.accept(failure, null));
+ Assert.assertEquals(
+ PipeResourceFailureType.NETWORK_TIMEOUT,
+ PipeStopStrategy.getResourceFailureType(failure, null));
+ }
+ }
+
+ @Test
+ public void
testConnectionResetVariantsRemainRetryableThroughCriticalWrapper() {
+ final Exception unixReset =
+ new PipeRuntimeSinkRetryTimesConfigurableException(
+ "transfer failed",
+ Integer.MAX_VALUE,
+ new TTransportException(new SocketException("Connection reset")));
+ Assert.assertFalse(PipeStopStrategy.accept(unixReset, null));
+ Assert.assertEquals(
+ PipeResourceFailureType.NETWORK_TIMEOUT,
+ PipeStopStrategy.getResourceFailureType(unixReset, null));
+
+ final Exception windowsReset =
+ new PipeRuntimeSinkRetryTimesConfigurableException(
+ "transfer failed",
+ Integer.MAX_VALUE,
+ new TTransportException(
+ new SocketException(
+ "An existing connection was forcibly closed by the remote
host")));
+ Assert.assertFalse(PipeStopStrategy.accept(windowsReset, null));
+ Assert.assertEquals(
+ PipeResourceFailureType.NETWORK_TIMEOUT,
+ PipeStopStrategy.getResourceFailureType(windowsReset, null));
+ }
+
@Test
public void testOtherFailuresKeepExistingStopPolicy() {
Assert.assertTrue(PipeStopStrategy.accept(new IOException("network
disconnected"), null));
@@ -81,4 +168,41 @@ public class PipeStopStrategyTest {
Assert.assertTrue(PipeStopStrategy.isResourceFailureRecorded(failure));
}
+
+ private static class ConnectionResetTransport extends TTransport {
+
+ @Override
+ public boolean isOpen() {
+ return true;
+ }
+
+ @Override
+ public void open() {}
+
+ @Override
+ public void close() {}
+
+ @Override
+ public int read(final byte[] buffer, final int offset, final int length)
+ throws TTransportException {
+ throw new TTransportException(new SocketException("Connection reset"));
+ }
+
+ @Override
+ public void write(final byte[] buffer, final int offset, final int length)
{}
+
+ @Override
+ public TConfiguration getConfiguration() {
+ return new TConfiguration();
+ }
+
+ @Override
+ public void updateKnownMessageSize(final long size) {}
+
+ @Override
+ public void checkReadBytesAvailable(final long numBytes) {}
+
+ @Override
+ public void resetMessageSizeAndConsumedBytes(final long newSize) {}
+ }
}