-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-6344] Flink MDT bulk_insert for initial commit #8914
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ | |
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
|
|
@@ -107,6 +108,17 @@ protected void initRegistry() { | |
|
|
||
| @Override | ||
| protected void commit(String instantTime, Map<MetadataPartitionType, HoodieData<HoodieRecord>> partitionRecordsMap) { | ||
| doCommit(instantTime, partitionRecordsMap, false); | ||
| } | ||
|
|
||
| @Override | ||
| protected void bulkCommit(String instantTime, MetadataPartitionType partitionType, HoodieData<HoodieRecord> records, int fileGroupCount) { | ||
| Map<MetadataPartitionType, HoodieData<HoodieRecord>> partitionRecordsMap = new HashMap<>(); | ||
| partitionRecordsMap.put(partitionType, records); | ||
| doCommit(instantTime, partitionRecordsMap, true); | ||
| } | ||
|
|
||
| private void doCommit(String instantTime, Map<MetadataPartitionType, HoodieData<HoodieRecord>> partitionRecordsMap, boolean isInitializing) { | ||
| ValidationUtils.checkState(metadataMetaClient != null, "Metadata table is not fully initialized yet."); | ||
| HoodieData<HoodieRecord> preppedRecords = prepRecords(partitionRecordsMap); | ||
| List<HoodieRecord> preppedRecordList = preppedRecords.collectAsList(); | ||
|
|
@@ -149,9 +161,9 @@ protected void commit(String instantTime, Map<MetadataPartitionType, HoodieData< | |
| writeClient.getHeartbeatClient().start(instantTime); | ||
| } | ||
|
|
||
| List<WriteStatus> statuses = preppedRecordList.size() > 0 | ||
| ? writeClient.upsertPreppedRecords(preppedRecordList, instantTime) | ||
| : Collections.emptyList(); | ||
| List<WriteStatus> statuses = isInitializing | ||
| ? writeClient.bulkInsertPreppedRecords(preppedRecordList, instantTime, Option.empty()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. major reason to use bulkInsert is that, we use a custom partitioner based on file group and so the spark tasks will be such that, each spark task will get records pertaining to one file group of interest. we can try to incorporate that as well. esply with RLI, record mapping to file groups is based on hash. So, we can't have diff set of records routed to one spark task.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Flink does not support flexible partitioner like Spark do, but we can still get some benefits because writing Hfiles directly for initilization of MDT is more efficient. For example, when user enable the MDT for a existing table and there are plenty of metadata records to bootstrap with.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. records to file group mapping is deterministic and we can have only one file written per file group. for eg, if we instanttiate col stats with 4 file groups, we should spin up 4 spark tasks and each spark task should get records pertaining to the file group of interest (remember records are mapped to file group based on hashing). So, if one spark task gets records for all file groups, then we might end up w/ n*m files (where n is no of spark tasks and m is number of file groups) which may not work. we need only m files created and m spark tasks should spin up where each spark tasks writes to just 1 file group.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What the spark partitioner does is to repartition the records by the file group (index) to avoid concurrent write from different tasks into one file group. Flink already does that, even though it is parallelized in single JVM process.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if its already taken care of, then we are good |
||
| : writeClient.upsertPreppedRecords(preppedRecordList, instantTime); | ||
| // flink does not support auto-commit yet, also the auto commit logic is not complete as BaseHoodieWriteClient now. | ||
| writeClient.commit(instantTime, statuses, Option.empty(), HoodieActiveTimeline.DELTA_COMMIT_ACTION, Collections.emptyMap()); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * 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.table.action.commit; | ||
|
|
||
| import org.apache.hudi.client.WriteStatus; | ||
| import org.apache.hudi.common.engine.HoodieEngineContext; | ||
| import org.apache.hudi.common.model.HoodieRecord; | ||
| import org.apache.hudi.common.model.WriteOperationType; | ||
| import org.apache.hudi.config.HoodieWriteConfig; | ||
| import org.apache.hudi.io.HoodieWriteHandle; | ||
| import org.apache.hudi.table.HoodieTable; | ||
| import org.apache.hudi.table.action.HoodieWriteMetadata; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Flink insert prepped commit action executor. | ||
| */ | ||
| public class FlinkBulkInsertPreppedCommitActionExecutor<T> extends BaseFlinkCommitActionExecutor<T> { | ||
|
|
||
| private final List<HoodieRecord<T>> preppedRecords; | ||
|
|
||
| public FlinkBulkInsertPreppedCommitActionExecutor(HoodieEngineContext context, | ||
| HoodieWriteHandle<?, ?, ?, ?> writeHandle, | ||
| HoodieWriteConfig config, HoodieTable table, | ||
| String instantTime, List<HoodieRecord<T>> preppedRecords) { | ||
| super(context, writeHandle, config, table, instantTime, WriteOperationType.BULK_INSERT_PREPPED); | ||
| this.preppedRecords = preppedRecords; | ||
| } | ||
|
|
||
| @Override | ||
| public HoodieWriteMetadata<List<WriteStatus>> execute() { | ||
| return super.execute(preppedRecords); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why setting instantTime to
I? Should it not beinstantTimepassed to the method?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flink relies on this flag to distinguish which write handle to use. A little hacky but it's the minimum change right now.