fapaul commented on code in PR #154: URL: https://github.com/apache/flink-connector-kafka/pull/154#discussion_r1975559008
########## flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/internal/TransactionNamingStrategyImpl.java: ########## @@ -0,0 +1,77 @@ +/* + * 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.connector.kafka.sink.internal; + +import org.apache.flink.connector.kafka.sink.KafkaSinkOptions.TransactionNamingStrategy; + +import static org.apache.flink.util.Preconditions.checkState; + +/** Implementation of {@link TransactionNamingStrategy}. */ +public enum TransactionNamingStrategyImpl { + INCREMENTING { Review Comment: Nit: `INCREMENTAL` ########## flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/internal/TransactionAbortStrategyImpl.java: ########## @@ -0,0 +1,134 @@ +/* + * 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.connector.kafka.sink.internal; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +/** Implementations of an abort strategy for transactions left over from previous runs. */ +public enum TransactionAbortStrategyImpl { Review Comment: Should this now be marked as internal? ########## flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/internal/TransactionNamingStrategyImpl.java: ########## @@ -0,0 +1,77 @@ +/* + * 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.connector.kafka.sink.internal; + +import org.apache.flink.connector.kafka.sink.KafkaSinkOptions.TransactionNamingStrategy; + +import static org.apache.flink.util.Preconditions.checkState; + +/** Implementation of {@link TransactionNamingStrategy}. */ +public enum TransactionNamingStrategyImpl { Review Comment: Something looks off why is `PROBING` not defined in this class. ########## flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/internal/TransactionNamingStrategyImpl.java: ########## @@ -0,0 +1,77 @@ +/* + * 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.connector.kafka.sink.internal; + +import org.apache.flink.connector.kafka.sink.KafkaSinkOptions.TransactionNamingStrategy; + +import static org.apache.flink.util.Preconditions.checkState; + +/** Implementation of {@link TransactionNamingStrategy}. */ +public enum TransactionNamingStrategyImpl { + INCREMENTING { + /** + * For each checkpoint we create new {@link FlinkKafkaInternalProducer} so that new + * transactions will not clash with transactions created during previous checkpoints ({@code + * producer.initTransactions()} assures that we obtain new producerId and epoch counters). + * + * <p>Ensures that all transaction ids in between lastCheckpointId and checkpointId are + * initialized. + */ + @Override + public FlinkKafkaInternalProducer<byte[], byte[]> getTransactionalProducer( + Context context) { + long expectedCheckpointId = context.getNextCheckpointId(); + long lastCheckpointId = context.getLastCheckpointId(); + checkState( + expectedCheckpointId > lastCheckpointId, + "Expected %s > %s", + expectedCheckpointId, + lastCheckpointId); + // in case checkpoints have been aborted, Flink would create non-consecutive transaction + // ids + // this loop ensures that all gaps are filled with initialized (empty) transactions + for (long checkpointId = lastCheckpointId + 1; + checkpointId < expectedCheckpointId; + checkpointId++) { + context.recycle(context.getProducer(context.buildTransactionalId(checkpointId))); + } Review Comment: Is this newly added logic or was this previously part of the recovery? ########## flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/internal/TransactionNamingStrategyContextImpl.java: ########## @@ -0,0 +1,78 @@ +/* + * 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.connector.kafka.sink.internal; + +import static org.apache.flink.util.Preconditions.checkNotNull; + +/** Implementation of {@link TransactionNamingStrategyImpl.Context}. */ +public class TransactionNamingStrategyContextImpl implements TransactionNamingStrategyImpl.Context { Review Comment: Internal? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org