Search in sources :

Example 1 with BlockGroup

use of org.apache.hadoop.ozone.common.BlockGroup in project ozone by apache.

the class SCMBlockProtocolServer method deleteKeyBlocks.

/**
 * Delete blocks for a set of object keys.
 *
 * @param keyBlocksInfoList list of block keys with object keys to delete.
 * @return deletion results.
 */
@Override
public List<DeleteBlockGroupResult> deleteKeyBlocks(List<BlockGroup> keyBlocksInfoList) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("SCM is informed by OM to delete {} blocks", keyBlocksInfoList.size());
    }
    List<DeleteBlockGroupResult> results = new ArrayList<>();
    Map<String, String> auditMap = Maps.newHashMap();
    ScmBlockLocationProtocolProtos.DeleteScmBlockResult.Result resultCode;
    Exception e = null;
    try {
        scm.getScmBlockManager().deleteBlocks(keyBlocksInfoList);
        resultCode = ScmBlockLocationProtocolProtos.DeleteScmBlockResult.Result.success;
    } catch (IOException ioe) {
        e = ioe;
        LOG.warn("Fail to delete {} keys", keyBlocksInfoList.size(), ioe);
        switch(ioe instanceof SCMException ? ((SCMException) ioe).getResult() : IO_EXCEPTION) {
            case SAFE_MODE_EXCEPTION:
                resultCode = ScmBlockLocationProtocolProtos.DeleteScmBlockResult.Result.safeMode;
                break;
            case FAILED_TO_FIND_BLOCK:
                resultCode = ScmBlockLocationProtocolProtos.DeleteScmBlockResult.Result.errorNotFound;
                break;
            default:
                resultCode = ScmBlockLocationProtocolProtos.DeleteScmBlockResult.Result.unknownFailure;
        }
    }
    for (BlockGroup bg : keyBlocksInfoList) {
        auditMap.put("KeyBlockToDelete", bg.toString());
        List<DeleteBlockResult> blockResult = new ArrayList<>();
        for (BlockID b : bg.getBlockIDList()) {
            blockResult.add(new DeleteBlockResult(b, resultCode));
        }
        results.add(new DeleteBlockGroupResult(bg.getGroupID(), blockResult));
    }
    if (e == null) {
        AUDIT.logWriteSuccess(buildAuditMessageForSuccess(SCMAction.DELETE_KEY_BLOCK, auditMap));
    } else {
        AUDIT.logWriteFailure(buildAuditMessageForFailure(SCMAction.DELETE_KEY_BLOCK, auditMap, e));
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) SCMException(org.apache.hadoop.hdds.scm.exceptions.SCMException) DeleteBlockResult(org.apache.hadoop.hdds.scm.container.common.helpers.DeleteBlockResult) DeleteBlockGroupResult(org.apache.hadoop.ozone.common.DeleteBlockGroupResult) BlockID(org.apache.hadoop.hdds.client.BlockID) SCMException(org.apache.hadoop.hdds.scm.exceptions.SCMException) BlockGroup(org.apache.hadoop.ozone.common.BlockGroup)

Example 2 with BlockGroup

use of org.apache.hadoop.ozone.common.BlockGroup in project ozone by apache.

the class ScmBlockLocationProtocolServerSideTranslatorPB method deleteScmKeyBlocks.

public DeleteScmKeyBlocksResponseProto deleteScmKeyBlocks(DeleteScmKeyBlocksRequestProto req) throws IOException {
    DeleteScmKeyBlocksResponseProto.Builder resp = DeleteScmKeyBlocksResponseProto.newBuilder();
    List<BlockGroup> infoList = req.getKeyBlocksList().stream().map(BlockGroup::getFromProto).collect(Collectors.toList());
    final List<DeleteBlockGroupResult> results = impl.deleteKeyBlocks(infoList);
    for (DeleteBlockGroupResult result : results) {
        DeleteKeyBlocksResultProto.Builder deleteResult = DeleteKeyBlocksResultProto.newBuilder().setObjectKey(result.getObjectKey()).addAllBlockResults(result.getBlockResultProtoList());
        resp.addResults(deleteResult.build());
    }
    return resp.build();
}
Also used : DeleteBlockGroupResult(org.apache.hadoop.ozone.common.DeleteBlockGroupResult) DeleteScmKeyBlocksResponseProto(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.DeleteScmKeyBlocksResponseProto) DeleteKeyBlocksResultProto(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.DeleteKeyBlocksResultProto) BlockGroup(org.apache.hadoop.ozone.common.BlockGroup)

