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

make load hive table more robust #1687

Conversation

wg1026688210
Copy link
Contributor

@wg1026688210 wg1026688210 commented Oct 29, 2020

Fixes #1688

  1. we will seek previous_metadata_location when it occurs File Not Found seek from metadata_location of hive table properties
    2 if we used previous_metadata_location on freshing operation ,we will set it to metadata_location in case of both metadataLocation no found when next fresh

@wg1026688210 wg1026688210 changed the title make hive table commit more robust make load hive table more robust Oct 29, 2020
}

protected void refreshFromMetadataLocation(String newLocation, Predicate<Exception> shouldRetry,
int numRetries) {
protected boolean refreshFromMetadataLocation(
Copy link
Member

Choose a reason for hiding this comment

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

iceberg style is to put the new line only before the arguments that don't fit within the line width. So

foo( x, y,
  z)

Not

foo (x,
 y, 
 z)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@RussellSpitzer
Copy link
Member

I have some general concerns before looking more closely, one thing that this PR would do is double the time to failure on misconfiguration which is already quite long. I'm also a little confused about the use case for this PR, are the two locations both equally valid? It seems like we don't wouldn't normally want to fall back to different location?

@wg1026688210
Copy link
Contributor Author

hi~ @RussellSpitzer thanks for your concerns .
I do some improvments on trying previous_location use quite a long time on a new commit .
The parsing metadata retry will stop when it throws NotFoundException.

about the use case for this PR
I found the metadata_location file was deleted when commit fail as I mentioned in #1688 ,
but the metadata_location property of the hive table still became the metadata_location which is deleted.
Flink job fail to restart from checkpoint all the time due to the deleted file

if (threw) {
// if anything went wrong, clean up the uncommitted metadata file
io().deleteFile(newMetadataLocation);
}

I want to make a improvment that trying the previous_metadata_location only if geting the metadata_location throws NotFoundException, and if the metadata_location is no found , I will set the previous_metadata_location value to it in case of both metadata_location are not found.

2.the improvment of trying previous_location use quite a long time
if (refreshFromMetadataLocation(metadataLocation, previousMetadataLocation) && table != null) {
Map<String, String> parameters = table.getParameters();
parameters.put(METADATA_LOCATION_PROP, previousMetadataLocation);
persistTable(table, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

This introduces a write operation in the Iceberg read path of a table. I feel that it is not a good idea for readers to modify table metadata in the metastore. Would it be okay to not try to fix the table during reads? The readers can still probably use the previousMetadataLocation for loads. To solve the issue you see in #1688 would it better if the writer itself fixes the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Committing this change introduces a correctness problem. I don't think this should be committed. It is not safe to automatically roll back if there is a problem loading the current metadata file because the changes in the current metadata file are lost.

There are cases where the current metadata file may not be found. The S3A file system may throw NotFoundException because of negative caching in S3, even though the metadata file exists. If that happens, then this would silently roll back anything committed in the current metadata. There are other cases where this may happen as well and we simply don't know why the current metadata file was deleted. Assuming a specific cause is not a viable solution.

The problem in #1688 is that the Hive table was updated, but the operation appeared to fail on the client. The client deletes the metadata file from the commit attempt so that the commit cannot be accidentally successful (the case you hit) because the client will throw an exception that will very likely result in a retry. For example, Flink appending files will keep trying to append the same files.

I think the right solution to the problem is to improve the handling in the commit path, not the read path. The commit path can load the table again and check whether the metadata file is the one it attempted to commit. If it is, then it can return success instead of deleting the metadata file.

@shardulm94 thanks for your suggestions .I'll try some improvments on writing.

@rdblue
Copy link
Contributor

rdblue commented Nov 1, 2020

Committing this change introduces a correctness problem. I don't think this should be committed. It is not safe to automatically roll back if there is a problem loading the current metadata file because the changes in the current metadata file are lost.

There are cases where the current metadata file may not be found. The S3A file system may throw NotFoundException because of negative caching in S3, even though the metadata file exists. If that happens, then this would silently roll back anything committed in the current metadata. There are other cases where this may happen as well and we simply don't know why the current metadata file was deleted. Assuming a specific cause is not a viable solution.

The problem in #1688 is that the Hive table was updated, but the operation appeared to fail on the client. The client deletes the metadata file from the commit attempt so that the commit cannot be accidentally successful (the case you hit) because the client will throw an exception that will very likely result in a retry. For example, Flink appending files will keep trying to append the same files.

I think the right solution to the problem is to improve the handling in the commit path, not the read path. The commit path can load the table again and check whether the metadata file is the one it attempted to commit. If it is, then it can return success instead of deleting the metadata file.

@wg1026688210
Copy link
Contributor Author

Committing this change introduces a correctness problem. I don't think this should be committed. It is not safe to automatically roll back if there is a problem loading the current metadata file because the changes in the current metadata file are lost.

There are cases where the current metadata file may not be found. The S3A file system may throw NotFoundException because of negative caching in S3, even though the metadata file exists. If that happens, then this would silently roll back anything committed in the current metadata. There are other cases where this may happen as well and we simply don't know why the current metadata file was deleted. Assuming a specific cause is not a viable solution.

The problem in #1688 is that the Hive table was updated, but the operation appeared to fail on the client. The client deletes the metadata file from the commit attempt so that the commit cannot be accidentally successful (the case you hit) because the client will throw an exception that will very likely result in a retry. For example, Flink appending files will keep trying to append the same files.

I think the right solution to the problem is to improve the handling in the commit path, not the read path. The commit path can load the table again and check whether the metadata file is the one it attempted to commit. If it is, then it can return success instead of deleting the metadata file.

thanks @rdblue ,I will add some retry on commit and try checking whether the metadata file is the one it attempted to commit before deleting the metadata file .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

iceberg flink sink job can't restart due to metadata location not found
4 participants