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

fix: Set max number of failures in the write loop #13

Merged
merged 1 commit into from
Oct 26, 2023
Merged
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 @@ -187,6 +187,11 @@ public class HdfsSinkConnectorConfig extends StorageSinkConnectorConfig {
= new ParentValueRecommender(FORMAT_CLASS_CONFIG, AvroFormat.class, AVRO_SUPPORTED_CODECS);
private static final ParquetCodecRecommender PARQUET_COMPRESSION_RECOMMENDER
= new ParquetCodecRecommender();
public static final String WRITE_FAILURE_TOLERANCE_CONFIG = "write.failure.tolerance";
private static final Integer WRITE_FAILURE_TOLERANCE_DEFAULT = 10;
private static final String WRITE_FAILURE_TOLERANCE_DOC = "The maximum number of times that the"
+ "task is going to handle consecutive write exceptions.";
private static final String WRITE_FAILURE_TOLERANCE_DISPLAY = "Failure Tolerance";

static {
STORAGE_CLASS_RECOMMENDER.addValidValues(
Expand Down Expand Up @@ -307,6 +312,17 @@ public static ConfigDef newConfigDef() {
ROTATE_MAX_FILE_SIZE_BYTES_DISPLAY
);

configDef.define(
WRITE_FAILURE_TOLERANCE_CONFIG,
Type.INT,
WRITE_FAILURE_TOLERANCE_DEFAULT,
Importance.MEDIUM,
WRITE_FAILURE_TOLERANCE_DOC,
group,
++orderInGroup,
Width.MEDIUM,
WRITE_FAILURE_TOLERANCE_DISPLAY
);
}

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public class TopicPartitionWriter {
private final Map<String, Long> endOffsets;
private final long timeoutMs;
private long failureTime;
private int failureCount;
private int failureTolerance;
private final StorageSchemaCompatibility compatibility;
private Schema currentSchema;
private final String extension;
Expand Down Expand Up @@ -205,6 +207,7 @@ public TopicPartitionWriter(
maxFileSizeRotationBytes = config.getLong(HdfsSinkConnectorConfig
.ROTATE_MAX_FILE_SIZE_BYTES_CONFIG);
timeoutMs = config.getLong(HdfsSinkConnectorConfig.RETRY_BACKOFF_CONFIG);
failureTolerance = config.getInt(HdfsSinkConnectorConfig.WRITE_FAILURE_TOLERANCE_CONFIG);
compatibility = StorageSchemaCompatibility.getCompatibility(
config.getString(StorageSinkConnectorConfig.SCHEMA_COMPATIBILITY_CONFIG));

Expand All @@ -222,6 +225,7 @@ public TopicPartitionWriter(
endOffsets = new HashMap<>();
state = State.RECOVERY_STARTED;
failureTime = -1L;
failureCount = 0;
// The next offset to consume after the last commit (one more than last offset written to HDFS)
offset = -1L;
if (writerProvider != null) {
Expand Down Expand Up @@ -339,6 +343,11 @@ public void write() {
if (failureTime > 0 && now - failureTime < timeoutMs) {
return;
}
if (failureCount > failureTolerance) {
log.error("The writer has failed {} times consecutively.", failureCount);
// Kill the task as it has been failing more than the max retries
throw new ConnectException("The task has exceeded the failure tolerance.");
}
if (state.compareTo(State.WRITE_STARTED) < 0) {
boolean success = recover();
if (!success) {
Expand Down Expand Up @@ -424,8 +433,9 @@ public void write() {
} catch (ConnectException e) {
log.error("Exception on topic partition {}: ", tp, e);
failureTime = time.milliseconds();
failureCount += 1;
setRetryTimeout(timeoutMs);
break;
return;
}
}
if (buffer.isEmpty()) {
Expand Down Expand Up @@ -464,13 +474,15 @@ public void write() {
} catch (ConnectException e) {
log.error("Exception on topic partition {}: ", tp, e);
failureTime = time.milliseconds();
failureCount += 1;
setRetryTimeout(timeoutMs);
return;
}

resume();
state = State.WRITE_STARTED;
}
this.failureCount = 0;
}

public void close() throws ConnectException {
Expand Down