Skip to content

Commit

Permalink
INTERNAL: Refactor collectionGetOp and BTreeGet.
Browse files Browse the repository at this point in the history
  • Loading branch information
brido4125 authored and jhpark816 committed Aug 24, 2023
1 parent c7d2b03 commit cc0aa26
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 35 deletions.
32 changes: 13 additions & 19 deletions src/main/java/net/spy/memcached/collection/BTreeGet.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
public class BTreeGet extends CollectionGet {

private static final String command = "bop get";

protected int offset = -1;
protected int count = -1;

protected ElementFlagFilter elementFlagFilter;

private boolean isFirstParsing = true;
private boolean elementFlagExists = false;


private BTreeGet(String range,
boolean delete, boolean dropIfEmpty,
ElementFlagFilter elementFlagFilter) {
Expand Down Expand Up @@ -71,10 +73,6 @@ public BTreeGet(byte[] from, byte[] to, int offset, int count,
offset, count, delete, dropIfEmpty, elementFlagFilter);
}

public ElementFlagFilter getElementFlagFilter() {
return elementFlagFilter;
}

public String getRange() {
return range;
}
Expand Down Expand Up @@ -123,17 +121,10 @@ public String getCommand() {
return command;
}

public void resetHeaderCount(int count) {
this.headerCount = count;
}

private int headerParseStep = 1;

private boolean elementFlagExists = false;

public boolean eachRecordParseCompleted() {
if (elementFlagExists) {
return headerParseStep == 1;
// isFirstParsing true means item header with eFlag was parsed completely
return isFirstParsing;
} else {
return true;
}
Expand All @@ -146,13 +137,15 @@ public byte[] getAddtionalArgs() {

@Override
public boolean headerReady(int spaceCount) {
// non-eFlag header has spaceCount 2 and eFlag header has spaceCount 3
return spaceCount == 2 || spaceCount == 3;
}

@Override
public void decodeItemHeader(String itemHeader) {
String[] splited = itemHeader.split(" ");

if (headerParseStep == 1) {
if (isFirstParsing) {
// found bkey
if (splited[0].startsWith("0x")) {
this.subkey = splited[0].substring(2);
Expand All @@ -164,14 +157,15 @@ public void decodeItemHeader(String itemHeader) {
if (splited[1].startsWith("0x")) {
this.elementFlagExists = true;
this.elementFlag = BTreeUtil.hexStringToByteArrays(splited[1].substring(2));
//this.headerCount++;
headerParseStep = 2;
// need second parsing because of EFlag field
isFirstParsing = false;
} else {
this.dataLength = Integer.parseInt(splited[1]);
}
} else {
this.headerParseStep = 1;
this.dataLength = Integer.parseInt(splited[1]);
// revert true for next B+Tree element parsing
this.isFirstParsing = true;
}
}
}
8 changes: 0 additions & 8 deletions src/main/java/net/spy/memcached/collection/CollectionGet.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ public boolean headerReady(int spaceCount) {
return headerCount == spaceCount;
}

public void setHeaderCount(int headerCount) {
this.headerCount = headerCount;
}

public int getHeaderCount() {
return headerCount;
}

public boolean eachRecordParseCompleted() {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void handleLine(String line) {
public final void handleRead(ByteBuffer bb) {
// Decode a collection data header.
if (lookingFor == '\0' && data == null) {
for (int i = 0; bb.remaining() > 0; i++) {
while (bb.hasRemaining()) {
byte b = bb.get();

// Handle spaces.
Expand All @@ -160,15 +160,10 @@ public final void handleRead(ByteBuffer bb) {
set: <bytes> <data>\r\n
map: <field> <bytes> <data>\r\n
*/
collectionGet.decodeItemHeader(new String(byteBuffer.toByteArray()));
collectionGet.decodeItemHeader(byteBuffer.toString());
byteBuffer.reset();

if (collectionGet.headerReady(spaceCount)
&& collectionGet.eachRecordParseCompleted()) {
// if (collectionGet.getElementFlag() != null) {
// collectionGet.setHeaderCount(collectionGet
// .getHeaderCount() - 1);
// }
if (collectionGet.headerReady(spaceCount) && collectionGet.eachRecordParseCompleted()) {
data = new byte[collectionGet.getDataLength()];
spaceCount = 0;
break;
Expand Down

0 comments on commit cc0aa26

Please sign in to comment.