Search in sources :

Example 1 with IgfsBlockLocationImpl

use of org.apache.ignite.internal.processors.igfs.IgfsBlockLocationImpl in project ignite by apache.

the class LocalIgfsSecondaryFileSystem method affinity.

/** {@inheritDoc} */
@Override
public Collection<IgfsBlockLocation> affinity(IgfsPath path, long start, long len, long maxLen) throws IgniteException {
    File f = fileForPath(path);
    if (!f.exists())
        throw new IgfsPathNotFoundException("File not found: " + path);
    // Create fake block & fake affinity for blocks
    long blockSize = igfs.configuration().getBlockSize();
    if (maxLen <= 0)
        maxLen = Long.MAX_VALUE;
    assert maxLen > 0 : "maxLen : " + maxLen;
    long end = start + len;
    Collection<IgfsBlockLocation> blocks = new ArrayList<>((int) (len / maxLen));
    IgfsDataManager data = igfs.context().data();
    Collection<ClusterNode> lastNodes = null;
    long lastBlockIdx = -1;
    IgfsBlockLocationImpl lastBlock = null;
    for (long offset = start; offset < end; ) {
        long blockIdx = offset / blockSize;
        // Each step is min of maxLen and end of block.
        long lenStep = Math.min(maxLen - (lastBlock != null ? lastBlock.length() : 0), (blockIdx + 1) * blockSize - offset);
        lenStep = Math.min(lenStep, end - offset);
        // Create fake affinity key to map blocks of secondary filesystem to nodes.
        LocalFileSystemBlockKey affKey = new LocalFileSystemBlockKey(path, blockIdx);
        if (blockIdx != lastBlockIdx) {
            Collection<ClusterNode> nodes = data.affinityNodes(affKey);
            if (!nodes.equals(lastNodes) && lastNodes != null && lastBlock != null) {
                blocks.add(lastBlock);
                lastBlock = null;
            }
            lastNodes = nodes;
            lastBlockIdx = blockIdx;
        }
        if (lastBlock == null)
            lastBlock = new IgfsBlockLocationImpl(offset, lenStep, lastNodes);
        else
            lastBlock.increaseLength(lenStep);
        if (lastBlock.length() == maxLen || lastBlock.start() + lastBlock.length() == end) {
            blocks.add(lastBlock);
            lastBlock = null;
        }
        offset += lenStep;
    }
    return blocks;
}
Also used : IgfsDataManager(org.apache.ignite.internal.processors.igfs.IgfsDataManager) ClusterNode(org.apache.ignite.cluster.ClusterNode) LocalFileSystemBlockKey(org.apache.ignite.internal.processors.igfs.secondary.local.LocalFileSystemBlockKey) IgfsBlockLocationImpl(org.apache.ignite.internal.processors.igfs.IgfsBlockLocationImpl) ArrayList(java.util.ArrayList) IgfsBlockLocation(org.apache.ignite.igfs.IgfsBlockLocation) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException) IgfsFile(org.apache.ignite.igfs.IgfsFile) LocalFileSystemIgfsFile(org.apache.ignite.internal.processors.igfs.secondary.local.LocalFileSystemIgfsFile) File(java.io.File)

Example 2 with IgfsBlockLocationImpl

use of org.apache.ignite.internal.processors.igfs.IgfsBlockLocationImpl in project ignite by apache.

the class IgfsControlResponse method readExternal.

