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

Allow overwrites during rename. This is required for doing atomic puts. #210

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

Apteryx0
Copy link
Contributor

To implement atomic writes/puts, you need to write to a temporary file (non-atomic operation) and then rename the temporary file to the destination in a single (atomic) operation. Since rename does not currently support this (i.e. if the destination file already exists rename will fail and thus a delete and then rename is required, which is not atomic), added an option to pass the renameoptions="overwrite" to the WebHDFS rename API. This is received by this code here: https://github.com/apache/hadoop/blob/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/web/resources/NamenodeWebHdfsMethods.java#L749

Which in turn calls: https://github.com/apache/hadoop/blob/trunk/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/ClientProtocol.java#L545

Which is documented as being atomic.

Haven't updated or run any hdfs tests - this is tested and works though in my own code base.

@mtth mtth merged commit 039a7f4 into mtth:master Sep 24, 2024
6 checks passed
@mtth
Copy link
Owner

mtth commented Sep 24, 2024

Thanks @Apteryx0.

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.

2 participants