Search in sources :

Example 6 with BlockInfo

use of org.apache.crail.metadata.BlockInfo in project incubator-crail by apache.

the class NameNodeService method getLocation.

@Override
public short getLocation(RpcRequestMessage.GetLocationReq request, RpcResponseMessage.GetLocationRes response, RpcNameNodeState errorState) throws Exception {
    // check protocol
    if (!RpcProtocol.verifyProtocol(RpcProtocol.CMD_GET_LOCATION, request, response)) {
        return RpcErrors.ERR_PROTOCOL_MISMATCH;
    }
    // get params
    FileName fileName = request.getFileName();
    long position = request.getPosition();
    // check params
    if (position < 0) {
        return RpcErrors.ERR_POSITION_NEGATIV;
    }
    // rpc
    AbstractNode fileInfo = fileTree.retrieveFile(fileName, errorState);
    if (errorState.getError() != RpcErrors.ERR_OK) {
        return errorState.getError();
    }
    if (fileInfo == null) {
        return RpcErrors.ERR_GET_FILE_FAILED;
    }
    int index = CrailUtils.computeIndex(position);
    if (index < 0) {
        return RpcErrors.ERR_POSITION_NEGATIV;
    }
    BlockInfo block = fileInfo.getBlock(index);
    if (block == null) {
        return RpcErrors.ERR_OFFSET_TOO_LARGE;
    }
    response.setBlockInfo(block);
    return RpcErrors.ERR_OK;
}
Also used : BlockInfo(org.apache.crail.metadata.BlockInfo) FileName(org.apache.crail.metadata.FileName)

Example 7 with BlockInfo

use of org.apache.crail.metadata.BlockInfo in project incubator-crail by apache.

the class CoreDataStore method _lookupNode.

CoreNode _lookupNode(RpcGetFile fileRes, String path) throws Exception {
    if (fileRes.getError() == RpcErrors.ERR_GET_FILE_FAILED) {
        return null;
    } else if (fileRes.getError() != RpcErrors.ERR_OK) {
        LOG.info("lookupDirectory: " + RpcErrors.messages[fileRes.getError()]);
        return null;
    }
    FileInfo fileInfo = fileRes.getFile();
    CoreNode node = null;
    if (fileInfo != null) {
        if (CrailConstants.DEBUG) {
            LOG.info("lookup: name " + path + ", success, fd " + fileInfo.getFd());
        }
        BlockInfo fileBlock = fileRes.getFileBlock();
        getBlockCache(fileInfo.getFd()).put(CoreSubOperation.createKey(fileInfo.getFd(), 0), fileBlock);
        node = CoreNode.create(this, fileInfo, path);
    }
    return node;
}
Also used : FileInfo(org.apache.crail.metadata.FileInfo) BlockInfo(org.apache.crail.metadata.BlockInfo)

Example 8 with BlockInfo

use of org.apache.crail.metadata.BlockInfo in project incubator-crail by apache.

the class CoreStream method dataOperation.

