ChenSammi commented on a change in pull request #2538:
URL: https://github.com/apache/ozone/pull/2538#discussion_r692827259
##########
File path:
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java
##########
@@ -183,17 +180,39 @@ private static long writeDataToChannel(FileChannel
channel, ChunkBuffer data,
public static void readData(File file, ByteBuffer[] buffers,
long offset, long len, HddsVolume volume)
throws StorageContainerException {
+ readData(file, null, buffers, offset, len, volume);
+ }
+
+ public static void readData(File file, FileChannel channel,
+ ByteBuffer[] buffers, long offset, long len, HddsVolume volume)
+ throws StorageContainerException {
final Path path = file.toPath();
final long startTime = Time.monotonicNow();
final long bytesRead;
+ final long endOffsetToRead = offset + len;
try {
+ if (file.length() > 0) {
+ Preconditions.checkArgument(file.length() >= endOffsetToRead,
+ "file length should atleast match the last offset to read");
+ }
bytesRead = processFileExclusively(path, () -> {
- try (FileChannel channel = open(path, READ_OPTIONS, NO_ATTRIBUTES);
- FileLock ignored = channel.lock(offset, len, true)) {
+ // if the file handle is already cached, just use that for reads.
+ if (channel != null) {
+ try (FileLock lock = channel.lock(offset, len, true)) {
+ channel.position(offset);
+ return channel.position(offset).read(buffers);
Review comment:
channel.position is called twice.
--
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]