Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Retry vitess connection refused errors 100 times #2

Open
wants to merge 2 commits into
base: v.1.9.8.final
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -12,8 +12,12 @@
import io.debezium.pipeline.ErrorHandler;
import io.grpc.StatusRuntimeException;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

public class VitessErrorHandler extends ErrorHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(VitessErrorHandler.class);
private static AtomicInteger connectionRefusedRestarts = new AtomicInteger(100);

public VitessErrorHandler(VitessConnectorConfig connectorConfig, ChangeEventQueue<?> queue) {
super(VitessConnector.class, connectorConfig, queue);
Expand All @@ -34,6 +38,9 @@ protected boolean isRetriable(Throwable throwable) {
}
return false;
case UNAVAILABLE:
if (throwable.getCause().toString().contains("AnnotatedConnectException: Connection refused")) {
return connectionRefusedRestarts.getAndDecrement() > 0;
}
return true;
case UNKNOWN:
// Stream timeout error due to idle VStream or vstream ended unexpectedly.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.debezium.connector.vitess;

import io.debezium.connector.base.ChangeEventQueue;
import io.debezium.pipeline.DataChangeEvent;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class VitessErrorHandlerTest {

VitessConnectorConfig config = new VitessConnectorConfig(TestHelper.defaultConfig().build());
ChangeEventQueue<DataChangeEvent> queue = new ChangeEventQueue.Builder<DataChangeEvent>().build();
VitessErrorHandler vitessErrorHandler = new VitessErrorHandler(config, queue);

@Test
public void isRetriable_returnsTrueForConnectionRefusedExceptionThat() {
boolean result = vitessErrorHandler.isRetriable(createConnectionRefusedException());
assertTrue(result);
}

@Test
public void isRetriable_ReturnsFalseAfter100Retries() {
for (int i = 0; i < 100; i++) {
vitessErrorHandler.isRetriable(createConnectionRefusedException());
}
assertFalse(vitessErrorHandler.isRetriable(createConnectionRefusedException()));
}

private StatusRuntimeException createConnectionRefusedException() {
Throwable connectionRefused = new AnnotatedConnectException("Connection refused");
return Status.UNAVAILABLE.withDescription("io exception").withCause(connectionRefused).asRuntimeException();
}

// mocks com.ververica.cdc.connectors.vitess.shaded.io.netty.channel.AbstractChannel$AnnotatedConnectException
static class AnnotatedConnectException extends RuntimeException {
public AnnotatedConnectException(String message) {
super(message);
}
}
}
Loading