Chu Cheng Li created HDDS-16844:
-----------------------------------
Summary: Remove duplicate overwrite checks in ChunkUtils
Key: HDDS-16844
URL: https://issues.apache.org/jira/browse/HDDS-16844
Project: Apache Ozone
Issue Type: Improvement
Reporter: Chu Cheng Li
Assignee: Chu Cheng Li
*Background*
HDDS-16327 added {{validateChunkForOverwrite(long fileLen, ChunkInfo)}} and
{{isOverWriteRequested(long fileLen, ChunkInfo)}} to {{{}ChunkUtils{}}}. The
caller gives the file length, so the method does not read it again.
*Problem*
The old {{File}} overloads of these two methods are still in
{{{}ChunkUtils{}}}. Their bodies are copies of the {{long}} versions. Both
copies have the same "Duplicate write chunk request" warning and the same TODO.
Only {{FilePerChunkStrategy}} calls the {{File}} version. No code outside
{{ChunkUtils}} calls {{{}isOverWriteRequested{}}}.
*Changes*
* Keep only {{{}validateChunkForOverwrite(long fileLen, ChunkInfo){}}}. Put
the check {{info.getOffset() < fileLen}} directly in this method.
* Remove the two {{isOverWriteRequested}} overloads.
* {{FilePerChunkStrategy.writeChunk}} calls
{{{}validateChunkForOverwrite(chunkFile.length(), info){}}}.
{{File.length()}} returns 0 when the file does not exist. Thus, the
{{exists()}} check in the old {{File}} version has no effect when the offset is
0 or more. {{File.length()}} also returns 0 on an I/O error, and the old code
had the same behavior. The change removes one file system call for each chunk
write in the FilePerChunk layout.
One edge case changes. For a negative offset on a chunk file that does not
exist, the result is now true. Before, it was false. The offset is a {{uint64}}
in the protocol, and {{FilePerBlockStrategy}} already gives true in this case.
*Tests*
{{TestChunkUtils.validateChunkForOverwrite}} tests only the {{long}} version.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]