LakshSingla commented on code in PR #13368:
URL: https://github.com/apache/druid/pull/13368#discussion_r1033448685
##########
extensions-core/s3-extensions/src/test/java/org/apache/druid/storage/s3/output/S3StorageConnectorTest.java:
##########
@@ -117,6 +118,56 @@ public void pathRead() throws IOException
EasyMock.reset(S3_CLIENT);
}
+ @Test
+ public void testReadRange() throws IOException
+ {
+ String data = "test";
+
+ // normal reads
Review Comment:
nit: Can you please define "normal" here.
##########
processing/src/main/java/org/apache/druid/frame/channel/DurableStoragePartitionedReadableFrameChannel.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.frame.channel;
+
+import org.apache.druid.frame.file.FrameFileFooter;
+import org.apache.druid.frame.file.FrameFileWriter;
+import org.apache.druid.storage.StorageConnector;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.concurrent.ExecutorService;
+import java.util.function.Supplier;
+
+public class DurableStoragePartitionedReadableFrameChannel implements
PartitionedReadableFrameChannel
+{
+ private final StorageConnector storageConnector;
+ private final Supplier<FrameFileFooter> frameFileFooterSupplier;
+ private final String frameFileFullPath;
+ private final ExecutorService remoteInputStreamPool;
+ private final File footerFile;
+
+ public DurableStoragePartitionedReadableFrameChannel(
+ StorageConnector storageConnector,
+ Supplier<FrameFileFooter> frameFileFooterSupplier,
+ String frameFileFullPath,
+ ExecutorService remoteInputStreamPool,
+ File footerFile
+ )
+ {
+ this.storageConnector = storageConnector;
+ this.frameFileFooterSupplier = frameFileFooterSupplier;
+ this.frameFileFullPath = frameFileFullPath;
+ this.remoteInputStreamPool = remoteInputStreamPool;
+ this.footerFile = footerFile;
Review Comment:
nit: Do we need this? I didn't find relevance of this param in the file
apart from in the close method.
##########
processing/src/main/java/org/apache/druid/frame/channel/DurableStoragePartitionedReadableFrameChannel.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.frame.channel;
+
+import org.apache.druid.frame.file.FrameFileFooter;
+import org.apache.druid.frame.file.FrameFileWriter;
+import org.apache.druid.storage.StorageConnector;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.concurrent.ExecutorService;
+import java.util.function.Supplier;
+
+public class DurableStoragePartitionedReadableFrameChannel implements
PartitionedReadableFrameChannel
+{
+ private final StorageConnector storageConnector;
+ private final Supplier<FrameFileFooter> frameFileFooterSupplier;
+ private final String frameFileFullPath;
+ private final ExecutorService remoteInputStreamPool;
+ private final File footerFile;
+
+ public DurableStoragePartitionedReadableFrameChannel(
+ StorageConnector storageConnector,
+ Supplier<FrameFileFooter> frameFileFooterSupplier,
+ String frameFileFullPath,
+ ExecutorService remoteInputStreamPool,
+ File footerFile
+ )
+ {
+ this.storageConnector = storageConnector;
+ this.frameFileFooterSupplier = frameFileFooterSupplier;
+ this.frameFileFullPath = frameFileFullPath;
+ this.remoteInputStreamPool = remoteInputStreamPool;
+ this.footerFile = footerFile;
+ }
+
+ @Override
+ public ReadableFrameChannel getReadableFrameChannel(int partitionNumber)
+ {
+ FrameFileFooter frameFileFooter = frameFileFooterSupplier.get();
+ // find the range to read for partition
+ int startFrame = frameFileFooter.getPartitionStartFrame(partitionNumber);
+ int endFrame = frameFileFooter.getPartitionStartFrame(partitionNumber + 1);
+ long startByte = startFrame == 0 ? FrameFileWriter.MAGIC.length :
frameFileFooter.getFrameEndPosition(startFrame - 1);
+ long endByte = endFrame == 0 ? FrameFileWriter.MAGIC.length :
frameFileFooter.getFrameEndPosition(endFrame - 1);
+
+ long size = endByte - startByte;
+ if (size <= 0) {
+ return ReadableNilFrameChannel.INSTANCE;
+ }
+ try {
+ return ReadableInputStreamFrameChannel.open(
+ storageConnector.readRange(frameFileFullPath, startByte, endByte -
startByte),
+ frameFileFullPath,
+ remoteInputStreamPool,
+ true
+ );
+ }
+ catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ @Override
+ public void close()
+ {
+ try {
+ storageConnector.deleteFile(frameFileFullPath);
Review Comment:
If the `footerFile` and `frameFileFullPath` are not created in the channel
then should they be deleted on close or should the responsibility lie with the
object's creator?
##########
processing/src/main/java/org/apache/druid/frame/processor/SuperSorter.java:
##########
@@ -606,12 +587,14 @@ private void runMerger(
final int level,
final long rank,
final List<ReadableFrameChannel> in,
- @Nullable final ClusterByPartitions partitions
+ @Nullable final ClusterByPartitions partitions,
+ List<PartitionedReadableFrameChannel> partitionedReadableChannelsToClose
Review Comment:
nit: Can be made final for consistency
##########
processing/src/main/java/org/apache/druid/frame/processor/SuperSorter.java:
##########
@@ -811,15 +797,16 @@ private void cleanUp()
outputsReadyByLevel.clear();
inputBuffer.clear();
-
- for (FrameFile frameFile : penultimateFrameFileCache.values()) {
- CloseableUtils.closeAndSuppressExceptions(
- frameFile,
- e -> log.warn(e, "Could not close intermediate file [%s]",
frameFile.file())
- );
+ for (Map.Entry<String, PartitionedOutputChannel> cleanupEntry :
+ levelAndRankToReadableChannelMap.entrySet()) {
+ try {
+ cleanupEntry.getValue().getReadableChannelSupplier().get().close();
+ }
+ catch (IOException e) {
Review Comment:
On [Line
642](https://github.com/apache/druid/pull/13368/files#diff-6ab806ec1a5129c4c908965096a09b749ed597101e5f74b84fb82675bda8f8b2R642)
we are warning but here we are throwing if close() throws an error. Why is
that so?
##########
processing/src/main/java/org/apache/druid/frame/processor/SuperSorter.java:
##########
@@ -517,19 +504,26 @@ private boolean runNextMiddleMerger()
(pos == maxChannelsPerProcessor - 1 || (totalInputs !=
UNKNOWN_TOTAL && w == totalInputs - 1))) {
// We found a set to merge. Let's collect the input channels and
launch the merger.
final List<ReadableFrameChannel> in = new ArrayList<>();
+ final List<PartitionedReadableFrameChannel>
partitionedReadableFrameChannels = new ArrayList<>();
for (long i = currentSetStart; i < currentSetStart +
maxChannelsPerProcessor; i++) {
if (inputsReady.remove(i)) {
- try {
- final FrameFile handle =
FrameFile.open(mergerOutputFile(inLevel, i), FrameFile.Flag.DELETE_ON_CLOSE);
- in.add(new ReadableFileFrameChannel(handle));
- }
- catch (IOException e) {
- throw new RuntimeException(e);
- }
+ String levelAndRankKey = StringUtils.format("merged.%d.%d",
inLevel, i);
Review Comment:
`StringUtils.format("merged.%d.%d", inLevel, i);` is used somewhere else as
well when updating the map. I think it would be better to extract it out in a
function analogous to the original `mergerOutputFile()`
--
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]