Skip to content

Commit e9fccf4

Browse files
GeorgeJahadxichen01
authored andcommitted
HDDS-10059. TestOMRatisSnapshots.testInstallSnapshot should only validate live files. (#6069)
(cherry picked from commit b90d109)
1 parent 92c617f commit e9fccf4

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.hadoop.hdds.utils.TransactionInfo;
3232
import org.apache.hadoop.hdds.utils.db.DBCheckpoint;
3333
import org.apache.hadoop.hdds.utils.db.RDBCheckpointUtils;
34+
import org.apache.hadoop.hdds.utils.db.RDBStore;
3435
import org.apache.hadoop.ozone.MiniOzoneCluster;
3536
import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl;
3637
import org.apache.hadoop.ozone.client.BucketArgs;
@@ -60,8 +61,8 @@
6061
import org.junit.jupiter.api.TestInfo;
6162
import org.junit.jupiter.api.Timeout;
6263
import org.junit.jupiter.api.io.TempDir;
63-
import org.junit.jupiter.params.ParameterizedTest;
64-
import org.junit.jupiter.params.provider.ValueSource;
64+
import org.rocksdb.RocksDB;
65+
import org.rocksdb.RocksDBException;
6566
import org.slf4j.Logger;
6667
import org.slf4j.event.Level;
6768

@@ -198,11 +199,12 @@ public void shutdown() {
198199
}
199200
}
200201

201-
@ParameterizedTest
202-
@ValueSource(ints = {100})
203202
// tried up to 1000 snapshots and this test works, but some of the
204203
// timeouts have to be increased.
205-
public void testInstallSnapshot(int numSnapshotsToCreate) throws Exception {
204+
private static final int SNAPSHOTS_TO_CREATE = 100;
205+
206+
@Test
207+
public void testInstallSnapshot(@TempDir Path tempDir) throws Exception {
206208
// Get the leader OM
207209
String leaderOMNodeId = OmFailoverProxyUtil
208210
.getFailoverProxyProvider(objectStore.getClientProxy())
@@ -230,8 +232,7 @@ public void testInstallSnapshot(int numSnapshotsToCreate) throws Exception {
230232
String snapshotName = "";
231233
List<String> keys = new ArrayList<>();
232234
SnapshotInfo snapshotInfo = null;
233-
for (int snapshotCount = 0; snapshotCount < numSnapshotsToCreate;
234-
snapshotCount++) {
235+
for (int snapshotCount = 0; snapshotCount < SNAPSHOTS_TO_CREATE; snapshotCount++) {
235236
snapshotName = snapshotNamePrefix + snapshotCount;
236237
keys = writeKeys(keyIncrement);
237238
snapshotInfo = createOzoneSnapshot(leaderOM, snapshotName);
@@ -326,7 +327,7 @@ public void testInstallSnapshot(int numSnapshotsToCreate) throws Exception {
326327
private void checkSnapshot(OzoneManager leaderOM, OzoneManager followerOM,
327328
String snapshotName,
328329
List<String> keys, SnapshotInfo snapshotInfo)
329-
throws IOException {
330+
throws IOException, RocksDBException {
330331
// Read back data from snapshot.
331332
OmKeyArgs omKeyArgs = new OmKeyArgs.Builder()
332333
.setVolumeName(volumeName)
@@ -347,18 +348,28 @@ private void checkSnapshot(OzoneManager leaderOM, OzoneManager followerOM,
347348
Path leaderActiveDir = Paths.get(leaderMetaDir.toString(), OM_DB_NAME);
348349
Path leaderSnapshotDir =
349350
Paths.get(getSnapshotPath(leaderOM.getConfiguration(), snapshotInfo));
351+
352+
// Get list of live files on the leader.
353+
RocksDB activeRocksDB = ((RDBStore) leaderOM.getMetadataManager().getStore())
354+
.getDb().getManagedRocksDb().get();
355+
// strip the leading "/".
356+
Set<String> liveSstFiles = activeRocksDB.getLiveFiles().files.stream()
357+
.map(s -> s.substring(1))
358+
.collect(Collectors.toSet());
359+
350360
// Get the list of hardlinks from the leader. Then confirm those links
351361
// are on the follower
352362
int hardLinkCount = 0;
353-
try (Stream<Path>list = Files.list(leaderSnapshotDir)) {
363+
try (Stream<Path> list = Files.list(leaderSnapshotDir)) {
354364
for (Path leaderSnapshotSST: list.collect(Collectors.toList())) {
355365
String fileName = leaderSnapshotSST.getFileName().toString();
356366
if (fileName.toLowerCase().endsWith(".sst")) {
357367

358368
Path leaderActiveSST =
359369
Paths.get(leaderActiveDir.toString(), fileName);
360370
// Skip if not hard link on the leader
361-
if (!leaderActiveSST.toFile().exists()) {
371+
// First confirm it is live
372+
if (!liveSstFiles.contains(fileName)) {
362373
continue;
363374
}
364375
// If it is a hard link on the leader, it should be a hard

0 commit comments

Comments
 (0)