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");
}
}
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;
}
Aggregations