Skip to content

Commit

Permalink
fix NIO connector problem to work with version higher than v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Lei Gao committed Mar 17, 2011
1 parent 899b53d commit 059c7ba
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/single_node_cluster/config/server.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mysql.password=3306
mysql.database=test

#NIO connector settings.
enable.nio.connector=false
enable.nio.connector=true

request.format=vp3
storage.configs=voldemort.store.bdb.BdbStorageConfiguration, voldemort.store.readonly.ReadOnlyStorageConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,52 @@ public boolean isCompleteRequest(final ByteBuffer buffer) {
inputStream.readUTF();

// Read the 'is routed' flag in, but just to skip the byte.
if(protocolVersion > 0)
inputStream.readBoolean();
if(protocolVersion > 0) {
boolean routed = inputStream.readBoolean();
if(logger.isDebugEnabled()) {
logger.debug("isRouted=" + routed);
}
}

// Read routing type
if(protocolVersion > 1) {
int routingTypeCode = inputStream.readByte();
if(logger.isDebugEnabled()) {
logger.debug("routingTypeCode=" + routingTypeCode);
}
}

switch(opCode) {
case VoldemortOpCode.GET_OP_CODE:
case VoldemortOpCode.GET_VERSION_OP_CODE:
// Read the key just to skip the bytes.
readKey(inputStream);
break;
case VoldemortOpCode.GET_OP_CODE:
// Read the key just to skip the bytes.
readKey(inputStream);
if(protocolVersion > 2) {
boolean hasTransform = inputStream.readBoolean();
if(hasTransform) {
readTransforms(inputStream);
}
}
break;
case VoldemortOpCode.GET_ALL_OP_CODE:
int numKeys = inputStream.readInt();

// Read the keys to skip the bytes.
for(int i = 0; i < numKeys; i++)
readKey(inputStream);

if(protocolVersion > 2) {
boolean hasTransform = inputStream.readBoolean();
if(hasTransform) {
int numTrans = inputStream.readInt();
for(int i = 0; i < numTrans; i++) {
readTransforms(inputStream);
}
}
}
break;
case VoldemortOpCode.PUT_OP_CODE: {
readKey(inputStream);
Expand All @@ -165,6 +195,12 @@ public boolean isCompleteRequest(final ByteBuffer buffer) {
// Here we skip over the data (without reading it in) and
// move our position to just past it.
buffer.position(newPosition);
if(protocolVersion > 2) {
boolean hasTransform = inputStream.readBoolean();
if(hasTransform) {
readTransforms(inputStream);
}
}
break;
}
case VoldemortOpCode.DELETE_OP_CODE: {
Expand Down Expand Up @@ -206,6 +242,11 @@ private ByteArray readKey(DataInputStream inputStream) throws IOException {
int keySize = inputStream.readInt();
byte[] key = new byte[keySize];
inputStream.readFully(key);

if(logger.isDebugEnabled()) {
logger.debug(new String(key));
}

return new ByteArray(key);
}

Expand All @@ -215,6 +256,11 @@ private byte[] readTransforms(DataInputStream inputStream) throws IOException {
return null;
byte[] transforms = new byte[size];
inputStream.readFully(transforms);

if(logger.isDebugEnabled()) {
logger.debug(new String(transforms));
}

return transforms;
}

Expand Down

0 comments on commit 059c7ba

Please sign in to comment.