|
@@ -22,7 +22,9 @@ import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_DB_DIRS;
|
|
|
import static org.apache.hadoop.ozone.recon.ReconServerConfigKeys.OZONE_RECON_OM_SNAPSHOT_DB_DIR;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
|
|
|
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
|
|
|
import org.apache.hadoop.ozone.om.OMMetadataManager;
|
|
@@ -31,6 +33,7 @@ import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
|
|
|
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
|
|
|
import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
|
|
|
import org.apache.hadoop.hdds.utils.db.DBCheckpoint;
|
|
|
+import org.apache.hadoop.ozone.recon.ReconUtils;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Rule;
|
|
|
import org.junit.Test;
|
|
@@ -44,9 +47,95 @@ public class TestReconOmMetadataManagerImpl {
|
|
|
@Rule
|
|
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testStart() throws Exception {
|
|
|
+
|
|
|
+ OMMetadataManager omMetadataManager = getOMMetadataManager();
|
|
|
+
|
|
|
+ //Take checkpoint of the above OM DB.
|
|
|
+ DBCheckpoint checkpoint = omMetadataManager.getStore()
|
|
|
+ .getCheckpoint(true);
|
|
|
+ File snapshotFile = new File(
|
|
|
+ checkpoint.getCheckpointLocation().getParent() + "/" +
|
|
|
+ "om.snapshot.db_" + System.currentTimeMillis());
|
|
|
+ checkpoint.getCheckpointLocation().toFile().renameTo(snapshotFile);
|
|
|
+
|
|
|
+ //Create new Recon OM Metadata manager instance.
|
|
|
+ File reconOmDbDir = temporaryFolder.newFolder();
|
|
|
+ OzoneConfiguration configuration = new OzoneConfiguration();
|
|
|
+ configuration.set(OZONE_RECON_OM_SNAPSHOT_DB_DIR, reconOmDbDir
|
|
|
+ .getAbsolutePath());
|
|
|
+ FileUtils.copyDirectory(snapshotFile.getParentFile(), reconOmDbDir);
|
|
|
+
|
|
|
+ ReconOMMetadataManager reconOMMetadataManager =
|
|
|
+ new ReconOmMetadataManagerImpl(configuration, new ReconUtils());
|
|
|
+ reconOMMetadataManager.start(configuration);
|
|
|
+
|
|
|
+ Assert.assertNotNull(reconOMMetadataManager.getBucketTable());
|
|
|
+ Assert.assertNotNull(reconOMMetadataManager.getVolumeTable()
|
|
|
+ .get("/sampleVol"));
|
|
|
+ Assert.assertNotNull(reconOMMetadataManager.getBucketTable()
|
|
|
+ .get("/sampleVol/bucketOne"));
|
|
|
+ Assert.assertNotNull(reconOMMetadataManager.getKeyTable()
|
|
|
+ .get("/sampleVol/bucketOne/key_one"));
|
|
|
+ Assert.assertNotNull(reconOMMetadataManager.getKeyTable()
|
|
|
+ .get("/sampleVol/bucketOne/key_two"));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testUpdateOmDB() throws Exception {
|
|
|
|
|
|
+ OMMetadataManager omMetadataManager = getOMMetadataManager();
|
|
|
+ //Make sure OM Metadata reflects the keys that were inserted.
|
|
|
+ Assert.assertNotNull(omMetadataManager.getKeyTable()
|
|
|
+ .get("/sampleVol/bucketOne/key_one"));
|
|
|
+ Assert.assertNotNull(omMetadataManager.getKeyTable()
|
|
|
+ .get("/sampleVol/bucketOne/key_two"));
|
|
|
+
|
|
|
+ //Take checkpoint of OM DB.
|
|
|
+ DBCheckpoint checkpoint = omMetadataManager.getStore()
|
|
|
+ .getCheckpoint(true);
|
|
|
+ Assert.assertNotNull(checkpoint.getCheckpointLocation());
|
|
|
+
|
|
|
+ //Create new Recon OM Metadata manager instance.
|
|
|
+ File reconOmDbDir = temporaryFolder.newFolder();
|
|
|
+ OzoneConfiguration configuration = new OzoneConfiguration();
|
|
|
+ configuration.set(OZONE_RECON_OM_SNAPSHOT_DB_DIR, reconOmDbDir
|
|
|
+ .getAbsolutePath());
|
|
|
+ ReconOMMetadataManager reconOMMetadataManager =
|
|
|
+ new ReconOmMetadataManagerImpl(configuration, new ReconUtils());
|
|
|
+ reconOMMetadataManager.start(configuration);
|
|
|
+
|
|
|
+ //Before accepting a snapshot, the metadata should have null tables.
|
|
|
+ Assert.assertNull(reconOMMetadataManager.getBucketTable());
|
|
|
+
|
|
|
+ //Update Recon OM DB with the OM DB checkpoint location.
|
|
|
+ reconOMMetadataManager.updateOmDB(
|
|
|
+ checkpoint.getCheckpointLocation().toFile());
|
|
|
+
|
|
|
+ //Now, the tables should have been initialized.
|
|
|
+ Assert.assertNotNull(reconOMMetadataManager.getBucketTable());
|
|
|
+
|
|
|
+ // Check volume and bucket entries.
|
|
|
+ Assert.assertNotNull(reconOMMetadataManager.getVolumeTable()
|
|
|
+ .get("/sampleVol"));
|
|
|
+ Assert.assertNotNull(reconOMMetadataManager.getBucketTable()
|
|
|
+ .get("/sampleVol/bucketOne"));
|
|
|
+
|
|
|
+ //Verify Keys inserted in OM DB are available in Recon OM DB.
|
|
|
+ Assert.assertNotNull(reconOMMetadataManager.getKeyTable()
|
|
|
+ .get("/sampleVol/bucketOne/key_one"));
|
|
|
+ Assert.assertNotNull(reconOMMetadataManager.getKeyTable()
|
|
|
+ .get("/sampleVol/bucketOne/key_two"));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get test OM metadata manager.
|
|
|
+ * @return OMMetadataManager instance
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ private OMMetadataManager getOMMetadataManager() throws IOException {
|
|
|
//Create a new OM Metadata Manager instance + DB.
|
|
|
File omDbDir = temporaryFolder.newFolder();
|
|
|
OzoneConfiguration omConfiguration = new OzoneConfiguration();
|
|
@@ -93,48 +182,6 @@ public class TestReconOmMetadataManagerImpl {
|
|
|
.setReplicationType(HddsProtos.ReplicationType.STAND_ALONE)
|
|
|
.build());
|
|
|
|
|
|
- //Make sure OM Metadata reflects the keys that were inserted.
|
|
|
- Assert.assertNotNull(omMetadataManager.getKeyTable()
|
|
|
- .get("/sampleVol/bucketOne/key_one"));
|
|
|
- Assert.assertNotNull(omMetadataManager.getKeyTable()
|
|
|
- .get("/sampleVol/bucketOne/key_two"));
|
|
|
-
|
|
|
- //Take checkpoint of OM DB.
|
|
|
- DBCheckpoint checkpoint = omMetadataManager.getStore()
|
|
|
- .getCheckpoint(true);
|
|
|
- Assert.assertNotNull(checkpoint.getCheckpointLocation());
|
|
|
-
|
|
|
- //Create new Recon OM Metadata manager instance.
|
|
|
- File reconOmDbDir = temporaryFolder.newFolder();
|
|
|
- OzoneConfiguration configuration = new OzoneConfiguration();
|
|
|
- configuration.set(OZONE_RECON_OM_SNAPSHOT_DB_DIR, reconOmDbDir
|
|
|
- .getAbsolutePath());
|
|
|
- ReconOMMetadataManager reconOMMetadataManager =
|
|
|
- new ReconOmMetadataManagerImpl(configuration);
|
|
|
- reconOMMetadataManager.start(configuration);
|
|
|
-
|
|
|
- //Before accepting a snapshot, the metadata should have null tables.
|
|
|
- Assert.assertNull(reconOMMetadataManager.getBucketTable());
|
|
|
-
|
|
|
- //Update Recon OM DB with the OM DB checkpoint location.
|
|
|
- reconOMMetadataManager.updateOmDB(
|
|
|
- checkpoint.getCheckpointLocation().toFile());
|
|
|
-
|
|
|
- //Now, the tables should have been initialized.
|
|
|
- Assert.assertNotNull(reconOMMetadataManager.getBucketTable());
|
|
|
-
|
|
|
- // Check volume and bucket entries.
|
|
|
- Assert.assertNotNull(reconOMMetadataManager.getVolumeTable()
|
|
|
- .get(volumeKey));
|
|
|
- Assert.assertNotNull(reconOMMetadataManager.getBucketTable()
|
|
|
- .get(bucketKey));
|
|
|
-
|
|
|
- //Verify Keys inserted in OM DB are available in Recon OM DB.
|
|
|
- Assert.assertNotNull(reconOMMetadataManager.getKeyTable()
|
|
|
- .get("/sampleVol/bucketOne/key_one"));
|
|
|
- Assert.assertNotNull(reconOMMetadataManager.getKeyTable()
|
|
|
- .get("/sampleVol/bucketOne/key_two"));
|
|
|
-
|
|
|
+ return omMetadataManager;
|
|
|
}
|
|
|
-
|
|
|
}
|