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-5968] Fix global index duplicate and handle custom payload when update partition #8490

Merged
merged 15 commits into from
May 5, 2023

Conversation

xushiyan
Copy link
Member

Change Logs

When using global index (bloom or simple), and update partition is set to true. There is a chance where record is in p1 at the beginning, and later updated to p2, when updating to p3 and compaction not yet happened, global index joined both old versions of the record in p1 and p2, and tagged 2 records to insert to p3. This sort of duplicates will reside in the dataset and won't be reconciled unless manually dedup the table.

When records are inserted into new partitions, existing logic does not honor custom payload, which should be handled by record merger API.

Impact

Global index will load fileslice to perform merge and tagging, which slows down the whole process if a lot partition updates happen.

Risk level

High.

  • End to end testing and UT.

Documentation Update

  • New config hoodie.global.index.reconcile.parallelism

Contributor's checklist

  • Read through contributor's guide
  • Change Logs and Impact were stated clearly
  • Adequate tests were added if applicable
  • CI passed

@xushiyan xushiyan marked this pull request as draft April 18, 2023 16:39
@xushiyan
Copy link
Member Author

More code clean up needed

@xushiyan xushiyan force-pushed the HUDI-5968-fix-global-index-dup-2 branch 2 times, most recently from dbe76d5 to df20633 Compare April 24, 2023 05:28
@xushiyan xushiyan marked this pull request as ready for review April 24, 2023 05:39
@xushiyan xushiyan force-pushed the HUDI-5968-fix-global-index-dup-2 branch from 991afee to f5ebd44 Compare April 24, 2023 05:48
@vinothchandar vinothchandar added release-0.14.0 priority:critical production down; pipelines stalled; Need help asap. labels Apr 25, 2023
@nsivabalan
Copy link
Contributor

so, #8344 is not valid anymore ?

@nsivabalan
Copy link
Contributor

do you think we should do the snapshot read only when updatePartitionPath is set to true and avoid when its set to false.
I am inclined towards leave it uniform(and not have two code paths). but just bringing up a point if we feel we really need to avoid the overhead if not required.

@xushiyan xushiyan force-pushed the HUDI-5968-fix-global-index-dup-2 branch from f5ebd44 to 85dd094 Compare May 2, 2023 08:48
@xushiyan xushiyan requested a review from nsivabalan May 2, 2023 17:54
HoodieData<HoodieRecord<R>> newRecords = taggedHoodieRecords.filter(p -> !p.getRight().isPresent()).map(Pair::getLeft);
// the records tagged to existing base files
HoodieData<HoodieRecord<R>> updatingRecords = taggedHoodieRecords.filter(p -> p.getRight().isPresent()).map(Pair::getLeft)
.distinctWithKey(HoodieRecord::getRecordKey, config.getGlobalIndexReconcileParallelism());
Copy link
Contributor

Choose a reason for hiding this comment

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

I see we are doing distinctWithKey here. So, we assume that records may not be duplicated at all?
what happens if there are duplicates already. for eg, some one ingested same batch of data w/ bulk_insert. may be we need to revisit overall end to end flow for this scenario of how our global index will work.
but trying to think through how it might surface after this fix?

Copy link
Contributor

Choose a reason for hiding this comment

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

we may not require to fix anything as such. but wanted to see what will be outcome.

Copy link
Member Author

Choose a reason for hiding this comment

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

the tagged records at this point will contain dups in case of last write updated partition and inserted a new record to new partition, and compaction has not happened yet. The first look up will still get 2 records due to join only with base files.


private Option<FileSlice> getLatestFileSlice() {
if (nonEmpty(instantTime)
&& hoodieTable.getMetaClient().getCommitsTimeline().filterCompletedInstants().lastInstant().isPresent()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move these checks to constructor.

@apache apache deleted a comment from hudi-bot May 4, 2023
}

/**
* Utility method to convert bytes to HoodieRecord using schema and payload class.
*/
private static HoodieRecord<InternalRow> convertToHoodieSparkRecord(StructType structType, HoodieSparkRecord record, Pair<String, String> recordKeyPartitionPathFieldPair,
boolean withOperationField, Option<String> partitionName) {
boolean withOperationField, Option<String> partitionName, Option<StructType> structTypeWithoutMetaFields) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you enhance the java doc on when and how to use this method. for eg, when should the last arg be set?
or should we introduce overloaded method.

@nsivabalan
Copy link
Contributor

MergeHandle needs some thorough testing. can you file a follow up ticket for that

Copy link
Contributor

@nsivabalan nsivabalan left a comment

Choose a reason for hiding this comment

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

Once CI is green, we can go ahead!

@hudi-bot
Copy link

hudi-bot commented May 5, 2023

CI report:

Bot commands @hudi-bot supports the following commands:
  • @hudi-bot run azure re-run the last Azure build

@xushiyan xushiyan merged commit cabcb2b into apache:master May 5, 2023
17 checks passed
@xushiyan xushiyan deleted the HUDI-5968-fix-global-index-dup-2 branch May 5, 2023 13:28
yihua pushed a commit to yihua/hudi that referenced this pull request May 15, 2023
yihua pushed a commit to yihua/hudi that referenced this pull request May 15, 2023
String key = record.getRecordKey();
if (deltaRecordMap.containsKey(key)) {
deltaRecordKeys.remove(key);
Option<Pair<HoodieRecord, Schema>> mergeResult = recordMerger
Copy link
Member Author

Choose a reason for hiding this comment

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

this merge result needs to be wrapped back to the original payload so that caller won't have to do it. fixed in #8736

Comment on lines +267 to +269
if (incoming.getData() instanceof EmptyHoodieRecordPayload) {
// incoming is a delete: force tag the incoming to the old partition
return Collections.singletonList(getTaggedRecord(incoming, Option.of(existing.getCurrentLocation()))).iterator();
Copy link
Member Author

Choose a reason for hiding this comment

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

this needs to use isDelete() api to check and incoming's key need to be overwritten to the existing's key. fixed in #8736

HoodieRecord incomingWithMetaFields = incomingPrepended
.wrapIntoHoodieRecordPayloadWithParams(writeSchema, config.getProps(), Option.empty(), config.allowOperationMetadataField(), Option.empty(), false, Option.empty());
Option<Pair<HoodieRecord, Schema>> mergeResult = config.getRecordMerger()
.merge(existing, existingSchema, incomingWithMetaFields, writeSchemaWithMetaFields, config.getProps());
Copy link
Contributor

Choose a reason for hiding this comment

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

The record merger is instantiated for each time, will cause unnecessary onverhead.

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch! saw it's been fixed now

@loukey-lj
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:critical production down; pipelines stalled; Need help asap. release-0.14.0
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

6 participants