/**
     * Reads object from data input.
     *
     * @param in Data input.
     * @throws IOException If read failed.
     * @throws ClassNotFoundException If could not find class.
     */
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    byte[] hdr = new byte[RES_HEADER_SIZE];
    in.readFully(hdr);
    resType = U.bytesToInt(hdr, 0);
    boolean hasErr = hdr[4] != 0;
    if (hasErr) {
        err = in.readUTF();
        errCode = in.readInt();
        if (resType == RES_TYPE_ERR_STREAM_ID)
            res = in.readLong();
        return;
    }
    switch(resType) {
        case RES_TYPE_BOOLEAN:
            res = in.readBoolean();
            break;
        case RES_TYPE_LONG:
            res = in.readLong();
            break;
        case RES_TYPE_IGFS_PATH:
            {
                boolean hasVal = in.readBoolean();
                if (hasVal)
                    res = IgfsUtils.readPath(in);
                break;
            }
        case RES_TYPE_IGFS_PATH_SUMMARY:
            {
                boolean hasVal = in.readBoolean();
                if (hasVal) {
                    IgfsPathSummary sum = new IgfsPathSummary();
                    sum.readExternal(in);
                    res = sum;
                }
                break;
            }
        case RES_TYPE_IGFS_FILE:
            {
                boolean hasVal = in.readBoolean();
                if (hasVal) {
                    IgfsFileImpl file = new IgfsFileImpl();
                    file.readExternal(in);
                    res = file;
                }
                break;
            }
        case RES_TYPE_IGFS_STREAM_DESCRIPTOR:
            {
                boolean hasVal = in.readBoolean();
                if (hasVal) {
                    IgfsInputStreamDescriptor desc = new IgfsInputStreamDescriptor();
                    desc.readExternal(in);
                    res = desc;
                }
                break;
            }
        case RES_TYPE_HANDSHAKE:
            {
                boolean hasVal = in.readBoolean();
                if (hasVal) {
                    IgfsHandshakeResponse msg = new IgfsHandshakeResponse();
                    msg.readExternal(in);
                    res = msg;
                }
                break;
            }
        case RES_TYPE_STATUS:
            {
                boolean hasVal = in.readBoolean();
                if (hasVal) {
                    IgfsStatus msg = new IgfsStatus();
                    msg.readExternal(in);
                    res = msg;
                }
                break;
            }
        case RES_TYPE_COL_IGFS_FILE:
            {
                Collection<IgfsFile> files = null;
                int size = in.readInt();
                if (size >= 0) {
                    files = new ArrayList<>(size);
                    for (int i = 0; i < size; i++) {
                        IgfsFileImpl file = new IgfsFileImpl();
                        file.readExternal(in);
                        files.add(file);
                    }
                }
                res = files;
                break;
            }
        case RES_TYPE_COL_IGFS_PATH:
            {
                Collection<IgfsPath> paths = null;
                int size = in.readInt();
                if (size >= 0) {
                    paths = new ArrayList<>(size);
                    for (int i = 0; i < size; i++) paths.add(IgfsUtils.readPath(in));
                }
                res = paths;
                break;
            }
        case RES_TYPE_COL_IGFS_BLOCK_LOCATION:
            {
                Collection<IgfsBlockLocation> locations = null;
                int size = in.readInt();
                if (size >= 0) {
                    locations = new ArrayList<>(size);
                    for (int i = 0; i < size; i++) {
                        IgfsBlockLocationImpl location = new IgfsBlockLocationImpl();
                        location.readExternal(in);
                        locations.add(location);
                    }
                }
                res = locations;
                break;
            }
        case RES_TYPE_MODE_RESOLVER:
            {
                boolean hasVal = in.readBoolean();
                if (hasVal) {
                    IgfsModeResolver msg = new IgfsModeResolver();
                    msg.readExternal(in);
                    res = msg;
                }
                break;
            }
        case RES_TYPE_BYTE_ARRAY:
            assert false : "Response type of byte array should never be processed by marshaller.";
    }
}
Also used : IgfsPathSummary(org.apache.ignite.igfs.IgfsPathSummary) IgfsModeResolver(org.apache.ignite.internal.processors.igfs.IgfsModeResolver) IgfsHandshakeResponse(org.apache.ignite.internal.processors.igfs.IgfsHandshakeResponse) IgfsBlockLocationImpl(org.apache.ignite.internal.processors.igfs.IgfsBlockLocationImpl) ArrayList(java.util.ArrayList) IgfsInputStreamDescriptor(org.apache.ignite.internal.processors.igfs.IgfsInputStreamDescriptor) Collection(java.util.Collection) IgfsFileImpl(org.apache.ignite.internal.processors.igfs.IgfsFileImpl) IgfsStatus(org.apache.ignite.internal.processors.igfs.IgfsStatus)

Aggregations

ArrayList (java.util.ArrayList)2 IgfsBlockLocationImpl (org.apache.ignite.internal.processors.igfs.IgfsBlockLocationImpl)2 File (java.io.File)1 Collection (java.util.Collection)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 IgfsBlockLocation (org.apache.ignite.igfs.IgfsBlockLocation)1 IgfsFile (org.apache.ignite.igfs.IgfsFile)1 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)1 IgfsPathSummary (org.apache.ignite.igfs.IgfsPathSummary)1 IgfsDataManager (org.apache.ignite.internal.processors.igfs.IgfsDataManager)1 IgfsFileImpl (org.apache.ignite.internal.processors.igfs.IgfsFileImpl)1 IgfsHandshakeResponse (org.apache.ignite.internal.processors.igfs.IgfsHandshakeResponse)1 IgfsInputStreamDescriptor (org.apache.ignite.internal.processors.igfs.IgfsInputStreamDescriptor)1 IgfsModeResolver (org.apache.ignite.internal.processors.igfs.IgfsModeResolver)1 IgfsStatus (org.apache.ignite.internal.processors.igfs.IgfsStatus)1 LocalFileSystemBlockKey (org.apache.ignite.internal.processors.igfs.secondary.local.LocalFileSystemBlockKey)1 LocalFileSystemIgfsFile (org.apache.ignite.internal.processors.igfs.secondary.local.LocalFileSystemIgfsFile)1