Search in sources :

Example 11 with CrailBuffer

use of org.apache.crail.CrailBuffer in project incubator-crail by apache.

the class RdmaStorageLocalEndpoint method read.

@Override
public StorageFuture read(CrailBuffer buffer, BlockInfo remoteMr, long remoteOffset) throws IOException, InterruptedException {
    if (buffer.remaining() > CrailConstants.BLOCK_SIZE) {
        throw new IOException("read size too large");
    }
    if (buffer.remaining() <= 0) {
        throw new IOException("read size too small, len " + buffer.remaining());
    }
    if (remoteOffset < 0) {
        throw new IOException("remote offset too small " + remoteOffset);
    }
    if (buffer.position() < 0) {
        throw new IOException("local offset too small " + buffer.position());
    }
    long alignedLba = getAlignedLba(remoteMr.getLba());
    long lbaOffset = getLbaOffset(remoteMr.getLba());
    CrailBuffer mappedBuffer = bufferMap.get(alignedLba);
    if (mappedBuffer == null) {
        throw new IOException("No mapped buffer for this key");
    }
    if (lbaOffset + remoteOffset + buffer.remaining() > RdmaConstants.STORAGE_RDMA_ALLOCATION_SIZE) {
        long tmpAddr = lbaOffset + remoteOffset + buffer.remaining();
        throw new IOException("remote fileOffset + remoteOffset + len too large " + tmpAddr);
    }
    long srcAddr = mappedBuffer.address() + lbaOffset + remoteOffset;
    long dstAddr = buffer.address() + buffer.position();
    RdmaLocalFuture future = new RdmaLocalFuture(unsafe, srcAddr, dstAddr, buffer.remaining());
    return future;
}
Also used : IOException(java.io.IOException) CrailBuffer(org.apache.crail.CrailBuffer)

Example 12 with CrailBuffer

use of org.apache.crail.CrailBuffer in project incubator-crail by apache.

the class RdmaStorageLocalEndpoint method write.

@Override
public StorageFuture write(CrailBuffer buffer, BlockInfo remoteMr, long remoteOffset) throws IOException, InterruptedException {
    if (buffer.remaining() > CrailConstants.BLOCK_SIZE) {
        throw new IOException("write size too large " + buffer.remaining());
    }
    if (buffer.remaining() <= 0) {
        throw new IOException("write size too small, len " + buffer.remaining());
    }
    if (remoteOffset < 0) {
        throw new IOException("remote offset too small " + remoteOffset);
    }
    long alignedLba = getAlignedLba(remoteMr.getLba());
    long lbaOffset = getLbaOffset(remoteMr.getLba());
    CrailBuffer mappedBuffer = bufferMap.get(alignedLba);
    if (mappedBuffer == null) {
        throw new IOException("No mapped buffer for this key " + remoteMr.getLkey() + ", address " + address);
    }
    if (lbaOffset + remoteOffset + buffer.remaining() > RdmaConstants.STORAGE_RDMA_ALLOCATION_SIZE) {
        long tmpAddr = lbaOffset + remoteOffset + buffer.remaining();
        throw new IOException("remote fileOffset + remoteOffset + len too large " + tmpAddr);
    }
    long srcAddr = buffer.address() + buffer.position();
    long dstAddr = mappedBuffer.address() + lbaOffset + remoteOffset;
    RdmaLocalFuture future = new RdmaLocalFuture(unsafe, srcAddr, dstAddr, buffer.remaining());
    return future;
}
Also used : IOException(java.io.IOException) CrailBuffer(org.apache.crail.CrailBuffer)

Example 13 with CrailBuffer

use of org.apache.crail.CrailBuffer in project incubator-crail by apache.

the class NvmfStorageEndpoint method Op.

