Search in sources :

Example 1 with TransactionInfo

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

the class SCMStateMachine method takeSnapshot.

@Override
public long takeSnapshot() throws IOException {
    TermIndex lastTermIndex = getLastAppliedTermIndex();
    long lastAppliedIndex = lastTermIndex.getIndex();
    if (!isInitialized) {
        return lastAppliedIndex;
    }
    long startTime = Time.monotonicNow();
    TransactionInfo latestTrxInfo = transactionBuffer.getLatestTrxInfo();
    TransactionInfo lastAppliedTrxInfo = TransactionInfo.fromTermIndex(lastTermIndex);
    if (latestTrxInfo.compareTo(lastAppliedTrxInfo) < 0) {
        transactionBuffer.updateLatestTrxInfo(lastAppliedTrxInfo);
        transactionBuffer.setLatestSnapshot(lastAppliedTrxInfo.toSnapshotInfo());
    } else {
        lastAppliedIndex = latestTrxInfo.getTransactionIndex();
    }
    transactionBuffer.flush();
    LOG.info("Current Snapshot Index {}, takeSnapshot took {} ms", lastAppliedIndex, Time.monotonicNow() - startTime);
    return lastAppliedIndex;
}
Also used : TransactionInfo(org.apache.hadoop.hdds.utils.TransactionInfo) TermIndex(org.apache.ratis.server.protocol.TermIndex)

Example 2 with TransactionInfo

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

the class TestOzoneManagerDoubleBufferWithOMResponse method testDoubleBufferWithMixOfTransactions.

/**
 * This test first creates a volume, and then does a mix of transactions
 * like create/delete buckets and add them to double buffer. Then it
 * verifies OM DB entries are matching with actual responses added to
 * double buffer or not.
 */
@Test
public void testDoubleBufferWithMixOfTransactions() throws Exception {
    // This test checks count, data in table is correct or not.
    Queue<OMBucketCreateResponse> bucketQueue = new ConcurrentLinkedQueue<>();
    Queue<OMBucketDeleteResponse> deleteBucketQueue = new ConcurrentLinkedQueue<>();
    String volumeName = UUID.randomUUID().toString();
    OMVolumeCreateResponse omVolumeCreateResponse = (OMVolumeCreateResponse) createVolume(volumeName, trxId.incrementAndGet());
    int bucketCount = 10;
    doMixTransactions(volumeName, bucketCount, deleteBucketQueue, bucketQueue);
    // As for every 2 transactions of create bucket we add deleted bucket.
    final int deleteCount = 5;
    // We are doing +1 for volume transaction.
    GenericTestUtils.waitFor(() -> doubleBuffer.getFlushedTransactionCount() == (bucketCount + deleteCount + 1), 100, 120000);
    Assert.assertEquals(1, omMetadataManager.countRowsInTable(omMetadataManager.getVolumeTable()));
    Assert.assertEquals(5, omMetadataManager.countRowsInTable(omMetadataManager.getBucketTable()));
    // Now after this in our DB we should have 5 buckets and one volume
    checkVolume(volumeName, omVolumeCreateResponse);
    checkCreateBuckets(bucketQueue);
    checkDeletedBuckets(deleteBucketQueue);
    // Check lastAppliedIndex is updated correctly or not.
    GenericTestUtils.waitFor(() -> bucketCount + deleteCount + 1 == lastAppliedIndex, 100, 30000);
    TransactionInfo transactionInfo = omMetadataManager.getTransactionInfoTable().get(TRANSACTION_INFO_KEY);
    assertNotNull(transactionInfo);
    Assert.assertEquals(lastAppliedIndex, transactionInfo.getTransactionIndex());
    Assert.assertEquals(term, transactionInfo.getTerm());
}
Also used : OMBucketDeleteResponse(org.apache.hadoop.ozone.om.response.bucket.OMBucketDeleteResponse) OMBucketCreateResponse(org.apache.hadoop.ozone.om.response.bucket.OMBucketCreateResponse) TransactionInfo(org.apache.hadoop.hdds.utils.TransactionInfo) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) OMVolumeCreateResponse(org.apache.hadoop.ozone.om.response.volume.OMVolumeCreateResponse) Test(org.junit.Test)

Example 3 with TransactionInfo

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

the class OzoneManager method instantiatePrepareStateOnStartup.

/**
 * Determines if the prepare gate should be enabled on this OM after OM
 * is restarted.
 * This must be done after metadataManager is instantiated
 * and before the RPC server is started.
 */
