Search in sources :

Example 1 with DeletedBlockLog

use of org.apache.hadoop.hdds.scm.block.DeletedBlockLog in project ozone by apache.

the class SCMHADBTransactionBufferImpl method flush.

@Override
public void flush() throws IOException {
    // write latest trx info into trx table in the same batch
    Table<String, TransactionInfo> transactionInfoTable = metadataStore.getTransactionInfoTable();
    transactionInfoTable.putWithBatch(currentBatchOperation, TRANSACTION_INFO_KEY, latestTrxInfo);
    metadataStore.getStore().commitBatchOperation(currentBatchOperation);
    currentBatchOperation.close();
    this.latestSnapshot = latestTrxInfo.toSnapshotInfo();
    // reset batch operation
    currentBatchOperation = metadataStore.getStore().initBatchOperation();
    DeletedBlockLog deletedBlockLog = scm.getScmBlockManager().getDeletedBlockLog();
    Preconditions.checkArgument(deletedBlockLog instanceof DeletedBlockLogImpl);
    ((DeletedBlockLogImpl) deletedBlockLog).onFlush();
}
Also used : DeletedBlockLogImpl(org.apache.hadoop.hdds.scm.block.DeletedBlockLogImpl) TransactionInfo(org.apache.hadoop.hdds.utils.TransactionInfo) DeletedBlockLog(org.apache.hadoop.hdds.scm.block.DeletedBlockLog)

Example 2 with DeletedBlockLog

use of org.apache.hadoop.hdds.scm.block.DeletedBlockLog in project ozone by apache.

the class TestStorageContainerManager method testBlockDeletionTransactions.

