This is an automated email from the ASF dual-hosted git repository.
peterxcli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 6c46be9dc67 HDDS-16844. Remove duplicate overwrite checks in
ChunkUtils (#11465)
6c46be9dc67 is described below
commit 6c46be9dc67ee81179347b0ea0a811d1d472cda9
Author: Peter Lee <[email protected]>
AuthorDate: Sun Oct 11 17:41:33 2026 +0800
HDDS-16844. Remove duplicate overwrite checks in ChunkUtils (#11465)
---
.../container/keyvalue/helpers/ChunkUtils.java | 62 +---------------------
.../keyvalue/impl/FilePerChunkStrategy.java | 3 +-
.../container/keyvalue/helpers/TestChunkUtils.java | 14 +----
3 files changed, 4 insertions(+), 75 deletions(-)
diff --git
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java
index fa55cbe793b..dcee2507d66 100644
---
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java
+++
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java
@@ -332,44 +332,18 @@ private static List<ByteBuf> readDataNettyChunkedNioFile(
return buffers;
}
- /**
- * Validates chunk data and returns a file object to Chunk File that we are
- * expected to write data to.
- *
- * @param chunkFile - chunkFile to write data into.
- * @param info - chunk info.
- * @return true if the chunkFile exists and chunkOffset < chunkFile
length,
- * false otherwise.
- */
- public static boolean validateChunkForOverwrite(File chunkFile,
- ChunkInfo info) {
-
- if (isOverWriteRequested(chunkFile, info)) {
- if (!isOverWritePermitted(info)) {
- LOG.warn("Duplicate write chunk request. Chunk overwrite " +
- "without explicit request. {}", info);
- }
- return true;
- }
-
- // TODO: when overwriting a chunk, we should ensure that the new chunk
- // size is same as the old chunk size
-
- return false;
- }
-
/**
* Validates chunk data and returns a boolean value that indicates if the
* chunk data should be overwritten.
*
- * @param fileLen - current length of the block file.
+ * @param fileLen - current length of the chunk or block file.
* @param info - chunk info.
* @return true if the chunkOffset is less than the chunkFile length,
* false otherwise.
*/
public static boolean validateChunkForOverwrite(long fileLen, ChunkInfo
info) {
- if (isOverWriteRequested(fileLen, info)) {
+ if (info.getOffset() < fileLen) {
if (!isOverWritePermitted(info)) {
LOG.warn("Duplicate write chunk request. Chunk overwrite " +
"without explicit request. {}", info);
@@ -383,38 +357,6 @@ public static boolean validateChunkForOverwrite(long
fileLen, ChunkInfo info) {
return false;
}
- /**
- * Checks if we are getting a request to overwrite an existing range of
- * chunk.
- *
- * @param chunkFile - File
- * @param chunkInfo - Buffer to write
- * @return bool
- */
- public static boolean isOverWriteRequested(File chunkFile, ChunkInfo
- chunkInfo) {
-
- if (!chunkFile.exists()) {
- return false;
- }
-
- long offset = chunkInfo.getOffset();
- return offset < chunkFile.length();
- }
-
- /**
- * Checks if a request to overwrite an existing range of a chunk has been
- * received.
- *
- * @param fileLen - current length of the block file
- * @param chunkInfo - Chunk information containing the offset
- * @return true if the offset is less than the file length, indicating
- * a request to overwrite an existing range; false otherwise
- */
- public static boolean isOverWriteRequested(long fileLen, ChunkInfo
chunkInfo) {
- return chunkInfo.getOffset() < fileLen;
- }
-
/**
* Overwrite is permitted if an only if the user explicitly asks for it. We
* permit this iff the key/value pair contains a flag called
diff --git
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/impl/FilePerChunkStrategy.java
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/impl/FilePerChunkStrategy.java
index a36d8471a8f..b210f9d730e 100644
---
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/impl/FilePerChunkStrategy.java
+++
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/impl/FilePerChunkStrategy.java
@@ -118,8 +118,7 @@ public void writeChunk(Container container, BlockID
blockID, ChunkInfo info,
File chunkFile = getChunkFile(kvContainer, blockID, info);
- boolean isOverwrite = ChunkUtils.validateChunkForOverwrite(
- chunkFile, info);
+ boolean isOverwrite =
ChunkUtils.validateChunkForOverwrite(chunkFile.length(), info);
File tmpChunkFile = getTmpChunkFile(chunkFile, dispatcherContext);
if (LOG.isDebugEnabled()) {
LOG.debug(
diff --git
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/helpers/TestChunkUtils.java
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/helpers/TestChunkUtils.java
index 4cf31c1ea79..b94305b2882 100644
---
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/helpers/TestChunkUtils.java
+++
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/helpers/TestChunkUtils.java
@@ -219,19 +219,7 @@ void serialRead() throws IOException {
}
@Test
- void validateChunkForOverwrite() throws IOException {
-
- Path tempFile = tempDir.toPath().resolve("overwrite");
- FileUtils.write(tempFile.toFile(), "test", UTF_8);
-
- assertTrue(
- ChunkUtils.validateChunkForOverwrite(tempFile.toFile(),
- new ChunkInfo("chunk", 3, 5)));
-
- assertFalse(
- ChunkUtils.validateChunkForOverwrite(tempFile.toFile(),
- new ChunkInfo("chunk", 5, 5)));
-
+ void validateChunkForOverwrite() {
assertTrue(ChunkUtils.validateChunkForOverwrite(4L, new ChunkInfo("chunk",
3, 5)));
assertFalse(ChunkUtils.validateChunkForOverwrite(4L, new
ChunkInfo("chunk", 5, 5)));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]