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

[FLINK-36455] Sinks retry synchronously [1.20] #25661

Open
wants to merge 6 commits into
base: release-1.20
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 @@ -26,5 +26,11 @@
<td>String</td>
<td>Directories for temporary files, separated by",", "|", or the system's java.io.File.pathSeparator.</td>
</tr>
<tr>
<td><h5>sink.committer.retries</h5></td>
<td style="word-wrap: break-word;">10</td>
<td>Integer</td>
<td>The number of retries a Flink application attempts for committable operations (such as transactions) on retriable errors, as specified by the sink connector, before Flink fails and potentially restarts.</td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.apache.flink.streaming.api.connector.sink2.CommittableMessage;
import org.apache.flink.streaming.api.connector.sink2.CommittableSummary;
import org.apache.flink.streaming.api.connector.sink2.CommittableWithLineage;
import org.apache.flink.streaming.api.connector.sink2.SinkV2Assertions;
import org.apache.flink.streaming.api.functions.sink.filesystem.BucketWriter;
import org.apache.flink.streaming.api.functions.sink.filesystem.CompactingFileWriter;
import org.apache.flink.streaming.api.functions.sink.filesystem.InProgressFileWriter;
Expand All @@ -45,6 +44,7 @@
import org.apache.flink.streaming.util.OneInputStreamOperatorTestHarness;
import org.apache.flink.types.Either;

import org.assertj.core.api.ListAssert;
import org.junit.jupiter.api.Test;

import java.io.BufferedWriter;
Expand All @@ -57,6 +57,9 @@
import java.util.Collections;
import java.util.List;

import static org.apache.flink.streaming.api.connector.sink2.SinkV2Assertions.committableSummary;
import static org.apache.flink.streaming.api.connector.sink2.SinkV2Assertions.committableWithLineage;
import static org.assertj.core.api.Assertions.as;
import static org.assertj.core.api.Assertions.assertThat;

/** Test for {@link CompactorOperator}. */
Expand Down Expand Up @@ -93,16 +96,13 @@ void testCompact() throws Exception {
harness.prepareSnapshotPreBarrier(2);

// 1summary+1compacted+2cleanup
List<CommittableMessage<FileSinkCommittable>> results = harness.extractOutputValues();
assertThat(results).hasSize(4);
SinkV2Assertions.assertThat((CommittableSummary<?>) results.get(0))
.hasPendingCommittables(3);
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(1))
ListAssert<CommittableMessage<FileSinkCommittable>> results =
assertThat(harness.extractOutputValues()).hasSize(4);
results.element(0, as(committableSummary())).hasPendingCommittables(3);
results.element(1, as(committableWithLineage()))
.hasCommittable(committable("0", "compacted-0", 10));
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(2))
.hasCommittable(cleanupPath("0", ".0"));
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(3))
.hasCommittable(cleanupPath("0", ".1"));
results.element(2, as(committableWithLineage())).hasCommittable(cleanupPath("0", ".0"));
results.element(3, as(committableWithLineage())).hasCommittable(cleanupPath("0", ".1"));
}
}

Expand Down Expand Up @@ -138,14 +138,12 @@ void testPassthrough() throws Exception {

harness.prepareSnapshotPreBarrier(2);

List<CommittableMessage<FileSinkCommittable>> results = harness.extractOutputValues();
assertThat(results).hasSize(3);
SinkV2Assertions.assertThat((CommittableSummary<?>) results.get(0))
.hasPendingCommittables(2);
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(1))
ListAssert<CommittableMessage<FileSinkCommittable>> messages =
assertThat(harness.extractOutputValues()).hasSize(3);
messages.element(0, as(committableSummary())).hasPendingCommittables(2);
messages.element(1, as(committableWithLineage()))
.hasCommittable(cleanupInprogressRequest);
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(2))
.hasCommittable(cleanupPathRequest);
messages.element(2, as(committableWithLineage())).hasCommittable(cleanupPathRequest);
}
}

Expand Down Expand Up @@ -207,25 +205,19 @@ void testRestore() throws Exception {
assertThat(harness.extractOutputValues()).hasSize(8);

// 1summary+1compacted+2cleanup * 2
List<CommittableMessage<FileSinkCommittable>> results = harness.extractOutputValues();
assertThat(results).hasSize(8);
SinkV2Assertions.assertThat((CommittableSummary<?>) results.get(0))
.hasPendingCommittables(3);
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(1))
ListAssert<CommittableMessage<FileSinkCommittable>> results =
assertThat(harness.extractOutputValues()).hasSize(8);
results.element(0, as(committableSummary())).hasPendingCommittables(3);
results.element(1, as(committableWithLineage()))
.hasCommittable(committable("0", "compacted-0", 10));
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(2))
.hasCommittable(cleanupPath("0", ".0"));
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(3))
.hasCommittable(cleanupPath("0", ".1"));

SinkV2Assertions.assertThat((CommittableSummary<?>) results.get(4))
.hasPendingCommittables(3);
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(5))
results.element(2, as(committableWithLineage())).hasCommittable(cleanupPath("0", ".0"));
results.element(3, as(committableWithLineage())).hasCommittable(cleanupPath("0", ".1"));

results.element(4, as(committableSummary())).hasPendingCommittables(3);
results.element(5, as(committableWithLineage()))
.hasCommittable(committable("0", "compacted-2", 10));
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(6))
.hasCommittable(cleanupPath("0", ".2"));
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(7))
.hasCommittable(cleanupPath("0", ".3"));
results.element(6, as(committableWithLineage())).hasCommittable(cleanupPath("0", ".2"));
results.element(7, as(committableWithLineage())).hasCommittable(cleanupPath("0", ".3"));
}
}

