Search in sources :

Example 1 with DBCheckpoint

use of org.apache.hadoop.hdds.utils.db.DBCheckpoint in project ozone by apache.

the class SCMStateMachine method reinitialize.

@Override
public void reinitialize() throws IOException {
    Preconditions.checkNotNull(installingDBCheckpoint);
    DBCheckpoint checkpoint = installingDBCheckpoint;
    // explicitly set installingDBCheckpoint to be null
    installingDBCheckpoint = null;
    TermIndex termIndex = null;
    try {
        termIndex = scm.getScmHAManager().installCheckpoint(checkpoint);
    } catch (Exception e) {
        LOG.error("Failed to reinitialize SCMStateMachine.", e);
        throw new IOException(e);
    }
    // re-initialize the DBTransactionBuffer and update the lastAppliedIndex.
    try {
        transactionBuffer.init();
        this.setLastAppliedTermIndex(termIndex);
    } catch (IOException ioe) {
        LOG.error("Failed to unpause ", ioe);
    }
    getLifeCycle().transition(LifeCycle.State.STARTING);
    getLifeCycle().transition(LifeCycle.State.RUNNING);
}
Also used : DBCheckpoint(org.apache.hadoop.hdds.utils.db.DBCheckpoint) IOException(java.io.IOException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TermIndex(org.apache.ratis.server.protocol.TermIndex)

Example 2 with DBCheckpoint

use of org.apache.hadoop.hdds.utils.db.DBCheckpoint in project ozone by apache.

the class SCMStateMachine method notifyInstallSnapshotFromLeader.

/**
 * Leader SCM has purged entries from its log. To catch up, SCM must download
 * the latest checkpoint from the leader SCM and install it.
 * @param roleInfoProto the leader node information
 * @param firstTermIndexInLog TermIndex of the first append entry available
 *                           in the Leader's log.
 * @return the last term index included in the installed snapshot.
 */
@Override
public CompletableFuture<TermIndex> notifyInstallSnapshotFromLeader(RaftProtos.RoleInfoProto roleInfoProto, TermIndex firstTermIndexInLog) {
    if (!roleInfoProto.getFollowerInfo().hasLeaderInfo()) {
        return JavaUtils.completeExceptionally(new IOException("Failed to " + "notifyInstallSnapshotFromLeader due to missing leader info"));
    }
    String leaderAddress = roleInfoProto.getFollowerInfo().getLeaderInfo().getId().getAddress();
    Optional<SCMNodeDetails> leaderDetails = scm.getSCMHANodeDetails().getPeerNodeDetails().stream().filter(p -> p.getRatisHostPortStr().equals(leaderAddress)).findFirst();
    Preconditions.checkState(leaderDetails.isPresent());
    final String leaderNodeId = leaderDetails.get().getNodeId();
    LOG.info("Received install snapshot notification from SCM leader: {} with " + "term index: {}", leaderAddress, firstTermIndexInLog);
    CompletableFuture<TermIndex> future = CompletableFuture.supplyAsync(() -> {
        DBCheckpoint checkpoint = scm.getScmHAManager().downloadCheckpointFromLeader(leaderNodeId);
        if (checkpoint == null) {
            return null;
        }
        TermIndex termIndex = scm.getScmHAManager().verifyCheckpointFromLeader(leaderNodeId, checkpoint);
        if (termIndex != null) {
            setInstallingDBCheckpoint(checkpoint);
        }
        return termIndex;
    }, installSnapshotExecutor);
    return future;
}
Also used : TransactionInfo(org.apache.hadoop.hdds.utils.TransactionInfo) TermIndex(org.apache.ratis.server.protocol.TermIndex) RaftGroupMemberId(org.apache.ratis.protocol.RaftGroupMemberId) TransactionContext(org.apache.ratis.statemachine.TransactionContext) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) DeletedBlockLogImpl(org.apache.hadoop.hdds.scm.block.DeletedBlockLogImpl) RaftGroupId(org.apache.ratis.protocol.RaftGroupId) Message(org.apache.ratis.protocol.Message) Map(java.util.Map) DBCheckpoint(org.apache.hadoop.hdds.utils.db.DBCheckpoint) RaftStorage(org.apache.ratis.server.storage.RaftStorage) JavaUtils(org.apache.ratis.util.JavaUtils) StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) ExecutorService(java.util.concurrent.ExecutorService) SnapshotInfo(org.apache.ratis.statemachine.SnapshotInfo) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) StateMachine(org.apache.ratis.statemachine.StateMachine) Logger(org.slf4j.Logger) EnumMap(java.util.EnumMap) Collection(java.util.Collection) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) RaftProtos(org.apache.ratis.proto.RaftProtos) DeletedBlockLog(org.apache.hadoop.hdds.scm.block.DeletedBlockLog) IOException(java.io.IOException) SimpleStateMachineStorage(org.apache.ratis.statemachine.impl.SimpleStateMachineStorage) RequestType(org.apache.hadoop.hdds.protocol.proto.SCMRatisProtocol.RequestType) InvocationTargetException(java.lang.reflect.InvocationTargetException) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) HadoopExecutors(org.apache.hadoop.util.concurrent.HadoopExecutors) BaseStateMachine(org.apache.ratis.statemachine.impl.BaseStateMachine) ExitUtils(org.apache.ratis.util.ExitUtils) LifeCycle(org.apache.ratis.util.LifeCycle) Optional(java.util.Optional) Time(org.apache.hadoop.util.Time) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RaftServer(org.apache.ratis.server.RaftServer) DBCheckpoint(org.apache.hadoop.hdds.utils.db.DBCheckpoint) IOException(java.io.IOException) TermIndex(org.apache.ratis.server.protocol.TermIndex)