Example 3 with BlockGroup

use of org.apache.hadoop.ozone.common.BlockGroup in project ozone by apache.

the class OmMetadataManagerImpl method getPendingDeletionKeys.

@Override
public List<BlockGroup> getPendingDeletionKeys(final int keyCount) throws IOException {
    List<BlockGroup> keyBlocksList = Lists.newArrayList();
    try (TableIterator<String, ? extends KeyValue<String, RepeatedOmKeyInfo>> keyIter = getDeletedTable().iterator()) {
        int currentCount = 0;
        while (keyIter.hasNext() && currentCount < keyCount) {
            KeyValue<String, RepeatedOmKeyInfo> kv = keyIter.next();
            if (kv != null) {
                RepeatedOmKeyInfo infoList = kv.getValue();
                // Get block keys as a list.
                for (OmKeyInfo info : infoList.getOmKeyInfoList()) {
                    OmKeyLocationInfoGroup latest = info.getLatestVersionLocations();
                    List<BlockID> item = latest.getLocationList().stream().map(b -> new BlockID(b.getContainerID(), b.getLocalID())).collect(Collectors.toList());
                    BlockGroup keyBlocks = BlockGroup.newBuilder().setKeyName(kv.getKey()).addAllBlockIDs(item).build();
                    keyBlocksList.add(keyBlocks);
                    currentCount++;
                }
            }
        }
    }
    return keyBlocksList;
}
Also used : TypedTable(org.apache.hadoop.hdds.utils.db.TypedTable) OmVolumeArgsCodec(org.apache.hadoop.ozone.om.codec.OmVolumeArgsCodec) LoggerFactory(org.slf4j.LoggerFactory) OzoneFSUtils(org.apache.hadoop.ozone.om.helpers.OzoneFSUtils) OmDirectoryInfoCodec(org.apache.hadoop.ozone.om.codec.OmDirectoryInfoCodec) DBStore(org.apache.hadoop.hdds.utils.db.DBStore) OZONE_OPEN_KEY_EXPIRE_THRESHOLD_SECONDS_DEFAULT(org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_OPEN_KEY_EXPIRE_THRESHOLD_SECONDS_DEFAULT) StringUtils(org.apache.commons.lang3.StringUtils) RepeatedOmKeyInfoCodec(org.apache.hadoop.ozone.om.codec.RepeatedOmKeyInfoCodec) OM_KEY_PREFIX(org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX) BucketLayout(org.apache.hadoop.ozone.om.helpers.BucketLayout) Duration(java.time.Duration) Map(java.util.Map) CacheValue(org.apache.hadoop.hdds.utils.db.cache.CacheValue) OzoneManagerLock(org.apache.hadoop.ozone.om.lock.OzoneManagerLock) OzoneTokenIdentifier(org.apache.hadoop.ozone.security.OzoneTokenIdentifier) OmMultipartUpload(org.apache.hadoop.ozone.om.helpers.OmMultipartUpload) DBStoreBuilder(org.apache.hadoop.hdds.utils.db.DBStoreBuilder) OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) TokenIdentifierCodec(org.apache.hadoop.ozone.om.codec.TokenIdentifierCodec) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) List(java.util.List) S3SecretValueCodec(org.apache.hadoop.ozone.om.codec.S3SecretValueCodec) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) RocksDBConfiguration(org.apache.hadoop.hdds.utils.db.RocksDBConfiguration) OM_DB_NAME(org.apache.hadoop.ozone.OzoneConsts.OM_DB_NAME) KeyValue(org.apache.hadoop.hdds.utils.db.Table.KeyValue) TransactionInfo(org.apache.hadoop.hdds.utils.TransactionInfo) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) OmPrefixInfo(org.apache.hadoop.ozone.om.helpers.OmPrefixInfo) BlockID(org.apache.hadoop.hdds.client.BlockID) HashMap(java.util.HashMap) OmUtils(org.apache.hadoop.ozone.OmUtils) TreeSet(java.util.TreeSet) ResultCodes(org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes) StringUtil(org.eclipse.jetty.util.StringUtil) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) UserVolumeInfoCodec(org.apache.hadoop.ozone.om.codec.UserVolumeInfoCodec) Lists(com.google.common.collect.Lists) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) S3SecretValue(org.apache.hadoop.ozone.om.helpers.S3SecretValue) DB_TRANSIENT_MARKER(org.apache.hadoop.ozone.OzoneConsts.DB_TRANSIENT_MARKER) OmDirectoryInfo(org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) CacheType(org.apache.hadoop.hdds.utils.db.cache.TableCache.CacheType) BlockGroup(org.apache.hadoop.ozone.common.BlockGroup) IOException(java.io.IOException) OzoneConsts(org.apache.hadoop.ozone.OzoneConsts) OmKeyInfoCodec(org.apache.hadoop.ozone.om.codec.OmKeyInfoCodec) File(java.io.File) OmPrefixInfoCodec(org.apache.hadoop.ozone.om.codec.OmPrefixInfoCodec) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) TransactionInfoCodec(org.apache.hadoop.hdds.utils.TransactionInfoCodec) ChronoUnit(java.time.temporal.ChronoUnit) TreeMap(java.util.TreeMap) RepeatedOmKeyInfo(org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo) Paths(java.nio.file.Paths) OmBucketInfoCodec(org.apache.hadoop.ozone.om.codec.OmBucketInfoCodec) Table(org.apache.hadoop.hdds.utils.db.Table) CacheKey(org.apache.hadoop.hdds.utils.db.cache.CacheKey) OmKeyLocationInfoGroup(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup) ExitUtils(org.apache.ratis.util.ExitUtils) OmMultipartKeyInfoCodec(org.apache.hadoop.ozone.om.codec.OmMultipartKeyInfoCodec) OZONE_OPEN_KEY_EXPIRE_THRESHOLD_SECONDS(org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_OPEN_KEY_EXPIRE_THRESHOLD_SECONDS) PersistedUserVolumeInfo(org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TableIterator(org.apache.hadoop.hdds.utils.db.TableIterator) OmMultipartKeyInfo(org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo) OmKeyLocationInfoGroup(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) RepeatedOmKeyInfo(org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo) BlockID(org.apache.hadoop.hdds.client.BlockID) BlockGroup(org.apache.hadoop.ozone.common.BlockGroup) RepeatedOmKeyInfo(org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo)

Example 4 with BlockGroup

use of org.apache.hadoop.ozone.common.BlockGroup in project ozone by apache.

the class BlockManagerImpl method deleteBlocks.

/**
 * Deletes a list of blocks in an atomic operation. Internally, SCM writes
 * these blocks into a
 * {@link DeletedBlockLog} and deletes them from SCM DB. If this is
 * successful, given blocks are
 * entering pending deletion state and becomes invisible from SCM namespace.
 *
 * @param keyBlocksInfoList . This is the list of BlockGroup which contains
 * groupID of keys and list of BlockIDs associated with them.
 * @throws IOException if exception happens, non of the blocks is deleted.
 */
@Override
public void deleteBlocks(List<BlockGroup> keyBlocksInfoList) throws IOException {
    if (scm.getScmContext().isInSafeMode()) {
        throw new SCMException("SafeModePrecheck failed for deleteBlocks", SCMException.ResultCodes.SAFE_MODE_EXCEPTION);
    }
    Map<Long, List<Long>> containerBlocks = new HashMap<>();
    // TODO: used space when the block is deleted.
    for (BlockGroup bg : keyBlocksInfoList) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Deleting blocks {}", StringUtils.join(",", bg.getBlockIDList()));
        }
        for (BlockID block : bg.getBlockIDList()) {
            long containerID = block.getContainerID();
            if (containerBlocks.containsKey(containerID)) {
                containerBlocks.get(containerID).add(block.getLocalID());
            } else {
                List<Long> item = new ArrayList<>();
                item.add(block.getLocalID());
                containerBlocks.put(containerID, item);
            }
        }
    }
    try {
        deletedBlockLog.addTransactions(containerBlocks);
    } catch (IOException e) {
        throw new IOException("Skip writing the deleted blocks info to" + " the delLog because addTransaction fails. " + keyBlocksInfoList.size() + "Keys skipped", e);
    }
