You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2021/06/14 07:26:55 UTC

[GitHub] [incubator-pinot] mayankshriv commented on a change in pull request #7046: Add utility to convert configs from IndexingConfig to the new IngestionConfig.

mayankshriv commented on a change in pull request #7046:
URL: https://github.com/apache/incubator-pinot/pull/7046#discussion_r649639860



##########
File path: pinot-common/src/main/java/org/apache/pinot/common/utils/config/TableConfigUtils.java
##########
@@ -212,4 +215,54 @@ public static ZNRecord toZNRecord(TableConfig tableConfig)
     znRecord.setSimpleFields(simpleFields);
     return znRecord;
   }
+
+  /**
+   * Helper method to convert from indexingConfig (that is deprecated) to ingestionConfig.
+   * Since we are moving from indexingConfig to ingestionConfig for ingestion related configs,
+   * this utility helps with that migration. It also handles corner cases where both these
+   * configs might exist, in which case ingestionConfig takes precedence, and only required
+   * fields absent there are carried over from indexingConfig.
+   *
+   * The conversion happens in-place, the specified tableConfig is mutated in-place.
+   *
+   * @param tableConfig Input table config.
+   */
+  public static void convertFromIndexToIngestionConfig(TableConfig tableConfig) {
+    IndexingConfig indexingConfig = tableConfig.getIndexingConfig();
+
+    // It is possible that indexing as well as ingestion configs exist, in which case we always honor ingestion config.
+    IngestionConfig ingestionConfig = tableConfig.getIngestionConfig();
+    BatchIngestionConfig batchIngestionConfig =
+        (ingestionConfig != null) ? ingestionConfig.getBatchIngestionConfig() : null;
+
+    SegmentsValidationAndRetentionConfig validationConfig = tableConfig.getValidationConfig();
+    if (batchIngestionConfig == null) {
+      batchIngestionConfig = new BatchIngestionConfig(null, validationConfig.getSegmentPushType(),
+          validationConfig.getSegmentPushFrequency());
+    } else {
+      // This should not happen typically, but since we are in repair mode, might as well cover this corner case.
+      if (batchIngestionConfig.getSegmentIngestionType() == null) {
+        batchIngestionConfig.setSegmentIngestionType(validationConfig.getSegmentPushType());
+      }
+
+      if (batchIngestionConfig.getSegmentIngestionFrequency() == null) {
+        batchIngestionConfig.setSegmentIngestionFrequency(validationConfig.getSegmentPushFrequency());
+      }
+    }
+
+    StreamIngestionConfig streamIngestionConfig =
+        (ingestionConfig != null) ? ingestionConfig.getStreamIngestionConfig() : null;
+    if (streamIngestionConfig == null) {
+      streamIngestionConfig = new StreamIngestionConfig(Collections.singletonList(indexingConfig.getStreamConfigs()));
+    }
+
+    if (ingestionConfig == null) {
+      ingestionConfig = new IngestionConfig(batchIngestionConfig, streamIngestionConfig, null, null, null);
+    } else {
+      ingestionConfig.setBatchIngestionConfig(batchIngestionConfig);
+      ingestionConfig.setStreamIngestionConfig(streamIngestionConfig);
+    }
+
+    tableConfig.setIngestionConfig(ingestionConfig);

Review comment:
       I haven't checked if there are any callers that rely on the deprecated configs. We can perform the cleanup separately.

##########
File path: pinot-common/src/main/java/org/apache/pinot/common/utils/config/TableConfigUtils.java
##########
@@ -212,4 +215,54 @@ public static ZNRecord toZNRecord(TableConfig tableConfig)
     znRecord.setSimpleFields(simpleFields);
     return znRecord;
   }