Example 3 with DBCheckpoint

use of org.apache.hadoop.hdds.utils.db.DBCheckpoint in project ozone by apache.

the class TestSCMInstallSnapshot method testInstallCheckPoint.

@Test
public void testInstallCheckPoint() throws Exception {
    DBCheckpoint checkpoint = downloadSnapshot();
    StorageContainerManager scm = cluster.getStorageContainerManager();
    DBStore db = HAUtils.loadDB(conf, checkpoint.getCheckpointLocation().getParent().toFile(), checkpoint.getCheckpointLocation().getFileName().toString(), new SCMDBDefinition());
    // Hack the transaction index in the checkpoint so as to ensure the
    // checkpointed transaction index is higher than when it was downloaded
    // from.
    Assert.assertNotNull(db);
    HAUtils.getTransactionInfoTable(db, new SCMDBDefinition()).put(OzoneConsts.TRANSACTION_INFO_KEY, TransactionInfo.builder().setCurrentTerm(10).setTransactionIndex(100).build());
    db.close();
    ContainerID cid = scm.getContainerManager().getContainers().get(0).containerID();
    PipelineID pipelineID = scm.getPipelineManager().getPipelines().get(0).getId();
    scm.getScmMetadataStore().getPipelineTable().delete(pipelineID);
    scm.getContainerManager().deleteContainer(cid);
    Assert.assertNull(scm.getScmMetadataStore().getPipelineTable().get(pipelineID));
    Assert.assertFalse(scm.getContainerManager().containerExist(cid));
    SCMStateMachine sm = scm.getScmHAManager().getRatisServer().getSCMStateMachine();
    sm.pause();
    sm.setInstallingDBCheckpoint(checkpoint);
    sm.reinitialize();
    Assert.assertNotNull(scm.getScmMetadataStore().getPipelineTable().get(pipelineID));
    Assert.assertNotNull(scm.getScmMetadataStore().getContainerTable().get(cid));
    Assert.assertTrue(scm.getPipelineManager().containsPipeline(pipelineID));
    Assert.assertTrue(scm.getContainerManager().containerExist(cid));
    Assert.assertEquals(100, scm.getScmMetadataStore().getTransactionInfoTable().get(OzoneConsts.TRANSACTION_INFO_KEY).getTransactionIndex());
    Assert.assertEquals(100, scm.getScmHAManager().asSCMHADBTransactionBuffer().getLatestTrxInfo().getTermIndex().getIndex());
}
Also used : StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) ContainerID(org.apache.hadoop.hdds.scm.container.ContainerID) DBCheckpoint(org.apache.hadoop.hdds.utils.db.DBCheckpoint) SCMDBDefinition(org.apache.hadoop.hdds.scm.metadata.SCMDBDefinition) PipelineID(org.apache.hadoop.hdds.scm.pipeline.PipelineID) SCMStateMachine(org.apache.hadoop.hdds.scm.ha.SCMStateMachine) DBStore(org.apache.hadoop.hdds.utils.db.DBStore) Test(org.junit.Test)

Example 4 with DBCheckpoint

use of org.apache.hadoop.hdds.utils.db.DBCheckpoint in project ozone by apache.

the class MockOzoneServiceProvider method testUpdateReconOmDBWithNewSnapshot.

