KKcorps commented on code in PR #11568: URL: https://github.com/apache/pinot/pull/11568#discussion_r1335218289
########## pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/PartialUpsertTableRebalanceIntegrationTest.java: ########## @@ -0,0 +1,458 @@ +/** + * 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 com.fasterxml.jackson.core.type.TypeReference; +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.commons.configuration.BaseConfiguration; +import org.apache.commons.configuration.Configuration; +import org.apache.helix.model.IdealState; +import org.apache.pinot.client.ResultSetGroup; +import org.apache.pinot.common.exception.HttpErrorStatusException; +import org.apache.pinot.common.utils.LLCSegmentName; +import org.apache.pinot.common.utils.SimpleHttpResponse; +import org.apache.pinot.common.utils.helix.HelixHelper; +import org.apache.pinot.common.utils.http.HttpClient; +import org.apache.pinot.controller.api.resources.PauseStatus; +import org.apache.pinot.controller.api.resources.ServerRebalanceJobStatusResponse; +import org.apache.pinot.controller.api.resources.ServerReloadControllerJobStatusResponse; +import org.apache.pinot.controller.helix.core.PinotHelixResourceManager; +import org.apache.pinot.controller.helix.core.rebalance.RebalanceResult; +import org.apache.pinot.controller.helix.core.rebalance.TableRebalancer; +import org.apache.pinot.server.starter.helix.BaseServerStarter; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.config.table.TableType; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.utils.CommonConstants; +import org.apache.pinot.spi.utils.JsonUtils; +import org.apache.pinot.spi.utils.RebalanceConfigConstants; +import org.apache.pinot.spi.utils.builder.TableNameBuilder; +import org.apache.pinot.util.TestUtils; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +public class PartialUpsertTableRebalanceIntegrationTest extends BaseClusterIntegrationTest { + private static final int NUM_SERVERS = 1; + private static final String PRIMARY_KEY_COL = "clientId"; + private static final String REALTIME_TABLE_NAME = TableNameBuilder.REALTIME.tableNameWithType(DEFAULT_TABLE_NAME); + + // Segment 1 contains records of pk value 100000 (partition 0) + private static final String UPLOADED_SEGMENT_1 = "mytable_10027_19736_0 %"; + // Segment 2 contains records of pk value 100001 (partition 1) + private static final String UPLOADED_SEGMENT_2 = "mytable_10072_19919_1 %"; + // Segment 3 contains records of pk value 100002 (partition 1) + private static final String UPLOADED_SEGMENT_3 = "mytable_10158_19938_2 %"; + + private PinotHelixResourceManager _resourceManager; + private TableRebalancer _tableRebalancer; + private static List<File> _avroFiles; + private TableConfig _tableConfig; + private Schema _schema; + + @BeforeClass + public void setUp() + throws Exception { + TestUtils.ensureDirectoriesExistAndEmpty(_tempDir, _segmentDir, _tarDir); + + startZk(); + startController(); + startBroker(); + startServers(NUM_SERVERS); + + // Start Kafka and push data into Kafka + startKafka(); + + _resourceManager = getControllerStarter().getHelixResourceManager(); + _tableRebalancer = new TableRebalancer(_resourceManager.getHelixZkManager(), null); + + createSchemaAndTable(); + } + + @Test + public void testRebalance() + throws Exception { + populateTables(); + + verifyIdealState(5, NUM_SERVERS); + + // setup the rebalance config + Configuration rebalanceConfig = new BaseConfiguration(); + rebalanceConfig.addProperty(RebalanceConfigConstants.DRY_RUN, false); + rebalanceConfig.addProperty(RebalanceConfigConstants.MIN_REPLICAS_TO_KEEP_UP_FOR_NO_DOWNTIME, 0); + rebalanceConfig.addProperty(RebalanceConfigConstants.INCLUDE_CONSUMING, true); + + // Add a new server + BaseServerStarter serverStarter1 = startOneServer(1234); + + // Now we trigger a rebalance operation + TableConfig tableConfig = _resourceManager.getTableConfig(REALTIME_TABLE_NAME); + RebalanceResult rebalanceResult = _tableRebalancer.rebalance(tableConfig, rebalanceConfig); + + // Check the number of replicas after rebalancing + int finalReplicas = _resourceManager.getServerInstancesForTable(getTableName(), TableType.REALTIME).size(); + + // Check that a replica has been added + assertEquals(finalReplicas, NUM_SERVERS + 1, "Rebalancing didn't correctly add the new server"); + + waitForRebalanceToComplete(rebalanceResult, 600_000L); + waitForAllDocsLoaded(600_000L); + + verifySegmentAssignment(rebalanceResult.getSegmentAssignment(), 5, finalReplicas); + + // Add a new server + BaseServerStarter serverStarter2 = startOneServer(4567); + rebalanceResult = _tableRebalancer.rebalance(tableConfig, rebalanceConfig); + + // Check the number of replicas after rebalancing + finalReplicas = _resourceManager.getServerInstancesForTable(getTableName(), TableType.REALTIME).size(); + + // Check that a replica has been added + assertEquals(finalReplicas, NUM_SERVERS + 2, "Rebalancing didn't correctly add the new server"); + + waitForRebalanceToComplete(rebalanceResult, 600_000L); + waitForAllDocsLoaded(600_000L); + + // number of instances assigned can't be more than number of partitions for rf = 1 + verifySegmentAssignment(rebalanceResult.getSegmentAssignment(), 5, getNumKafkaPartitions()); Review Comment: No the default is 2 partitons and that scenario is already covered. -- 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]
