adoroszlai commented on code in PR #8411:
URL: https://github.com/apache/ozone/pull/8411#discussion_r2080937652
##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Proto2Codec.java:
##########
@@ -64,24 +65,37 @@ public boolean supportCodecBuffer() {
@Override
public CodecBuffer toCodecBuffer(@Nonnull M message,
- CodecBuffer.Allocator allocator) throws IOException {
+ CodecBuffer.Allocator allocator) throws CodecException {
final int size = message.getSerializedSize();
return allocator.apply(size).put(writeTo(message, size));
}
private CheckedFunction<OutputStream, Integer, IOException> writeTo(
M message, int size) {
- return out -> {
- message.writeTo(out);
- return size;
+ return new CheckedFunction<OutputStream, Integer, IOException>() {
+ @Override
+ public Integer apply(OutputStream out) throws IOException {
+ message.writeTo(out);
+ return size;
+ }
+
+ @Override
+ public String toString() {
+ return "source: size=" + size + ", message=" + message;
+ }
};
}
@Override
public M fromCodecBuffer(@Nonnull CodecBuffer buffer)
- throws IOException {
- try (InputStream in = buffer.getInputStream()) {
+ throws CodecException {
+ final InputStream in = buffer.getInputStream();
+ try {
return parser.parseFrom(in);
+ } catch (InvalidProtocolBufferException e) {
+ throw new CodecException("Failed to parse " + buffer, e);
Review Comment:
Should it be the same?
https://github.com/apache/ozone/blob/a354d00bb01f195592b74a9b359170947d67399c/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/db/Proto3Codec.java#L88
##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/BlockData.java:
##########
@@ -92,15 +94,13 @@ public void setBlockCommitSequenceId(long
blockCommitSequenceId) {
*
* @param data - Protobuf data.
* @return - BlockData
- * @throws IOException
*/
- public static BlockData getFromProtoBuf(ContainerProtos.BlockData data)
throws
- IOException {
+ public static BlockData getFromProtoBuf(ContainerProtos.BlockData data)
throws CodecException {
BlockData blockData = new BlockData(
BlockID.getFromProtobuf(data.getBlockID()));
for (int x = 0; x < data.getMetadataCount(); x++) {
- blockData.addMetadata(data.getMetadata(x).getKey(),
- data.getMetadata(x).getValue());
+ final ContainerProtos.KeyValue meta = data.getMetadata(x);
+ blockData.addMetadata(meta.getKey(), meta.getValue(),
CodecException::new);
}
blockData.setChunks(data.getChunksList());
if (data.hasSize()) {
Review Comment:
Should we throw `CodecException` on size mismatch?
https://github.com/apache/ozone/blob/a354d00bb01f195592b74a9b359170947d67399c/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/BlockData.java#L106-L107
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]