@Test
public void testBlockDeletionTransactions() throws Exception {
    int numKeys = 5;
    OzoneConfiguration conf = new OzoneConfiguration();
    conf.setTimeDuration(HDDS_CONTAINER_REPORT_INTERVAL, 100, TimeUnit.MILLISECONDS);
    conf.setTimeDuration(HDDS_COMMAND_STATUS_REPORT_INTERVAL, 100, TimeUnit.MILLISECONDS);
    conf.setTimeDuration(ScmConfigKeys.OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL, 3000, TimeUnit.MILLISECONDS);
    conf.setInt(ScmConfigKeys.OZONE_SCM_BLOCK_DELETION_MAX_RETRY, 5);
    conf.setTimeDuration(OzoneConfigKeys.OZONE_BLOCK_DELETING_SERVICE_INTERVAL, 1, TimeUnit.SECONDS);
    ScmConfig scmConfig = conf.getObject(ScmConfig.class);
    scmConfig.setBlockDeletionInterval(Duration.ofSeconds(1));
    conf.setFromObject(scmConfig);
    // Reset container provision size, otherwise only one container
    // is created by default.
    conf.setInt(ScmConfigKeys.OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT, numKeys);
    MiniOzoneCluster cluster = MiniOzoneCluster.newBuilder(conf).setHbInterval(100).build();
    cluster.waitForClusterToBeReady();
    try {
        DeletedBlockLog delLog = cluster.getStorageContainerManager().getScmBlockManager().getDeletedBlockLog();
        Assert.assertEquals(0, delLog.getNumOfValidTransactions());
        // Create {numKeys} random names keys.
        TestStorageContainerManagerHelper helper = new TestStorageContainerManagerHelper(cluster, conf);
        Map<String, OmKeyInfo> keyLocations = helper.createKeys(numKeys, 4096);
        // Wait for container report
        Thread.sleep(1000);
        for (OmKeyInfo keyInfo : keyLocations.values()) {
            OzoneTestUtils.closeContainers(keyInfo.getKeyLocationVersions(), cluster.getStorageContainerManager());
        }
        Map<Long, List<Long>> containerBlocks = createDeleteTXLog(cluster.getStorageContainerManager(), delLog, keyLocations, helper);
        // Verify a few TX gets created in the TX log.
        Assert.assertTrue(delLog.getNumOfValidTransactions() > 0);
        // Once TXs are written into the log, SCM starts to fetch TX
        // entries from the log and schedule block deletions in HB interval,
        // after sometime, all the TX should be proceed and by then
        // the number of containerBlocks of all known containers will be
        // empty again.
        GenericTestUtils.waitFor(() -> {
            try {
                if (SCMHAUtils.isSCMHAEnabled(cluster.getConf())) {
                    cluster.getStorageContainerManager().getScmHAManager().asSCMHADBTransactionBuffer().flush();
                }
                return delLog.getNumOfValidTransactions() == 0;
            } catch (IOException e) {
                return false;
            }
        }, 1000, 10000);
        Assert.assertTrue(helper.verifyBlocksWithTxnTable(containerBlocks));
        // but unknown block IDs.
        for (Long containerID : containerBlocks.keySet()) {
            // Add 2 TXs per container.
            Map<Long, List<Long>> deletedBlocks = new HashMap<>();
            List<Long> blocks = new ArrayList<>();
            blocks.add(RandomUtils.nextLong());
            blocks.add(RandomUtils.nextLong());
            deletedBlocks.put(containerID, blocks);
            addTransactions(cluster.getStorageContainerManager(), delLog, deletedBlocks);
        }
        // Verify a few TX gets created in the TX log.
        Assert.assertTrue(delLog.getNumOfValidTransactions() > 0);
        // These blocks cannot be found in the container, skip deleting them
        // eventually these TX will success.
        GenericTestUtils.waitFor(() -> {
            try {
                if (SCMHAUtils.isSCMHAEnabled(cluster.getConf())) {
                    cluster.getStorageContainerManager().getScmHAManager().asSCMHADBTransactionBuffer().flush();
                }
                return delLog.getFailedTransactions().size() == 0;
            } catch (IOException e) {
                return false;
            }
        }, 1000, 20000);
    } finally {
        cluster.shutdown();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) DeletedBlockLog(org.apache.hadoop.hdds.scm.block.DeletedBlockLog) IOException(java.io.IOException) ScmConfig(org.apache.hadoop.hdds.scm.ScmConfig) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 3 with DeletedBlockLog

use of org.apache.hadoop.hdds.scm.block.DeletedBlockLog in project ozone by apache.

the class TestStorageContainerManager method testBlockDeletingThrottling.

@Test
public void testBlockDeletingThrottling() throws Exception {
    int numKeys = 15;
    OzoneConfiguration conf = new OzoneConfiguration();
    conf.setTimeDuration(HDDS_CONTAINER_REPORT_INTERVAL, 1, TimeUnit.SECONDS);
    conf.setInt(ScmConfigKeys.OZONE_SCM_BLOCK_DELETION_MAX_RETRY, 5);
    conf.setTimeDuration(OzoneConfigKeys.OZONE_BLOCK_DELETING_SERVICE_INTERVAL, 100, TimeUnit.MILLISECONDS);
    ScmConfig scmConfig = conf.getObject(ScmConfig.class);
    scmConfig.setBlockDeletionInterval(Duration.ofMillis(100));
    conf.setFromObject(scmConfig);
    conf.setInt(ScmConfigKeys.OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT, numKeys);
    conf.setBoolean(HDDS_SCM_SAFEMODE_PIPELINE_CREATION, false);
    MiniOzoneCluster cluster = MiniOzoneCluster.newBuilder(conf).setHbInterval(1000).setHbProcessorInterval(3000).setNumDatanodes(1).build();
    cluster.waitForClusterToBeReady();
    cluster.waitForPipelineTobeReady(HddsProtos.ReplicationFactor.ONE, 30000);
    try {
        DeletedBlockLog delLog = cluster.getStorageContainerManager().getScmBlockManager().getDeletedBlockLog();
        Assert.assertEquals(0, delLog.getNumOfValidTransactions());
        int limitSize = 1;
        // Reset limit value to 1, so that we only allow one TX is dealt per
        // datanode.
        SCMBlockDeletingService delService = cluster.getStorageContainerManager().getScmBlockManager().getSCMBlockDeletingService();
        delService.setBlockDeleteTXNum(limitSize);
        // Create {numKeys} random names keys.
        TestStorageContainerManagerHelper helper = new TestStorageContainerManagerHelper(cluster, conf);
        Map<String, OmKeyInfo> keyLocations = helper.createKeys(numKeys, 4096);
        // Wait for container report
        Thread.sleep(5000);
        for (OmKeyInfo keyInfo : keyLocations.values()) {
            OzoneTestUtils.closeContainers(keyInfo.getKeyLocationVersions(), cluster.getStorageContainerManager());
        }
        createDeleteTXLog(cluster.getStorageContainerManager(), delLog, keyLocations, helper);
        // Verify a few TX gets created in the TX log.
        Assert.assertTrue(delLog.getNumOfValidTransactions() > 0);
        // Verify the size in delete commands is expected.
        GenericTestUtils.waitFor(() -> {
            NodeManager nodeManager = cluster.getStorageContainerManager().getScmNodeManager();
            LayoutVersionManager versionManager = nodeManager.getLayoutVersionManager();
            StorageContainerDatanodeProtocolProtos.LayoutVersionProto layoutInfo = StorageContainerDatanodeProtocolProtos.LayoutVersionProto.newBuilder().setSoftwareLayoutVersion(versionManager.getSoftwareLayoutVersion()).setMetadataLayoutVersion(versionManager.getMetadataLayoutVersion()).build();
            List<SCMCommand> commands = nodeManager.processHeartbeat(nodeManager.getNodes(NodeStatus.inServiceHealthy()).get(0), layoutInfo);
            if (commands != null) {
                for (SCMCommand cmd : commands) {
                    if (cmd.getType() == SCMCommandProto.Type.deleteBlocksCommand) {
                        List<DeletedBlocksTransaction> deletedTXs = ((DeleteBlocksCommand) cmd).blocksTobeDeleted();
                        return deletedTXs != null && deletedTXs.size() == limitSize;
                    }
                }
            }
            return false;
        }, 500, 10000);
    } finally {
        cluster.shutdown();
    }
}
Also used : SCMBlockDeletingService(org.apache.hadoop.hdds.scm.block.SCMBlockDeletingService) DeleteBlocksCommand(org.apache.hadoop.ozone.protocol.commands.DeleteBlocksCommand) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) DeletedBlockLog(org.apache.hadoop.hdds.scm.block.DeletedBlockLog) ScmConfig(org.apache.hadoop.hdds.scm.ScmConfig) NodeManager(org.apache.hadoop.hdds.scm.node.NodeManager) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) LayoutVersionManager(org.apache.hadoop.ozone.upgrade.LayoutVersionManager) StorageContainerDatanodeProtocolProtos(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos) DeletedBlocksTransaction(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.DeletedBlocksTransaction) SCMCommand(org.apache.hadoop.ozone.protocol.commands.SCMCommand) Test(org.junit.Test)