// TODO: Container report handling of the deleted blocks:
// Remove tombstone and update open container usage.
// We will revisit this when the closed container replication is done.
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlockID(org.apache.hadoop.hdds.client.BlockID) ContainerBlockID(org.apache.hadoop.hdds.client.ContainerBlockID) ArrayList(java.util.ArrayList) ExcludeList(org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList) List(java.util.List) IOException(java.io.IOException) SCMException(org.apache.hadoop.hdds.scm.exceptions.SCMException) BlockGroup(org.apache.hadoop.ozone.common.BlockGroup)

Example 5 with BlockGroup

use of org.apache.hadoop.ozone.common.BlockGroup in project ozone by apache.

the class ScmBlockLocationTestingClient method deleteKeyBlocks.

@Override
public List<DeleteBlockGroupResult> deleteKeyBlocks(List<BlockGroup> keyBlocksInfoList) throws IOException {
    List<DeleteBlockGroupResult> results = new ArrayList<>();
    List<DeleteBlockResult> blockResultList = new ArrayList<>();
    Result result;
    for (BlockGroup keyBlocks : keyBlocksInfoList) {
        for (BlockID blockKey : keyBlocks.getBlockIDList()) {
            currentCall++;
            switch(this.failCallsFrequency) {
                case 0:
                    result = success;
                    break;
                case 1:
                    result = unknownFailure;
                    break;
                default:
                    if (currentCall % this.failCallsFrequency == 0) {
                        result = unknownFailure;
                    } else {
                        result = success;
                    }
            }
            blockResultList.add(new DeleteBlockResult(blockKey, result));
        }
        results.add(new DeleteBlockGroupResult(keyBlocks.getGroupID(), blockResultList));
    }
    return results;
}
Also used : DeleteBlockGroupResult(org.apache.hadoop.ozone.common.DeleteBlockGroupResult) ArrayList(java.util.ArrayList) BlockID(org.apache.hadoop.hdds.client.BlockID) ContainerBlockID(org.apache.hadoop.hdds.client.ContainerBlockID) DeleteBlockResult(org.apache.hadoop.hdds.scm.container.common.helpers.DeleteBlockResult) DeleteBlockResult(org.apache.hadoop.hdds.scm.container.common.helpers.DeleteBlockResult) DeleteBlockGroupResult(org.apache.hadoop.ozone.common.DeleteBlockGroupResult) Result(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.DeleteScmBlockResult.Result) BlockGroup(org.apache.hadoop.ozone.common.BlockGroup)

Aggregations

BlockGroup (org.apache.hadoop.ozone.common.BlockGroup)5 ArrayList (java.util.ArrayList)4 BlockID (org.apache.hadoop.hdds.client.BlockID)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)2 List (java.util.List)2 ContainerBlockID (org.apache.hadoop.hdds.client.ContainerBlockID)2 DeleteBlockResult (org.apache.hadoop.hdds.scm.container.common.helpers.DeleteBlockResult)2 SCMException (org.apache.hadoop.hdds.scm.exceptions.SCMException)2 DeleteBlockGroupResult (org.apache.hadoop.ozone.common.DeleteBlockGroupResult)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 File (java.io.File)1 Paths (java.nio.file.Paths)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1