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

[HUDI-7147] Fix CDC write flush bug #10186

Merged
Merged
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 @@ -53,10 +53,10 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import static org.apache.hudi.common.table.cdc.HoodieCDCSupplementalLoggingMode.DATA_BEFORE;
import static org.apache.hudi.common.table.cdc.HoodieCDCSupplementalLoggingMode.DATA_BEFORE_AFTER;
Expand Down Expand Up @@ -84,7 +84,7 @@ public class HoodieCDCLogger implements Closeable {
private final Schema cdcSchema;

// the cdc data
private final Map<String, HoodieAvroPayload> cdcData;
private final ExternalSpillableMap<String, HoodieAvroPayload> cdcData;

private final Map<HoodieLogBlock.HeaderMetadataType, String> cdcDataBlockHeader;

Expand Down Expand Up @@ -183,15 +183,16 @@ public void put(HoodieRecord hoodieRecord,
private void flushIfNeeded(Boolean force) {
if (force || numOfCDCRecordsInMemory.get() * averageCDCRecordSize >= maxBlockSize) {
try {
List<HoodieRecord> records = cdcData.values().stream()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values has risk of OOM excepion, might need an improvement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, will have a deeper look.

.map(record -> {
try {
return new HoodieAvroIndexedRecord(record.getInsertValue(cdcSchema).get());
} catch (IOException e) {
throw new HoodieIOException("Failed to get cdc record", e);
}
}).collect(Collectors.toList());

ArrayList<HoodieRecord> records = new ArrayList<>();
Iterator<HoodieAvroPayload> recordIter = cdcData.iterator();
while (recordIter.hasNext()) {
HoodieAvroPayload record = recordIter.next();
try {
records.add(new HoodieAvroIndexedRecord(record.getInsertValue(cdcSchema).get()));
} catch (IOException e) {
throw new HoodieIOException("Failed to get cdc record", e);
}
}
HoodieLogBlock block = new HoodieCDCDataBlock(records, cdcDataBlockHeader, keyField);
AppendResult result = cdcWriter.appendBlocks(Collections.singletonList(block));

Expand Down
Loading