szetszwo commented on code in PR #9649:
URL: https://github.com/apache/ozone/pull/9649#discussion_r2789577171


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/impl/ChunkManagerDummyImpl.java:
##########
@@ -72,9 +125,26 @@ public ChunkBuffer readChunk(Container container, BlockID 
blockID,
       ChunkInfo info, DispatcherContext dispatcherContext)
       throws StorageContainerException {
 
-    limitReadSize(info.getLen());

Review Comment:
   Let's keeping using `limitReadSize(..)`.  It limits the len <= 
OZONE_SCM_CHUNK_MAX_SIZE.
   
   Then, we may create the backing file using the size OZONE_SCM_CHUNK_MAX_SIZE.



##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/impl/ChunkManagerDummyImpl.java:
##########
@@ -40,6 +46,53 @@
  */
 public class ChunkManagerDummyImpl implements ChunkManager {
 
+  private static final int DEFAULT_MAP_SIZE = 1 * 1024 * 1024; // 1MB
+
+  private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+  private volatile MappedByteBuffer mapped;
+  private volatile int mappedSize;
+  private volatile Path backingFile;
+
+  private void ensureMapped(int minSize)
+      throws StorageContainerException {
+    if (mapped != null && mappedSize >= minSize) {
+      return;
+    }
+
+    lock.writeLock().lock();
+    try {
+      if (mapped != null && mappedSize >= minSize) {
+        return;
+      }
+
+      int newSize = Math.max(DEFAULT_MAP_SIZE, minSize);
+      if (backingFile == null) {
+        backingFile = Files.createTempFile("ozone-dummy-chunk-", ".bin");
+        backingFile.toFile().deleteOnExit();
+      }
+
+      try (FileChannel ch = FileChannel.open(backingFile,
+          StandardOpenOption.READ, StandardOpenOption.WRITE)) {
+        long currentSize = ch.size();
+        if (currentSize < newSize) {
+          ch.position(newSize - 1L);

Review Comment:
   > ... A later attempt to write bytes at such a position will cause the file 
to be grown to accommodate the new bytes; the values of any bytes between the 
previous end-of-file and the newly-written bytes are unspecified.
   
   From the [FileChannel 
javadoc](https://docs.oracle.com/javase/8/docs/api/java/nio/channels/FileChannel.html#position-long-)
 above, we should write zeros for the zero-filled buffer..



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