Search in sources :

Example 1 with BlockInfo

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

the class CoreDataStore method _createNode.

CoreNode _createNode(String path, CrailNodeType type, RpcCreateFile fileRes) throws Exception {
    if (fileRes.getError() == RpcErrors.ERR_PARENT_MISSING) {
        throw new IOException("createNode: " + RpcErrors.messages[fileRes.getError()] + ", name " + path);
    } else if (fileRes.getError() == RpcErrors.ERR_FILE_EXISTS) {
        throw new IOException("createNode: " + RpcErrors.messages[fileRes.getError()] + ", name " + path);
    } else if (fileRes.getError() != RpcErrors.ERR_OK) {
        LOG.info("createNode: " + RpcErrors.messages[fileRes.getError()] + ", name " + path);
        throw new IOException("createNode: " + RpcErrors.messages[fileRes.getError()] + ", error " + fileRes.getError());
    }
    FileInfo fileInfo = fileRes.getFile();
    FileInfo dirInfo = fileRes.getParent();
    if (fileInfo == null || dirInfo == null) {
        throw new IOException("createFile: " + RpcErrors.messages[RpcErrors.ERR_UNKNOWN]);
    }
    if (fileInfo.getType() != type) {
        throw new IOException("createFile: " + "file type mismatch");
    }
    blockCache.remove(fileInfo.getFd());
    nextBlockCache.remove(fileInfo.getFd());
    CoreNode node = CoreNode.create(this, fileInfo, path);
    BlockInfo fileBlock = fileRes.getFileBlock();
    getBlockCache(fileInfo.getFd()).put(CoreSubOperation.createKey(fileInfo.getFd(), 0), fileBlock);
    // write directory record is a directory slot has been assigned to the file
    if (fileInfo.getDirOffset() >= 0) {
        BlockInfo dirBlock = fileRes.getDirBlock();
        getBlockCache(dirInfo.getFd()).put(CoreSubOperation.createKey(dirInfo.getFd(), fileInfo.getDirOffset()), dirBlock);
        CoreSyncOperation syncOperation = getSyncOperation(dirInfo, fileInfo, path, true);
        node.addSyncOperation(syncOperation);
    }
    if (CrailConstants.DEBUG) {
        LOG.info("createFile: name " + path + ", success, fd " + fileInfo.getFd() + ", token " + fileInfo.getToken());
    }
    return node;
}
Also used : FileInfo(org.apache.crail.metadata.FileInfo) BlockInfo(org.apache.crail.metadata.BlockInfo) IOException(java.io.IOException)

Example 2 with BlockInfo

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

the class CoreDataStore method _rename.

CrailNode _rename(RpcRenameFile renameRes, String src, String dst) throws Exception {
    if (renameRes.getError() == RpcErrors.ERR_SRC_FILE_NOT_FOUND) {
        LOG.info("rename: " + RpcErrors.messages[renameRes.getError()]);
        return null;
    }
    if (renameRes.getError() == RpcErrors.ERR_DST_PARENT_NOT_FOUND) {
        LOG.info("rename: " + RpcErrors.messages[renameRes.getError()]);
        return null;
    }
    if (renameRes.getError() == RpcErrors.ERR_FILE_EXISTS) {
        LOG.info("rename: " + RpcErrors.messages[renameRes.getError()]);
        return null;
    }
    if (renameRes.getError() != RpcErrors.ERR_OK) {
        LOG.info("rename: " + RpcErrors.messages[renameRes.getError()]);
        throw new IOException(RpcErrors.messages[renameRes.getError()]);
    }
    if (renameRes.getDstParent().getCapacity() < renameRes.getDstFile().getDirOffset() + CrailConstants.DIRECTORY_RECORD) {
        LOG.info("rename: parent capacity does not match dst file offset, capacity " + renameRes.getDstParent().getCapacity() + ", offset " + renameRes.getDstFile().getDirOffset());
    }
    FileInfo srcParent = renameRes.getSrcParent();
    FileInfo srcFile = renameRes.getSrcFile();
    FileInfo dstDir = renameRes.getDstParent();
    FileInfo dstFile = renameRes.getDstFile();
    BlockInfo srcBlock = renameRes.getSrcBlock();
    getBlockCache(srcParent.getFd()).put(CoreSubOperation.createKey(srcParent.getFd(), srcFile.getDirOffset()), srcBlock);
    BlockInfo dirBlock = renameRes.getDstBlock();
    getBlockCache(dstDir.getFd()).put(CoreSubOperation.createKey(dstDir.getFd(), dstFile.getDirOffset()), dirBlock);
    CoreSyncOperation syncOperationSrc = getSyncOperation(srcParent, srcFile, src, false);
    CoreSyncOperation syncOperationDst = getSyncOperation(dstDir, dstFile, dst, true);
    blockCache.remove(srcFile.getFd());
    if (CrailConstants.DEBUG) {
        LOG.info("rename: srcname " + src + ", dstname " + dst + ", success");
    }
    CoreNode node = CoreNode.create(this, dstFile, dst);
    node.addSyncOperation(syncOperationSrc);
    node.addSyncOperation(syncOperationDst);
    return node;
}
Also used : FileInfo(org.apache.crail.metadata.FileInfo) BlockInfo(org.apache.crail.metadata.BlockInfo) IOException(java.io.IOException)

