Skip to content

Commit

Permalink
Fixing CrailClient::read
Browse files Browse the repository at this point in the history
- Thanks @PepperJo
  • Loading branch information
patrickstuedi committed Dec 6, 2018
1 parent 805feed commit 444a0b9
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions crail/src/main/java/com/yahoo/ycsb/db/CrailClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,39 @@ public Status read(String table, String key, Set<String> fields, Map<String, Byt
String path = table + "/" + key;
CrailKeyValue file = client.lookup(path).get().asKeyValue();
CrailBufferedInputStream stream = file.getBufferedInputStream(1024);
while(stream.available() > 0){
int fieldKeyLength = stream.readInt();
byte[] fieldKey = new byte[fieldKeyLength];
int res = stream.read(fieldKey);
if (res != fieldKey.length){
return Status.ERROR;
}
int fieldValueLength = stream.readInt();
byte[] fieldValue = new byte[fieldValueLength];
res = stream.read(fieldValue);
if (res != fieldValue.length){
return Status.ERROR;
}
result.put(new String(fieldKey), new ByteArrayByteIterator(fieldValue));
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){
System.out.println("error when reading " + table + "/" + key + ", exception " + e.getMessage());
return Status.ERROR;
e.printStackTrace();
return new Status("read error", "reading exception");
}
}

Expand Down

0 comments on commit 444a0b9

Please sign in to comment.