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-12094. Update BasicKeyInfo to include isFile payload #7740

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public BasicKeyInfo getProtobuf() {
.setDataSize(dataSize)
.setCreationTime(creationTime)
.setModificationTime(modificationTime)
.setIsFile(isFile)
.setType(replicationConfig.getReplicationType());
if (ownerName != null) {
builder.setOwnerName(ownerName);
Expand Down Expand Up @@ -228,7 +229,7 @@ public static BasicOmKeyInfo getFromProtobuf(BasicKeyInfo basicKeyInfo,
basicKeyInfo.getFactor(),
basicKeyInfo.getEcReplicationConfig()))
.setETag(basicKeyInfo.getETag())
.setIsFile(!keyName.endsWith("/"))
.setIsFile(basicKeyInfo.getIsFile())
.setOwnerName(basicKeyInfo.getOwnerName());

return builder.build();
Expand All @@ -254,7 +255,7 @@ public static BasicOmKeyInfo getFromProtobuf(String volumeName,
basicKeyInfo.getFactor(),
basicKeyInfo.getEcReplicationConfig()))
.setETag(basicKeyInfo.getETag())
.setIsFile(!keyName.endsWith("/"))
.setIsFile(basicKeyInfo.getIsFile())
Copy link
Contributor

Choose a reason for hiding this comment

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

If an old client send a request containing BasicKeyInfo to a new OM, the isFile field will not be set and a file would always be identified as not a file.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ptlrs can you please add test case in hadoop-ozone/dist/src/main/smoketest/compatibility/read.robot?

.setOwnerName(basicKeyInfo.getOwnerName());

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2839,6 +2839,46 @@ public void testListKey()
assertFalse(volABucketBIter.hasNext());
}

@Test
public void testListKeyDirectoriesAreNotFiles()
throws IOException {
Comment on lines +2842 to +2844
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could not add this test to testListKey due to checkstyle limit of 150 lines per method. Created a new test instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to use ParameterizedTest in testListKey to include the NotFile cases you added here?

// Test that directories in multilevel keys are not marked as files

String volumeA = "volume-a-" + RandomStringUtils.randomNumeric(5);
String bucketA = "bucket-a-" + RandomStringUtils.randomNumeric(5);
store.createVolume(volumeA);
OzoneVolume volA = store.getVolume(volumeA);
volA.createBucket(bucketA);
OzoneBucket volAbucketA = volA.getBucket(bucketA);

String keyBaseA = "key-a/";
for (int i = 0; i < 10; i++) {
byte[] value = RandomStringUtils.randomAscii(10240).getBytes(UTF_8);
OzoneOutputStream one = volAbucketA.createKey(
keyBaseA + i + "-" + RandomStringUtils.randomNumeric(5),
value.length, RATIS, ONE,
new HashMap<>());
one.write(value);
one.close();
}

Iterator<? extends OzoneKey> volABucketAIter1 = volAbucketA.listKeys(null);
while (volABucketAIter1.hasNext()) {
OzoneKey key = volABucketAIter1.next();
if (key.getName().endsWith("/")) {
assertFalse(key.isFile(), "Key '" + key.getName() + "' is not a file");
}
}

Iterator<? extends OzoneKey> volABucketAIter2 = volAbucketA.listKeys("key-");
while (volABucketAIter2.hasNext()) {
OzoneKey key = volABucketAIter2.next();
if (key.getName().endsWith("/")) {
assertFalse(key.isFile(), "Key '" + key.getName() + "' is not a file");
}
}
}

@Test
public void testListKeyOnEmptyBucket()
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ message BasicKeyInfo {
optional hadoop.hdds.ECReplicationConfig ecReplicationConfig = 7;
optional string eTag = 8;
optional string ownerName = 9;
optional bool isFile = 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

BasicKeyInfo was added in HDDS-9079 (1.4.0).

}

message DirectoryInfo {
Expand Down
Loading