|
@@ -421,6 +421,7 @@ public class KeyValueHandler extends Handler {
|
|
ContainerCommandResponseProto handlePutKey(
|
|
ContainerCommandResponseProto handlePutKey(
|
|
ContainerCommandRequestProto request, KeyValueContainer kvContainer) {
|
|
ContainerCommandRequestProto request, KeyValueContainer kvContainer) {
|
|
|
|
|
|
|
|
+ long blockLength;
|
|
if (!request.hasPutKey()) {
|
|
if (!request.hasPutKey()) {
|
|
LOG.debug("Malformed Put Key request. trace ID: {}",
|
|
LOG.debug("Malformed Put Key request. trace ID: {}",
|
|
request.getTraceID());
|
|
request.getTraceID());
|
|
@@ -433,7 +434,7 @@ public class KeyValueHandler extends Handler {
|
|
KeyData keyData = KeyData.getFromProtoBuf(
|
|
KeyData keyData = KeyData.getFromProtoBuf(
|
|
request.getPutKey().getKeyData());
|
|
request.getPutKey().getKeyData());
|
|
long numBytes = keyData.getProtoBufMessage().toByteArray().length;
|
|
long numBytes = keyData.getProtoBufMessage().toByteArray().length;
|
|
- commitKey(keyData, kvContainer);
|
|
|
|
|
|
+ blockLength = commitKey(keyData, kvContainer);
|
|
metrics.incContainerBytesStats(Type.PutKey, numBytes);
|
|
metrics.incContainerBytesStats(Type.PutKey, numBytes);
|
|
} catch (StorageContainerException ex) {
|
|
} catch (StorageContainerException ex) {
|
|
return ContainerUtils.logAndReturnError(LOG, ex, request);
|
|
return ContainerUtils.logAndReturnError(LOG, ex, request);
|
|
@@ -443,7 +444,7 @@ public class KeyValueHandler extends Handler {
|
|
request);
|
|
request);
|
|
}
|
|
}
|
|
|
|
|
|
- return KeyUtils.getKeyResponseSuccess(request);
|
|
|
|
|
|
+ return KeyUtils.putKeyResponseSuccess(request, blockLength);
|
|
}
|
|
}
|
|
|
|
|
|
private void commitPendingKeys(KeyValueContainer kvContainer)
|
|
private void commitPendingKeys(KeyValueContainer kvContainer)
|
|
@@ -456,12 +457,13 @@ public class KeyValueHandler extends Handler {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void commitKey(KeyData keyData, KeyValueContainer kvContainer)
|
|
|
|
|
|
+ private long commitKey(KeyData keyData, KeyValueContainer kvContainer)
|
|
throws IOException {
|
|
throws IOException {
|
|
Preconditions.checkNotNull(keyData);
|
|
Preconditions.checkNotNull(keyData);
|
|
- keyManager.putKey(kvContainer, keyData);
|
|
|
|
|
|
+ long length = keyManager.putKey(kvContainer, keyData);
|
|
//update the open key Map in containerManager
|
|
//update the open key Map in containerManager
|
|
this.openContainerBlockMap.removeFromKeyMap(keyData.getBlockID());
|
|
this.openContainerBlockMap.removeFromKeyMap(keyData.getBlockID());
|
|
|
|
+ return length;
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* Handle Get Key operation. Calls KeyManager to process the request.
|
|
* Handle Get Key operation. Calls KeyManager to process the request.
|
|
@@ -662,8 +664,12 @@ public class KeyValueHandler extends Handler {
|
|
request.getWriteChunk().getStage() == Stage.COMBINED) {
|
|
request.getWriteChunk().getStage() == Stage.COMBINED) {
|
|
metrics.incContainerBytesStats(Type.WriteChunk, request.getWriteChunk()
|
|
metrics.incContainerBytesStats(Type.WriteChunk, request.getWriteChunk()
|
|
.getChunkData().getLen());
|
|
.getChunkData().getLen());
|
|
- // the openContainerBlockMap should be updated only while writing data
|
|
|
|
- // not during COMMIT_STAGE of handling write chunk request.
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (request.getWriteChunk().getStage() == Stage.COMMIT_DATA
|
|
|
|
+ || request.getWriteChunk().getStage() == Stage.COMBINED) {
|
|
|
|
+ // the openContainerBlockMap should be updated only during
|
|
|
|
+ // COMMIT_STAGE of handling write chunk request.
|
|
openContainerBlockMap.addChunk(blockID, chunkInfoProto);
|
|
openContainerBlockMap.addChunk(blockID, chunkInfoProto);
|
|
}
|
|
}
|
|
} catch (StorageContainerException ex) {
|
|
} catch (StorageContainerException ex) {
|