Search in sources :

Example 1 with IgfsDataManager

use of org.apache.ignite.internal.processors.igfs.IgfsDataManager 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)

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)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 IgfsBlockLocationImpl (org.apache.ignite.internal.processors.igfs.IgfsBlockLocationImpl)1 IgfsDataManager (org.apache.ignite.internal.processors.igfs.IgfsDataManager)1 LocalFileSystemBlockKey (org.apache.ignite.internal.processors.igfs.secondary.local.LocalFileSystemBlockKey)1 LocalFileSystemIgfsFile (org.apache.ignite.internal.processors.igfs.secondary.local.LocalFileSystemIgfsFile)1