Skip to content

Commit 490e6bb

Browse files
authored
HDDS-13402. Speed up TestOmSnapshotFileSystem (#8756)
1 parent e0b804e commit 490e6bb

7 files changed

Lines changed: 143 additions & 164 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hadoop.ozone.om.snapshot;
19+
20+
import static org.apache.hadoop.ozone.om.helpers.BucketLayout.FILE_SYSTEM_OPTIMIZED;
21+
import static org.apache.hadoop.ozone.om.helpers.BucketLayout.LEGACY;
22+
23+
import org.apache.hadoop.ozone.MiniOzoneCluster;
24+
import org.apache.ozone.test.ClusterForTests;
25+
import org.junit.jupiter.api.Nested;
26+
27+
abstract class SnapshotTests extends ClusterForTests<MiniOzoneCluster> {
28+
29+
@Override
30+
protected void onClusterReady() throws Exception {
31+
// stop the deletion services so that keys can still be read
32+
getCluster().getOzoneManager().getKeyManager().stop();
33+
}
34+
35+
@Nested
36+
class OmSnapshotFileSystemFso extends TestOmSnapshotFileSystem {
37+
OmSnapshotFileSystemFso() {
38+
super(FILE_SYSTEM_OPTIMIZED, false);
39+
}
40+
41+
@Override
42+
public MiniOzoneCluster cluster() {
43+
return getCluster();
44+
}
45+
}
46+
47+
@Nested
48+
class OmSnapshotFileSystemFsoWithLinkedBuckets extends TestOmSnapshotFileSystem {
49+
OmSnapshotFileSystemFsoWithLinkedBuckets() {
50+
super(FILE_SYSTEM_OPTIMIZED, true);
51+
}
52+
53+
@Override
54+
public MiniOzoneCluster cluster() {
55+
return getCluster();
56+
}
57+
}
58+
59+
@Nested
60+
class OmSnapshotFileSystemLegacy extends TestOmSnapshotFileSystem {
61+
OmSnapshotFileSystemLegacy() {
62+
super(LEGACY, false);
63+
}
64+
65+
@Override
66+
public MiniOzoneCluster cluster() {
67+
return getCluster();
68+
}
69+
}
70+
71+
@Nested
72+
class OmSnapshotFileSystemLegacyWithLinkedBuckets extends TestOmSnapshotFileSystem {
73+
OmSnapshotFileSystemLegacyWithLinkedBuckets() {
74+
super(LEGACY, true);
75+
}
76+
77+
@Override
78+
public MiniOzoneCluster cluster() {
79+
return getCluster();
80+
}
81+
}
82+
}

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOmSnapshotFileSystem.java

Lines changed: 44 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
2424
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_SCHEME;
2525
import static org.apache.hadoop.ozone.om.OmSnapshotManager.getSnapshotPath;
26-
import static org.apache.hadoop.ozone.om.helpers.BucketLayout.FILE_SYSTEM_OPTIMIZED;
27-
import static org.apache.hadoop.ozone.om.helpers.BucketLayout.LEGACY;
2826
import static org.assertj.core.api.Assertions.assertThat;
2927
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
3028
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -54,7 +52,6 @@
5452
import java.util.UUID;
5553
import java.util.concurrent.TimeoutException;
5654
import org.apache.commons.io.IOUtils;
57-
import org.apache.commons.lang3.RandomStringUtils;
5855
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
5956
import org.apache.hadoop.fs.FSDataInputStream;
6057
import org.apache.hadoop.fs.FSDataOutputStream;
@@ -66,27 +63,26 @@
6663
import org.apache.hadoop.fs.permission.FsPermission;
6764
import org.apache.hadoop.hdds.client.StandaloneReplicationConfig;
6865
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
69-
import org.apache.hadoop.ozone.MiniOzoneCluster;
7066
import org.apache.hadoop.ozone.OzoneConsts;
7167
import org.apache.hadoop.ozone.TestDataUtil;
72-
import org.apache.hadoop.ozone.client.BucketArgs;
7368
import org.apache.hadoop.ozone.client.ObjectStore;
7469
import org.apache.hadoop.ozone.client.OzoneBucket;
7570
import org.apache.hadoop.ozone.client.OzoneClient;
7671
import org.apache.hadoop.ozone.client.OzoneKey;
7772
import org.apache.hadoop.ozone.client.OzoneSnapshot;
7873
import org.apache.hadoop.ozone.client.OzoneVolume;
79-
import org.apache.hadoop.ozone.om.KeyManagerImpl;
80-
import org.apache.hadoop.ozone.om.OMConfigKeys;
74+
import org.apache.hadoop.ozone.om.OmConfig;
8175
import org.apache.hadoop.ozone.om.OmSnapshotManager;
8276
import org.apache.hadoop.ozone.om.OzoneManager;
8377
import org.apache.hadoop.ozone.om.exceptions.OMException;
78+
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
8479
import org.apache.hadoop.ozone.om.helpers.OmKeyArgs;
8580
import org.apache.hadoop.ozone.om.helpers.OpenKeySession;
8681
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
8782
import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
8883
import org.apache.hadoop.security.UserGroupInformation;
8984
import org.apache.ozone.test.GenericTestUtils;
85+
import org.apache.ozone.test.NonHATests;
9086
import org.junit.jupiter.api.AfterAll;
9187
import org.junit.jupiter.api.AfterEach;
9288
import org.junit.jupiter.api.BeforeAll;
@@ -99,72 +95,53 @@
9995
* Abstract class for OmSnapshot file system tests.
10096
*/
10197
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
102-
public abstract class TestOmSnapshotFileSystem {
103-
protected static final String VOLUME_NAME =
104-
"volume" + RandomStringUtils.secure().nextNumeric(5);
105-
protected static final String BUCKET_NAME_FSO =
106-
"bucket-fso-" + RandomStringUtils.secure().nextNumeric(5);
107-
protected static final String BUCKET_NAME_LEGACY =
108-
"bucket-legacy-" + RandomStringUtils.secure().nextNumeric(5);
109-
110-
private MiniOzoneCluster cluster = null;
98+
public abstract class TestOmSnapshotFileSystem implements NonHATests.TestCase {
99+
111100
private OzoneClient client;
112101
private ObjectStore objectStore;
113102
private OzoneConfiguration conf;
114103
private OzoneManagerProtocol writeClient;
115104
private OzoneManager ozoneManager;
116105
private String keyPrefix;
117-
private final String bucketName;
106+
private String volumeName;
107+
private String bucketName;
108+
private final BucketLayout bucketLayout;
118109
private final boolean createLinkedBuckets;
119110
private FileSystem fs;
120111
private OzoneFileSystem o3fs;
121-
private Map<String, String> linkedBucketMaps = new HashMap<>();
112+
private final Map<String, String> linkedBucketMaps = new HashMap<>();
113+
private OmConfig originalOmConfig;
122114

123115
private static final Logger LOG =
124-
LoggerFactory.getLogger(TestOmSnapshot.class);
116+
LoggerFactory.getLogger(TestOmSnapshotFileSystem.class);
125117

126-
public TestOmSnapshotFileSystem(String bucketName, boolean createLinkedBuckets) throws Exception {
127-
this.bucketName = bucketName;
118+
protected TestOmSnapshotFileSystem(BucketLayout layout, boolean createLinkedBuckets) {
119+
this.bucketLayout = layout;
128120
this.createLinkedBuckets = createLinkedBuckets;
129-
init();
130121
}
131122

132-
private void init() throws Exception {
133-
conf = new OzoneConfiguration();
134-
conf.setBoolean(OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS, true);
135-
cluster = MiniOzoneCluster.newBuilder(conf).build();
136-
cluster.waitForClusterToBeReady();
137-
client = cluster.newClient();
123+
@BeforeAll
124+
public void setupFsClient() throws IOException {
125+
OmConfig omConfig = cluster().getOzoneManager().getConfig();
126+
originalOmConfig = omConfig.copy();
127+
omConfig.setFileSystemPathEnabled(true);
128+
129+
client = cluster().newClient();
138130

139131
objectStore = client.getObjectStore();
140132
writeClient = objectStore.getClientProxy().getOzoneManagerClient();
141-
ozoneManager = cluster.getOzoneManager();
133+
ozoneManager = cluster().getOzoneManager();
142134

143-
TestDataUtil.createVolume(client, VOLUME_NAME);
144-
OzoneBucket bucket = TestDataUtil.createBucket(client, VOLUME_NAME,
145-
new BucketArgs.Builder().setBucketLayout(FILE_SYSTEM_OPTIMIZED).build(),
146-
BUCKET_NAME_FSO, createLinkedBuckets);
135+
OzoneBucket bucket = TestDataUtil.createVolumeAndBucket(client, bucketLayout, createLinkedBuckets);
147136
if (createLinkedBuckets) {
148137
linkedBucketMaps.put(bucket.getName(), bucket.getSourceBucket());
149138
}
150-
bucket = TestDataUtil.createBucket(client, VOLUME_NAME,
151-
new BucketArgs.Builder().setBucketLayout(LEGACY).build(),
152-
BUCKET_NAME_LEGACY, createLinkedBuckets);
153-
if (createLinkedBuckets) {
154-
linkedBucketMaps.put(bucket.getName(), bucket.getSourceBucket());
155-
}
156-
157-
158-
159-
// stop the deletion services so that keys can still be read
160-
KeyManagerImpl keyManager = (KeyManagerImpl) ozoneManager.getKeyManager();
161-
keyManager.stop();
162-
}
139+
volumeName = bucket.getVolumeName();
140+
bucketName = bucket.getName();
163141

164-
@BeforeAll
165-
public void setupFsClient() throws IOException {
166142
String rootPath = String.format("%s://%s.%s/",
167-
OzoneConsts.OZONE_URI_SCHEME, bucketName, VOLUME_NAME);
143+
OzoneConsts.OZONE_URI_SCHEME, bucketName, volumeName);
144+
conf = new OzoneConfiguration(cluster().getConf());
168145
// Set the fs.defaultFS and start the filesystem
169146
conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, rootPath);
170147
// Set the number of keys to be processed during batch operate.
@@ -177,9 +154,7 @@ public void setupFsClient() throws IOException {
177154
void tearDown() {
178155
IOUtils.closeQuietly(client);
179156
IOUtils.closeQuietly(fs);
180-
if (cluster != null) {
181-
cluster.shutdown();
182-
}
157+
cluster().getOzoneManager().getConfig().setFrom(originalOmConfig);
183158
}
184159

185160
/**
@@ -198,24 +173,16 @@ public void deleteRootDir()
198173
}
199174

200175
for (FileStatus fStatus : fileStatuses) {
176+
assertEquals(fs.getScheme(), fStatus.getPath().toUri().getScheme(), "unexpected scheme");
201177
fs.delete(fStatus.getPath(), true);
202178
}
203-
204-
205-
GenericTestUtils.waitFor(() -> {
206-
try {
207-
return fs.listStatus(root).length == 0;
208-
} catch (Exception e) {
209-
return false;
210-
}
211-
}, 1000, 120000);
212179
}
213180

214181
@Test
215182
// based on TestObjectStoreWithFSO:testListKeysAtDifferentLevels
216183
public void testListKeysAtDifferentLevels() throws Exception {
217-
OzoneVolume ozoneVolume = objectStore.getVolume(VOLUME_NAME);
218-
assertEquals(ozoneVolume.getName(), VOLUME_NAME);
184+
OzoneVolume ozoneVolume = objectStore.getVolume(volumeName);
185+
assertEquals(ozoneVolume.getName(), volumeName);
219186
OzoneBucket ozoneBucket = ozoneVolume.getBucket(bucketName);
220187
assertEquals(ozoneBucket.getName(), bucketName);
221188

@@ -282,7 +249,7 @@ public void testListKeysAtDifferentLevels() throws Exception {
282249
deleteSnapshot(snapshotName);
283250
String expectedMessage = String.format("Unable to load snapshot. " +
284251
"Snapshot with table key '/%s/%s/%s' is no longer active",
285-
VOLUME_NAME, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName);
252+
volumeName, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName);
286253
OMException exception = assertThrows(OMException.class,
287254
() -> ozoneBucket.listKeys(keyPrefix + "a/", null));
288255
assertEquals(expectedMessage, exception.getMessage());
@@ -370,7 +337,7 @@ private void readkey(OzoneBucket ozoneBucket, String key, int length, byte[] inp
370337

371338
// Read using filesystem.
372339
String rootPath = String.format("%s://%s.%s/", OZONE_URI_SCHEME,
373-
bucketName, VOLUME_NAME);
340+
bucketName, volumeName);
374341
OzoneFileSystem o3fsNew = (OzoneFileSystem) FileSystem
375342
.get(new URI(rootPath), conf);
376343
try (InputStream fsDataInputStream = o3fsNew.open(new Path(key))) {
@@ -497,21 +464,21 @@ public void testListStatus() throws Exception {
497464
() -> fs.listStatus(snapshotRoot1));
498465
assertEquals(String.format("Unable to load snapshot. " +
499466
"Snapshot with table key '/%s/%s/%s' is no longer active",
500-
VOLUME_NAME, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName1), exception1.getMessage());
467+
volumeName, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName1), exception1.getMessage());
501468

502469
deleteSnapshot(snapshotName2);
503470
FileNotFoundException exception2 = assertThrows(FileNotFoundException.class,
504471
() -> fs.listStatus(snapshotRoot2));
505472
assertEquals(String.format("Unable to load snapshot. " +
506473
"Snapshot with table key '/%s/%s/%s' is no longer active",
507-
VOLUME_NAME, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName2), exception2.getMessage());
474+
volumeName, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName2), exception2.getMessage());
508475

509476
deleteSnapshot(snapshotName3);
510477
FileNotFoundException exception3 = assertThrows(FileNotFoundException.class,
511478
() -> fs.listStatus(snapshotParent3));
512479
assertEquals(String.format("Unable to load snapshot. " +
513480
"Snapshot with table key '/%s/%s/%s' is no longer active",
514-
VOLUME_NAME, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName3), exception3.getMessage());
481+
volumeName, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName3), exception3.getMessage());
515482
}
516483

517484
@Test
@@ -546,7 +513,7 @@ public void testListStatusWithIntermediateDir() throws Exception {
546513
() -> fs.listStatus(snapshotParent));
547514
assertEquals(String.format("Unable to load snapshot. " +
548515
"Snapshot with table key '/%s/%s/%s' is no longer active",
549-
VOLUME_NAME, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName), exception.getMessage());
516+
volumeName, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName), exception.getMessage());
550517
}
551518

552519
@Test
@@ -582,7 +549,7 @@ public void testGetFileStatus() throws Exception {
582549
() -> fs.listStatus(snapshotParent));
583550
assertEquals(String.format("Unable to load snapshot. " +
584551
"Snapshot with table key '/%s/%s/%s' is no longer active",
585-
VOLUME_NAME, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName), exception.getMessage());
552+
volumeName, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName), exception.getMessage());
586553
}
587554

588555
@Test
@@ -623,11 +590,11 @@ void testReadFileFromSnapshot() throws Exception {
623590
() -> fs.open(fileInSnapshot));
624591
assertEquals(String.format("FILE_NOT_FOUND: Unable to load snapshot. " +
625592
"Snapshot with table key '/%s/%s/%s' is no longer active",
626-
VOLUME_NAME, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName), exception.getMessage());
593+
volumeName, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName), exception.getMessage());
627594
}
628595

629596
private void createAndCommitKey(String keyName) throws IOException {
630-
OmKeyArgs keyArgs = new OmKeyArgs.Builder().setVolumeName(VOLUME_NAME)
597+
OmKeyArgs keyArgs = new OmKeyArgs.Builder().setVolumeName(volumeName)
631598
.setBucketName(bucketName).setKeyName(keyName)
632599
.setAcls(Collections.emptyList())
633600
.setReplicationConfig(StandaloneReplicationConfig.getInstance(ONE))
@@ -673,7 +640,7 @@ public void testListStatusOnRoot() throws Exception {
673640
() -> fs.listStatus(snapshotRoot));
674641
assertEquals(String.format("Unable to load snapshot. " +
675642
"Snapshot with table key '/%s/%s/%s' is no longer active",
676-
VOLUME_NAME, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName), exception.getMessage());
643+
volumeName, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName), exception.getMessage());
677644
}
678645

679646
/**
@@ -728,17 +695,17 @@ public void testListStatusOnLargeDirectory() throws Exception {
728695
() -> fs.listStatus(snapshotRoot));
729696
assertEquals(String.format("Unable to load snapshot. " +
730697
"Snapshot with table key '/%s/%s/%s' is no longer active",
731-
VOLUME_NAME, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName), exception.getMessage());
698+
volumeName, linkedBucketMaps.getOrDefault(bucketName, bucketName), snapshotName), exception.getMessage());
732699
}
733700

734701
private String createSnapshot(String snapshotName)
735702
throws IOException, InterruptedException, TimeoutException {
736703

737704
// create snapshot
738-
writeClient.createSnapshot(VOLUME_NAME, bucketName, snapshotName);
705+
writeClient.createSnapshot(volumeName, bucketName, snapshotName);
739706

740707
// wait till the snapshot directory exists
741-
OzoneSnapshot snapshot = objectStore.getSnapshotInfo(VOLUME_NAME, bucketName, snapshotName);
708+
OzoneSnapshot snapshot = objectStore.getSnapshotInfo(volumeName, bucketName, snapshotName);
742709
SnapshotInfo snapshotInfo = ozoneManager.getMetadataManager()
743710
.getSnapshotInfoTable()
744711
.get(SnapshotInfo.getTableKey(snapshot.getVolumeName(), snapshot.getBucketName(), snapshotName));
@@ -751,6 +718,6 @@ private String createSnapshot(String snapshotName)
751718
}
752719

753720
private void deleteSnapshot(String snapshotName) throws IOException {
754-
writeClient.deleteSnapshot(VOLUME_NAME, bucketName, snapshotName);
721+
writeClient.deleteSnapshot(volumeName, bucketName, snapshotName);
755722
}
756723
}

0 commit comments

Comments
 (0)