Example 4 with DeletedBlockLog

use of org.apache.hadoop.hdds.scm.block.DeletedBlockLog in project ozone by apache.

the class SCMStateMachine method notifyLeaderChanged.

@Override
public void notifyLeaderChanged(RaftGroupMemberId groupMemberId, RaftPeerId newLeaderId) {
    if (!isInitialized) {
        return;
    }
    currentLeaderTerm.set(scm.getScmHAManager().getRatisServer().getDivision().getInfo().getCurrentTerm());
    if (!groupMemberId.getPeerId().equals(newLeaderId)) {
        LOG.info("leader changed, yet current SCM is still follower.");
        return;
    }
    LOG.info("current SCM becomes leader of term {}.", currentLeaderTerm);
    scm.getScmContext().updateLeaderAndTerm(true, currentLeaderTerm.get());
    scm.getSequenceIdGen().invalidateBatch();
    DeletedBlockLog deletedBlockLog = scm.getScmBlockManager().getDeletedBlockLog();
    Preconditions.checkArgument(deletedBlockLog instanceof DeletedBlockLogImpl);
    ((DeletedBlockLogImpl) deletedBlockLog).onBecomeLeader();
    scm.getScmDecommissionManager().onBecomeLeader();
}
Also used : DeletedBlockLogImpl(org.apache.hadoop.hdds.scm.block.DeletedBlockLogImpl) DeletedBlockLog(org.apache.hadoop.hdds.scm.block.DeletedBlockLog)

Aggregations

DeletedBlockLog (org.apache.hadoop.hdds.scm.block.DeletedBlockLog)4 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)2 ScmConfig (org.apache.hadoop.hdds.scm.ScmConfig)2 DeletedBlockLogImpl (org.apache.hadoop.hdds.scm.block.DeletedBlockLogImpl)2 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 StorageContainerDatanodeProtocolProtos (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos)1 DeletedBlocksTransaction (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.DeletedBlocksTransaction)1 SCMBlockDeletingService (org.apache.hadoop.hdds.scm.block.SCMBlockDeletingService)1 NodeManager (org.apache.hadoop.hdds.scm.node.NodeManager)1 TransactionInfo (org.apache.hadoop.hdds.utils.TransactionInfo)1 DeleteBlocksCommand (org.apache.hadoop.ozone.protocol.commands.DeleteBlocksCommand)1 SCMCommand (org.apache.hadoop.ozone.protocol.commands.SCMCommand)1 LayoutVersionManager (org.apache.hadoop.ozone.upgrade.LayoutVersionManager)1