Search in sources :

Example 16 with CompactFileState

use of org.smartdata.model.CompactFileState in project SSM by Intel-bigdata.

the class SmartDFSClient method isFileClosed.

@Override
public boolean isFileClosed(String src) throws IOException {
    boolean isFileClosed = super.isFileClosed(src);
    if (!isFileClosed) {
        FileState fileState = getFileState(src);
        if (fileState instanceof CompactFileState) {
            String containerFile = ((CompactFileState) fileState).getFileContainerInfo().getContainerFilePath();
            isFileClosed = super.isFileClosed(containerFile);
        }
    }
    return isFileClosed;
}
Also used : NormalFileState(org.smartdata.model.NormalFileState) CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) CompactFileState(org.smartdata.model.CompactFileState)

Example 17 with CompactFileState

use of org.smartdata.model.CompactFileState in project SSM by Intel-bigdata.

the class SmartDFSClient method getBlockLocations.

@Override
public BlockLocation[] getBlockLocations(String src, long start, long length) throws IOException {
    BlockLocation[] blockLocations = super.getBlockLocations(src, start, length);
    if (blockLocations.length == 0) {
        FileState fileState = getFileState(src);
        if (fileState instanceof CompactFileState) {
            String containerFile = ((CompactFileState) fileState).getFileContainerInfo().getContainerFilePath();
            long offset = ((CompactFileState) fileState).getFileContainerInfo().getOffset();
            blockLocations = super.getBlockLocations(containerFile, offset + start, length);
            for (BlockLocation blockLocation : blockLocations) {
                blockLocation.setOffset(blockLocation.getOffset() - offset);
            }
            return blockLocations;
        }
    } else {
        FileState fileState = getFileState(src);
        if (fileState instanceof CompressionFileState) {
            CompressionFileState compressionInfo = (CompressionFileState) fileState;
            Long[] originalPos = compressionInfo.getOriginalPos().clone();
            Long[] compressedPos = compressionInfo.getCompressedPos().clone();
            int startIndex = compressionInfo.getPosIndexByOriginalOffset(start);
            int endIndex = compressionInfo.getPosIndexByOriginalOffset(start + length - 1);
            long compressedStart = compressedPos[startIndex];
            long compressedLength = 0;
            if (endIndex < compressedPos.length - 1) {
                compressedLength = compressedPos[endIndex + 1] - compressedStart;
            } else {
                compressedLength = compressionInfo.getCompressedLength() - compressedStart;
            }
            LocatedBlocks originalLocatedBlocks = super.getLocatedBlocks(src, compressedStart, compressedLength);
            List<LocatedBlock> blocks = new ArrayList<>();
            for (LocatedBlock block : originalLocatedBlocks.getLocatedBlocks()) {
                // TODO handle CDH2.6 storage type
                // blocks.add(new LocatedBlock(
                // block.getBlock(),
                // block.getLocations(),
                // block.getStorageIDs(),
                // block.getStorageTypes(),
                // compressionInfo
                // .getPosIndexByCompressedOffset(block.getStartOffset()),
                // block.isCorrupt(),
                // block.getCachedLocations()
                // ));
                blocks.add(new LocatedBlock(block.getBlock(), block.getLocations(), compressionInfo.getPosIndexByCompressedOffset(block.getStartOffset()), block.isCorrupt()));
            }
            LocatedBlock lastLocatedBlock = originalLocatedBlocks.getLastLocatedBlock();
            long fileLength = compressionInfo.getOriginalLength();
            return new LocatedBlocks(fileLength, originalLocatedBlocks.isUnderConstruction(), blocks, lastLocatedBlock, originalLocatedBlocks.isLastBlockComplete(), originalLocatedBlocks.getFileEncryptionInfo()).getLocatedBlocks().toArray(new BlockLocation[0]);
        }
    }
    return blockLocations;
}
Also used : NormalFileState(org.smartdata.model.NormalFileState) CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) LocatedBlocks(org.apache.hadoop.hdfs.protocol.LocatedBlocks) ArrayList(java.util.ArrayList) LocatedBlock(org.apache.hadoop.hdfs.protocol.LocatedBlock) BlockLocation(org.apache.hadoop.fs.BlockLocation) CompressionFileState(org.smartdata.model.CompressionFileState) CompactFileState(org.smartdata.model.CompactFileState)

Example 18 with CompactFileState

use of org.smartdata.model.CompactFileState in project SSM by Intel-bigdata.

the class SmartDFSClient method getFileLinkInfo.

@Override
public HdfsFileStatus getFileLinkInfo(String src) throws IOException {
    HdfsFileStatus fileStatus = super.getFileLinkInfo(src);
    if (fileStatus.getLen() == 0) {
        String target = super.getLinkTarget(src);
        FileState fileState = getFileState(target);
        if (fileState instanceof CompactFileState) {
            fileStatus = getFileInfo(target);
        }
    }
    return fileStatus;
}
Also used : NormalFileState(org.smartdata.model.NormalFileState) CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) CompactFileState(org.smartdata.model.CompactFileState)

Example 19 with CompactFileState

use of org.smartdata.model.CompactFileState in project SSM by Intel-bigdata.

the class MetaStore method insertUpdateFileState.

public void insertUpdateFileState(FileState fileState) throws MetaStoreException {
    try {
        // Update corresponding tables according to the file state
        fileStateDao.insertUpdate(fileState);
        switch(fileState.getFileType()) {
            case COMPACT:
                CompactFileState compactFileState = (CompactFileState) fileState;
                smallFileDao.insertUpdate(compactFileState);
                break;
            case COMPRESSION:
                CompressionFileState compressionFileState = (CompressionFileState) fileState;
                compressionFileDao.insertUpdate(compressionFileState);
                break;
            case S3:
                break;
            default:
        }
    } catch (Exception e) {
        throw new MetaStoreException(e);
    }
}
Also used : CompressionFileState(org.smartdata.model.CompressionFileState) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) SQLException(java.sql.SQLException) CompactFileState(org.smartdata.model.CompactFileState)

Aggregations

CompactFileState (org.smartdata.model.CompactFileState)19 CompressionFileState (org.smartdata.model.CompressionFileState)15 FileState (org.smartdata.model.FileState)14 NormalFileState (org.smartdata.model.NormalFileState)8 ArrayList (java.util.ArrayList)5 Gson (com.google.gson.Gson)3 IOException (java.io.IOException)3 Path (org.apache.hadoop.fs.Path)3 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)3 FileContainerInfo (org.smartdata.model.FileContainerInfo)3 TypeToken (com.google.gson.reflect.TypeToken)2 BlockLocation (org.apache.hadoop.fs.BlockLocation)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 LocatedFileStatus (org.apache.hadoop.fs.LocatedFileStatus)2 HdfsLocatedFileStatus (org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus)2 HdfsNamedFileStatus (org.apache.hadoop.hdfs.protocol.HdfsNamedFileStatus)2 LocatedBlocks (org.apache.hadoop.hdfs.protocol.LocatedBlocks)2 CompactFileStateProto (org.smartdata.protocol.ClientServerProto.CompactFileStateProto)2 CompressionFileStateProto (org.smartdata.protocol.ClientServerProto.CompressionFileStateProto)2 S3FileStateProto (org.smartdata.protocol.ClientServerProto.S3FileStateProto)2