Search in sources :

Example 6 with RaftStorageImpl

use of org.apache.ratis.server.storage.RaftStorageImpl in project alluxio by Alluxio.

the class EmbeddedJournalIntegrationTestFaultTolerance method copySnapshotToFollower.

@Test
public void copySnapshotToFollower() throws Exception {
    mCluster = MultiProcessCluster.newBuilder(PortCoordination.EMBEDDED_JOURNAL_SNAPSHOT_FOLLOWER).setClusterName("EmbeddedJournalFaultTolerance_copySnapshotToFollower").setNumMasters(NUM_MASTERS).setNumWorkers(NUM_WORKERS).addProperty(PropertyKey.MASTER_JOURNAL_TYPE, JournalType.EMBEDDED.toString()).addProperty(PropertyKey.MASTER_JOURNAL_FLUSH_TIMEOUT_MS, "5min").addProperty(PropertyKey.MASTER_JOURNAL_CHECKPOINT_PERIOD_ENTRIES, "1000").addProperty(PropertyKey.MASTER_JOURNAL_LOG_SIZE_BYTES_MAX, "50KB").addProperty(PropertyKey.MASTER_EMBEDDED_JOURNAL_MIN_ELECTION_TIMEOUT, "3s").addProperty(PropertyKey.MASTER_EMBEDDED_JOURNAL_MAX_ELECTION_TIMEOUT, "6s").addProperty(PropertyKey.MASTER_STANDBY_HEARTBEAT_INTERVAL, "5s").build();
    mCluster.start();
    int catchUpMasterIndex = (mCluster.getPrimaryMasterIndex(MASTER_INDEX_WAIT_TIME) + 1) % NUM_MASTERS;
    AlluxioURI testDir = new AlluxioURI("/dir");
    FileSystem fs = mCluster.getFileSystemClient();
    fs.createDirectory(testDir);
    for (int i = 0; i < 2000; i++) {
        fs.createDirectory(testDir.join("file" + i));
    }
    mCluster.getMetaMasterClient().checkpoint();
    mCluster.stopMaster(catchUpMasterIndex);
    File catchupJournalDir = new File(mCluster.getJournalDir(catchUpMasterIndex));
    FileUtils.deleteDirectory(catchupJournalDir);
    assertTrue(catchupJournalDir.mkdirs());
    mCluster.startMaster(catchUpMasterIndex);
    File raftDir = new File(RaftJournalUtils.getRaftJournalDir(catchupJournalDir), RaftJournalSystem.RAFT_GROUP_UUID.toString());
    waitForSnapshot(raftDir);
    mCluster.stopMaster(catchUpMasterIndex);
    SimpleStateMachineStorage storage = new SimpleStateMachineStorage();
    storage.init(new RaftStorageImpl(raftDir, RaftServerConfigKeys.Log.CorruptionPolicy.getDefault()));
    SingleFileSnapshotInfo snapshot = storage.findLatestSnapshot();
    assertNotNull(snapshot);
    mCluster.notifySuccess();
}
Also used : SingleFileSnapshotInfo(org.apache.ratis.statemachine.impl.SingleFileSnapshotInfo) FileSystem(alluxio.client.file.FileSystem) SimpleStateMachineStorage(org.apache.ratis.statemachine.impl.SimpleStateMachineStorage) RaftStorageImpl(org.apache.ratis.server.storage.RaftStorageImpl) File(java.io.File) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

RaftStorageImpl (org.apache.ratis.server.storage.RaftStorageImpl)6 SimpleStateMachineStorage (org.apache.ratis.statemachine.impl.SimpleStateMachineStorage)5 File (java.io.File)4 RaftStorage (org.apache.ratis.server.storage.RaftStorage)4 SingleFileSnapshotInfo (org.apache.ratis.statemachine.impl.SingleFileSnapshotInfo)4 IOException (java.io.IOException)3 AlluxioURI (alluxio.AlluxioURI)2 FileSystem (alluxio.client.file.FileSystem)2 FileNotFoundException (java.io.FileNotFoundException)2 Test (org.junit.Test)2 CheckpointInputStream (alluxio.master.journal.checkpoint.CheckpointInputStream)1 Journal (alluxio.proto.journal.Journal)1 BufferedOutputStream (java.io.BufferedOutputStream)1 DataInputStream (java.io.DataInputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 LogSegmentPath (org.apache.ratis.server.raftlog.segmented.LogSegmentPath)1