Expand Down Expand Up @@ -317,10 +309,9 @@ void testStateHandler() throws Exception {

// 1 summary + (1 compacted committable + 1 compacted cleanup) * 6 + 1 hidden + 1 normal
// + 1 summary + 1 cleanup + 1 summary
List<CommittableMessage<FileSinkCommittable>> results = harness.extractOutputValues();
assertThat(results).hasSize(18);
SinkV2Assertions.assertThat((CommittableSummary<?>) results.get(0))
.hasPendingCommittables(14);
ListAssert<CommittableMessage<FileSinkCommittable>> results =
assertThat(harness.extractOutputValues()).hasSize(18);
results.element(0, as(committableSummary())).hasPendingCommittables(14);

List<FileSinkCommittable> expectedResult =
Arrays.asList(
Expand All @@ -340,17 +331,15 @@ void testStateHandler() throws Exception {
committable("0", "7", 8));

for (int i = 0; i < expectedResult.size(); ++i) {
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(i + 1))
results.element(i + 1, as(committableWithLineage()))
.hasCommittable(expectedResult.get(i));
}

SinkV2Assertions.assertThat((CommittableSummary<?>) results.get(15))
.hasPendingCommittables(1);
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(16))
results.element(15, as(committableSummary())).hasPendingCommittables(1);
results.element(16, as(committableWithLineage()))
.hasCommittable(cleanupPath("0", ".6"));

SinkV2Assertions.assertThat((CommittableSummary<?>) results.get(17))
.hasPendingCommittables(3);
results.element(17, as(committableSummary())).hasPendingCommittables(3);
}
}

Expand Down Expand Up @@ -386,14 +375,12 @@ void testStateHandlerRestore() throws Exception {

state = harness.snapshot(1, 1L);

List<CommittableMessage<FileSinkCommittable>> results = harness.extractOutputValues();
assertThat(results).hasSize(3);
SinkV2Assertions.assertThat((CommittableSummary<?>) results.get(0))
.hasPendingCommittables(4);
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(1))
ListAssert<CommittableMessage<FileSinkCommittable>> results =
assertThat(harness.extractOutputValues()).hasSize(3);
results.element(0, as(committableSummary())).hasPendingCommittables(4);
results.element(1, as(committableWithLineage()))
.hasCommittable(committable("0", "compacted-1", 1));
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(2))
.hasCommittable(cleanupPath("0", ".1"));
results.element(2, as(committableWithLineage())).hasCommittable(cleanupPath("0", ".1"));
}

try (OneInputStreamOperatorTestHarness<
Expand Down Expand Up @@ -422,11 +409,11 @@ void testStateHandlerRestore() throws Exception {

state = harness.snapshot(2, 2L);

List<CommittableMessage<FileSinkCommittable>> results = harness.extractOutputValues();
assertThat(results).hasSize(2);
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(0))
ListAssert<CommittableMessage<FileSinkCommittable>> results =
assertThat(harness.extractOutputValues()).hasSize(2);
results.element(0, as(committableWithLineage()))
.hasCommittable(committable("0", "2", 2));
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(1))
results.element(1, as(committableWithLineage()))
.hasCommittable(committable("0", "3", 3));
}

Expand All @@ -445,12 +432,10 @@ void testStateHandlerRestore() throws Exception {
harness.processElement(
new StreamRecord<>(Either.Left(new CommittableSummary<>(0, 1, 2L, 0, 0, 0))));

List<CommittableMessage<FileSinkCommittable>> results = harness.extractOutputValues();
assertThat(results).hasSize(2);
SinkV2Assertions.assertThat((CommittableSummary<?>) results.get(0))
.hasPendingCommittables(1);
SinkV2Assertions.assertThat((CommittableWithLineage<?>) results.get(1))
.hasCommittable(cleanupPath("0", ".2"));
ListAssert<CommittableMessage<FileSinkCommittable>> results =
assertThat(harness.extractOutputValues()).hasSize(2);
results.element(0, as(committableSummary())).hasPendingCommittables(1);
results.element(1, as(committableWithLineage())).hasCommittable(cleanupPath("0", ".2"));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.flink.configuration;

import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.annotation.docs.Documentation;

import static org.apache.flink.configuration.ConfigOptions.key;

/** Configuration options for sinks. */
@PublicEvolving
public class SinkOptions {
/**
* The number of retries on a committable (e.g., transaction) before Flink application fails and
* potentially restarts.
*/
@Documentation.Section(Documentation.Sections.COMMON_MISCELLANEOUS)
public static final ConfigOption<Integer> COMMITTER_RETRIES =
key("sink.committer.retries")
.intType()
.defaultValue(10)
.withDescription(
"The number of retries a Flink application attempts for committable operations (such as transactions) on retriable errors, as specified by the sink connector, before Flink fails and potentially restarts.");

private SinkOptions() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public <NewCommT> CommittableWithLineage<NewCommT> map(Function<CommT, NewCommT>
return new CommittableWithLineage<>(mapper.apply(committable), checkpointId, subtaskId);
}

/** Creates a shallow copy with the given subtaskId. */
public CommittableWithLineage<CommT> withSubtaskId(int subtaskId) {
return new CommittableWithLineage<>(committable, checkpointId, subtaskId);
}

@Override
public String toString() {
return "CommittableWithLineage{"
Expand Down
Loading