Skip to content

Commit

Permalink
HDDS-10059. TestOMRatisSnapshots.testInstallSnapshot should only vali…
Browse files Browse the repository at this point in the history
…date live files. (#6069)

(cherry picked from commit b90d109)
  • Loading branch information
GeorgeJahad authored and xichen01 committed Oct 1, 2024
1 parent 92c617f commit e9fccf4
Showing 1 changed file with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.hadoop.hdds.utils.TransactionInfo;
import org.apache.hadoop.hdds.utils.db.DBCheckpoint;
import org.apache.hadoop.hdds.utils.db.RDBCheckpointUtils;
import org.apache.hadoop.hdds.utils.db.RDBStore;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl;
import org.apache.hadoop.ozone.client.BucketArgs;
Expand Down Expand Up @@ -60,8 +61,8 @@
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;
import org.slf4j.Logger;
import org.slf4j.event.Level;

Expand Down Expand Up @@ -198,11 +199,12 @@ public void shutdown() {
}
}

@ParameterizedTest
@ValueSource(ints = {100})
// tried up to 1000 snapshots and this test works, but some of the
// timeouts have to be increased.
public void testInstallSnapshot(int numSnapshotsToCreate) throws Exception {
private static final int SNAPSHOTS_TO_CREATE = 100;

@Test
public void testInstallSnapshot(@TempDir Path tempDir) throws Exception {
// Get the leader OM
String leaderOMNodeId = OmFailoverProxyUtil
.getFailoverProxyProvider(objectStore.getClientProxy())
Expand Down Expand Up @@ -230,8 +232,7 @@ public void testInstallSnapshot(int numSnapshotsToCreate) throws Exception {
String snapshotName = "";
List<String> keys = new ArrayList<>();
SnapshotInfo snapshotInfo = null;
for (int snapshotCount = 0; snapshotCount < numSnapshotsToCreate;
snapshotCount++) {
for (int snapshotCount = 0; snapshotCount < SNAPSHOTS_TO_CREATE; snapshotCount++) {
snapshotName = snapshotNamePrefix + snapshotCount;
keys = writeKeys(keyIncrement);
snapshotInfo = createOzoneSnapshot(leaderOM, snapshotName);
Expand Down Expand Up @@ -326,7 +327,7 @@ public void testInstallSnapshot(int numSnapshotsToCreate) throws Exception {
private void checkSnapshot(OzoneManager leaderOM, OzoneManager followerOM,
String snapshotName,
List<String> keys, SnapshotInfo snapshotInfo)
throws IOException {
throws IOException, RocksDBException {
// Read back data from snapshot.
OmKeyArgs omKeyArgs = new OmKeyArgs.Builder()
.setVolumeName(volumeName)
Expand All @@ -347,18 +348,28 @@ private void checkSnapshot(OzoneManager leaderOM, OzoneManager followerOM,
Path leaderActiveDir = Paths.get(leaderMetaDir.toString(), OM_DB_NAME);
Path leaderSnapshotDir =
Paths.get(getSnapshotPath(leaderOM.getConfiguration(), snapshotInfo));

// Get list of live files on the leader.
RocksDB activeRocksDB = ((RDBStore) leaderOM.getMetadataManager().getStore())
.getDb().getManagedRocksDb().get();
// strip the leading "/".
Set<String> liveSstFiles = activeRocksDB.getLiveFiles().files.stream()
.map(s -> s.substring(1))
.collect(Collectors.toSet());

// Get the list of hardlinks from the leader. Then confirm those links
// are on the follower
int hardLinkCount = 0;
try (Stream<Path>list = Files.list(leaderSnapshotDir)) {
try (Stream<Path> list = Files.list(leaderSnapshotDir)) {
for (Path leaderSnapshotSST: list.collect(Collectors.toList())) {
String fileName = leaderSnapshotSST.getFileName().toString();
if (fileName.toLowerCase().endsWith(".sst")) {

Path leaderActiveSST =
Paths.get(leaderActiveDir.toString(), fileName);
// Skip if not hard link on the leader
if (!leaderActiveSST.toFile().exists()) {
// First confirm it is live
if (!liveSstFiles.contains(fileName)) {
continue;
}
// If it is a hard link on the leader, it should be a hard
Expand Down

0 comments on commit e9fccf4

Please sign in to comment.