You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "tsreaper (via GitHub)" <gi...@apache.org> on 2024/09/19 08:15:11 UTC
[PR] [flink] Remove state from append only unaware bucket writer [paimon]
tsreaper opened a new pull request, #4219:
URL: https://github.com/apache/paimon/pull/4219
### Purpose
Currently Paimon writer operators in Flink have states, which record the `commitUser` (for all writers) and the list of active buckets (for lookup or full-compaction changelog producer). These states prevent a writer object to be closed too early and cause conflicts.
However for append only unaware bucket writers, because they only create new files, there is no conflict. So for these writers we can remove Flink state. This optimization is also useful for bounded stream jobs, because when chaining source and write operator together, if some source parallelism have finished, checkpoint cannot be performed if there are union list states in the operators which are still running.
### Tests
Existing tests should cover this change.
### API and Format
No format changes.
### Documentation
No new feature.
--
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-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [flink] Remove state from append only unaware bucket writer [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4219:
URL: https://github.com/apache/paimon/pull/4219#discussion_r1770790164
##########
paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreWrite.java:
##########
@@ -266,6 +246,37 @@ public List<CommitMessage> prepareCommit(boolean waitCompaction, long commitIden
return result;
}
+ protected abstract Function<WriterContainer<T>, Boolean> createWriterCleanChecker();
Review Comment:
Should we do this abstraction? Or just introducing a `boolean doWriterCleanChecker`?
--
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-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [flink] Remove state from append only unaware bucket writer [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4219:
URL: https://github.com/apache/paimon/pull/4219#discussion_r1770787453
##########
paimon-core/src/main/java/org/apache/paimon/operation/AppendOnlyFileStoreWrite.java:
##########
@@ -143,50 +109,38 @@ protected RecordWriter<InternalRow> createWriter(
@Nullable CommitIncrement restoreIncrement,
ExecutorService compactExecutor,
@Nullable DeletionVectorsMaintainer dvMaintainer) {
- CompactManager compactManager = new NoopCompactManager();
- if (!skipCompaction) {
- Function<String, DeletionVector> dvFactory =
- dvMaintainer != null
- ? f -> dvMaintainer.deletionVectorOf(f).orElse(null)
- : null;
- compactManager =
- new BucketedAppendCompactManager(
- compactExecutor,
- restoredFiles,
- dvMaintainer,
- compactionMinFileNum,
- compactionMaxFileNum,
- targetFileSize,
- files -> compactRewrite(partition, bucket, dvFactory, files),
- compactionMetrics == null
- ? null
- : compactionMetrics.createReporter(partition, bucket));
- }
-
return new AppendOnlyWriter(
fileIO,
ioManager,
schemaId,
fileFormat,
- targetFileSize,
+ options.targetFileSize(false),
rowType,
restoredMaxSeqNumber,
- compactManager,
+ getCompactManager(partition, bucket, restoredFiles, compactExecutor, dvMaintainer),
// it is only for new files, no dv
files -> createFilesIterator(partition, bucket, files, null),
- commitForceCompact,
+ options.commitForceCompact(),
pathFactory.createDataFilePathFactory(partition, bucket),
restoreIncrement,
- useWriteBuffer || forceBufferSpill,
- spillable || forceBufferSpill,
- fileCompression,
- spillCompression,
+ options.useWriteBufferForAppend() || forceBufferSpill,
+ options.writeBufferSpillable(fileIO.isObjectStore(), isStreamingMode)
+ || forceBufferSpill,
+ options.fileCompression(),
+ options.spillCompressOptions(),
statsCollectors,
- maxDiskSize,
+ options.writeBufferSpillDiskSize(),
fileIndexOptions,
options.asyncFileWrite());
}
+ protected abstract CompactManager getCompactManager(
+ BinaryRow partition,
+ int bucket,
+ List<DataFileMeta> restoredFiles,
+ ExecutorService compactExecutor,
+ @javax.annotation.Nullable DeletionVectorsMaintainer dvMaintainer);
Review Comment:
import this
--
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-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [flink] Remove state from append only unaware bucket writer [paimon]
Posted by "wwj6591812 (via GitHub)" <gi...@apache.org>.
wwj6591812 commented on PR #4219:
URL: https://github.com/apache/paimon/pull/4219#issuecomment-2367591671
+1
--
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-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [flink] Remove state from append only unaware bucket writer [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #4219:
URL: https://github.com/apache/paimon/pull/4219
--
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-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [flink] Remove state from append only unaware bucket writer [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4219:
URL: https://github.com/apache/paimon/pull/4219#discussion_r1770788690
##########
paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreWrite.java:
##########
@@ -266,6 +246,37 @@ public List<CommitMessage> prepareCommit(boolean waitCompaction, long commitIden
return result;
}
+ protected abstract Function<WriterContainer<T>, Boolean> createWriterCleanChecker();
+
+ protected static <T>
+ Function<WriterContainer<T>, Boolean> createConflictAwareWriterCleanChecker(
+ String commitUser, SnapshotManager snapshotManager) {
+ long latestCommittedIdentifier =
+ snapshotManager
+ .latestSnapshotOfUser(commitUser)
+ .map(Snapshot::commitIdentifier)
+ .orElse(Long.MIN_VALUE);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Latest committed identifier is {}", latestCommittedIdentifier);
+ }
+
+ // Condition 1: There is no more record waiting to be committed. Note that the
+ // condition is < (instead of <=), because each commit identifier may have
+ // multiple snapshots. We must make sure all snapshots of this identifier are
+ // committed.
+ //
+ // Condition 2: No compaction is in progress. That is, no more changelog will be
+ // produced.
+ return writerContainer ->
+ writerContainer.lastModifiedCommitIdentifier < latestCommittedIdentifier
+ && !writerContainer.writer.isCompacting();
+ }
+
+ protected static <T>
+ Function<WriterContainer<T>, Boolean> createNoConflictAwareWriterCleanChecker() {
Review Comment:
Just inline this method in `AppendOnlyUnawareBucketFileStoreWrite`.
--
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-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [flink] Remove state from append only unaware bucket writer [paimon]
Posted by "wwj6591812 (via GitHub)" <gi...@apache.org>.
wwj6591812 commented on code in PR #4219:
URL: https://github.com/apache/paimon/pull/4219#discussion_r1770999147
##########
paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/UnawareBucketAppendOnlyTableITCase.java:
##########
@@ -346,6 +357,95 @@ public void testFileIndex() {
.containsExactlyInAnyOrder(Row.of(2, "c", "BBB"), Row.of(3, "c", "BBB"));
}
+ @Timeout(60)
+ @Test
+ public void testStatelessWriter() throws Exception {
+ FileStoreTable table =
+ FileStoreTableFactory.create(
+ LocalFileIO.create(), new Path(path, "default.db/append_table"));
+
+ StreamExecutionEnvironment env =
+ streamExecutionEnvironmentBuilder()
+ .streamingMode()
+ .parallelism(2)
+ .checkpointIntervalMs(500)
+ .build();
+ DataStream<Integer> source =
+ env.addSource(new TestStatelessWriterSource(table)).setParallelism(2).forward();
+
+ StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
+ tEnv.registerCatalog("mycat", sEnv.getCatalog("PAIMON").get());
+ tEnv.executeSql("USE CATALOG mycat");
+ tEnv.createTemporaryView("S", tEnv.fromDataStream(source).as("id"));
+
+ tEnv.executeSql("INSERT INTO append_table SELECT id, 'test' FROM S").await();
+ assertThat(batchSql("SELECT * FROM append_table"))
+ .containsExactlyInAnyOrder(Row.of(1, "test"), Row.of(2, "test"));
+ System.out.println(table.snapshotManager().latestSnapshotId());
Review Comment:
cut System.out.println.
--
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-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [flink] Remove state from append only unaware bucket writer [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4219:
URL: https://github.com/apache/paimon/pull/4219#discussion_r1770790164
##########
paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreWrite.java:
##########
@@ -266,6 +246,37 @@ public List<CommitMessage> prepareCommit(boolean waitCompaction, long commitIden
return result;
}
+ protected abstract Function<WriterContainer<T>, Boolean> createWriterCleanChecker();
Review Comment:
Should we do this abstraction? Or just introducing a `boolean checkWriterClean`?
--
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-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [flink] Remove state from append only unaware bucket writer [paimon]
Posted by "wwj6591812 (via GitHub)" <gi...@apache.org>.
wwj6591812 commented on code in PR #4219:
URL: https://github.com/apache/paimon/pull/4219#discussion_r1766630567
##########
paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreWrite.java:
##########
@@ -226,14 +214,8 @@ public List<CommitMessage> prepareCommit(boolean waitCompaction, long commitIden
result.add(committable);
if (committable.isEmpty()) {
- // Condition 1: There is no more record waiting to be committed. Note that the
- // condition is < (instead of <=), because each commit identifier may have
- // multiple snapshots. We must make sure all snapshots of this identifier are
- // committed.
- // Condition 2: No compaction is in progress. That is, no more changelog will be
- // produced.
- if (writerContainer.lastModifiedCommitIdentifier < latestCommittedIdentifier
- && !writerContainer.writer.isCompacting()) {
+
Review Comment:
Excess blank line
##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/TableWriteOperator.java:
##########
@@ -39,7 +38,7 @@ public abstract class TableWriteOperator<IN> extends PrepareCommitOperator<IN, C
private final StoreSinkWrite.Provider storeSinkWriteProvider;
private final String initialCommitUser;
- private transient StoreSinkWriteState state;
+ protected transient StoreSinkWriteState state;
Review Comment:
why protected ?
Now this state is only used in this class.
##########
paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/sink/FlinkSinkTest.java:
##########
@@ -90,20 +88,14 @@ private boolean testSpillable(
((OneInputTransformation) written.getTransformation())
.getOperatorFactory())
.getOperator());
- StateInitializationContextImpl context =
- new StateInitializationContextImpl(
- null,
- new MockOperatorStateStore() {
- @Override
- public <S> ListState<S> getUnionListState(
- ListStateDescriptor<S> stateDescriptor) throws Exception {
- return getListState(stateDescriptor);
- }
- },
- null,
- null,
- null);
- operator.initStateAndWriter(context, (a, b, c) -> true, new IOManagerAsync(), "123");
+
+ TypeSerializer<Committable> serializer =
+ new CommittableTypeInfo().createSerializer(new ExecutionConfig());
+ OneInputStreamOperatorTestHarness<InternalRow, Committable> harness =
+ new OneInputStreamOperatorTestHarness<>(operator);
+ harness.setup(serializer);
+ harness.initializeEmptyState();
+
return ((KeyValueFileStoreWrite) ((StoreSinkWriteImpl) operator.write).write.getWrite())
Review Comment:
Could you add It case to test :
After apply this pr, when chaining source and write operator together, if some source parallelism have finished, checkpoint can be performed?
##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/TableWriteOperator.java:
##########
@@ -74,27 +73,21 @@ public void initializeState(StateInitializationContext context) throws Exception
return task == getRuntimeContext().getIndexOfThisSubtask();
};
- initStateAndWriter(
- context,
- stateFilter,
- getContainingTask().getEnvironment().getIOManager(),
- commitUser);
+ state = createState(context, stateFilter);
Review Comment:
In this function, line 61 - 63, StateUtils.getSingleValueFromState will be called, then context.getOperatorStateStore().getUnionListState will be called.
This will lead to :
When chaining source and write operator together, if some source parallelism have finished, checkpoint cannot be performed.
--
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-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [flink] Remove state from append only unaware bucket writer [paimon]
Posted by "tsreaper (via GitHub)" <gi...@apache.org>.
tsreaper commented on code in PR #4219:
URL: https://github.com/apache/paimon/pull/4219#discussion_r1770921494
##########
paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreWrite.java:
##########
@@ -266,6 +246,37 @@ public List<CommitMessage> prepareCommit(boolean waitCompaction, long commitIden
return result;
}
+ protected abstract Function<WriterContainer<T>, Boolean> createWriterCleanChecker();
Review Comment:
This abstract function returns a whole function (instead of just a boolean value), because we do not want to introduce `commitUser` into this base class.
For writers with no conflicts, `commitUser` might be some random value.
--
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-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [flink] Remove state from append only unaware bucket writer [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4219:
URL: https://github.com/apache/paimon/pull/4219#discussion_r1770785826
##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/NoopStoreSinkWriteState.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.paimon.flink.sink;
+
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * A {@link StoreSinkWriteState} which stores nothing. Currently only used for append only unaware
+ * bucket table writers.
+ */
+public class NoopStoreSinkWriteState implements StoreSinkWriteState {
+
+ private final StateValueFilter stateValueFilter;
+
+ public NoopStoreSinkWriteState(StateValueFilter stateValueFilter) {
+ this.stateValueFilter = stateValueFilter;
+ }
+
+ @Override
+ public StateValueFilter stateValueFilter() {
+ return stateValueFilter;
+ }
+
+ @Override
+ public @Nullable List<StateValue> get(String tableName, String key) {
+ return Collections.emptyList();
Review Comment:
Should we throw exception for get and put?
--
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-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [flink] Remove state from append only unaware bucket writer [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4219:
URL: https://github.com/apache/paimon/pull/4219#discussion_r1770790164
##########
paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreWrite.java:
##########
@@ -266,6 +246,37 @@ public List<CommitMessage> prepareCommit(boolean waitCompaction, long commitIden
return result;
}
+ protected abstract Function<WriterContainer<T>, Boolean> createWriterCleanChecker();
Review Comment:
Should we do this abstraction? Or just introducing a `boolean doWriterCleanCheck`?
--
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-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org