adoroszlai commented on code in PR #7625:
URL: https://github.com/apache/ozone/pull/7625#discussion_r1901870364


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChunkBufferToByteStringByByteBufs.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.ozone.common;
+
+import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
+import org.apache.ratis.thirdparty.io.netty.buffer.ByteBuf;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * A {@link ChunkBufferToByteString} implementation
+ * using a list of {@link ByteBuf}s.
+ */
+class ChunkBufferToByteStringByByteBufs implements ChunkBufferToByteString {
+  private final List<ByteBuf> buffers;
+
+  private volatile List<ByteString> byteStrings;
+  private volatile ByteString byteString;
+
+  ChunkBufferToByteStringByByteBufs(List<ByteBuf> buffers) {
+    this.buffers = buffers == null || buffers.isEmpty() ?
+        Collections.emptyList() : Collections.unmodifiableList(buffers);
+  }
+
+  @Override
+  public ByteString toByteStringImpl(Function<ByteBuffer, ByteString> f) {
+    if (byteString != null) {
+      return byteString;
+    }
+    initByteStrings(f);
+    return Objects.requireNonNull(byteString, "byteString == null");
+  }
+
+  @Override
+  public List<ByteString> toByteStringListImpl(
+      Function<ByteBuffer, ByteString> f) {
+    if (byteStrings != null) {
+      return byteStrings;
+    }
+    return initByteStrings(f);
+  }
+
+  private synchronized List<ByteString> initByteStrings(
+      Function<ByteBuffer, ByteString> f) {
+    if (byteStrings != null) {
+      return byteStrings;
+    }
+
+    byteStrings = new ArrayList<>();
+    byteString = ByteString.EMPTY;
+    for (ByteBuf buf : buffers) {
+      final ByteString s = f.apply(buf.nioBuffer());
+      buf.release();
+      byteStrings.add(s);
+      byteString = byteString.concat(s);
+    }

Review Comment:
   Incompletely initialized value may be used by other threads due to assigning 
multiple times.  The method should use local variables first, and only assign 
to the fields after the loop.



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ScmConfigKeys.java:
##########
@@ -153,6 +153,9 @@ public final class ScmConfigKeys {
       "ozone.chunk.read.mapped.buffer.max.count";
   // this max_count could not be greater than Linux platform max_map_count 
which by default is 65530.
   public static final int OZONE_CHUNK_READ_MAPPED_BUFFER_MAX_COUNT_DEFAULT = 0;
+  public static final String OZONE_CHUNK_READ_NETTY_CHUNKED_NIO_FILE_KEY =
+      "ozone.chunk.read.netty.ChunkedNioFile";

Review Comment:
   If you would like to hide this config setting, please add it as an exception 
in `TestOzoneConfigurationFields`.
   
   
https://github.com/apache/ozone/blob/60a7fdb628a3dba692ec68ad816c2ab69d687a47/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestOzoneConfigurationFields.java#L83-L86
   
   
   ```
   [ERROR] Tests run: 4, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 
0.505 s <<< FAILURE! - in org.apache.hadoop.ozone.TestOzoneConfigurationFields
   [ERROR] 
org.apache.hadoop.ozone.TestOzoneConfigurationFields.testCompareConfigurationClassAgainstXml
  Time elapsed: 0.024 s  <<< FAILURE!
   org.opentest4j.AssertionFailedError: class 
org.apache.hadoop.ozone.OzoneConfigKeys class 
org.apache.hadoop.hdds.scm.ScmConfigKeys class 
org.apache.hadoop.ozone.om.OMConfigKeys class 
org.apache.hadoop.hdds.HddsConfigKeys class 
org.apache.hadoop.hdds.recon.ReconConfigKeys class 
org.apache.hadoop.ozone.recon.ReconServerConfigKeys class 
org.apache.hadoop.ozone.s3.S3GatewayConfigKeys class 
org.apache.hadoop.ozone.s3secret.S3SecretConfigKeys class 
org.apache.hadoop.hdds.scm.server.SCMHTTPServerConfig class 
org.apache.hadoop.hdds.scm.server.SCMHTTPServerConfig$ConfigStrings class 
org.apache.hadoop.hdds.scm.ScmConfig$ConfigStrings has 1 variables missing in 
ozone-default.xml Entries:   ozone.chunk.read.netty.ChunkedNioFile ==> 
expected: <0> but was: <1>
   ```



-- 
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]

Reply via email to