wecharyu commented on code in PR #10886:
URL: https://github.com/apache/hudi/pull/10886#discussion_r1572163511
##########
hudi-common/src/main/java/org/apache/hudi/common/model/HoodiePartitionMetadata.java:
##########
@@ -94,36 +96,32 @@ public int getPartitionDepth() {
/**
* Write the metadata safely into partition atomically.
*/
- public void trySave(int taskPartitionId) {
+ public void trySave() throws HoodieIOException {
String extension = getMetafileExtension();
- StoragePath tmpMetaPath =
- new StoragePath(partitionPath,
HoodiePartitionMetadata.HOODIE_PARTITION_METAFILE_PREFIX + "_" +
taskPartitionId + extension);
- StoragePath metaPath = new StoragePath(partitionPath,
HoodiePartitionMetadata.HOODIE_PARTITION_METAFILE_PREFIX + extension);
- boolean metafileExists = false;
+ StoragePath metaPath = new StoragePath(
+ partitionPath,
HoodiePartitionMetadata.HOODIE_PARTITION_METAFILE_PREFIX + extension);
- try {
- metafileExists = storage.exists(metaPath);
- if (!metafileExists) {
- // write to temporary file
- writeMetafile(tmpMetaPath);
- // move to actual path
- storage.rename(tmpMetaPath, metaPath);
- }
- } catch (IOException ioe) {
- LOG.warn("Error trying to save partition metadata (this is okay, as long
as at least 1 of these succeeded), "
- + partitionPath, ioe);
- } finally {
- if (!metafileExists) {
- try {
- // clean up tmp file, if still lying around
- if (storage.exists(tmpMetaPath)) {
- storage.deleteFile(tmpMetaPath);
+ // This retry mechanism enables an exit-fast in metaPath exists check,
which avoid the
+ // tasks failures when there are two or more tasks trying to create the
same metaPath.
+ RetryHelper<Void, HoodieIOException> retryHelper = new RetryHelper(1000,
3, 1000, HoodieIOException.class.getName())
+ .tryWith(() -> {
+ if (!storage.exists(metaPath)) {
+ if (format.isPresent()) {
+ StoragePath tmpMetaPath = new StoragePath(
Review Comment:
Done.
--
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]