public StorageFuture Op(Operation op, CrailBuffer buffer, BlockInfo remoteMr, long remoteOffset) throws IOException, InterruptedException {
    int length = buffer.remaining();
    if (length > CrailConstants.BLOCK_SIZE) {
        throw new IOException("write size too large " + length);
    }
    if (length <= 0) {
        throw new IOException("write size too small, len " + length);
    }
    if (buffer.position() < 0) {
        throw new IOException("local offset too small " + buffer.position());
    }
    if (remoteOffset < 0) {
        throw new IOException("remote offset too small " + remoteOffset);
    }
    if (remoteMr.getAddr() + remoteOffset + length > endpoint.getNamespaceSize()) {
        long tmpAddr = remoteMr.getAddr() + remoteOffset + length;
        throw new IOException("remote fileOffset + remoteOffset + len = " + tmpAddr + " - size = " + endpoint.getNamespaceSize());
    }
    // LOG.info("op = " + op.name() +
    // ", position = " + buffer.position() +
    // ", localOffset = " + buffer.position() +
    // ", remoteOffset = " + remoteOffset +
    // ", remoteAddr = " + remoteMr.getAddr() +
    // ", length = " + length);
    NvmeCommand command = freeCommands.poll();
    while (command == null) {
        poll();
        command = freeCommands.poll();
    }
    boolean aligned = NvmfStorageUtils.namespaceSectorOffset(sectorSize, remoteOffset) == 0 && NvmfStorageUtils.namespaceSectorOffset(sectorSize, length) == 0;
    long lba = NvmfStorageUtils.linearBlockAddress(remoteMr, remoteOffset, sectorSize);
    StorageFuture future = null;
    if (aligned) {
        // LOG.info("aligned");
        command.setBuffer(buffer.getByteBuffer()).setLinearBlockAddress(lba);
        switch(op) {
            case READ:
                command.read();
                break;
            case WRITE:
                command.write();
                break;
        }
        future = futures[(int) command.getId()] = new NvmfStorageFuture(this, length);
        command.execute();
    } else {
        // LOG.info("unaligned");
        long alignedLength = NvmfStorageUtils.alignLength(sectorSize, remoteOffset, length);
        CrailBuffer stagingBuffer = cache.allocateBuffer();
        stagingBuffer.limit((int) alignedLength);
        try {
            switch(op) {
                case READ:
                    {
                        NvmfStorageFuture f = futures[(int) command.getId()] = new NvmfStorageFuture(this, (int) alignedLength);
                        command.setBuffer(stagingBuffer.getByteBuffer()).setLinearBlockAddress(lba).read().execute();
                        future = new NvmfStorageUnalignedReadFuture(f, this, buffer, remoteMr, remoteOffset, stagingBuffer);
                        break;
                    }
                case WRITE:
                    {
                        if (NvmfStorageUtils.namespaceSectorOffset(sectorSize, remoteOffset) == 0) {
                            // Do not read if the offset is aligned to sector size
                            int sizeToWrite = length;
                            stagingBuffer.put(buffer.getByteBuffer());
                            stagingBuffer.position(0);
                            command.setBuffer(stagingBuffer.getByteBuffer()).setLinearBlockAddress(lba).write().execute();
                            future = futures[(int) command.getId()] = new NvmfStorageUnalignedWriteFuture(this, sizeToWrite, stagingBuffer);
                        } else {
                            // RMW but append only file system allows only reading last sector
                            // and dir entries are sector aligned
                            stagingBuffer.limit(sectorSize);
                            NvmfStorageFuture f = futures[(int) command.getId()] = new NvmfStorageFuture(this, sectorSize);
                            command.setBuffer(stagingBuffer.getByteBuffer()).setLinearBlockAddress(lba).read().execute();
                            future = new NvmfStorageUnalignedRMWFuture(f, this, buffer, remoteMr, remoteOffset, stagingBuffer);
                        }
                        break;
                    }
            }
        } catch (NoSuchFieldException e) {
            throw new IOException(e);
        } catch (IllegalAccessException e) {
            throw new IOException(e);
        }
    }
    return future;
}
Also used : NvmeCommand(com.ibm.disni.nvmef.NvmeCommand) IOException(java.io.IOException) StorageEndpoint(org.apache.crail.storage.StorageEndpoint) NvmeEndpoint(com.ibm.disni.nvmef.NvmeEndpoint) CrailBuffer(org.apache.crail.CrailBuffer) StorageFuture(org.apache.crail.storage.StorageFuture)

Example 14 with CrailBuffer

use of org.apache.crail.CrailBuffer in project incubator-crail by apache.

the class CrailBenchmark method createFile.

