Search in sources :

Example 1 with CrailKeyValue

use of org.apache.crail.CrailKeyValue 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 2 with CrailKeyValue

use of org.apache.crail.CrailKeyValue 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

CrailKeyValue (org.apache.crail.CrailKeyValue)2 ByteArrayByteIterator (site.ycsb.ByteArrayByteIterator)2 DBException (site.ycsb.DBException)2 CrailBufferedInputStream (org.apache.crail.CrailBufferedInputStream)1 CrailBufferedOutputStream (org.apache.crail.CrailBufferedOutputStream)1 ByteIterator (site.ycsb.ByteIterator)1 Status (site.ycsb.Status)1