kaijchen commented on a change in pull request #2628:
URL: https://github.com/apache/ozone/pull/2628#discussion_r705865472
##########
File path:
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java
##########
@@ -256,12 +257,21 @@ public static boolean validateChunkForOverwrite(File
chunkFile,
public static boolean isOverWriteRequested(File chunkFile, ChunkInfo
chunkInfo) {
- if (!chunkFile.exists()) {
+ long offset = chunkInfo.getOffset();
+ try {
+ FileInputStream inputStream = new FileInputStream(chunkFile);
+ inputStream.getChannel().position(offset);
Review comment:
If my understanding is correct, you are trying to solve sparse file
"overwrite" problem.
But this code still prints true.
```java
public static void main(String[] args) {
File f = new File("/tmp/hello");
try (FileOutputStream out = new FileOutputStream(f);
FileInputStream in = new FileInputStream(f)) {
out.getChannel().position(8 << 10); // 8KB
out.write("hello, world".getBytes(StandardCharsets.UTF_8));
System.out.println(f.length()); // prints 8204 (= 8192 + 12)
in.getChannel().position(4 << 10); // 4KB
if (in.read() == -1) { // read() = 0
System.out.println(false);
} else {
System.out.println(true); // prints true
}
} catch (IOException e) {
System.out.println(e);
}
}
```
--
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]