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

HDDS-10770. [Hsync] Allow overwrite hsynced file #6603

Merged
merged 6 commits into from
May 9, 2024

Conversation

ChenSammi
Copy link
Contributor

@ChenSammi ChenSammi commented Apr 28, 2024

What changes were proposed in this pull request?

Allow overwritten a hsynced file, without calling data loss.

image

The overall rule is
a. the later commit overwrites early commit
b. avoid mutual overwrites. Once a file is overwritten, it cannot later overwritten others again.
To support this, when a hsynced file is overwritten, it will have "overwritten" metadata as a flag. All following allocate block, further hsync or commit of this file will fail.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-10770

How was this patch tested?

new integration tests

@ChenSammi ChenSammi changed the title Hdds 10770 HDDS-10770. [Hsync] Allow overwrite hsynced file Apr 28, 2024
sb.append(" ");
sb.append("length ").append(length);
sb.append(" ");
sb.append("keyOffset ").append(keyOffset);
Copy link
Contributor

Choose a reason for hiding this comment

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

should it print offset as well?

Comment on lines 1018 to 1024
try {
outputStream1.write(newData);
} catch (IOException e) {
assertTrue(e.getCause() instanceof OMException);
assertTrue(((OMException)e.getCause()).getResult() == OMException.ResultCodes.KEY_NOT_FOUND);
assertTrue(e.getMessage().contains("already deleted/overwritten"));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If exception is expected here, use assertThrows()

Suggested change
try {
outputStream1.write(newData);
} catch (IOException e) {
assertTrue(e.getCause() instanceof OMException);
assertTrue(((OMException)e.getCause()).getResult() == OMException.ResultCodes.KEY_NOT_FOUND);
assertTrue(e.getMessage().contains("already deleted/overwritten"));
}
IOException e = assertThrows(IOException.class,
() -> outputStream1.write(newData));
assertTrue(e.getCause() instanceof OMException);
assertTrue(((OMException)e.getCause()).getResult() == OMException.ResultCodes.KEY_NOT_FOUND);
assertTrue(e.getMessage().contains("already deleted/overwritten"));

}
// commit overwritten hsync key, should fail
try {
outputStream1.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

here, too

@ChenSammi
Copy link
Contributor Author

@jojochuang , thanks for the review. The comments are addressed in a new patch.

Copy link
Contributor

@ashishkumar50 ashishkumar50 left a comment

Choose a reason for hiding this comment

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

@ChenSammi Thanks for the patch, Overall LGTM.

@@ -369,7 +390,7 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn

omClientResponse = new OMKeyCommitResponse(omResponse.build(),
omKeyInfo, dbOzoneKey, dbOpenKey, omBucketInfo.copyObject(),
oldKeyVersionsToDeleteMap, isHSync, newOpenKeyInfo);
oldKeyVersionsToDeleteMap, isHSync, newOpenKeyInfo, dbOpenKeyToDeleteKey, openKeyToDelete);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ignore passing dbOpenKeyToDeleteKey, can be retrieved using openKeyToDelete.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ashishkumar50 , thanks for the review. I would prefer keep passing the dbOpenKeyToDeleteKey.

if (openKeyInfo.getMetadata().containsKey(OzoneConsts.DELETED_HSYNC_KEY)) {
throw new OMException("Open Key " + openKeyName + " is already deleted",
if (openKeyInfo.getMetadata().containsKey(OzoneConsts.DELETED_HSYNC_KEY) ||
openKeyInfo.getMetadata().containsKey(OzoneConsts.OVERWRITTEN_HSYNC_KEY)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

OVERWRITTEN_HSYNC_KEY is added during commit/hsync. If hsync is not called and allocate block request is called from client, in the corner case it will allocate block for both clients. Doesn't impact but an extra block will be allocated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This case cannot be avoided due to the invisibility of openKey.

@@ -225,6 +225,7 @@ private RecoverLeaseResponse doWork(OzoneManager ozoneManager,
throw new OMException("Open Key " + keyName + " is already deleted",
KEY_NOT_FOUND);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unchanged file.

Copy link
Contributor

@ashishkumar50 ashishkumar50 left a comment

Choose a reason for hiding this comment

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

@ChenSammi Thanks, LGTM +1.

@ChenSammi ChenSammi merged commit d7e5b3a into apache:HDDS-7593 May 9, 2024
38 checks passed
@ChenSammi
Copy link
Contributor Author

Thanks @ashishkumar50 and @jojochuang for the code review.

jojochuang pushed a commit to jojochuang/ozone that referenced this pull request May 29, 2024
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.

3 participants