Repository navigation
perf(flink): buffer unsorted data and index writes in sequential pages #21004
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
Open
cshuo
wants to merge
2
commits into
apache:master
Choose a base branch
from
cshuo:perf/flink-sequential-bucket-buffer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+313
−182
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/buffer/RowDataBinaryBuffer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * 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.hudi.sink.buffer; | ||
|
|
||
| import org.apache.flink.table.data.RowData; | ||
| import org.apache.flink.table.data.binary.BinaryRowData; | ||
| import org.apache.flink.util.MutableObjectIterator; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** Paged row storage owned by one write bucket. */ | ||
| public interface RowDataBinaryBuffer { | ||
| /** | ||
| * Appends a row, returning false if the buffer runs out of pages. | ||
| * A failed append may leave a partial row, so the caller must not write to this buffer again. | ||
| * Previously appended rows remain available for sorting and iteration. Dispose of this buffer | ||
| * and retry the failed row in a fresh buffer. | ||
| */ | ||
| boolean write(RowData row) throws IOException; | ||
|
|
||
| boolean isEmpty(); | ||
|
|
||
| MutableObjectIterator<BinaryRowData> getIterator(); | ||
|
|
||
| default void sortIfNeeded() throws IOException { | ||
|
cshuo marked this conversation as resolved.
Resolved
|
||
| // Sequential buffers already have the required iteration order. | ||
| } | ||
|
|
||
| void dispose(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...asource/hudi-flink/src/main/java/org/apache/hudi/sink/buffer/SequentialRowDataBuffer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * 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.hudi.sink.buffer; | ||
|
|
||
| import org.apache.hudi.sink.exception.MemoryPagesExhaustedException; | ||
|
|
||
| import org.apache.flink.core.memory.MemorySegment; | ||
| import org.apache.flink.runtime.io.disk.RandomAccessInputView; | ||
| import org.apache.flink.runtime.io.disk.SimpleCollectingOutputView; | ||
| import org.apache.flink.table.data.RowData; | ||
| import org.apache.flink.table.data.binary.BinaryRowData; | ||
| import org.apache.flink.table.runtime.typeutils.RowDataSerializer; | ||
| import org.apache.flink.table.runtime.util.MemorySegmentPool; | ||
| import org.apache.flink.table.types.logical.RowType; | ||
| import org.apache.flink.util.MutableObjectIterator; | ||
|
|
||
| import java.io.EOFException; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
|
|
||
| /** Stores rows in arrival order without a per-row offset index. */ | ||
| public final class SequentialRowDataBuffer implements RowDataBinaryBuffer { | ||
| private final ArrayList<MemorySegment> pages = new ArrayList<>(); | ||
| private final MemorySegmentPool pool; | ||
| private final RowDataSerializer serializer; | ||
| private final SimpleCollectingOutputView output; | ||
| private int numRecords; | ||
|
|
||
| public SequentialRowDataBuffer(RowType rowType, MemorySegmentPool pool) { | ||
| if (pool.freePages() < 1) { | ||
| throw new MemoryPagesExhaustedException("No free page to create a sequential RowData buffer."); | ||
| } | ||
| this.pool = pool; | ||
| this.serializer = new RowDataSerializer(rowType); | ||
| this.output = new SimpleCollectingOutputView(pages, pool, pool.pageSize()); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean write(RowData row) throws IOException { | ||
| try { | ||
| serializer.serializeToPages(row, output); | ||
| } catch (EOFException e) { | ||
| // A partial row can occupy several pages. Only complete rows are visible to readers. | ||
| return false; | ||
| } | ||
| numRecords++; | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isEmpty() { | ||
| return numRecords == 0; | ||
| } | ||
|
|
||
| @Override | ||
| public MutableObjectIterator<BinaryRowData> getIterator() { | ||
| return new MutableObjectIterator<BinaryRowData>() { | ||
| private final RandomAccessInputView input = new RandomAccessInputView(pages, pool.pageSize()); | ||
| private int remaining = numRecords; | ||
|
|
||
| @Override | ||
| public BinaryRowData next(BinaryRowData reuse) throws IOException { | ||
| if (remaining == 0) { | ||
| return null; | ||
| } | ||
| remaining--; | ||
| return (BinaryRowData) serializer.mapFromPages(reuse, input); | ||
| } | ||
|
|
||
| @Override | ||
| public BinaryRowData next() throws IOException { | ||
| return next(new BinaryRowData(serializer.getArity())); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public void dispose() { | ||
| pool.returnAll(pages); | ||
| pages.clear(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.