Search in sources :

Example 1 with DataNodeInfo

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

the class StorageRpcClient method getDataNode.

public DataNodeStatistics getDataNode() throws Exception {
    InetSocketAddress inetAddress = serverAddress;
    DataNodeInfo dnInfo = new DataNodeInfo(storageType, storageClass.value(), locationClass.value(), inetAddress.getAddress().getAddress(), inetAddress.getPort());
    return this.rpcConnection.getDataNode(dnInfo).get(CrailConstants.RPC_TIMEOUT, TimeUnit.MILLISECONDS).getStatistics();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DataNodeInfo(org.apache.crail.metadata.DataNodeInfo)

Example 2 with DataNodeInfo

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

the class NameNodeService method getDataNode.

@Override
public short getDataNode(RpcRequestMessage.GetDataNodeReq request, RpcResponseMessage.GetDataNodeRes response, RpcNameNodeState errorState) throws Exception {
    // check protocol
    if (!RpcProtocol.verifyProtocol(RpcProtocol.CMD_GET_DATANODE, request, response)) {
        return RpcErrors.ERR_PROTOCOL_MISMATCH;
    }
    // get params
    DataNodeInfo dnInfo = request.getInfo();
    // rpc
    DataNodeBlocks dnInfoNn = blockStore.getDataNode(dnInfo);
    if (dnInfoNn == null) {
        return RpcErrors.ERR_DATANODE_NOT_REGISTERED;
    }
    dnInfoNn.touch();
    response.setServiceId(serviceId);
    response.setFreeBlockCount(dnInfoNn.getBlockCount());
    return RpcErrors.ERR_OK;
}
Also used : DataNodeInfo(org.apache.crail.metadata.DataNodeInfo)

Example 3 with DataNodeInfo

use of org.apache.crail.metadata.DataNodeInfo 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 4 with DataNodeInfo

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

the class CoreDataStore method getBlockLocations.

public CrailBlockLocation[] getBlockLocations(String path, long start, long len) throws Exception {
    if (CrailConstants.DEBUG) {
        LOG.info("location: path " + path + ", start " + start + ", len " + len);
    }
    if (path == null) {
        LOG.info("Path null");
        return null;
    }
    if (start < 0 || len < 0) {
        LOG.info("Start or len invalid");
        throw new IOException("Invalid start or len parameter");
    }
    FileName name = new FileName(path);
    long rangeStart = CrailUtils.blockStartAddress(start);
    long range = start + len - CrailUtils.blockStartAddress(start);
    long blockCount = range / CrailConstants.BLOCK_SIZE;
    if (range % CrailConstants.BLOCK_SIZE > 0) {
        blockCount++;
    }
    CoreBlockLocation[] blockLocations = new CoreBlockLocation[(int) blockCount];
    HashMap<Long, DataNodeInfo> dataNodeSet = new HashMap<Long, DataNodeInfo>();
    HashMap<Long, DataNodeInfo> offset2DataNode = new HashMap<Long, DataNodeInfo>();
    for (long current = CrailUtils.blockStartAddress(start); current < start + len; current += CrailConstants.BLOCK_SIZE) {
        RpcGetLocation getLocationRes = rpcConnection.getLocation(name, current).get(CrailConstants.RPC_TIMEOUT, TimeUnit.MILLISECONDS);
        if (getLocationRes.getError() != RpcErrors.ERR_OK) {
            LOG.info("location: " + RpcErrors.messages[getLocationRes.getError()]);
            throw new IOException(RpcErrors.messages[getLocationRes.getError()]);
        }
        DataNodeInfo dataNodeInfo = getLocationRes.getBlockInfo().getDnInfo();
        dataNodeSet.put(dataNodeInfo.key(), dataNodeInfo);
        CoreBlockLocation location = new CoreBlockLocation();
        location.setOffset(current);
        location.setLength(Math.min(start + len - current, CrailConstants.BLOCK_SIZE));
        long index = (current - rangeStart) / CrailConstants.BLOCK_SIZE;
        blockLocations[(int) index] = location;
        offset2DataNode.put(current, dataNodeInfo);
    }
    // asign an identifier to each data node
    ArrayList<DataNodeInfo> dataNodeArray = new ArrayList<DataNodeInfo>(dataNodeSet.size());
    int index = 0;
    for (DataNodeInfo dn : dataNodeSet.values()) {
        dataNodeArray.add(index, dn);
        index++;
    }
    int locationSize = Math.min(CrailConstants.SHADOW_REPLICATION, dataNodeSet.size());
    int blockIndex = 0;
    for (int i = 0; i < blockLocations.length; i++) {
        CoreBlockLocation location = blockLocations[i];
        String[] hosts = new String[locationSize];
        String[] names = new String[locationSize];
        String[] topology = new String[locationSize];
        int[] storageType = new int[locationSize];
        int[] storageClass = new int[locationSize];
        int[] locationTiers = new int[locationSize];
        DataNodeInfo dnInfo = offset2DataNode.get(location.getOffset());
        DataNodeInfo mainDataNode = dataNodeSet.get(dnInfo.key());
        InetSocketAddress address = CrailUtils.datanodeInfo2SocketAddr(mainDataNode);
        names[0] = getMappedLocation(address.getAddress().getCanonicalHostName()) + ":" + address.getPort();
        hosts[0] = getMappedLocation(address.getAddress().getCanonicalHostName());
        topology[0] = "/default-rack/" + names[0];
        storageType[0] = mainDataNode.getStorageType();
        storageClass[0] = mainDataNode.getStorageClass();
        locationTiers[0] = mainDataNode.getLocationClass();
        for (int j = 1; j < locationSize; j++) {
            DataNodeInfo replicaDataNode = dataNodeArray.get(blockIndex);
            address = CrailUtils.datanodeInfo2SocketAddr(replicaDataNode);
            names[j] = getMappedLocation(address.getAddress().getCanonicalHostName()) + ":" + address.getPort();
            hosts[j] = getMappedLocation(address.getAddress().getCanonicalHostName());
            topology[j] = "/default-rack/" + names[j];
            storageType[j] = replicaDataNode.getStorageType();
            storageClass[j] = replicaDataNode.getStorageClass();
            locationTiers[j] = replicaDataNode.getLocationClass();
            blockIndex = (blockIndex + 1) % dataNodeArray.size();
        }
        location.setNames(names);
        location.setHosts(hosts);
        location.setTopologyPaths(topology);
        location.setStorageTypes(storageType);
        location.setStorageClasses(storageClass);
        location.setLocationAffinities(locationTiers);
    }
    return blockLocations;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) RpcGetLocation(org.apache.crail.rpc.RpcGetLocation) InetSocketAddress(java.net.InetSocketAddress) FileName(org.apache.crail.metadata.FileName) ArrayList(java.util.ArrayList) DataNodeInfo(org.apache.crail.metadata.DataNodeInfo) IOException(java.io.IOException) BufferCheckpoint(org.apache.crail.utils.BufferCheckpoint) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Aggregations

DataNodeInfo (org.apache.crail.metadata.DataNodeInfo)4 InetSocketAddress (java.net.InetSocketAddress)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BlockInfo (org.apache.crail.metadata.BlockInfo)1 FileName (org.apache.crail.metadata.FileName)1 RpcGetLocation (org.apache.crail.rpc.RpcGetLocation)1 RpcVoid (org.apache.crail.rpc.RpcVoid)1 BufferCheckpoint (org.apache.crail.utils.BufferCheckpoint)1