Search in sources :

Example 1 with RadosObjectInfo

use of com.ceph.rados.jna.RadosObjectInfo in project YCSB by brianfrankcooper.

the class RadosClient method read.

@Override
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    byte[] buffer;
    try {
        RadosObjectInfo info = ioctx.stat(key);
        buffer = new byte[(int) info.getSize()];
        ReadOp rop = ioctx.readOpCreate();
        ReadResult readResult = rop.queueRead(0, info.getSize());
        // TODO: more size than byte length possible;
        // rop.operate(key, Rados.OPERATION_NOFLAG); // for rados-java 0.3.0
        rop.operate(key, 0);
        // readResult.raiseExceptionOnError("Error ReadOP(%d)", readResult.getRVal()); // for rados-java 0.3.0
        if (readResult.getRVal() < 0) {
            throw new RadosException("Error ReadOP", readResult.getRVal());
        }
        if (info.getSize() != readResult.getBytesRead()) {
            return new Status("ERROR", "Error the object size read");
        }
        readResult.getBuffer().get(buffer);
    } catch (RadosException e) {
        return new Status("ERROR-" + e.getReturnValue(), e.getMessage());
    }
    JSONObject json = new JSONObject(new String(buffer, java.nio.charset.StandardCharsets.UTF_8));
    Set<String> fieldsToReturn = (fields == null ? json.keySet() : fields);
    for (String name : fieldsToReturn) {
        result.put(name, new StringByteIterator(json.getString(name)));
    }
    return result.isEmpty() ? Status.ERROR : Status.OK;
}
Also used : RadosObjectInfo(com.ceph.rados.jna.RadosObjectInfo) Status(com.yahoo.ycsb.Status) JSONObject(org.json.JSONObject) StringByteIterator(com.yahoo.ycsb.StringByteIterator) ReadResult(com.ceph.rados.ReadOp.ReadResult) RadosException(com.ceph.rados.exceptions.RadosException) ReadOp(com.ceph.rados.ReadOp)

Aggregations

ReadOp (com.ceph.rados.ReadOp)1 ReadResult (com.ceph.rados.ReadOp.ReadResult)1 RadosException (com.ceph.rados.exceptions.RadosException)1 RadosObjectInfo (com.ceph.rados.jna.RadosObjectInfo)1 Status (com.yahoo.ycsb.Status)1 StringByteIterator (com.yahoo.ycsb.StringByteIterator)1 JSONObject (org.json.JSONObject)1