final CoreDataOperation dataOperation(CrailBuffer dataBuf) throws Exception {
    blockMap.clear();
    pendingBlocks.clear();
    CoreDataOperation multiOperation = new CoreDataOperation(this, dataBuf);
    // compute off, len for the fragments, start transfer or start RPC if block info is missing
    while (multiOperation.remaining() > 0) {
        long blockRemaining = blockRemaining();
        int opLen = CrailUtils.minFileBuf(blockRemaining, multiOperation.remaining());
        CoreSubOperation subOperation = new CoreSubOperation(fileInfo.getFd(), position, multiOperation.getCurrentBufferPosition(), opLen);
        // LOG.info("OpDesc: " + opDesc.toString());
        ioStats.incTotalOps((long) opLen);
        if (blockCache.containsKey(subOperation.key())) {
            BlockInfo block = blockCache.get(subOperation.key());
            StorageFuture subFuture = this.prepareAndTrigger(subOperation, dataBuf, block);
            multiOperation.add(subFuture);
            this.ioStats.incCachedOps();
        } else if (nextBlockCache.containsKey(subOperation.key())) {
            RpcFuture<RpcGetBlock> rpcFuture = nextBlockCache.get(subOperation.key());
            blockMap.put(rpcFuture.getTicket(), subOperation);
            pendingBlocks.add(rpcFuture);
        } else {
            this.syncedCapacity = fileInfo.getCapacity();
            RpcFuture<RpcGetBlock> rpcFuture = namenodeClientRpc.getBlock(fileInfo.getFd(), fileInfo.getToken(), position, syncedCapacity);
            blockMap.put(rpcFuture.getTicket(), subOperation);
            pendingBlocks.add(rpcFuture);
        }
        position += opLen;
        multiOperation.incProcessedLen(opLen);
    }
    // wait for RPC results and start reads for those blocks as well
    for (RpcFuture<RpcGetBlock> rpcFuture = pendingBlocks.poll(); rpcFuture != null; rpcFuture = pendingBlocks.poll()) {
        if (!rpcFuture.isDone()) {
            this.ioStats.incBlockingOps();
            if (rpcFuture.isPrefetched()) {
                this.ioStats.incPrefetchedBlockingOps();
            }
        } else {
            this.ioStats.incNonblockingOps();
            if (rpcFuture.isPrefetched()) {
                this.ioStats.incPrefetchedNonblockingOps();
            }
        }
        RpcGetBlock getBlockRes = rpcFuture.get(CrailConstants.RPC_TIMEOUT, TimeUnit.MILLISECONDS);
        if (!rpcFuture.isDone()) {
            throw new IOException("rpc timeout ");
        }
        if (getBlockRes.getError() != RpcErrors.ERR_OK) {
            LOG.info("inputStream: " + RpcErrors.messages[getBlockRes.getError()]);
            throw new IOException(RpcErrors.messages[getBlockRes.getError()]);
        }
        BlockInfo block = getBlockRes.getBlockInfo();
        CoreSubOperation subOperation = blockMap.get(rpcFuture.getTicket());
        StorageFuture subFuture = prepareAndTrigger(subOperation, dataBuf, block);
        multiOperation.add(subFuture);
        blockCache.put(subOperation.key(), block);
    }
    if (!multiOperation.isProcessed()) {
        throw new IOException("Internal error, processed data != operation length");
    }
    dataBuf.limit(multiOperation.getBufferLimit());
    dataBuf.position(multiOperation.getCurrentBufferPosition());
    return multiOperation;
}
Also used : StorageFuture(org.apache.crail.storage.StorageFuture) RpcGetBlock(org.apache.crail.rpc.RpcGetBlock) BlockInfo(org.apache.crail.metadata.BlockInfo) RpcFuture(org.apache.crail.rpc.RpcFuture) IOException(java.io.IOException) BufferCheckpoint(org.apache.crail.utils.BufferCheckpoint) StorageEndpoint(org.apache.crail.storage.StorageEndpoint)

Aggregations

BlockInfo (org.apache.crail.metadata.BlockInfo)8 IOException (java.io.IOException)4 FileInfo (org.apache.crail.metadata.FileInfo)3 FileName (org.apache.crail.metadata.FileName)2 InetSocketAddress (java.net.InetSocketAddress)1 DataNodeInfo (org.apache.crail.metadata.DataNodeInfo)1 RpcFuture (org.apache.crail.rpc.RpcFuture)1 RpcGetBlock (org.apache.crail.rpc.RpcGetBlock)1 RpcVoid (org.apache.crail.rpc.RpcVoid)1 StorageEndpoint (org.apache.crail.storage.StorageEndpoint)1 StorageFuture (org.apache.crail.storage.StorageFuture)1 BufferCheckpoint (org.apache.crail.utils.BufferCheckpoint)1