use of org.apache.crail.CrailBufferedInputStream 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.CrailBufferedInputStream in project incubator-crail by apache.
the class CrailHadoopFileSystem method open.
public FSDataInputStream open(Path path, int bufferSize) throws IOException {
CrailFile fileInfo = null;
try {
fileInfo = dfs.lookup(path.toUri().getRawPath()).get().asFile();
CrailBufferedInputStream inputStream = fileInfo.getBufferedInputStream(fileInfo.getCapacity());
return new CrailHDFSInputStream(inputStream);
} catch (Exception e) {
throw new IOException(e);
}
}
use of org.apache.crail.CrailBufferedInputStream in project incubator-crail by apache.
the class CrailBenchmark method readInt.
void readInt(String filename, int loop) throws Exception {
System.out.println("seek, filename " + filename + ", loop " + loop);
// benchmark
System.out.println("starting benchmark...");
double ops = 0;
CrailFile file = fs.lookup(filename).get().asFile();
CrailBufferedInputStream inputStream = file.getBufferedInputStream(loop * 4);
System.out.println("starting read at position " + inputStream.position());
while (ops < loop) {
System.out.print("reading position " + inputStream.position() + ", expected " + inputStream.position() / 4 + " ");
int intValue = inputStream.readInt();
System.out.println(", value " + intValue);
ops++;
}
inputStream.close();
fs.getStatistics().print("close");
}
use of org.apache.crail.CrailBufferedInputStream in project incubator-crail by apache.
the class CrailBenchmark method seekInt.
void seekInt(String filename, int loop) throws Exception {
System.out.println("seek, filename " + filename + ", loop " + loop);
// benchmark
System.out.println("starting benchmark...");
double ops = 0;
CrailFile file = fs.lookup(filename).get().asFile();
Random random = new Random();
long nbrOfInts = file.getCapacity() / 4;
CrailBufferedInputStream seekStream = file.getBufferedInputStream(loop * 4);
System.out.println("starting seek phase, nbrOfInts " + nbrOfInts + ", position " + seekStream.position());
long falseMatches = 0;
while (ops < loop) {
int intIndex = random.nextInt((int) nbrOfInts);
int pos = intIndex * 4;
seekStream.seek((long) pos);
int intValue = seekStream.readInt();
if (intIndex != intValue) {
falseMatches++;
System.out.println("reading, position " + pos + ", expected " + pos / 4 + ", ########## value " + intValue);
} else {
System.out.println("reading, position " + pos + ", expected " + pos / 4 + ", value " + intValue);
}
ops++;
}
seekStream.close();
long end = System.currentTimeMillis();
System.out.println("falseMatches " + falseMatches);
fs.getStatistics().print("close");
}
Aggregations