HDDS-246. Datanode should throw BlockNotCommittedException for uncommitted blocks to Ozone Client. Contributed by Shashikant Banerjee.
This commit is contained in:
parent
3d586841ab
commit
6b038f82da
@ -138,6 +138,7 @@ enum Result {
|
||||
CONTAINER_FILES_CREATE_ERROR = 32;
|
||||
CONTAINER_CHECKSUM_ERROR = 33;
|
||||
UNKNOWN_CONTAINER_TYPE = 34;
|
||||
BLOCK_NOT_COMMITTED = 35;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,6 +129,18 @@ public void removeFromKeyMap(BlockID blockID) {
|
||||
-> blocks.removeAndGetSize(blockID.getLocalID()) == 0? null: blocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the block exists in the map, false otherwise
|
||||
*
|
||||
* @param blockID
|
||||
* @return True, if it exists, false otherwise
|
||||
*/
|
||||
public boolean checkIfBlockExists(BlockID blockID) {
|
||||
KeyDataMap keyDataMap = containers.get(blockID.getContainerID());
|
||||
return keyDataMap == null ? false :
|
||||
keyDataMap.get(blockID.getLocalID()) != null;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
KeyDataMap getKeyDataMap(long containerId) {
|
||||
return containers.get(containerId);
|
||||
|
@ -91,6 +91,8 @@
|
||||
.Result.GET_SMALL_FILE_ERROR;
|
||||
import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos
|
||||
.Result.PUT_SMALL_FILE_ERROR;
|
||||
import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos
|
||||
.Result.BLOCK_NOT_COMMITTED;
|
||||
|
||||
import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos
|
||||
.Stage;
|
||||
@ -494,10 +496,14 @@ ContainerCommandResponseProto handleGetCommittedBlockLength(
|
||||
|
||||
long blockLength;
|
||||
try {
|
||||
BlockID blockID = BlockID.getFromProtobuf(
|
||||
request.getGetCommittedBlockLength().getBlockID());
|
||||
BlockID blockID = BlockID
|
||||
.getFromProtobuf(request.getGetCommittedBlockLength().getBlockID());
|
||||
// Check if it really exists in the openContainerBlockMap
|
||||
if (openContainerBlockMap.checkIfBlockExists(blockID)) {
|
||||
String msg = "Block " + blockID + " is not committed yet.";
|
||||
throw new StorageContainerException(msg, BLOCK_NOT_COMMITTED);
|
||||
}
|
||||
blockLength = keyManager.getCommittedBlockLength(kvContainer, blockID);
|
||||
|
||||
} catch (StorageContainerException ex) {
|
||||
return ContainerUtils.logAndReturnError(LOG, ex, request);
|
||||
} catch (IOException ex) {
|
||||
|
@ -104,16 +104,6 @@ public void tesGetCommittedBlockLength() throws Exception {
|
||||
.getWriteChunkRequest(container.getPipeline(), blockID,
|
||||
data.length);
|
||||
client.sendCommand(writeChunkRequest);
|
||||
try {
|
||||
// since there is neither explicit putKey request made for the block,
|
||||
// nor the container is closed, GetCommittedBlockLength request
|
||||
// should fail here.
|
||||
response = ContainerProtocolCalls
|
||||
.getCommittedBlockLength(client, blockID, traceID);
|
||||
Assert.fail("Expected exception not thrown");
|
||||
} catch (StorageContainerException sce) {
|
||||
Assert.assertTrue(sce.getMessage().contains("Unable to find the key"));
|
||||
}
|
||||
// Now, explicitly make a putKey request for the block.
|
||||
ContainerProtos.ContainerCommandRequestProto putKeyRequest =
|
||||
ContainerTestHelper
|
||||
@ -188,4 +178,39 @@ public void tesGetCommittedBlockLengthForInvalidBlock() throws Exception {
|
||||
}
|
||||
xceiverClientManager.releaseClient(client);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCommittedBlockLengthForOpenBlock() throws Exception {
|
||||
String traceID = UUID.randomUUID().toString();
|
||||
ContainerWithPipeline container = storageContainerLocationClient
|
||||
.allocateContainer(xceiverClientManager.getType(),
|
||||
HddsProtos.ReplicationFactor.ONE, containerOwner);
|
||||
long containerID = container.getContainerInfo().getContainerID();
|
||||
XceiverClientSpi client = xceiverClientManager
|
||||
.acquireClient(container.getPipeline(), containerID);
|
||||
ContainerProtocolCalls
|
||||
.createContainer(client, containerID, traceID);
|
||||
|
||||
BlockID blockID =
|
||||
ContainerTestHelper.getTestBlockID(containerID);
|
||||
ContainerProtos.ContainerCommandRequestProto requestProto =
|
||||
ContainerTestHelper
|
||||
.getWriteChunkRequest(container.getPipeline(), blockID, 1024);
|
||||
client.sendCommand(requestProto);
|
||||
try {
|
||||
ContainerProtocolCalls.getCommittedBlockLength(client, blockID, traceID);
|
||||
Assert.fail("Expected Exception not thrown");
|
||||
} catch (StorageContainerException sce) {
|
||||
Assert.assertEquals(ContainerProtos.Result.BLOCK_NOT_COMMITTED,
|
||||
sce.getResult());
|
||||
}
|
||||
// now close the container, it should auto commit pending open blocks
|
||||
ContainerProtocolCalls
|
||||
.closeContainer(client, containerID, traceID);
|
||||
ContainerProtos.GetCommittedBlockLengthResponseProto response =
|
||||
ContainerProtocolCalls
|
||||
.getCommittedBlockLength(client, blockID, traceID);
|
||||
Assert.assertTrue(response.getBlockLength() == 1024);
|
||||
xceiverClientManager.releaseClient(client);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user