Search in sources :

Example 6 with CrailBufferedInputStream

use of org.apache.crail.CrailBufferedInputStream in project YCSB by brianfrankcooper.

the class CrailClient method read.

@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
    try {
        String path = table + "/" + key;
        CrailKeyValue file = client.lookup(path).get().asKeyValue();
        CrailBufferedInputStream stream = file.getBufferedInputStream(1024);
        while (stream.available() < Integer.BYTES) {
            assert true;
        }
        int fieldKeyLength = stream.readInt();
        while (stream.available() < fieldKeyLength) {
            assert true;
        }
        byte[] fieldKey = new byte[fieldKeyLength];
        int res = stream.read(fieldKey);
        if (res != fieldKey.length) {
            stream.close();
            return Status.ERROR;
        }
        while (stream.available() < Integer.BYTES) {
            assert true;
        }
        int fieldValueLength = stream.readInt();
        while (stream.available() < fieldValueLength) {
            assert true;
        }
        byte[] fieldValue = new byte[fieldValueLength];
        res = stream.read(fieldValue);
        if (res != fieldValue.length) {
            stream.close();
            return Status.ERROR;
        }
        result.put(new String(fieldKey), new ByteArrayByteIterator(fieldValue));
        stream.close();
        return Status.OK;
    } catch (Exception e) {
        LOG.error("Error during read, table " + table + ", key " + key + ", exception " + e.getMessage());
        return new Status("read error", "reading exception");
    }
}
Also used : Status(site.ycsb.Status) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) CrailKeyValue(org.apache.crail.CrailKeyValue) CrailBufferedInputStream(org.apache.crail.CrailBufferedInputStream) DBException(site.ycsb.DBException)

Example 7 with CrailBufferedInputStream

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

the class CrailHadoopFileSystem method open.

public FSDataInputStream open(Path path, int bufferSize) throws IOException {
    CrailFile fileInfo = null;
    try {
        fileInfo = dfs.lookup(path.toUri().getRawPath()).get().asFile();
        CrailBufferedInputStream inputStream = fileInfo.getBufferedInputStream(fileInfo.getCapacity());
        return new CrailHDFSInputStream(inputStream);
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : CrailFile(org.apache.crail.CrailFile) IOException(java.io.IOException) CrailBufferedInputStream(org.apache.crail.CrailBufferedInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 8 with CrailBufferedInputStream

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

the class CrailBenchmark method readInt.

void readInt(String filename, int loop) throws Exception {
    System.out.println("seek, filename " + filename + ", loop " + loop);
    // benchmark
    System.out.println("starting benchmark...");
    double ops = 0;
    CrailFile file = fs.lookup(filename).get().asFile();
    CrailBufferedInputStream inputStream = file.getBufferedInputStream(loop * 4);
    System.out.println("starting read at position " + inputStream.position());
    while (ops < loop) {
        System.out.print("reading position " + inputStream.position() + ", expected " + inputStream.position() / 4 + " ");
        int intValue = inputStream.readInt();
        System.out.println(", value " + intValue);
        ops++;
    }
    inputStream.close();
    fs.getStatistics().print("close");
}
Also used : CrailFile(org.apache.crail.CrailFile) CrailBufferedInputStream(org.apache.crail.CrailBufferedInputStream)

Example 9 with CrailBufferedInputStream

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

the class CrailBenchmark method seekInt.

void seekInt(String filename, int loop) throws Exception {
    System.out.println("seek, filename " + filename + ", loop " + loop);
    // benchmark
    System.out.println("starting benchmark...");
    double ops = 0;
    CrailFile file = fs.lookup(filename).get().asFile();
    Random random = new Random();
    long nbrOfInts = file.getCapacity() / 4;
    CrailBufferedInputStream seekStream = file.getBufferedInputStream(loop * 4);
    System.out.println("starting seek phase, nbrOfInts " + nbrOfInts + ", position " + seekStream.position());
    long falseMatches = 0;
    while (ops < loop) {
        int intIndex = random.nextInt((int) nbrOfInts);
        int pos = intIndex * 4;
        seekStream.seek((long) pos);
        int intValue = seekStream.readInt();
        if (intIndex != intValue) {
            falseMatches++;
            System.out.println("reading, position " + pos + ", expected " + pos / 4 + ", ########## value " + intValue);
        } else {
            System.out.println("reading, position " + pos + ", expected " + pos / 4 + ", value " + intValue);
        }
        ops++;
    }
    seekStream.close();
    long end = System.currentTimeMillis();
    System.out.println("falseMatches " + falseMatches);
    fs.getStatistics().print("close");
}
Also used : Random(java.util.Random) CrailFile(org.apache.crail.CrailFile) CrailBufferedInputStream(org.apache.crail.CrailBufferedInputStream)

Aggregations

CrailBufferedInputStream (org.apache.crail.CrailBufferedInputStream)9 CrailFile (org.apache.crail.CrailFile)6 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)3 CrailBuffer (org.apache.crail.CrailBuffer)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Random (java.util.Random)2 CrailInputStream (org.apache.crail.CrailInputStream)2 URISyntaxException (java.net.URISyntaxException)1 ByteBuffer (java.nio.ByteBuffer)1 CrailKeyValue (org.apache.crail.CrailKeyValue)1 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)1 ParentNotDirectoryException (org.apache.hadoop.fs.ParentNotDirectoryException)1 UnresolvedLinkException (org.apache.hadoop.fs.UnresolvedLinkException)1 UnsupportedFileSystemException (org.apache.hadoop.fs.UnsupportedFileSystemException)1 AccessControlException (org.apache.hadoop.security.AccessControlException)1 ByteArrayByteIterator (site.ycsb.ByteArrayByteIterator)1 DBException (site.ycsb.DBException)1 Status (site.ycsb.Status)1