void createFile(String filename, int loop) throws Exception, InterruptedException {
    System.out.println("createFile, filename " + filename + ", loop " + loop);
    // warmup
    ConcurrentLinkedQueue<CrailBuffer> bufferQueue = new ConcurrentLinkedQueue<CrailBuffer>();
    CrailBuffer buf = fs.allocateBuffer();
    bufferQueue.add(buf);
    warmUp(filename, warmup, bufferQueue);
    fs.freeBuffer(buf);
    // benchmark
    System.out.println("starting benchmark...");
    fs.getStatistics().reset();
    LinkedBlockingQueue<String> pathQueue = new LinkedBlockingQueue<String>();
    fs.create(filename, CrailNodeType.DIRECTORY, CrailStorageClass.DEFAULT, CrailLocationClass.DEFAULT, true).get().syncDir();
    int filecounter = 0;
    for (int i = 0; i < loop; i++) {
        String name = "" + filecounter++;
        String f = filename + "/" + name;
        pathQueue.add(f);
    }
    double ops = 0;
    long start = System.currentTimeMillis();
    while (!pathQueue.isEmpty()) {
        String path = pathQueue.poll();
        fs.create(path, CrailNodeType.DATAFILE, CrailStorageClass.DEFAULT, CrailLocationClass.DEFAULT, true).get().syncDir();
    }
    long end = System.currentTimeMillis();
    double executionTime = ((double) (end - start)) / 1000.0;
    double latency = 0.0;
    if (executionTime > 0) {
        latency = 1000000.0 * executionTime / ops;
    }
    System.out.println("execution time " + executionTime);
    System.out.println("ops " + ops);
    System.out.println("latency " + latency);
    fs.getStatistics().print("close");
}
Also used : ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CrailBuffer(org.apache.crail.CrailBuffer)

Example 15 with CrailBuffer

use of org.apache.crail.CrailBuffer in project incubator-crail by apache.

the class CrailBenchmark method getFile.

void getFile(String filename, int loop) throws Exception, InterruptedException {
    System.out.println("getFile, filename " + filename + ", loop " + loop);
    // warmup
    ConcurrentLinkedQueue<CrailBuffer> bufferQueue = new ConcurrentLinkedQueue<CrailBuffer>();
    CrailBuffer buf = fs.allocateBuffer();
    bufferQueue.add(buf);
    warmUp(filename, warmup, bufferQueue);
    fs.freeBuffer(buf);
    // benchmark
    System.out.println("starting benchmark...");
    fs.getStatistics().reset();
    double ops = 0;
    long start = System.currentTimeMillis();
    while (ops < loop) {
        ops = ops + 1.0;
        fs.lookup(filename).get().asFile();
    }
    long end = System.currentTimeMillis();
    double executionTime = ((double) (end - start)) / 1000.0;
    double latency = 0.0;
    if (executionTime > 0) {
        latency = 1000000.0 * executionTime / ops;
    }
    System.out.println("execution time " + executionTime);
    System.out.println("ops " + ops);
    System.out.println("latency " + latency);
    fs.getStatistics().print("close");
    fs.close();
}
Also used : ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CrailBuffer(org.apache.crail.CrailBuffer)

Aggregations

CrailBuffer (org.apache.crail.CrailBuffer)19 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)11 CrailFile (org.apache.crail.CrailFile)8 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)5 Future (java.util.concurrent.Future)4 CrailInputStream (org.apache.crail.CrailInputStream)4 IOException (java.io.IOException)3 CrailBufferedInputStream (org.apache.crail.CrailBufferedInputStream)3 CrailOutputStream (org.apache.crail.CrailOutputStream)3 HashMap (java.util.HashMap)2 Random (java.util.Random)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CrailBufferedOutputStream (org.apache.crail.CrailBufferedOutputStream)2 CrailNode (org.apache.crail.CrailNode)2 CrailResult (org.apache.crail.CrailResult)2 NvmeCommand (com.ibm.disni.nvmef.NvmeCommand)1 NvmeEndpoint (com.ibm.disni.nvmef.NvmeEndpoint)1 RandomAccessFile (java.io.RandomAccessFile)1 ByteBuffer (java.nio.ByteBuffer)1 MappedByteBuffer (java.nio.MappedByteBuffer)1