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