+
+  /**
+   * Helper method to convert from indexingConfig (that is deprecated) to ingestionConfig.
+   * Since we are moving from indexingConfig to ingestionConfig for ingestion related configs,
+   * this utility helps with that migration. It also handles corner cases where both these
+   * configs might exist, in which case ingestionConfig takes precedence, and only required
+   * fields absent there are carried over from indexingConfig.
+   *
+   * The conversion happens in-place, the specified tableConfig is mutated in-place.
+   *
+   * @param tableConfig Input table config.
+   */
+  public static void convertFromIndexToIngestionConfig(TableConfig tableConfig) {
+    IndexingConfig indexingConfig = tableConfig.getIndexingConfig();
+
+    // It is possible that indexing as well as ingestion configs exist, in which case we always honor ingestion config.
+    IngestionConfig ingestionConfig = tableConfig.getIngestionConfig();
+    BatchIngestionConfig batchIngestionConfig =
+        (ingestionConfig != null) ? ingestionConfig.getBatchIngestionConfig() : null;
+
+    SegmentsValidationAndRetentionConfig validationConfig = tableConfig.getValidationConfig();
+    if (batchIngestionConfig == null) {
+      batchIngestionConfig = new BatchIngestionConfig(null, validationConfig.getSegmentPushType(),
+          validationConfig.getSegmentPushFrequency());
+    } else {
+      // This should not happen typically, but since we are in repair mode, might as well cover this corner case.
+      if (batchIngestionConfig.getSegmentIngestionType() == null) {
+        batchIngestionConfig.setSegmentIngestionType(validationConfig.getSegmentPushType());
+      }
+
+      if (batchIngestionConfig.getSegmentIngestionFrequency() == null) {
+        batchIngestionConfig.setSegmentIngestionFrequency(validationConfig.getSegmentPushFrequency());
+      }
+    }
+
+    StreamIngestionConfig streamIngestionConfig =
+        (ingestionConfig != null) ? ingestionConfig.getStreamIngestionConfig() : null;
+    if (streamIngestionConfig == null) {
+      streamIngestionConfig = new StreamIngestionConfig(Collections.singletonList(indexingConfig.getStreamConfigs()));
+    }
+
+    if (ingestionConfig == null) {
+      ingestionConfig = new IngestionConfig(batchIngestionConfig, streamIngestionConfig, null, null, null);
+    } else {
+      ingestionConfig.setBatchIngestionConfig(batchIngestionConfig);
+      ingestionConfig.setStreamIngestionConfig(streamIngestionConfig);
+    }
+
+    tableConfig.setIngestionConfig(ingestionConfig);

Review comment:
       Added TODO: https://github.com/apache/incubator-pinot/pull/7050

##########
File path: pinot-common/src/test/java/org/apache/pinot/common/utils/config/TableConfigUtilsTest.java
##########
@@ -0,0 +1,150 @@
+/**
+ * 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.common.utils.config;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.config.table.ingestion.BatchIngestionConfig;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.apache.pinot.spi.stream.PartitionLevelConsumer;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConfigProperties;
+import org.apache.pinot.spi.stream.StreamConsumerFactory;
+import org.apache.pinot.spi.stream.StreamLevelConsumer;
+import org.apache.pinot.spi.stream.StreamMessageDecoder;
+import org.apache.pinot.spi.stream.StreamMetadataProvider;
+import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+/**
+ * Unit test for {@link TableConfigUtils} class.
+ */
+public class TableConfigUtilsTest {
+
+  private static final String TABLE_NAME = "testTable";
+
+  /**
+   * Test the {@link TableConfigUtils#convertFromLegacyTableConfig(TableConfig)} utility.
+   * <ul>
+   *   <li>Creates a Table Config setting deprecated fields in Indexing Config.</li>
+   *   <li>Asserts that the utility can convert these fields into Ingestion Config.</li>
+   * </ul>
+   */
+  @Test
+  public void testIndexToIngestionConfigConversion() {

Review comment:
       Done: https://github.com/apache/incubator-pinot/pull/7050




-- 
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.

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