Search in sources :

Example 6 with CrailBufferedOutputStream

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

the class CrailBenchmark method writeInt.

void writeInt(String filename, int loop) throws Exception {
    System.out.println("writeInt, filename " + filename + ", loop " + loop);
    // benchmark
    System.out.println("starting benchmark...");
    double ops = 0;
    CrailFile file = fs.create(filename, CrailNodeType.DATAFILE, CrailStorageClass.DEFAULT, CrailLocationClass.DEFAULT, true).get().asFile();
    CrailBufferedOutputStream outputStream = file.getBufferedOutputStream(loop * 4);
    int intValue = 0;
    System.out.println("starting write at position " + outputStream.position());
    while (ops < loop) {
        System.out.println("writing position " + outputStream.position() + ", value " + intValue);
        outputStream.writeInt(intValue);
        intValue++;
        ops++;
    }
    outputStream.purge().get();
    outputStream.sync().get();
    fs.getStatistics().print("close");
}
Also used : CrailFile(org.apache.crail.CrailFile) CrailBufferedOutputStream(org.apache.crail.CrailBufferedOutputStream)

Example 7 with CrailBufferedOutputStream

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

the class CrailClient method insert.

@Override
public Status insert(String table, String key, Map<String, ByteIterator> values) {
    try {
        String path = table + "/" + key;
        CrailKeyValue file = client.create(path, CrailNodeType.KEYVALUE, CrailStorageClass.DEFAULT, CrailLocationClass.DEFAULT, enumerateKeys).get().asKeyValue();
        CrailBufferedOutputStream stream = file.getBufferedOutputStream(1024);
        for (Entry<String, ByteIterator> entry : values.entrySet()) {
            byte[] fieldKey = entry.getKey().getBytes();
            int fieldKeyLength = fieldKey.length;
            byte[] fieldValue = entry.getValue().toArray();
            int fieldValueLength = fieldValue.length;
            stream.writeInt(fieldKeyLength);
            stream.write(fieldKey);
            stream.writeInt(fieldValueLength);
            stream.write(fieldValue);
        }
        file.syncDir();
        stream.close();
    } catch (Exception e) {
        LOG.error("Error during insert, table " + table + ", key " + key + ", exception " + e.getMessage());
        return Status.ERROR;
    }
    return Status.OK;
}
Also used : ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) CrailKeyValue(org.apache.crail.CrailKeyValue) CrailBufferedOutputStream(org.apache.crail.CrailBufferedOutputStream) DBException(site.ycsb.DBException)

Aggregations

CrailBufferedOutputStream (org.apache.crail.CrailBufferedOutputStream)7 CrailFile (org.apache.crail.CrailFile)6 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 CrailBuffer (org.apache.crail.CrailBuffer)2 Path (org.apache.hadoop.fs.Path)2 URISyntaxException (java.net.URISyntaxException)1 ByteBuffer (java.nio.ByteBuffer)1 Random (java.util.Random)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 CrailKeyValue (org.apache.crail.CrailKeyValue)1 CrailOutputStream (org.apache.crail.CrailOutputStream)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 ByteIterator (site.ycsb.ByteIterator)1 DBException (site.ycsb.DBException)1