private void instantiatePrepareStateOnStartup() throws IOException {
    TransactionInfo txnInfo = metadataManager.getTransactionInfoTable().get(TRANSACTION_INFO_KEY);
    if (txnInfo == null) {
        // No prepare request could be received if there are not transactions.
        prepareState = new OzoneManagerPrepareState(configuration);
    } else {
        prepareState = new OzoneManagerPrepareState(configuration, txnInfo.getTransactionIndex());
        TransactionInfo dbPrepareValue = metadataManager.getTransactionInfoTable().get(PREPARE_MARKER_KEY);
        boolean hasMarkerFile = (prepareState.getState().getStatus() == PrepareStatus.PREPARE_COMPLETED);
        boolean hasDBMarker = (dbPrepareValue != null);
        if (hasDBMarker) {
            long dbPrepareIndex = dbPrepareValue.getTransactionIndex();
            if (hasMarkerFile) {
                long prepareFileIndex = prepareState.getState().getIndex();
                // since this is synced through Ratis, to avoid divergence.
                if (prepareFileIndex != dbPrepareIndex) {
                    LOG.warn("Prepare marker file index {} does not match DB prepare " + "index {}. Writing DB index to prepare file and maintaining " + "prepared state.", prepareFileIndex, dbPrepareIndex);
                    prepareState.finishPrepare(dbPrepareIndex);
                }
            // Else, marker and DB are present and match, so OM is prepared.
            } else {
                // Prepare cancelled with startup flag to remove marker file.
                // Persist this to the DB.
                // If the startup flag is used it should be used on all OMs to avoid
                // divergence.
                metadataManager.getTransactionInfoTable().delete(PREPARE_MARKER_KEY);
            }
        } else if (hasMarkerFile) {
            // through, OM should replay it so both the DB and marker file exist.
            throw new OMException("Prepare marker file found on startup without " + "a corresponding database entry. Corrupt prepare state.", ResultCodes.PREPARE_FAILED);
        }
    // Else, no DB or marker file, OM is not prepared.
    }
}
Also used : TransactionInfo(org.apache.hadoop.hdds.utils.TransactionInfo) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Example 4 with TransactionInfo

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

the class OzoneManager method installCheckpoint.

/**
 * Install checkpoint. If the checkpoints snapshot index is greater than
 * OM's last applied transaction index, then re-initialize the OM
 * state via this checkpoint. Before re-initializing OM state, the OM Ratis
 * server should be stopped so that no new transactions can be applied.
 */
TermIndex installCheckpoint(String leaderId, DBCheckpoint omDBCheckpoint) throws Exception {
    Path checkpointLocation = omDBCheckpoint.getCheckpointLocation();
    TransactionInfo checkpointTrxnInfo = OzoneManagerRatisUtils.getTrxnInfoFromCheckpoint(configuration, checkpointLocation);
    LOG.info("Installing checkpoint with OMTransactionInfo {}", checkpointTrxnInfo);
    return installCheckpoint(leaderId, checkpointLocation, checkpointTrxnInfo);
}
Also used : Path(java.nio.file.Path) TransactionInfo(org.apache.hadoop.hdds.utils.TransactionInfo)

Example 5 with TransactionInfo

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

the class TestTransactionInfoCodec method toAndFromPersistedFormat.

@Test
public void toAndFromPersistedFormat() throws Exception {
    TransactionInfo transactionInfo = new TransactionInfo.Builder().setTransactionIndex(100).setCurrentTerm(11).build();
    TransactionInfo convertedTransactionInfo = codec.fromPersistedFormat(codec.toPersistedFormat(transactionInfo));
    Assert.assertEquals(transactionInfo, convertedTransactionInfo);
}
Also used : TransactionInfo(org.apache.hadoop.hdds.utils.TransactionInfo) Test(org.junit.Test)

Aggregations

TransactionInfo (org.apache.hadoop.hdds.utils.TransactionInfo)18 Path (java.nio.file.Path)5 TermIndex (org.apache.ratis.server.protocol.TermIndex)5 Test (org.junit.Test)5 SCMDBDefinition (org.apache.hadoop.hdds.scm.metadata.SCMDBDefinition)4 StorageContainerManager (org.apache.hadoop.hdds.scm.server.StorageContainerManager)3 DBCheckpoint (org.apache.hadoop.hdds.utils.db.DBCheckpoint)3 Test (org.junit.jupiter.api.Test)3 File (java.io.File)2 IOException (java.io.IOException)2 OzoneManagerRatisServer (org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer)2 GenericTestUtils (org.apache.ozone.test.GenericTestUtils)2 Preconditions (com.google.common.base.Preconditions)1 Arrays (java.util.Arrays)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 CopyDBCheckpointRequestProto (org.apache.hadoop.hdds.protocol.scm.proto.InterSCMProtocolProtos.CopyDBCheckpointRequestProto)1 CopyDBCheckpointResponseProto (org.apache.hadoop.hdds.protocol.scm.proto.InterSCMProtocolProtos.CopyDBCheckpointResponseProto)1 InterSCMProtocolServiceGrpc (org.apache.hadoop.hdds.protocol.scm.proto.InterSCMProtocolServiceGrpc)1 DeletedBlockLog (org.apache.hadoop.hdds.scm.block.DeletedBlockLog)1 DeletedBlockLogImpl (org.apache.hadoop.hdds.scm.block.DeletedBlockLogImpl)1