Skip to content

Commit

Permalink
HDDS-11969. getFilechecksum() API fails if checksum type is NONE. (ap…
Browse files Browse the repository at this point in the history
  • Loading branch information
sadanand48 authored Jan 9, 2025
1 parent 80dc87a commit a4f4821
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,16 @@ public ChecksumCombineMode getChecksumCombineMode() {
try {
return ChecksumCombineMode.valueOf(checksumCombineMode);
} catch (IllegalArgumentException iae) {
LOG.warn("Bad checksum combine mode: {}. Using default {}",
checksumCombineMode,
ChecksumCombineMode.COMPOSITE_CRC.name());
return ChecksumCombineMode.valueOf(
ChecksumCombineMode.COMPOSITE_CRC.name());
LOG.warn("Bad checksum combine mode: {}.",
checksumCombineMode);
return null;
}
}

public void setChecksumCombineMode(String checksumCombineMode) {
this.checksumCombineMode = checksumCombineMode;
}

public void setEcReconstructStripeReadPoolLimit(int poolLimit) {
this.ecReconstructStripeReadPoolLimit = poolLimit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.hadoop.hdds.client.StandaloneReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.scm.OzoneClientConfig;
import org.apache.hadoop.hdds.utils.IOUtils;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.OzoneConfigKeys;
Expand Down Expand Up @@ -1581,40 +1582,42 @@ public void testCreateKeyShouldUseRefreshedBucketReplicationConfig()
Configuration conf = new OzoneConfiguration(cluster.getConf());
conf.set(FS_DEFAULT_NAME_KEY, rootPath);
// Set the number of keys to be processed during batch operate.
OzoneFileSystem o3FS = (OzoneFileSystem) FileSystem.get(conf);
try (FileSystem fileSystem = FileSystem.get(conf)) {
OzoneFileSystem o3FS = (OzoneFileSystem) fileSystem;

//Let's reset the clock to control the time.
((BasicOzoneClientAdapterImpl) (o3FS.getAdapter())).setClock(testClock);
//Let's reset the clock to control the time.
((BasicOzoneClientAdapterImpl) (o3FS.getAdapter())).setClock(testClock);

createKeyAndAssertKeyType(bucket, o3FS, new Path(rootPath, "key"),
ReplicationType.RATIS);
createKeyAndAssertKeyType(bucket, o3FS, new Path(rootPath, "key"),
ReplicationType.RATIS);

bucket.setReplicationConfig(new ECReplicationConfig("rs-3-2-1024k"));
bucket.setReplicationConfig(new ECReplicationConfig("rs-3-2-1024k"));

//After changing the bucket policy, it should create ec key, but o3fs will
// refresh after some time. So, it will be sill old type.
createKeyAndAssertKeyType(bucket, o3FS, new Path(rootPath, "key1"),
ReplicationType.RATIS);
//After changing the bucket policy, it should create ec key, but o3fs will
// refresh after some time. So, it will be sill old type.
createKeyAndAssertKeyType(bucket, o3FS, new Path(rootPath, "key1"),
ReplicationType.RATIS);

testClock.fastForward(300 * 1000 + 1);
testClock.fastForward(300 * 1000 + 1);

//After client bucket refresh time, it should create new type what is
// available on bucket at that moment.
createKeyAndAssertKeyType(bucket, o3FS, new Path(rootPath, "key2"),
ReplicationType.EC);
//After client bucket refresh time, it should create new type what is
// available on bucket at that moment.
createKeyAndAssertKeyType(bucket, o3FS, new Path(rootPath, "key2"),
ReplicationType.EC);

// Rechecking the same steps with changing to Ratis again to check the
// behavior is consistent.
bucket.setReplicationConfig(
RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.THREE));
// Rechecking the same steps with changing to Ratis again to check the
// behavior is consistent.
bucket.setReplicationConfig(RatisReplicationConfig.getInstance(
HddsProtos.ReplicationFactor.THREE));

createKeyAndAssertKeyType(bucket, o3FS, new Path(rootPath, "key3"),
ReplicationType.EC);
createKeyAndAssertKeyType(bucket, o3FS, new Path(rootPath, "key3"),
ReplicationType.EC);

testClock.fastForward(300 * 1000 + 1);
testClock.fastForward(300 * 1000 + 1);

createKeyAndAssertKeyType(bucket, o3FS, new Path(rootPath, "key4"),
ReplicationType.RATIS);
createKeyAndAssertKeyType(bucket, o3FS, new Path(rootPath, "key4"),
ReplicationType.RATIS);
}
}

private void createKeyAndAssertKeyType(OzoneBucket bucket,
Expand Down Expand Up @@ -1668,9 +1671,11 @@ public void testDeleteRootWithTrash() throws IOException {
OzoneConfiguration conf2 = new OzoneConfiguration(cluster.getConf());
conf2.setClass("fs.trash.classname", TrashPolicyDefault.class,
TrashPolicy.class);
Trash trashPolicyDefault = new Trash(conf2);
assertThrows(IOException.class,
() -> trashPolicyDefault.moveToTrash(root));
try (FileSystem fs = FileSystem.get(conf2)) {
Trash trashPolicyDefault = new Trash(fs, conf2);
assertThrows(IOException.class,
() -> trashPolicyDefault.moveToTrash(root));
}
}

/**
Expand Down Expand Up @@ -2275,6 +2280,24 @@ void testFileSystemWithObjectStoreLayout() throws IOException {
}
}

@Test
public void testGetFileChecksumWithInvalidCombineMode() throws IOException {
final String root = "/root";
Path rootPath = new Path(fs.getUri().toString() + root);
fs.mkdirs(rootPath);
Path file = new Path(fs.getUri().toString() + root
+ "/dummy");
ContractTestUtils.touch(fs, file);
OzoneClientConfig clientConfig = cluster.getConf().getObject(OzoneClientConfig.class);
clientConfig.setChecksumCombineMode("NONE");
OzoneConfiguration conf = cluster.getConf();
conf.setFromObject(clientConfig);
conf.setBoolean("fs.o3fs.impl.disable.cache", true);
try (FileSystem fileSystem = FileSystem.get(conf)) {
assertNull(fileSystem.getFileChecksum(file));
}
}

private String getCurrentUser() {
try {
return UserGroupInformation.getCurrentUser().getShortUserName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,13 @@ public FileChecksum getFileChecksum(String keyName, long length)
throws IOException {
OzoneClientConfig.ChecksumCombineMode combineMode =
config.getObject(OzoneClientConfig.class).getChecksumCombineMode();

if (combineMode == null) {
return null;
}
return OzoneClientUtils.getFileChecksumWithCombineMode(
volume, bucket, keyName,
length, combineMode, ozoneClient.getObjectStore().getClientProxy());

length, combineMode,
ozoneClient.getObjectStore().getClientProxy());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1298,14 +1298,16 @@ public FileChecksum getFileChecksum(String keyName, long length)
throws IOException {
OzoneClientConfig.ChecksumCombineMode combineMode =
config.getObject(OzoneClientConfig.class).getChecksumCombineMode();

if (combineMode == null) {
return null;
}
OFSPath ofsPath = new OFSPath(keyName, config);

OzoneVolume volume = objectStore.getVolume(ofsPath.getVolumeName());
OzoneBucket bucket = getBucket(ofsPath, false);
return OzoneClientUtils.getFileChecksumWithCombineMode(
volume, bucket, ofsPath.getKeyName(),
length, combineMode, ozoneClient.getObjectStore().getClientProxy());
length, combineMode,
ozoneClient.getObjectStore().getClientProxy());

}

Expand Down

0 comments on commit a4f4821

Please sign in to comment.