@Test
public void testUpdateReconOmDBWithNewSnapshot() throws Exception {
    OMMetadataManager omMetadataManager = initializeNewOmMetadataManager(temporaryFolder.newFolder());
    ReconOMMetadataManager reconOMMetadataManager = getTestReconOmMetadataManager(omMetadataManager, temporaryFolder.newFolder());
    writeDataToOm(omMetadataManager, "key_one");
    writeDataToOm(omMetadataManager, "key_two");
    DBCheckpoint checkpoint = omMetadataManager.getStore().getCheckpoint(true);
    File tarFile = createTarFile(checkpoint.getCheckpointLocation());
    InputStream inputStream = new FileInputStream(tarFile);
    ReconUtils reconUtilsMock = getMockReconUtils();
    HttpURLConnection httpURLConnectionMock = mock(HttpURLConnection.class);
    when(httpURLConnectionMock.getInputStream()).thenReturn(inputStream);
    when(reconUtilsMock.makeHttpCall(any(), anyString(), anyBoolean())).thenReturn(httpURLConnectionMock);
    ReconTaskController reconTaskController = getMockTaskController();
    OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = new OzoneManagerServiceProviderImpl(configuration, reconOMMetadataManager, reconTaskController, reconUtilsMock, ozoneManagerProtocol);
    Assert.assertNull(reconOMMetadataManager.getKeyTable(getBucketLayout()).get("/sampleVol/bucketOne/key_one"));
    Assert.assertNull(reconOMMetadataManager.getKeyTable(getBucketLayout()).get("/sampleVol/bucketOne/key_two"));
    assertTrue(ozoneManagerServiceProvider.updateReconOmDBWithNewSnapshot());
    assertNotNull(reconOMMetadataManager.getKeyTable(getBucketLayout()).get("/sampleVol/bucketOne/key_one"));
    assertNotNull(reconOMMetadataManager.getKeyTable(getBucketLayout()).get("/sampleVol/bucketOne/key_two"));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ReconUtils(org.apache.hadoop.ozone.recon.ReconUtils) DBCheckpoint(org.apache.hadoop.hdds.utils.db.DBCheckpoint) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ReconOMMetadataManager(org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) ReconTaskController(org.apache.hadoop.ozone.recon.tasks.ReconTaskController) ReconOMMetadataManager(org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager) ReconUtils.createTarFile(org.apache.hadoop.ozone.recon.ReconUtils.createTarFile) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 5 with DBCheckpoint

use of org.apache.hadoop.hdds.utils.db.DBCheckpoint in project ozone by apache.

the class MockOzoneServiceProvider method testGetOzoneManagerDBSnapshot.

@Test
public void testGetOzoneManagerDBSnapshot() throws Exception {
    File reconOmSnapshotDbDir = temporaryFolder.newFolder();
    File checkpointDir = Paths.get(reconOmSnapshotDbDir.getAbsolutePath(), "testGetOzoneManagerDBSnapshot").toFile();
    checkpointDir.mkdir();
    File file1 = Paths.get(checkpointDir.getAbsolutePath(), "file1").toFile();
    String str = "File1 Contents";
    BufferedWriter writer = null;
    try {
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file1), UTF_8));
        writer.write(str);
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
    File file2 = Paths.get(checkpointDir.getAbsolutePath(), "file2").toFile();
    str = "File2 Contents";
    try {
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file2), UTF_8));
        writer.write(str);
    } finally {
        writer.close();
    }
    // Create test tar file.
    File tarFile = createTarFile(checkpointDir.toPath());
    InputStream fileInputStream = new FileInputStream(tarFile);
    ReconUtils reconUtilsMock = getMockReconUtils();
    HttpURLConnection httpURLConnectionMock = mock(HttpURLConnection.class);
    when(httpURLConnectionMock.getInputStream()).thenReturn(fileInputStream);
    when(reconUtilsMock.makeHttpCall(any(), anyString(), anyBoolean())).thenReturn(httpURLConnectionMock);
    ReconOMMetadataManager reconOMMetadataManager = mock(ReconOMMetadataManager.class);
    ReconTaskController reconTaskController = getMockTaskController();
    OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = new OzoneManagerServiceProviderImpl(configuration, reconOMMetadataManager, reconTaskController, reconUtilsMock, ozoneManagerProtocol);
    DBCheckpoint checkpoint = ozoneManagerServiceProvider.getOzoneManagerDBSnapshot();
    assertNotNull(checkpoint);
    assertTrue(checkpoint.getCheckpointLocation().toFile().isDirectory());
    assertTrue(checkpoint.getCheckpointLocation().toFile().listFiles().length == 2);
}
Also used : ReconUtils(org.apache.hadoop.ozone.recon.ReconUtils) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DBCheckpoint(org.apache.hadoop.hdds.utils.db.DBCheckpoint) ReconTaskController(org.apache.hadoop.ozone.recon.tasks.ReconTaskController) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FileInputStream(java.io.FileInputStream) BufferedWriter(java.io.BufferedWriter) HttpURLConnection(java.net.HttpURLConnection) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) ReconOMMetadataManager(org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager) ReconUtils.createTarFile(org.apache.hadoop.ozone.recon.ReconUtils.createTarFile) File(java.io.File) Test(org.junit.Test)

Aggregations

DBCheckpoint (org.apache.hadoop.hdds.utils.db.DBCheckpoint)23 File (java.io.File)10 IOException (java.io.IOException)10 Path (java.nio.file.Path)7 TermIndex (org.apache.ratis.server.protocol.TermIndex)7 Test (org.junit.Test)6 StorageContainerManager (org.apache.hadoop.hdds.scm.server.StorageContainerManager)5 RocksDBCheckpoint (org.apache.hadoop.hdds.utils.db.RocksDBCheckpoint)5 Test (org.junit.jupiter.api.Test)5 InputStream (java.io.InputStream)4 ReconUtils (org.apache.hadoop.ozone.recon.ReconUtils)4 GenericTestUtils (org.apache.ozone.test.GenericTestUtils)4 HttpURLConnection (java.net.HttpURLConnection)3 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)3 SCMStateMachine (org.apache.hadoop.hdds.scm.ha.SCMStateMachine)3 TransactionInfo (org.apache.hadoop.hdds.utils.TransactionInfo)3 OzoneManagerRatisServer (org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 FileInputStream (java.io.FileInputStream)2