You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "snleee (via GitHub)" <gi...@apache.org> on 2023/06/09 02:06:31 UTC

[GitHub] [pinot] snleee commented on a diff in pull request #10874: Making segmentMapper do the init and cleanup of RecordReader

snleee commented on code in PR #10874:
URL: https://github.com/apache/pinot/pull/10874#discussion_r1223747098


##########
pinot-core/src/main/java/org/apache/pinot/core/segment/processing/framework/SegmentProcessorFramework.java:
##########
@@ -72,11 +74,30 @@ public SegmentProcessorFramework(List<RecordReader> recordReaders, SegmentProces
       File workingDir)
       throws IOException {
     Preconditions.checkState(!recordReaders.isEmpty(), "No record reader is provided");
-
     LOGGER.info("Initializing SegmentProcessorFramework with {} record readers, config: {}, working dir: {}",
         recordReaders.size(), segmentProcessorConfig, workingDir.getAbsolutePath());
 
     _recordReaders = recordReaders;
+    _recordReaderFileConfigs = null;
+    _segmentProcessorConfig = segmentProcessorConfig;
+
+    _mapperOutputDir = new File(workingDir, "mapper_output");
+    FileUtils.forceMkdir(_mapperOutputDir);
+    _reducerOutputDir = new File(workingDir, "reducer_output");
+    FileUtils.forceMkdir(_reducerOutputDir);
+    _segmentsOutputDir = new File(workingDir, "segments_output");
+    FileUtils.forceMkdir(_segmentsOutputDir);
+  }
+
+  public SegmentProcessorFramework(SegmentProcessorConfig segmentProcessorConfig, File workingDir,

Review Comment:
   Lets put `recordReaderFileConfigs` first to keep the ordering convention with the existing constructor.



##########
pinot-spi/src/main/java/org/apache/pinot/spi/data/readers/RecordReaderFileConfig.java:
##########
@@ -0,0 +1,57 @@
+/**
+ * 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.pinot.spi.data.readers;
+
+import java.io.File;
+import java.util.Set;
+import javax.annotation.Nullable;
+
+
+/**
+ * Wraps RecordReader info to instantiate a reader. Users can either pass in the
+ * RecordReader instance directly or the info required to initialize the RecordReader, so that the
+ * RecordReader can be initialized just when its about to be used, which avoids early/eager
+ * initialization/memory allocation.
+ */
+public class RecordReaderFileConfig {

Review Comment:
   `RecordReaderFactoryConfig` may be slightly better? :P 



##########
pinot-core/src/main/java/org/apache/pinot/core/segment/processing/mapper/SegmentMapper.java:
##########
@@ -122,32 +144,23 @@ public Map<String, GenericRowFileManager> map()
   private Map<String, GenericRowFileManager> doMap()
       throws Exception {
     Consumer<Object> observer = _processorConfig.getProgressObserver();
-    int totalCount = _recordReaders.size();
+    int totalCount = _recordReaderFileConfigs.size();
     int count = 1;
     GenericRow reuse = new GenericRow();
-    for (RecordReader recordReader : _recordReaders) {
-      observer.accept(String.format("Doing map phase on data from RecordReader (%d out of %d)", count++, totalCount));
-      while (recordReader.hasNext()) {
-        reuse = recordReader.next(reuse);
-
-        // TODO: Add ComplexTypeTransformer here. Currently it is not idempotent so cannot add it
-
-        if (reuse.getValue(GenericRow.MULTIPLE_RECORDS_KEY) != null) {
-          //noinspection unchecked
-          for (GenericRow row : (Collection<GenericRow>) reuse.getValue(GenericRow.MULTIPLE_RECORDS_KEY)) {
-            GenericRow transformedRow = _recordTransformer.transform(row);
-            if (transformedRow != null && IngestionUtils.shouldIngestRow(transformedRow)) {
-              writeRecord(transformedRow);
-            }
-          }
-        } else {
-          GenericRow transformedRow = _recordTransformer.transform(reuse);
-          if (transformedRow != null && IngestionUtils.shouldIngestRow(transformedRow)) {
-            writeRecord(transformedRow);
-          }
-        }
-
-        reuse.clear();
+    boolean inited = false;
+    for (RecordReaderFileConfig recordReaderFileConfig : _recordReaderFileConfigs) {

Review Comment:
   I think that it may be simpler to understand if we split the logic for `recordReaderFileConfig & recordReaders`?
   
   I initially had the questions like:
   
   1. why can't we directly do
   ```
   for readerFileConfig
      initialize record reader
      read...
      close
   ```
   
   2. I also had a question on why recordReaderFileConfig contains `RecordReader`.
   
   Both are needed because we are trying to combine the logic here. 
   
   
   How do you think?



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org