Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.hadoop.io.Text;
import org.apache.hadoop.ozone.om.protocolPB.OmTransport;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.BucketInfo;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CommitKeyRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CommitKeyResponse;
Expand Down Expand Up @@ -116,13 +117,24 @@ public OMResponse submitRequest(OMRequest payload) throws IOException {
return response(payload,
r -> r.setServiceListResponse(
serviceList(payload.getServiceListRequest())));
case AllocateBlock:
return response(payload, r -> r.setAllocateBlockResponse(
allocateBlock(payload.getAllocateBlockRequest())));
default:
throw new IllegalArgumentException(
"Mock version of om call " + payload.getCmdType()
+ " is not yet implemented");
}
}

private OzoneManagerProtocolProtos.AllocateBlockResponse allocateBlock(
OzoneManagerProtocolProtos.AllocateBlockRequest allocateBlockRequest) {
return OzoneManagerProtocolProtos.AllocateBlockResponse.newBuilder()
.setKeyLocation(
blockAllocator.allocateBlock(allocateBlockRequest.getKeyArgs())
.iterator().next()).build();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me add loop here for all KeyArgs available

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at SinglePipelineBlockAllocator, I am not sure it can return multiple results, or that you can request multiple blocks in one go from the AllocateBlockRequest. However it does return an Iterable<>, so you have to call next on it as you have done.

The response AllocateBlockResponse object just contains a single "KeyLocation", which contains a single "BlockID" and "Pipeline". Therefore I think your code is correct and it does not need a loop here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah. Looks like your are right. API name says keyLocation, but not keyLocations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to return with multiple key locations if the keyArgs contains a size which is huge enough. Today it's not supported by the block allocated, but looks to be safer to add all the results to the setKeyLocation...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks for the offline discussion with you, I got it. Pure allocateBlock supports one keyLocation. Open key supports multiple location. Strange, but this is what we have. Thanks to help me learninig it.

}

private DeleteVolumeResponse deleteVolume(
DeleteVolumeRequest deleteVolumeRequest) {
volumes.remove(deleteVolumeRequest.getVolumeName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,9 @@ public void testCreateBucket()

@Test
public void testPutKeyRatisOneNode() throws IOException {
String volumeName = UUID.randomUUID().toString();
String bucketName = UUID.randomUUID().toString();
Instant testStartTime = Instant.now();

String value = "sample value";
store.createVolume(volumeName);
OzoneVolume volume = store.getVolume(volumeName);
volume.createBucket(bucketName);
OzoneBucket bucket = volume.getBucket(bucketName);
OzoneBucket bucket = getOzoneBucket();

for (int i = 0; i < 10; i++) {
String keyName = UUID.randomUUID().toString();
Expand All @@ -171,4 +165,30 @@ public void testPutKeyRatisOneNode() throws IOException {
Assert.assertFalse(key.getModificationTime().isBefore(testStartTime));
}
}

@Test
public void testPutKeyAllocateBlock() throws IOException {
String value = new String(new byte[1024], UTF_8);
OzoneBucket bucket = getOzoneBucket();

for (int i = 0; i < 10; i++) {
String keyName = UUID.randomUUID().toString();

try (OzoneOutputStream out = bucket
.createKey(keyName, value.getBytes(UTF_8).length,
ReplicationType.RATIS, ONE, new HashMap<>())) {
out.write(value.getBytes(UTF_8));
out.write(value.getBytes(UTF_8));
}
}
}

private OzoneBucket getOzoneBucket() throws IOException {
String volumeName = UUID.randomUUID().toString();
String bucketName = UUID.randomUUID().toString();
store.createVolume(volumeName);
OzoneVolume volume = store.getVolume(volumeName);
volume.createBucket(bucketName);
return volume.getBucket(bucketName);
}
}