Example 3 with BlockInfo

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

the class NameNodeService method setBlock.

@Override
public short setBlock(RpcRequestMessage.SetBlockReq request, RpcResponseMessage.VoidRes response, RpcNameNodeState errorState) throws Exception {
    // check protocol
    if (!RpcProtocol.verifyProtocol(RpcProtocol.CMD_SET_BLOCK, request, response)) {
        return RpcErrors.ERR_PROTOCOL_MISMATCH;
    }
    // get params
    BlockInfo region = new BlockInfo();
    region.setBlockInfo(request.getBlockInfo());
    short error = RpcErrors.ERR_OK;
    if (blockStore.regionExists(region)) {
        error = blockStore.updateRegion(region);
    } else {
        // rpc
        int realBlocks = (int) (((long) region.getLength()) / CrailConstants.BLOCK_SIZE);
        long offset = 0;
        for (int i = 0; i < realBlocks; i++) {
            NameNodeBlockInfo nnBlock = new NameNodeBlockInfo(region, offset, (int) CrailConstants.BLOCK_SIZE);
            error = blockStore.addBlock(nnBlock);
            offset += CrailConstants.BLOCK_SIZE;
            if (error != RpcErrors.ERR_OK) {
                break;
            }
        }
    }
    return error;
}
Also used : BlockInfo(org.apache.crail.metadata.BlockInfo)

Example 4 with BlockInfo

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

the class StorageRpcClient method setBlock.

public void setBlock(long lba, long addr, int length, int key) throws Exception {
    InetSocketAddress inetAddress = serverAddress;
    DataNodeInfo dnInfo = new DataNodeInfo(storageType, storageClass.value(), locationClass.value(), inetAddress.getAddress().getAddress(), inetAddress.getPort());
    BlockInfo blockInfo = new BlockInfo(dnInfo, lba, addr, length, key);
    RpcVoid res = rpcConnection.setBlock(blockInfo).get(CrailConstants.RPC_TIMEOUT, TimeUnit.MILLISECONDS);
    if (res.getError() != RpcErrors.ERR_OK) {
        LOG.info("setBlock: " + RpcErrors.messages[res.getError()]);
        throw new IOException("setBlock: " + RpcErrors.messages[res.getError()]);
    }
}
Also used : RpcVoid(org.apache.crail.rpc.RpcVoid) InetSocketAddress(java.net.InetSocketAddress) BlockInfo(org.apache.crail.metadata.BlockInfo) DataNodeInfo(org.apache.crail.metadata.DataNodeInfo) IOException(java.io.IOException)

Example 5 with BlockInfo

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

the class NameNodeService method getFile.

@Override
public short getFile(RpcRequestMessage.GetFileReq request, RpcResponseMessage.GetFileRes response, RpcNameNodeState errorState) throws Exception {
    // check protocol
    if (!RpcProtocol.verifyProtocol(RpcProtocol.CMD_GET_FILE, request, response)) {
        return RpcErrors.ERR_PROTOCOL_MISMATCH;
    }
    // get params
    FileName fileHash = request.getFileName();
    boolean writeable = request.isWriteable();
    // rpc
    AbstractNode fileInfo = fileTree.retrieveFile(fileHash, errorState);
    if (errorState.getError() != RpcErrors.ERR_OK) {
        return errorState.getError();
    }
    if (fileInfo == null) {
        return RpcErrors.ERR_GET_FILE_FAILED;
    }
    if (writeable && !fileInfo.tokenFree()) {
        return RpcErrors.ERR_TOKEN_TAKEN;
    }
    if (writeable) {
        fileInfo.updateToken();
    }
    fileTable.put(fileInfo.getFd(), fileInfo);
    BlockInfo fileBlock = fileInfo.getBlock(0);
    response.setFileInfo(fileInfo);
    response.setFileBlock(fileBlock);
    if (writeable) {
        response.shipToken();
    }
    if (CrailConstants.DEBUG) {
        LOG.info("getFile: fd " + fileInfo.getFd() + ", isDir " + fileInfo.getType().isDirectory() + ", token " + fileInfo.getToken() + ", capacity " + fileInfo.getCapacity());
    }
    return RpcErrors.ERR_OK;
}
Also used : BlockInfo(org.apache.crail.metadata.BlockInfo) FileName(org.apache.crail.metadata.FileName)

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