Skip to content

Commit

Permalink
CLEANUP: Refactored the readState in BTreeSortMergeGetOperationImpl.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpark816 committed Dec 18, 2024
1 parent 9d9ffde commit ae6878e
Showing 1 changed file with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public final class BTreeSortMergeGetOperationImpl extends OperationImpl implemen
private byte lookingFor = '\0';
private int spaceCount = 0;

private ReadState readState = ReadState.VALUE;
private ReadState readState = ReadState.ELEMENTS;

public BTreeSortMergeGetOperationImpl(BTreeSMGet<?> smGet,
OperationCallback cb) {
Expand All @@ -92,7 +92,7 @@ public void handleLine(String line) {
getLogger().debug("Got line %s", line);

/*
VALUE|ELEMENTS <ecount>\r\n
ELEMENTS|VALUE <ecount>\r\n
<key> <flags> <bkey> [<eflag>] <bytes> <data>\r\n
[ ... ]
MISSED_KEYS <kcount>\r\n
Expand All @@ -103,16 +103,13 @@ public void handleLine(String line) {
[ ... ]
END|DUPLICATED|TRIMMED|DUPLICATRED_TRIMMED\r\n
*/
if (line.startsWith("VALUE ") ||
line.startsWith("ELEMENTS ")) {
readState = ReadState.VALUE;
if (line.startsWith("ELEMENTS ") || line.startsWith("VALUE ")) {
readState = ReadState.ELEMENTS;

String[] stuff = line.split(" ");
assert "VALUE".equals(stuff[0]) ||
"ELEMENTS".equals(stuff[0]);
assert "ELEMENTS".equals(stuff[0]) || "VALUE".equals(stuff[0]);

lineCount = Integer.parseInt(stuff[1]);

if (lineCount > 0) {
setReadType(OperationReadType.DATA);
}
Expand All @@ -123,7 +120,6 @@ public void handleLine(String line) {
assert "MISSED_KEYS".equals(stuff[0]);

lineCount = Integer.parseInt(stuff[1]);

if (lineCount > 0) {
setReadType(OperationReadType.DATA);
}
Expand All @@ -134,7 +130,6 @@ public void handleLine(String line) {
assert "TRIMMED_KEYS".equals(stuff[0]);

lineCount = Integer.parseInt(stuff[1]);

if (lineCount > 0) {
setReadType(OperationReadType.DATA);
}
Expand All @@ -151,8 +146,8 @@ public void handleLine(String line) {
@Override
public void handleRead(ByteBuffer bb) {
switch (readState) {
case VALUE:
readValue(bb);
case ELEMENTS:
readElements(bb);
break;
case MISSED_KEYS:
readMissedKeys(bb);
Expand All @@ -163,7 +158,7 @@ public void handleRead(ByteBuffer bb) {
}
}

private void readValue(ByteBuffer bb) {
private void readElements(ByteBuffer bb) {
// Decode a collection data header.
int count = 0;
if (lookingFor == '\0' && data == null) {
Expand Down Expand Up @@ -459,7 +454,7 @@ public BTreeSMGet<?> getSMGet() {
}

private enum ReadState {
VALUE,
ELEMENTS,
MISSED_KEYS,
TRIMMED_KEYS,
}
Expand Down

0 comments on commit ae6878e

Please sign in to comment.