Search in sources :

Example 1 with QuorumJournalManager

use of org.apache.hadoop.hdfs.qjournal.client.QuorumJournalManager in project hadoop by apache.

the class TestQuorumJournalManagerUnit method setup.

@Before
public void setup() throws Exception {
    spyLoggers = ImmutableList.of(mockLogger(), mockLogger(), mockLogger());
    qjm = new QuorumJournalManager(conf, new URI("qjournal://host/jid"), FAKE_NSINFO) {

        @Override
        protected List<AsyncLogger> createLoggers(AsyncLogger.Factory factory) {
            return spyLoggers;
        }
    };
    for (AsyncLogger logger : spyLoggers) {
        futureReturns(GetJournalStateResponseProto.newBuilder().setLastPromisedEpoch(0).setHttpPort(-1).build()).when(logger).getJournalState();
        futureReturns(NewEpochResponseProto.newBuilder().build()).when(logger).newEpoch(Mockito.anyLong());
        futureReturns(null).when(logger).format(Mockito.<NamespaceInfo>any());
    }
    qjm.recoverUnfinalizedSegments();
}
Also used : AsyncLogger(org.apache.hadoop.hdfs.qjournal.client.AsyncLogger) QuorumJournalManager(org.apache.hadoop.hdfs.qjournal.client.QuorumJournalManager) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) URI(java.net.URI) Before(org.junit.Before)

Example 2 with QuorumJournalManager

use of org.apache.hadoop.hdfs.qjournal.client.QuorumJournalManager in project hadoop by apache.

the class TestEpochsAreUnique method testSingleThreaded.

@Test
public void testSingleThreaded() throws IOException {
    Configuration conf = new Configuration();
    MiniJournalCluster cluster = new MiniJournalCluster.Builder(conf).build();
    cluster.waitActive();
    URI uri = cluster.getQuorumJournalURI(JID);
    QuorumJournalManager qjm = new QuorumJournalManager(conf, uri, FAKE_NSINFO);
    try {
        qjm.format(FAKE_NSINFO);
    } finally {
        qjm.close();
    }
    try {
        // With no failures or contention, epochs should increase one-by-one
        for (int i = 0; i < 5; i++) {
            qjm = new QuorumJournalManager(conf, uri, FAKE_NSINFO);
            try {
                qjm.createNewUniqueEpoch();
                assertEquals(i + 1, qjm.getLoggerSetForTests().getEpoch());
            } finally {
                qjm.close();
            }
        }
        long prevEpoch = 5;
        // skipping some
        for (int i = 0; i < 20; i++) {
            long newEpoch = -1;
            while (true) {
                qjm = new QuorumJournalManager(conf, uri, FAKE_NSINFO, new FaultyLoggerFactory());
                try {
                    qjm.createNewUniqueEpoch();
                    newEpoch = qjm.getLoggerSetForTests().getEpoch();
                    break;
                } catch (IOException ioe) {
                // It's OK to fail to create an epoch, since we randomly inject
                // faults. It's possible we'll inject faults in too many of the
                // underlying nodes, and a failure is expected in that case
                } finally {
                    qjm.close();
                }
            }
            LOG.info("Created epoch " + newEpoch);
            assertTrue("New epoch " + newEpoch + " should be greater than previous " + prevEpoch, newEpoch > prevEpoch);
            prevEpoch = newEpoch;
        }
    } finally {
        cluster.shutdown();
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) QuorumJournalManager(org.apache.hadoop.hdfs.qjournal.client.QuorumJournalManager) MiniJournalCluster(org.apache.hadoop.hdfs.qjournal.MiniJournalCluster) IOException(java.io.IOException) URI(java.net.URI) Test(org.junit.Test)

Aggregations

URI (java.net.URI)2 QuorumJournalManager (org.apache.hadoop.hdfs.qjournal.client.QuorumJournalManager)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 List (java.util.List)1 Configuration (org.apache.hadoop.conf.Configuration)1 MiniJournalCluster (org.apache.hadoop.hdfs.qjournal.MiniJournalCluster)1 AsyncLogger (org.apache.hadoop.hdfs.qjournal.client.AsyncLogger)1 Before (org.junit.Before)1 Test (org.junit.Test)1