Skip to content
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

Improve error logging and handling (#150) #46

Open
wants to merge 1 commit into
base: v1.11.x
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 @@ -31,6 +31,7 @@
import static java.util.stream.IntStream.range;
import static java.util.stream.IntStream.rangeClosed;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
Expand All @@ -53,7 +54,6 @@
import org.apache.kafka.connect.data.Schema;
import org.apache.kafka.connect.data.SchemaBuilder;
import org.apache.kafka.connect.data.Struct;
import org.apache.kafka.connect.errors.ConnectException;
import org.apache.kafka.connect.errors.DataException;
import org.apache.kafka.connect.source.SourceRecord;
import org.apache.kafka.connect.source.SourceTask;
Expand Down Expand Up @@ -483,6 +483,7 @@ void testSourceCanUseCustomOffsetPartitionNames() {
{
put(MongoSourceConfig.DATABASE_CONFIG, coll.getNamespace().getDatabaseName());
put(MongoSourceConfig.COLLECTION_CONFIG, coll.getNamespace().getCollectionName());
put(MongoSourceConfig.OVERRIDE_ERRORS_TOLERANCE_CONFIG, "all");
put(MongoSourceConfig.POLL_MAX_BATCH_SIZE_CONFIG, "50");
put(MongoSourceConfig.POLL_AWAIT_TIME_MS_CONFIG, "5000");
put(MongoSourceConfig.OFFSET_PARTITION_NAME_CONFIG, "oldPartitionName");
Expand All @@ -494,8 +495,7 @@ void testSourceCanUseCustomOffsetPartitionNames() {
.thenReturn(INVALID_OFFSET);
task.initialize(context);

assertThrows(
ConnectException.class,
assertDoesNotThrow(
() -> {
task.start(cfg);
getNextBatch(task);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,13 +594,23 @@ private List<BsonDocument> getNextBatch() {
} catch (MongoException e) {
closeCursor();
if (isRunning) {
if (sourceConfig.tolerateErrors() && changeStreamNotValid(e)) {
cursor = tryRecreateCursor(e);
if (sourceConfig.tolerateErrors()) {
if (changeStreamNotValid(e)) {
cursor = tryRecreateCursor(e);
} else {
LOGGER.error(
"An exception occurred when trying to get the next item from the Change Stream", e);
}
} else {
LOGGER.error(
"An exception occurred when trying to get the next item from the Change Stream", e);
if (e instanceof MongoQueryException && ((MongoQueryException) e).getErrorCode() == 286) {
throw new ConnectException("Failed to resume change stream", e);
} else {
throw new ConnectException(
"An exception occurred when trying to get the next item from the Change Stream: "
+ e.getMessage(),
e);
}
}
}
Expand Down