Skip to content

Commit

Permalink
HDDS-10226. Refactor OMRequestTestUtils.createOmKeyInfo (apache#6184)
Browse files Browse the repository at this point in the history
  • Loading branch information
Galsza authored Feb 8, 2024
1 parent 3d8365f commit 06399b5
Show file tree
Hide file tree
Showing 56 changed files with 483 additions and 537 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hdds.StringUtils;
import org.apache.hadoop.hdds.client.BlockID;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.utils.db.DBStore;
Expand Down Expand Up @@ -61,6 +62,7 @@
import java.util.stream.Stream;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType.STAND_ALONE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

Expand Down Expand Up @@ -295,8 +297,7 @@ private void prepareTable(String tableName, boolean schemaV3)
for (int i = 1; i <= 5; i++) {
String key = "key" + i;
OmKeyInfo value = OMRequestTestUtils.createOmKeyInfo("vol1", "buck1",
key, HddsProtos.ReplicationType.STAND_ALONE,
HddsProtos.ReplicationFactor.ONE);
key, ReplicationConfig.fromProtoTypeAndFactor(STAND_ALONE, HddsProtos.ReplicationFactor.ONE)).build();
keyTable.put(key.getBytes(UTF_8),
value.getProtobuf(ClientVersion.CURRENT_VERSION).toByteArray());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
import org.apache.hadoop.hdds.client.StandaloneReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType;
import org.apache.hadoop.hdds.scm.HddsWhiteboxTestUtils;
import org.apache.hadoop.hdds.scm.HddsTestUtils;
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
Expand Down Expand Up @@ -976,12 +974,11 @@ public void testListStatusWithTableCache() throws Exception {
if (i % 2 == 0) { // Add to DB
OMRequestTestUtils.addKeyToTable(false,
VOLUME_NAME, BUCKET_NAME, prefixKeyInDB + i,
1000L, HddsProtos.ReplicationType.RATIS,
ONE, metadataManager);
1000L, RatisReplicationConfig.getInstance(ONE), metadataManager);
} else { // Add to TableCache
OMRequestTestUtils.addKeyToTableCache(
VOLUME_NAME, BUCKET_NAME, prefixKeyInCache + i,
HddsProtos.ReplicationType.RATIS, ONE,
RatisReplicationConfig.getInstance(ONE),
metadataManager);
}
}
Expand Down Expand Up @@ -1048,13 +1045,12 @@ public void testListStatusWithTableCacheRecursive() throws Exception {
OMRequestTestUtils.addKeyToTable(false,
VOLUME_NAME, BUCKET_NAME,
keyNameDir1Subdir1 + OZONE_URI_DELIMITER + prefixKeyInDB + i,
1000L, HddsProtos.ReplicationType.RATIS,
ONE, metadataManager);
1000L, RatisReplicationConfig.getInstance(ONE), metadataManager);
} else { // Add to TableCache
OMRequestTestUtils.addKeyToTableCache(
VOLUME_NAME, BUCKET_NAME,
keyNameDir1Subdir1 + OZONE_URI_DELIMITER + prefixKeyInCache + i,
HddsProtos.ReplicationType.RATIS, ONE,
RatisReplicationConfig.getInstance(ONE),
metadataManager);
}
}
Expand Down Expand Up @@ -1092,13 +1088,12 @@ public void testListStatusWithDeletedEntriesInCache() throws Exception {
if (i % 2 == 0) {
OMRequestTestUtils.addKeyToTable(false,
VOLUME_NAME, BUCKET_NAME, prefixKey + i,
1000L, HddsProtos.ReplicationType.RATIS,
ONE, metadataManager);
1000L, RatisReplicationConfig.getInstance(ONE), metadataManager);
existKeySet.add(prefixKey + i);
} else {
OMRequestTestUtils.addKeyToTableCache(
VOLUME_NAME, BUCKET_NAME, prefixKey + i,
HddsProtos.ReplicationType.RATIS, ONE,
RatisReplicationConfig.getInstance(ONE),
metadataManager);

String key = metadataManager.getOzoneKey(
Expand Down Expand Up @@ -1446,8 +1441,7 @@ public void testRefreshPipeline() throws Exception {
when(scmClientMock.getContainerClient()).thenReturn(sclProtocolMock);

OmKeyInfo omKeyInfo = OMRequestTestUtils.createOmKeyInfo("v1",
"b1", "k1", ReplicationType.RATIS,
ReplicationFactor.THREE);
"b1", "k1", RatisReplicationConfig.getInstance(THREE)).build();

// Add block to key.
List<OmKeyLocationInfo> omKeyLocationInfoList = new ArrayList<>();
Expand Down Expand Up @@ -1501,8 +1495,7 @@ public void testRefreshPipelineException() throws Exception {
OMPerformanceMetrics metrics = mock(OMPerformanceMetrics.class);

OmKeyInfo omKeyInfo = OMRequestTestUtils.createOmKeyInfo("v1",
"b1", "k1", ReplicationType.RATIS,
ReplicationFactor.THREE);
"b1", "k1", RatisReplicationConfig.getInstance(THREE)).build();

// Add block to key.
List<OmKeyLocationInfo> omKeyLocationInfoList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

package org.apache.hadoop.ozone.om;
import org.apache.hadoop.hdds.client.RatisReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.StorageType;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
Expand All @@ -26,6 +27,7 @@
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
import org.apache.hadoop.hdds.utils.TransactionInfo;
Expand All @@ -49,6 +51,7 @@
import java.io.File;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
Expand All @@ -61,6 +64,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.ONE;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_MPU_EXPIRE_THRESHOLD;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_MPU_EXPIRE_THRESHOLD_DEFAULT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_OPEN_KEY_EXPIRE_THRESHOLD;
Expand Down Expand Up @@ -619,9 +623,10 @@ private void testGetExpiredOpenKeys(BucketLayout bucketLayout)
for (int i = 0; i < numExpiredOpenKeys + numUnexpiredOpenKeys; i++) {
final long creationTime = i < numExpiredOpenKeys ?
expiredOpenKeyCreationTime : Time.now();
final OmKeyInfo keyInfo = OMRequestTestUtils.createOmKeyInfo(volumeName,
bucketName, "expired" + i, HddsProtos.ReplicationType.RATIS,
HddsProtos.ReplicationFactor.ONE, 0L, creationTime);
final OmKeyInfo keyInfo = OMRequestTestUtils.createOmKeyInfo(
volumeName, bucketName, "expired" + i, RatisReplicationConfig.getInstance(ONE))
.setCreationTime(creationTime)
.build();

final String dbOpenKeyName;
if (bucketLayout.isFileSystemOptimized()) {
Expand Down Expand Up @@ -689,10 +694,10 @@ private void testGetExpiredOpenKeysExcludeMPUKeys(
// Ensure that "expired" MPU-related open keys are not fetched.
// MPU-related open keys, identified by isMultipartKey = false
for (int i = 0; i < numExpiredMPUOpenKeys; i++) {
final OmKeyInfo keyInfo = OMRequestTestUtils.createOmKeyInfo(volumeName,
bucketName, "expired" + i,
HddsProtos.ReplicationType.RATIS, HddsProtos.ReplicationFactor.ONE,
0L, expiredOpenKeyCreationTime, true);
final OmKeyInfo keyInfo = OMRequestTestUtils.createOmKeyInfo(volumeName, bucketName, "expired" + i,
RatisReplicationConfig.getInstance(ONE), new OmKeyLocationInfoGroup(0L, new ArrayList<>(), true))
.setCreationTime(expiredOpenKeyCreationTime)
.build();

final String uploadId = OMMultipartUploadUtils.getMultipartUploadId();
final OmMultipartKeyInfo multipartKeyInfo = OMRequestTestUtils.
Expand Down Expand Up @@ -722,10 +727,10 @@ private void testGetExpiredOpenKeysExcludeMPUKeys(
// HDDS-9017. Although these open keys are MPU-related,
// the isMultipartKey flags are set to false
for (int i = numExpiredMPUOpenKeys; i < 2 * numExpiredMPUOpenKeys; i++) {
final OmKeyInfo keyInfo = OMRequestTestUtils.createOmKeyInfo(volumeName,
bucketName, "expired" + i,
HddsProtos.ReplicationType.RATIS, HddsProtos.ReplicationFactor.ONE,
0L, expiredOpenKeyCreationTime, false);
final OmKeyInfo keyInfo = OMRequestTestUtils.createOmKeyInfo(
volumeName, bucketName, "expired" + i, RatisReplicationConfig.getInstance(ONE))
.setCreationTime(expiredOpenKeyCreationTime)
.build();

final String uploadId = OMMultipartUploadUtils.getMultipartUploadId();
final OmMultipartKeyInfo multipartKeyInfo = OMRequestTestUtils.
Expand Down Expand Up @@ -788,8 +793,9 @@ private void testGetExpiredMPUs() throws Exception {
String keyName = "expired" + i;
// Key info to construct the MPU DB key
final OmKeyInfo keyInfo = OMRequestTestUtils.createOmKeyInfo(volumeName,
bucketName, keyName, HddsProtos.ReplicationType.RATIS,
HddsProtos.ReplicationFactor.ONE, 0L, creationTime);
bucketName, keyName, RatisReplicationConfig.getInstance(ONE))
.setCreationTime(creationTime)
.build();


for (int j = 1; j <= numPartsPerMPU; j++) {
Expand Down Expand Up @@ -861,11 +867,10 @@ private void addKeysToOM(String volumeName, String bucketName,

if (i % 2 == 0) {
OMRequestTestUtils.addKeyToTable(false, volumeName, bucketName, keyName,
1000L, HddsProtos.ReplicationType.RATIS,
HddsProtos.ReplicationFactor.ONE, omMetadataManager);
1000L, RatisReplicationConfig.getInstance(ONE), omMetadataManager);
} else {
OMRequestTestUtils.addKeyToTableCache(volumeName, bucketName, keyName,
HddsProtos.ReplicationType.RATIS, HddsProtos.ReplicationFactor.ONE,
RatisReplicationConfig.getInstance(ONE),
omMetadataManager);
}
}
Expand Down
Loading

0 comments on commit 06399b5

Please sign in to comment.