voonhous opened a new pull request, #21107:
URL: https://github.com/apache/hudi/pull/21107
### Describe the issue this Pull Request addresses
Closes #21104. Part of #20449.
Enabling the record index on a bootstrapped table failed in the write that
initializes it:
```
HoodieMetadataException: Failed to create metadata payload for record index.
Instant time parsing for 00000000000001 failed
```
Bootstrapped file groups have a bootstrap instant as their base instant
time: `00000000000001` for METADATA_ONLY, `00000000000002` for FULL_RECORD. The
record index stores the instant time of an entry as epoch millis, and
`HoodieMetadataPayload#parseRecordIndexInstantTime` parsed it as a date, which
fails for these instants. This affects the global and the partitioned record
index, COW and MOR. It is not a regression of #18965: every release with the
record index (0.14.0 to 1.2.1) parses the base instant time of the file slice
the same way.
With the record index fixed, the secondary index failed next on
METADATA_ONLY bootstrapped tables: `Field 'rider' not found in schema:
[_hoodie_commit_time, ..., _hoodie_file_name]`.
`SecondaryIndexRecordGenerationUtils#readSecondaryKeysFromFileSlices` took the
reader schema from the footer of the base file, which for a bootstrapped file
group is a skeleton file with only the meta columns.
### Summary and Changelog
- `HoodieMetadataPayload#parseRecordIndexInstantTime` stores the special
instants (`TimelineUtils.NOT_PARSABLE_TIMESTAMPS`: `00000000000000`,
`00000000000001`, `00000000000002`) as their numeric value, 0, 1 and 2 ms. This
is the value `TimelineUtils#parseDateFromInstantTimeSafely` already gives them.
- New `HoodieMetadataPayload#formatRecordIndexInstantTime` is the inverse.
`HoodieTableMetadataUtil#getLocationFromRecordIndexInfo` uses it, so an entry
of a bootstrapped record reads back with the bootstrap instant, not
`19700101000000001`. No real instant is within milliseconds of the epoch, so
the values are unambiguous. Real instants decode as before.
- The fix is in the shared parse, so it covers record index initialization,
the update path (for example the bootstrap commit itself when the record index
is enabled at bootstrap time), and the deprecated base file path.
- `SecondaryIndexRecordGenerationUtils#readSecondaryKeysFromFileSlices` uses
the table schema for a base file with a bootstrap source file, as it does for
file slices without a base file. The file group reader then merges the skeleton
file with its source file. Other base files still use their footer schema.
- Tests:
-
`TestHoodieTableMetadataUtil#testRecordIndexEntryRoundTripsBootstrapInstant`:
both bootstrap instants parse to their numeric value and survive an Avro round
trip back to the same instant, in UTC and Asia/Kolkata. On master it fails with
`Instant time parsing for 00000000000001 failed`.
- `TestDataSourceForBootstrap#testRecordIndexOnBootstrappedTable`,
parameterized over COW and MOR, METADATA_ONLY and FULL_RECORD bootstrap, global
and partitioned record index. After the bootstrap, an upsert with the record
index enabled initializes it. The test checks that every bootstrapped key is
indexed with its partition, file group and bootstrap instant. A second upsert
of another bootstrapped key, tagged by the index, must update in place: the row
count stays the same, there are no duplicate keys, both keys read back updated,
and every key stays in its file group. On master every case fails with `Failed
to instantiate Metadata table`, caused by the parse error above.
- Two more cases (COW and MOR, METADATA_ONLY, global record index) also
create a secondary index on `rider` in that write. They check lookups with data
skipping on and off. Without the secondary index change they fail with `Field
'rider' not found in schema`.
### Impact
The record index and the secondary index can be enabled on bootstrapped
tables. Before, the write that enabled them failed, so no table has entries
written in the old format. The read side change only affects stored values of 0
to 2 ms, which no real instant produces.
### Risk Level
low
### Documentation Update
none
### Contributor's checklist
- [x] Read through [contributor's
guide](https://hudi.apache.org/contribute/how-to-contribute)
- [x] Enough context is provided in the sections above
- [x] Adequate tests were added if applicable
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]