Jackie-Jiang commented on code in PR #8589:
URL: https://github.com/apache/pinot/pull/8589#discussion_r879914734


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/PurgeMinionClusterIntegrationTest.java:
##########
@@ -0,0 +1,380 @@
+/**
+ * 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.integration.tests;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+import org.apache.helix.task.TaskState;
+import org.apache.pinot.common.lineage.SegmentLineageAccessHelper;
+import org.apache.pinot.common.metadata.segment.SegmentZKMetadata;
+import org.apache.pinot.common.minion.MinionTaskMetadataUtils;
+import org.apache.pinot.common.utils.TarGzCompressionUtils;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import 
org.apache.pinot.controller.helix.core.minion.PinotHelixTaskResourceManager;
+import org.apache.pinot.controller.helix.core.minion.PinotTaskManager;
+import org.apache.pinot.core.common.MinionConstants;
+import 
org.apache.pinot.segment.local.segment.creator.impl.SegmentIndexCreationDriverImpl;
+import org.apache.pinot.segment.spi.creator.SegmentGeneratorConfig;
+import org.apache.pinot.segment.spi.creator.SegmentIndexCreationDriver;
+import org.apache.pinot.spi.config.table.SegmentPartitionConfig;
+import org.apache.pinot.spi.config.table.SegmentZKPropsConfig;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableTaskConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.apache.pinot.util.TestUtils;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.*;
+
+
+/**
+ * Integration test for minion task of type "PurgeTask"
+ */
+public class PurgeMinionClusterIntegrationTest extends 
BaseClusterIntegrationTest {
+  private static final String PURGE_FIRST_RUN_TABLE = "myTable1";
+  private static final String PURGE_DELTA_PASSED_TABLE = "myTable2";
+  private static final String PURGE_DELTA_NOT_PASSED_TABLE = "myTable3";
+
+  protected PinotHelixTaskResourceManager _helixTaskResourceManager;
+  protected PinotTaskManager _taskManager;
+  protected PinotHelixResourceManager _pinotHelixResourceManager;
+
+  protected final File _segmentDir1 = new File(_tempDir, "segmentDir1");
+  protected final File _segmentDir2 = new File(_tempDir, "segmentDir2");
+  protected final File _segmentDir3 = new File(_tempDir, "segmentDir3");
+
+  protected final File _tarDir1 = new File(_tempDir, "tarDir1");
+  protected final File _tarDir2 = new File(_tempDir, "tarDir2");
+  protected final File _tarDir3 = new File(_tempDir, "tarDir3");
+
+  @BeforeClass
+  public void setUp()
+      throws Exception {
+    TestUtils.ensureDirectoriesExistAndEmpty(_tempDir, _segmentDir1, _tarDir1,
+        _segmentDir2, _tarDir2, _segmentDir3, _tarDir3);
+
+    // Start the Pinot cluster
+    startZk();
+    startController();
+    startBrokers(1);
+    startServers(1);
+
+    // Create and upload the schema and table config
+    Schema schema = createSchema();
+    addSchema(schema);
+    TableConfig purgeTableConfig =
+        createOfflineTableConfig(PURGE_FIRST_RUN_TABLE, getPurgeTaskConfig());
+    TableConfig purgeDeltaPassedTableConfig =
+        createOfflineTableConfig(PURGE_DELTA_PASSED_TABLE, 
getPurgeTaskConfig());
+    TableConfig purgeDeltaNotPassedTableConfig =
+        createOfflineTableConfig(PURGE_DELTA_NOT_PASSED_TABLE, 
getPurgeTaskConfig());
+    addTableConfig(purgeTableConfig);
+    addTableConfig(purgeDeltaPassedTableConfig);
+    addTableConfig(purgeDeltaNotPassedTableConfig);
+
+
+
+
+    // Unpack the Avro files
+    List<File> avroFiles = unpackAvroData(_tempDir);
+
+    // Create and upload segments
+    ClusterIntegrationTestUtils
+        .buildSegmentsFromAvro(avroFiles, purgeTableConfig, schema, 0, 
_segmentDir1, _tarDir1);
+
+    buildSegmentsFromAvroWithPurgeTime(avroFiles, purgeDeltaPassedTableConfig, 
schema, 0,
+        _segmentDir2, _tarDir2, String.valueOf(System.currentTimeMillis() - 
863660000));
+    buildSegmentsFromAvroWithPurgeTime(avroFiles, 
purgeDeltaNotPassedTableConfig, schema, 0,
+        _segmentDir3, _tarDir3, String.valueOf(System.currentTimeMillis() - 
400000));
+
+    uploadSegments(PURGE_FIRST_RUN_TABLE, _tarDir1);
+    uploadSegments(PURGE_DELTA_PASSED_TABLE, _tarDir2);
+    uploadSegments(PURGE_DELTA_NOT_PASSED_TABLE, _tarDir3);
+
+    // Set up the H2 connection
+    setUpH2Connection(avroFiles);
+
+    // Initialize the query generator
+    setUpQueryGenerator(avroFiles);

Review Comment:
   These 2 steps are redundant



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/PurgeMinionClusterIntegrationTest.java:
##########
@@ -0,0 +1,380 @@
+/**
+ * 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.integration.tests;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+import org.apache.helix.task.TaskState;
+import org.apache.pinot.common.lineage.SegmentLineageAccessHelper;
+import org.apache.pinot.common.metadata.segment.SegmentZKMetadata;
+import org.apache.pinot.common.minion.MinionTaskMetadataUtils;
+import org.apache.pinot.common.utils.TarGzCompressionUtils;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import 
org.apache.pinot.controller.helix.core.minion.PinotHelixTaskResourceManager;
+import org.apache.pinot.controller.helix.core.minion.PinotTaskManager;
+import org.apache.pinot.core.common.MinionConstants;
+import 
org.apache.pinot.segment.local.segment.creator.impl.SegmentIndexCreationDriverImpl;
+import org.apache.pinot.segment.spi.creator.SegmentGeneratorConfig;
+import org.apache.pinot.segment.spi.creator.SegmentIndexCreationDriver;
+import org.apache.pinot.spi.config.table.SegmentPartitionConfig;
+import org.apache.pinot.spi.config.table.SegmentZKPropsConfig;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableTaskConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.apache.pinot.util.TestUtils;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.*;
+
+
+/**
+ * Integration test for minion task of type "PurgeTask"
+ */
+public class PurgeMinionClusterIntegrationTest extends 
BaseClusterIntegrationTest {
+  private static final String PURGE_FIRST_RUN_TABLE = "myTable1";
+  private static final String PURGE_DELTA_PASSED_TABLE = "myTable2";
+  private static final String PURGE_DELTA_NOT_PASSED_TABLE = "myTable3";
+
+  protected PinotHelixTaskResourceManager _helixTaskResourceManager;
+  protected PinotTaskManager _taskManager;
+  protected PinotHelixResourceManager _pinotHelixResourceManager;
+
+  protected final File _segmentDir1 = new File(_tempDir, "segmentDir1");
+  protected final File _segmentDir2 = new File(_tempDir, "segmentDir2");
+  protected final File _segmentDir3 = new File(_tempDir, "segmentDir3");
+
+  protected final File _tarDir1 = new File(_tempDir, "tarDir1");
+  protected final File _tarDir2 = new File(_tempDir, "tarDir2");
+  protected final File _tarDir3 = new File(_tempDir, "tarDir3");
+
+  @BeforeClass
+  public void setUp()
+      throws Exception {
+    TestUtils.ensureDirectoriesExistAndEmpty(_tempDir, _segmentDir1, _tarDir1,
+        _segmentDir2, _tarDir2, _segmentDir3, _tarDir3);
+
+    // Start the Pinot cluster
+    startZk();
+    startController();
+    startBrokers(1);
+    startServers(1);
+
+    // Create and upload the schema and table config
+    Schema schema = createSchema();
+    addSchema(schema);
+    TableConfig purgeTableConfig =
+        createOfflineTableConfig(PURGE_FIRST_RUN_TABLE, getPurgeTaskConfig());
+    TableConfig purgeDeltaPassedTableConfig =
+        createOfflineTableConfig(PURGE_DELTA_PASSED_TABLE, 
getPurgeTaskConfig());
+    TableConfig purgeDeltaNotPassedTableConfig =
+        createOfflineTableConfig(PURGE_DELTA_NOT_PASSED_TABLE, 
getPurgeTaskConfig());
+    addTableConfig(purgeTableConfig);
+    addTableConfig(purgeDeltaPassedTableConfig);
+    addTableConfig(purgeDeltaNotPassedTableConfig);
+

Review Comment:
   (minor) Remove the consecutive empty lines. Same for other unnecessary 
whitespaces in this class



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/PurgeMinionClusterIntegrationTest.java:
##########
@@ -0,0 +1,380 @@
+/**
+ * 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.integration.tests;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+import org.apache.helix.task.TaskState;
+import org.apache.pinot.common.lineage.SegmentLineageAccessHelper;
+import org.apache.pinot.common.metadata.segment.SegmentZKMetadata;
+import org.apache.pinot.common.minion.MinionTaskMetadataUtils;
+import org.apache.pinot.common.utils.TarGzCompressionUtils;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import 
org.apache.pinot.controller.helix.core.minion.PinotHelixTaskResourceManager;
+import org.apache.pinot.controller.helix.core.minion.PinotTaskManager;
+import org.apache.pinot.core.common.MinionConstants;
+import 
org.apache.pinot.segment.local.segment.creator.impl.SegmentIndexCreationDriverImpl;
+import org.apache.pinot.segment.spi.creator.SegmentGeneratorConfig;
+import org.apache.pinot.segment.spi.creator.SegmentIndexCreationDriver;
+import org.apache.pinot.spi.config.table.SegmentPartitionConfig;
+import org.apache.pinot.spi.config.table.SegmentZKPropsConfig;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableTaskConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.apache.pinot.util.TestUtils;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.*;
+
+
+/**
+ * Integration test for minion task of type "PurgeTask"
+ */
+public class PurgeMinionClusterIntegrationTest extends 
BaseClusterIntegrationTest {
+  private static final String PURGE_FIRST_RUN_TABLE = "myTable1";
+  private static final String PURGE_DELTA_PASSED_TABLE = "myTable2";
+  private static final String PURGE_DELTA_NOT_PASSED_TABLE = "myTable3";
+
+  protected PinotHelixTaskResourceManager _helixTaskResourceManager;
+  protected PinotTaskManager _taskManager;
+  protected PinotHelixResourceManager _pinotHelixResourceManager;
+
+  protected final File _segmentDir1 = new File(_tempDir, "segmentDir1");
+  protected final File _segmentDir2 = new File(_tempDir, "segmentDir2");
+  protected final File _segmentDir3 = new File(_tempDir, "segmentDir3");
+
+  protected final File _tarDir1 = new File(_tempDir, "tarDir1");
+  protected final File _tarDir2 = new File(_tempDir, "tarDir2");
+  protected final File _tarDir3 = new File(_tempDir, "tarDir3");
+
+  @BeforeClass
+  public void setUp()
+      throws Exception {
+    TestUtils.ensureDirectoriesExistAndEmpty(_tempDir, _segmentDir1, _tarDir1,
+        _segmentDir2, _tarDir2, _segmentDir3, _tarDir3);
+
+    // Start the Pinot cluster
+    startZk();
+    startController();
+    startBrokers(1);
+    startServers(1);
+
+    // Create and upload the schema and table config
+    Schema schema = createSchema();
+    addSchema(schema);
+    TableConfig purgeTableConfig =
+        createOfflineTableConfig(PURGE_FIRST_RUN_TABLE, getPurgeTaskConfig());

Review Comment:
   You may override `getTableName()` and use the `createOfflineTableConfig()` 
from the base class



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/PurgeMinionClusterIntegrationTest.java:
##########
@@ -0,0 +1,380 @@
+/**
+ * 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.integration.tests;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+import org.apache.helix.task.TaskState;
+import org.apache.pinot.common.lineage.SegmentLineageAccessHelper;
+import org.apache.pinot.common.metadata.segment.SegmentZKMetadata;
+import org.apache.pinot.common.minion.MinionTaskMetadataUtils;
+import org.apache.pinot.common.utils.TarGzCompressionUtils;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import 
org.apache.pinot.controller.helix.core.minion.PinotHelixTaskResourceManager;
+import org.apache.pinot.controller.helix.core.minion.PinotTaskManager;
+import org.apache.pinot.core.common.MinionConstants;
+import 
org.apache.pinot.segment.local.segment.creator.impl.SegmentIndexCreationDriverImpl;
+import org.apache.pinot.segment.spi.creator.SegmentGeneratorConfig;
+import org.apache.pinot.segment.spi.creator.SegmentIndexCreationDriver;
+import org.apache.pinot.spi.config.table.SegmentPartitionConfig;
+import org.apache.pinot.spi.config.table.SegmentZKPropsConfig;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableTaskConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.apache.pinot.util.TestUtils;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.*;
+
+
+/**
+ * Integration test for minion task of type "PurgeTask"
+ */
+public class PurgeMinionClusterIntegrationTest extends 
BaseClusterIntegrationTest {
+  private static final String PURGE_FIRST_RUN_TABLE = "myTable1";
+  private static final String PURGE_DELTA_PASSED_TABLE = "myTable2";
+  private static final String PURGE_DELTA_NOT_PASSED_TABLE = "myTable3";
+
+  protected PinotHelixTaskResourceManager _helixTaskResourceManager;
+  protected PinotTaskManager _taskManager;
+  protected PinotHelixResourceManager _pinotHelixResourceManager;
+
+  protected final File _segmentDir1 = new File(_tempDir, "segmentDir1");
+  protected final File _segmentDir2 = new File(_tempDir, "segmentDir2");
+  protected final File _segmentDir3 = new File(_tempDir, "segmentDir3");
+
+  protected final File _tarDir1 = new File(_tempDir, "tarDir1");
+  protected final File _tarDir2 = new File(_tempDir, "tarDir2");
+  protected final File _tarDir3 = new File(_tempDir, "tarDir3");
+
+  @BeforeClass
+  public void setUp()
+      throws Exception {
+    TestUtils.ensureDirectoriesExistAndEmpty(_tempDir, _segmentDir1, _tarDir1,
+        _segmentDir2, _tarDir2, _segmentDir3, _tarDir3);
+
+    // Start the Pinot cluster
+    startZk();
+    startController();
+    startBrokers(1);
+    startServers(1);
+
+    // Create and upload the schema and table config
+    Schema schema = createSchema();
+    addSchema(schema);
+    TableConfig purgeTableConfig =
+        createOfflineTableConfig(PURGE_FIRST_RUN_TABLE, getPurgeTaskConfig());
+    TableConfig purgeDeltaPassedTableConfig =
+        createOfflineTableConfig(PURGE_DELTA_PASSED_TABLE, 
getPurgeTaskConfig());
+    TableConfig purgeDeltaNotPassedTableConfig =
+        createOfflineTableConfig(PURGE_DELTA_NOT_PASSED_TABLE, 
getPurgeTaskConfig());
+    addTableConfig(purgeTableConfig);
+    addTableConfig(purgeDeltaPassedTableConfig);
+    addTableConfig(purgeDeltaNotPassedTableConfig);
+
+
+
+
+    // Unpack the Avro files
+    List<File> avroFiles = unpackAvroData(_tempDir);
+
+    // Create and upload segments
+    ClusterIntegrationTestUtils
+        .buildSegmentsFromAvro(avroFiles, purgeTableConfig, schema, 0, 
_segmentDir1, _tarDir1);
+
+    buildSegmentsFromAvroWithPurgeTime(avroFiles, purgeDeltaPassedTableConfig, 
schema, 0,
+        _segmentDir2, _tarDir2, String.valueOf(System.currentTimeMillis() - 
863660000));
+    buildSegmentsFromAvroWithPurgeTime(avroFiles, 
purgeDeltaNotPassedTableConfig, schema, 0,
+        _segmentDir3, _tarDir3, String.valueOf(System.currentTimeMillis() - 
400000));
+
+    uploadSegments(PURGE_FIRST_RUN_TABLE, _tarDir1);
+    uploadSegments(PURGE_DELTA_PASSED_TABLE, _tarDir2);
+    uploadSegments(PURGE_DELTA_NOT_PASSED_TABLE, _tarDir3);
+
+    // Set up the H2 connection
+    setUpH2Connection(avroFiles);
+
+    // Initialize the query generator
+    setUpQueryGenerator(avroFiles);
+
+    startMinion();

Review Comment:
   Let's also setup the `RecordPurgerFactory` and `RecordModifierFactory` to do 
an end-to-end test. You may refer to `PurgeTaskExecutorTest` on how to set them 
up



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/PurgeMinionClusterIntegrationTest.java:
##########
@@ -0,0 +1,380 @@
+/**
+ * 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.integration.tests;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+import org.apache.helix.task.TaskState;
+import org.apache.pinot.common.lineage.SegmentLineageAccessHelper;
+import org.apache.pinot.common.metadata.segment.SegmentZKMetadata;
+import org.apache.pinot.common.minion.MinionTaskMetadataUtils;
+import org.apache.pinot.common.utils.TarGzCompressionUtils;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import 
org.apache.pinot.controller.helix.core.minion.PinotHelixTaskResourceManager;
+import org.apache.pinot.controller.helix.core.minion.PinotTaskManager;
+import org.apache.pinot.core.common.MinionConstants;
+import 
org.apache.pinot.segment.local.segment.creator.impl.SegmentIndexCreationDriverImpl;
+import org.apache.pinot.segment.spi.creator.SegmentGeneratorConfig;
+import org.apache.pinot.segment.spi.creator.SegmentIndexCreationDriver;
+import org.apache.pinot.spi.config.table.SegmentPartitionConfig;
+import org.apache.pinot.spi.config.table.SegmentZKPropsConfig;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableTaskConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.apache.pinot.util.TestUtils;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.*;
+
+
+/**
+ * Integration test for minion task of type "PurgeTask"
+ */
+public class PurgeMinionClusterIntegrationTest extends 
BaseClusterIntegrationTest {
+  private static final String PURGE_FIRST_RUN_TABLE = "myTable1";
+  private static final String PURGE_DELTA_PASSED_TABLE = "myTable2";
+  private static final String PURGE_DELTA_NOT_PASSED_TABLE = "myTable3";
+
+  protected PinotHelixTaskResourceManager _helixTaskResourceManager;
+  protected PinotTaskManager _taskManager;
+  protected PinotHelixResourceManager _pinotHelixResourceManager;
+
+  protected final File _segmentDir1 = new File(_tempDir, "segmentDir1");
+  protected final File _segmentDir2 = new File(_tempDir, "segmentDir2");
+  protected final File _segmentDir3 = new File(_tempDir, "segmentDir3");
+
+  protected final File _tarDir1 = new File(_tempDir, "tarDir1");
+  protected final File _tarDir2 = new File(_tempDir, "tarDir2");
+  protected final File _tarDir3 = new File(_tempDir, "tarDir3");
+
+  @BeforeClass
+  public void setUp()
+      throws Exception {
+    TestUtils.ensureDirectoriesExistAndEmpty(_tempDir, _segmentDir1, _tarDir1,
+        _segmentDir2, _tarDir2, _segmentDir3, _tarDir3);
+
+    // Start the Pinot cluster
+    startZk();
+    startController();
+    startBrokers(1);
+    startServers(1);
+
+    // Create and upload the schema and table config
+    Schema schema = createSchema();
+    addSchema(schema);
+    TableConfig purgeTableConfig =
+        createOfflineTableConfig(PURGE_FIRST_RUN_TABLE, getPurgeTaskConfig());
+    TableConfig purgeDeltaPassedTableConfig =
+        createOfflineTableConfig(PURGE_DELTA_PASSED_TABLE, 
getPurgeTaskConfig());
+    TableConfig purgeDeltaNotPassedTableConfig =
+        createOfflineTableConfig(PURGE_DELTA_NOT_PASSED_TABLE, 
getPurgeTaskConfig());
+    addTableConfig(purgeTableConfig);
+    addTableConfig(purgeDeltaPassedTableConfig);
+    addTableConfig(purgeDeltaNotPassedTableConfig);
+
+
+
+
+    // Unpack the Avro files
+    List<File> avroFiles = unpackAvroData(_tempDir);
+
+    // Create and upload segments
+    ClusterIntegrationTestUtils
+        .buildSegmentsFromAvro(avroFiles, purgeTableConfig, schema, 0, 
_segmentDir1, _tarDir1);
+
+    buildSegmentsFromAvroWithPurgeTime(avroFiles, purgeDeltaPassedTableConfig, 
schema, 0,
+        _segmentDir2, _tarDir2, String.valueOf(System.currentTimeMillis() - 
863660000));
+    buildSegmentsFromAvroWithPurgeTime(avroFiles, 
purgeDeltaNotPassedTableConfig, schema, 0,
+        _segmentDir3, _tarDir3, String.valueOf(System.currentTimeMillis() - 
400000));
+
+    uploadSegments(PURGE_FIRST_RUN_TABLE, _tarDir1);
+    uploadSegments(PURGE_DELTA_PASSED_TABLE, _tarDir2);
+    uploadSegments(PURGE_DELTA_NOT_PASSED_TABLE, _tarDir3);
+
+    // Set up the H2 connection
+    setUpH2Connection(avroFiles);
+
+    // Initialize the query generator
+    setUpQueryGenerator(avroFiles);
+
+    startMinion();
+    _helixTaskResourceManager = 
_controllerStarter.getHelixTaskResourceManager();
+    _taskManager = _controllerStarter.getTaskManager();
+    _pinotHelixResourceManager = _controllerStarter.getHelixResourceManager();
+
+    //set up metadata on segment to check how code handle passed and not 
passed delay
+    String tablenameOfflineNotPassed = 
TableNameBuilder.OFFLINE.tableNameWithType(PURGE_DELTA_NOT_PASSED_TABLE);
+    String tablenameOfflinePassed = 
TableNameBuilder.OFFLINE.tableNameWithType(PURGE_DELTA_PASSED_TABLE);
+
+    //set up passed delay
+    List<SegmentZKMetadata> segmentsZKMetadataDeltaPassed = 
_pinotHelixResourceManager
+        .getSegmentsZKMetadata(tablenameOfflinePassed);
+
+    Map<String, String> customSegmentMetadataPassed = new HashMap<>();
+    customSegmentMetadataPassed.put(MinionConstants.PurgeTask.TASK_TYPE
+        + MinionConstants.TASK_TIME_SUFFIX, 
String.valueOf(System.currentTimeMillis() - 88400000));
+
+    for (SegmentZKMetadata segmentZKMetadata : segmentsZKMetadataDeltaPassed) {
+      segmentZKMetadata.setCustomMap(customSegmentMetadataPassed);
+      _pinotHelixResourceManager.updateZkMetadata(tablenameOfflinePassed, 
segmentZKMetadata);
+    }
+    //set up not passed delay
+    List<SegmentZKMetadata> segmentsZKMetadataDeltaNotPassed = 
_pinotHelixResourceManager
+        .getSegmentsZKMetadata(tablenameOfflineNotPassed);
+    Map<String, String> customSegmentMetadataNotPassed = new HashMap<>();
+    customSegmentMetadataNotPassed.put(MinionConstants.PurgeTask.TASK_TYPE
+        + MinionConstants.TASK_TIME_SUFFIX, 
String.valueOf(System.currentTimeMillis() - 4000));
+    for (SegmentZKMetadata segmentZKMetadata : 
segmentsZKMetadataDeltaNotPassed) {
+      segmentZKMetadata.setCustomMap(customSegmentMetadataNotPassed);
+      _pinotHelixResourceManager.updateZkMetadata(tablenameOfflineNotPassed, 
segmentZKMetadata);
+    }
+  }
+
+  private TableConfig createOfflineTableConfig(String tableName, 
TableTaskConfig taskConfig) {
+    return createOfflineTableConfig(tableName, taskConfig, null);
+  }
+
+  private TableConfig createOfflineTableConfig(String tableName, 
TableTaskConfig taskConfig,
+      @Nullable SegmentPartitionConfig partitionConfig) {
+    return new 
TableConfigBuilder(TableType.OFFLINE).setTableName(tableName).setSchemaName(getSchemaName())
+        
.setTimeColumnName(getTimeColumnName()).setSortedColumn(getSortedColumn())
+        
.setInvertedIndexColumns(getInvertedIndexColumns()).setNoDictionaryColumns(getNoDictionaryColumns())
+        
.setRangeIndexColumns(getRangeIndexColumns()).setBloomFilterColumns(getBloomFilterColumns())
+        
.setFieldConfigList(getFieldConfigs()).setNumReplicas(getNumReplicas()).setSegmentVersion(getSegmentVersion())
+        
.setLoadMode(getLoadMode()).setTaskConfig(taskConfig).setBrokerTenant(getBrokerTenant())
+        
.setServerTenant(getServerTenant()).setIngestionConfig(getIngestionConfig())
+        
.setNullHandlingEnabled(getNullHandlingEnabled()).setSegmentPartitionConfig(partitionConfig).build();
+  }
+
+  private TableTaskConfig getPurgeTaskConfig() {
+    Map<String, String> tableTaskConfigs = new HashMap<>();
+    tableTaskConfigs.put("deltaPurgeTimePeriod", "1d");
+    return new 
TableTaskConfig(Collections.singletonMap(MinionConstants.PurgeTask.TASK_TYPE, 
tableTaskConfigs));
+  }
+
+
+
+  private static void buildSegmentsFromAvroWithPurgeTime(List<File> avroFiles, 
TableConfig tableConfig,
+      Schema schema, int baseSegmentIndex, File segmentDir, File tarDir, 
String purgeTime)

Review Comment:
   `purgeTime` is not used when creating the segments. You may create the 
segments once, and upload them to 3 tables



-- 
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-unsubscr...@pinot.apache.org

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


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

Reply via email to