This is an automated email from the ASF dual-hosted git repository. pravin pushed a commit to branch revert-4501-OptimizeGetPartitionAPI in repository https://gitbox.apache.org/repos/asf/hive.git
commit 1e845012fa7578b24f5b55a8456f75550bc7f912 Author: Pravin Kumar Sinha <[email protected]> AuthorDate: Sat Jul 29 18:44:08 2023 +0530 Revert "HIVE-27505: Added batching with retry mechanism in Hive.getAllPartitionsOf call. (#4501)" This reverts commit 255d7c4c509c2ce4ce79b4bb1f436ee67743a18c. --- .../org/apache/hadoop/hive/ql/metadata/Hive.java | 48 +--- .../apache/hadoop/hive/ql/exec/PartitionUtil.java | 85 ------- .../hive/ql/exec/TestGetPartitionInBatches.java | 259 --------------------- .../ql/exec/TestMsckCreatePartitionsInBatches.java | 75 +++++- .../ql/exec/TestMsckDropPartitionsInBatches.java | 48 +++- .../llap/temp_table_add_part_multiple.q.out | 2 +- .../hadoop/hive/metastore/conf/MetastoreConf.java | 8 - 7 files changed, 113 insertions(+), 412 deletions(-) diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index a67fa806024..e013db7db26 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -117,8 +117,6 @@ import org.apache.hadoop.hive.metastore.api.GetTableRequest; import org.apache.hadoop.hive.metastore.api.SourceTable; import org.apache.hadoop.hive.metastore.api.UpdateTransactionalStatsRequest; import org.apache.hadoop.hive.metastore.api.NoSuchObjectException; -import org.apache.hadoop.hive.metastore.conf.MetastoreConf; -import org.apache.hadoop.hive.metastore.utils.RetryUtilities; import org.apache.hadoop.hive.ql.ddl.table.AlterTableType; import org.apache.hadoop.hive.ql.io.HdfsUtils; import org.apache.hadoop.hive.metastore.HiveMetaException; @@ -267,7 +265,6 @@ public class Hive { private SynchronizedMetaStoreClient syncMetaStoreClient; private UserGroupInformation owner; private boolean isAllowClose = true; - private final static int DEFAULT_BATCH_DECAYING_FACTOR = 2; // metastore calls timing information private final ConcurrentHashMap<String, Long> metaCallTimeMap = new ConcurrentHashMap<>(); @@ -4146,7 +4143,7 @@ private void constructOneLBLocationMap(FileStatus fSta, * @param tbl table for which partitions are needed * @return list of partition objects */ - public Set<Partition> getAllPartitions(Table tbl) throws HiveException { + public Set<Partition> getAllPartitionsOf(Table tbl) throws HiveException { if (!tbl.isPartitioned()) { return Sets.newHashSet(new Partition(tbl)); } @@ -4165,49 +4162,6 @@ private void constructOneLBLocationMap(FileStatus fSta, return parts; } - /** - * Get all the partitions. Do it in batches if batchSize is more than 0 else get it in one call. - * @param tbl table for which partitions are needed - * @return list of partition objects - */ - public Set<Partition> getAllPartitionsOf(Table tbl) throws HiveException { - int batchSize= MetastoreConf.getIntVar( - Hive.get().getConf(), MetastoreConf.ConfVars.BATCH_RETRIEVE_MAX); - if (batchSize > 0) { - return getAllPartitionsInBatches(tbl, batchSize, DEFAULT_BATCH_DECAYING_FACTOR, MetastoreConf.getIntVar( - Hive.get().getConf(), MetastoreConf.ConfVars.GETPARTITIONS_BATCH_MAX_RETRIES)); - } else { - return getAllPartitions(tbl); - } - } - - public Set<Partition> getAllPartitionsInBatches(Table tbl, int batchSize, int decayingFactor, - int maxRetries) throws HiveException { - if (!tbl.isPartitioned()) { - return Sets.newHashSet(new Partition(tbl)); - } - Set<Partition> result = new LinkedHashSet<>(); - RetryUtilities.ExponentiallyDecayingBatchWork batchTask = new RetryUtilities - .ExponentiallyDecayingBatchWork<Void>(batchSize, decayingFactor, maxRetries) { - @Override - public Void execute(int size) throws HiveException { - try { - result.clear(); - new PartitionIterable(Hive.get(), tbl, null, size).forEach(result::add); - return null; - } catch (HiveException e) { - throw e; - } - } - }; - try { - batchTask.run(); - } catch (Exception e) { - throw new HiveException(e); - } - return result; - } - /** * get all the partitions of the table that matches the given partial * specification. partition columns whose value is can be anything should be diff --git a/ql/src/test/org/apache/hadoop/hive/ql/exec/PartitionUtil.java b/ql/src/test/org/apache/hadoop/hive/ql/exec/PartitionUtil.java deleted file mode 100644 index f449c79760f..00000000000 --- a/ql/src/test/org/apache/hadoop/hive/ql/exec/PartitionUtil.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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.hadoop.hive.ql.exec; - -import org.apache.hadoop.hive.metastore.CheckResult; -import org.apache.hadoop.hive.metastore.IMetaStoreClient; -import org.apache.hadoop.hive.metastore.api.FieldSchema; -import org.apache.hadoop.hive.metastore.api.SerDeInfo; -import org.apache.hadoop.hive.metastore.api.StorageDescriptor; -import org.apache.hadoop.hive.metastore.api.Table; -import org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat; -import org.apache.hadoop.hive.ql.stats.StatsUtils; -import org.apache.hadoop.mapred.TextInputFormat; -import org.apache.hadoop.util.StringUtils; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import static org.junit.Assert.fail; - -public class PartitionUtil { - - public static Table createPartitionedTable(IMetaStoreClient db, String catName, String dbName, String tableName) - throws Exception { - try { - db.dropTable(catName, dbName, tableName); - Table table = new Table(); - table.setCatName(catName); - table.setDbName(dbName); - table.setTableName(tableName); - FieldSchema col1 = new FieldSchema("key", "string", ""); - FieldSchema col2 = new FieldSchema("value", "int", ""); - FieldSchema col3 = new FieldSchema("city", "string", ""); - StorageDescriptor sd = new StorageDescriptor(); - sd.setSerdeInfo(new SerDeInfo()); - sd.setInputFormat(TextInputFormat.class.getCanonicalName()); - sd.setOutputFormat(HiveIgnoreKeyTextOutputFormat.class.getCanonicalName()); - sd.setCols(Arrays.asList(col1, col2)); - table.setPartitionKeys(Arrays.asList(col3)); - table.setSd(sd); - db.createTable(table); - return db.getTable(catName, dbName, tableName); - } catch (Exception exception) { - fail("Unable to drop and create table " + StatsUtils.getFullyQualifiedTableName(dbName, tableName) + " because " - + StringUtils.stringifyException(exception)); - throw exception; - } - } - - public static void cleanUpTableQuietly(IMetaStoreClient db, String catName, String dbName, String tableName) { - try { - db.dropTable(catName, dbName, tableName); - } catch (Exception exception) { - fail("Unexpected exception: " + StringUtils.stringifyException(exception)); - } - } - - public static Set<CheckResult.PartitionResult> createPartsNotInMs(int numOfParts) { - Set<CheckResult.PartitionResult> partsNotInMs = new HashSet<>(); - for (int i = 0; i < numOfParts; i++) { - CheckResult.PartitionResult result = new CheckResult.PartitionResult(); - result.setPartitionName("city=dummyCity_" + i); - result.setTableName("dummyTable"); - partsNotInMs.add(result); - } - return partsNotInMs; - } -} diff --git a/ql/src/test/org/apache/hadoop/hive/ql/exec/TestGetPartitionInBatches.java b/ql/src/test/org/apache/hadoop/hive/ql/exec/TestGetPartitionInBatches.java deleted file mode 100644 index 246afeb7921..00000000000 --- a/ql/src/test/org/apache/hadoop/hive/ql/exec/TestGetPartitionInBatches.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * 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.hadoop.hive.ql.exec; - -import org.apache.hadoop.hive.conf.HiveConf; -import org.apache.hadoop.hive.metastore.HiveMetaStoreClient; - -import org.apache.hadoop.hive.metastore.api.GetPartitionsByNamesRequest; -import org.apache.hadoop.hive.metastore.api.MetaException; -import org.apache.hadoop.hive.metastore.api.Partition; -import org.apache.hadoop.hive.metastore.api.Table; -import org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder; -import org.apache.hadoop.hive.ql.metadata.Hive; -import org.apache.hadoop.hive.ql.metadata.HiveException; -import org.apache.hadoop.hive.ql.session.SessionState; -import org.junit.Assert; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.mockito.ArgumentCaptor; - - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -public class TestGetPartitionInBatches { - - private final String catName = "hive"; - private final String dbName = "default"; - private final String tableName = "test_partition_batch"; - private static HiveConf hiveConf; - private static HiveMetaStoreClient msc; - private static Hive hive; - private Table table; - - @BeforeClass - public static void setupClass() throws HiveException { - hiveConf = new HiveConf(TestGetPartitionInBatches.class); - hive = Hive.get(); - SessionState.start(hiveConf); - try { - msc = new HiveMetaStoreClient(hiveConf); - } catch (MetaException e) { - throw new HiveException(e); - } - } - - @Before - public void before() throws Exception { - PartitionUtil.createPartitionedTable(msc, catName, dbName, tableName); - table = msc.getTable(catName, dbName, tableName); - addPartitions(dbName, tableName); - } - - @After - public void after() throws Exception { - PartitionUtil.cleanUpTableQuietly(msc, catName, dbName, tableName); - } - - private void addPartitions(String dbName, String tableName) throws Exception { - List<Partition> partitions = new ArrayList<>(); - for (int i = 0; i < 30; i++) { - partitions.add(buildPartition(dbName, tableName, String.valueOf(i), table.getSd().getLocation() + "/city=" + i)); - } - msc.add_partitions(partitions, true, true); - } - - protected Partition buildPartition(String dbName, String tableName, String value, - String location) throws MetaException { - return new PartitionBuilder() - .setDbName(dbName) - .setTableName(tableName) - .addValue(value) - .addCol("test_id", "int", "test col id") - .addCol("test_value", "string", "test col value") - .setLocation(location) - .build(hiveConf); - } - - /** - * Tests the number of partitions recieved from the HMS - * - * @throws Exception - */ - @Test - public void testgetAllPartitionsOf() throws Exception { - Set<org.apache.hadoop.hive.ql.metadata.Partition> part = hive.getAllPartitionsOf(hive.getTable(dbName, tableName)); - Assert.assertEquals(part.size(), 30); - } - - /** - * Tests the number of times Hive.getAllPartitionsOf calls are executed with total number of - * partitions to be added are equally divisible by batch size - * - * @throws Exception - */ - @Test - public void testNumberOfGetPartitionCalls() throws Exception { - HiveMetaStoreClient spyMSC = spy(msc); - hive.setMSC(spyMSC); - // test with a batch size of 10 and decaying factor of 2 - hive.getAllPartitionsInBatches(hive.getTable(dbName, tableName),10, 2, 0); - ArgumentCaptor<GetPartitionsByNamesRequest> req = ArgumentCaptor.forClass(GetPartitionsByNamesRequest.class); - // there should be 3 calls to get partitions - verify(spyMSC, times(3)).getPartitionsByNames(req.capture()); - Assert.assertEquals(10, req.getValue().getNames().size()); - } - - /** - * Tests the number of times Hive.getAllPartitionsOf calls are executed with total number of - * partitions to be added are not exactly divisible by batch size - * - * @throws Exception - */ - @Test - public void testUnevenNumberOfGetPartitionCalls() throws Exception { - HiveMetaStoreClient spyMSC = spy(msc); - hive.setMSC(spyMSC); - // there should be 2 calls to get partitions with batch sizes of 19, 11 - hive.getAllPartitionsInBatches(hive.getTable(dbName, tableName),19, 2, 0); - ArgumentCaptor<GetPartitionsByNamesRequest> req = ArgumentCaptor.forClass(GetPartitionsByNamesRequest.class); - // there should be 2 calls to get partitions - verify(spyMSC, times(2)).getPartitionsByNames(req.capture()); - // confirm the batch sizes were 19, 11 in the two calls to get partitions - List<GetPartitionsByNamesRequest> apds = req.getAllValues(); - Assert.assertEquals(19, apds.get(0).getNames().size()); - Assert.assertEquals(11, apds.get(1).getNames().size()); - } - - /** - * Tests the number of times Hive.getAllPartitionsOf calls are executed with total number of - * partitions to is less than batch size - * - * @throws Exception - */ - @Test - public void testSmallNumberOfPartitions() throws Exception { - HiveMetaStoreClient spyMSC = spy(msc); - hive.setMSC(spyMSC); - hive.getAllPartitionsInBatches(hive.getTable(dbName, tableName),100, 2, 0); - ArgumentCaptor<GetPartitionsByNamesRequest> req = ArgumentCaptor.forClass(GetPartitionsByNamesRequest.class); - // there should be 1 call to get partitions - verify(spyMSC, times(1)).getPartitionsByNames(req.capture()); - Assert.assertEquals(30, req.getValue().getNames().size()); - } - - /** - * Tests the retries exhausted case when getAllPartitionsOf method call always keep throwing - * HiveException. The batch sizes should exponentially decreased based on the decaying factor and - * ultimately give up when it reaches 0 - * - * @throws Exception - */ - @Test - public void testRetriesExhaustedBatchSize() throws Exception { - HiveMetaStoreClient spyMSC = spy(msc); - hive.setMSC(spyMSC); - doThrow(MetaException.class).when(spyMSC).getPartitionsByNames(any()); - try { - hive.getAllPartitionsInBatches(hive.getTable(dbName, tableName), 30, 2, 0); - } catch (Exception ignored) {} - ArgumentCaptor<GetPartitionsByNamesRequest> req = ArgumentCaptor.forClass(GetPartitionsByNamesRequest.class); - // there should be 5 call to get partitions with batch sizes as 30, 15, 7, 3, 1 - verify(spyMSC, times(5)).getPartitionsByNames(req.capture()); - List<GetPartitionsByNamesRequest> apds = req.getAllValues(); - Assert.assertEquals(5, apds.size()); - - Assert.assertEquals(30, apds.get(0).getNames().size()); - Assert.assertEquals(15, apds.get(1).getNames().size()); - Assert.assertEquals(7, apds.get(2).getNames().size()); - Assert.assertEquals(3, apds.get(3).getNames().size()); - Assert.assertEquals(1, apds.get(4).getNames().size()); - } - - /** - * Tests the maximum retry attempts provided by configuration - * @throws Exception - */ - @Test - public void testMaxRetriesReached() throws Exception { - HiveMetaStoreClient spyMSC = spy(msc); - hive.setMSC(spyMSC); - doThrow(MetaException.class).when(spyMSC).getPartitionsByNames(any()); - try { - hive.getAllPartitionsInBatches(hive.getTable(dbName, tableName), 30, 2, 2); - } catch (Exception ignored) {} - ArgumentCaptor<GetPartitionsByNamesRequest> req = ArgumentCaptor.forClass(GetPartitionsByNamesRequest.class); - // there should be 2 call to get partitions with batch sizes as 30, 15 - verify(spyMSC, times(2)).getPartitionsByNames(req.capture()); - List<GetPartitionsByNamesRequest> apds = req.getAllValues(); - Assert.assertEquals(2, apds.size()); - - Assert.assertEquals(30, apds.get(0).getNames().size()); - Assert.assertEquals(15, apds.get(1).getNames().size()); - } - - /** - * Tests the number of calls to getPartitions and the respective batch sizes when first call to - * getPartitions throws HiveException. The batch size should be reduced by the decayingFactor - * and the second call should fetch all the results - * - * @throws Exception - */ - @Test - public void testBatchingWhenException() throws Exception { - HiveMetaStoreClient spyMSC = spy(msc); - hive.setMSC(spyMSC); - // This will throw exception only the first time. - doThrow(new MetaException()).doCallRealMethod() - .when(spyMSC).getPartitionsByNames(any()); - - hive.getAllPartitionsInBatches(hive.getTable(dbName, tableName), 30, 2, 5); - ArgumentCaptor<GetPartitionsByNamesRequest> req = ArgumentCaptor.forClass(GetPartitionsByNamesRequest.class); - // The first call with batch size of 30 will fail, the rest two call will be of size 15 each. Total 3 calls - verify(spyMSC, times(3)).getPartitionsByNames(req.capture()); - List<GetPartitionsByNamesRequest> apds = req.getAllValues(); - Assert.assertEquals(3, apds.size()); - - Assert.assertEquals(30, apds.get(0).getNames().size()); - Assert.assertEquals(15, apds.get(1).getNames().size()); - Assert.assertEquals(15, apds.get(2).getNames().size()); - - Set<String> partNames = new HashSet<>(apds.get(1).getNames()); - partNames.addAll(apds.get(2).getNames()); - assert(partNames.size() == 30); - - List<String> partitionNames = hive.getPartitionNames(table.getDbName(),table.getTableName(), (short) -1); - assert(partitionNames.size() == 30); - partitionNames.forEach(partNames::remove); - assert(partitionNames.size() == 30); - // In case any duplicate/incomplete list is given by hive.getAllPartitionsInBatches, the below assertion will fail - assert(partNames.size() == 0); - } -} diff --git a/ql/src/test/org/apache/hadoop/hive/ql/exec/TestMsckCreatePartitionsInBatches.java b/ql/src/test/org/apache/hadoop/hive/ql/exec/TestMsckCreatePartitionsInBatches.java index b5ae42ace53..30c89322382 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/exec/TestMsckCreatePartitionsInBatches.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/exec/TestMsckCreatePartitionsInBatches.java @@ -23,12 +23,19 @@ import org.apache.hadoop.hive.metastore.CheckResult.PartitionResult; import org.apache.hadoop.hive.metastore.HiveMetaStoreClient; import org.apache.hadoop.hive.metastore.IMetaStoreClient; import org.apache.hadoop.hive.metastore.Msck; +import org.apache.hadoop.hive.metastore.api.FieldSchema; import org.apache.hadoop.hive.metastore.api.MetaException; import org.apache.hadoop.hive.metastore.api.Partition; +import org.apache.hadoop.hive.metastore.api.SerDeInfo; +import org.apache.hadoop.hive.metastore.api.StorageDescriptor; import org.apache.hadoop.hive.metastore.api.Table; import org.apache.hadoop.hive.metastore.utils.RetryUtilities; +import org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat; import org.apache.hadoop.hive.ql.metadata.HiveException; import org.apache.hadoop.hive.ql.session.SessionState; +import org.apache.hadoop.hive.ql.stats.StatsUtils; +import org.apache.hadoop.mapred.TextInputFormat; +import org.apache.hadoop.util.StringUtils; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -38,11 +45,14 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Set; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.doThrow; @@ -78,14 +88,59 @@ public class TestMsckCreatePartitionsInBatches { @Before public void before() throws Exception { - PartitionUtil.createPartitionedTable(db, catName, dbName, tableName); + createPartitionedTable(catName, dbName, tableName); table = db.getTable(catName, dbName, tableName); repairOutput = new ArrayList<String>(); } @After public void after() throws Exception { - PartitionUtil.cleanUpTableQuietly(db, catName, dbName, tableName); + cleanUpTableQuietly(catName, dbName, tableName); + } + + private Table createPartitionedTable(String catName, String dbName, String tableName) throws Exception { + try { + db.dropTable(catName, dbName, tableName); + Table table = new Table(); + table.setCatName(catName); + table.setDbName(dbName); + table.setTableName(tableName); + FieldSchema col1 = new FieldSchema("key", "string", ""); + FieldSchema col2 = new FieldSchema("value", "int", ""); + FieldSchema col3 = new FieldSchema("city", "string", ""); + StorageDescriptor sd = new StorageDescriptor(); + sd.setSerdeInfo(new SerDeInfo()); + sd.setInputFormat(TextInputFormat.class.getCanonicalName()); + sd.setOutputFormat(HiveIgnoreKeyTextOutputFormat.class.getCanonicalName()); + sd.setCols(Arrays.asList(col1, col2)); + table.setPartitionKeys(Arrays.asList(col3)); + table.setSd(sd); + db.createTable(table); + return db.getTable(catName, dbName, tableName); + } catch (Exception exception) { + fail("Unable to drop and create table " + StatsUtils.getFullyQualifiedTableName(dbName, tableName) + " because " + + StringUtils.stringifyException(exception)); + throw exception; + } + } + + private void cleanUpTableQuietly(String catName, String dbName, String tableName) { + try { + db.dropTable(catName, dbName, tableName); + } catch (Exception exception) { + fail("Unexpected exception: " + StringUtils.stringifyException(exception)); + } + } + + private Set<PartitionResult> createPartsNotInMs(int numOfParts) { + Set<PartitionResult> partsNotInMs = new HashSet<>(); + for (int i = 0; i < numOfParts; i++) { + PartitionResult result = new PartitionResult(); + result.setPartitionName("city=dummyCity_" + String.valueOf(i)); + result.setTableName("dummyTable"); + partsNotInMs.add(result); + } + return partsNotInMs; } /** @@ -97,7 +152,7 @@ public class TestMsckCreatePartitionsInBatches { @Test public void testNumberOfCreatePartitionCalls() throws Exception { // create 10 dummy partitions - Set<PartitionResult> partsNotInMs = PartitionUtil.createPartsNotInMs(10); + Set<PartitionResult> partsNotInMs = createPartsNotInMs(10); IMetaStoreClient spyDb = spy(db); // batch size of 5 and decaying factor of 2 msck.createPartitionsInBatches(spyDb, repairOutput, partsNotInMs, table, 5, 2, 0); @@ -126,7 +181,7 @@ public class TestMsckCreatePartitionsInBatches { @Test public void testUnevenNumberOfCreatePartitionCalls() throws Exception { // create 9 dummy partitions - Set<PartitionResult> partsNotInMs = PartitionUtil.createPartsNotInMs(9); + Set<PartitionResult> partsNotInMs = createPartsNotInMs(9); IMetaStoreClient spyDb = spy(db); // batch size of 5 and decaying factor of 2 msck.createPartitionsInBatches(spyDb, repairOutput, partsNotInMs, table, 5, 2, 0); @@ -155,7 +210,7 @@ public class TestMsckCreatePartitionsInBatches { @Test public void testEqualNumberOfPartitions() throws Exception { // create 13 dummy partitions - Set<PartitionResult> partsNotInMs = PartitionUtil.createPartsNotInMs(13); + Set<PartitionResult> partsNotInMs = createPartsNotInMs(13); IMetaStoreClient spyDb = spy(db); // batch size of 13 and decaying factor of 2 msck.createPartitionsInBatches(spyDb, repairOutput, partsNotInMs, table, 13, 2, 0); @@ -181,7 +236,7 @@ public class TestMsckCreatePartitionsInBatches { @Test public void testSmallNumberOfPartitions() throws Exception { // create 10 dummy partitions - Set<PartitionResult> partsNotInMs = PartitionUtil.createPartsNotInMs(10); + Set<PartitionResult> partsNotInMs = createPartsNotInMs(10); IMetaStoreClient spyDb = spy(db); // batch size of 20 and decaying factor of 2 msck.createPartitionsInBatches(spyDb, repairOutput, partsNotInMs, table, 20, 2, 0); @@ -208,7 +263,7 @@ public class TestMsckCreatePartitionsInBatches { @Test public void testBatchingWhenException() throws Exception { // create 13 dummy partitions - Set<PartitionResult> partsNotInMs = PartitionUtil.createPartsNotInMs(23); + Set<PartitionResult> partsNotInMs = createPartsNotInMs(23); IMetaStoreClient spyDb = spy(db); // first call to createPartitions should throw exception doThrow(MetaException.class).doCallRealMethod().doCallRealMethod().when(spyDb) @@ -247,7 +302,7 @@ public class TestMsckCreatePartitionsInBatches { */ @Test public void testRetriesExhaustedBatchSize() throws Exception { - Set<PartitionResult> partsNotInMs = PartitionUtil.createPartsNotInMs(17); + Set<PartitionResult> partsNotInMs = createPartsNotInMs(17); IMetaStoreClient spyDb = spy(db); doThrow(MetaException.class).when(spyDb) .add_partitions(any(), anyBoolean(), anyBoolean()); @@ -294,7 +349,7 @@ public class TestMsckCreatePartitionsInBatches { */ @Test public void testMaxRetriesReached() throws Exception { - Set<PartitionResult> partsNotInMs = PartitionUtil.createPartsNotInMs(17); + Set<PartitionResult> partsNotInMs = createPartsNotInMs(17); IMetaStoreClient spyDb = spy(db); doThrow(MetaException.class).when(spyDb) .add_partitions(any(), anyBoolean(), anyBoolean()); @@ -330,7 +385,7 @@ public class TestMsckCreatePartitionsInBatches { */ @Test public void testOneMaxRetries() throws Exception { - Set<PartitionResult> partsNotInMs = PartitionUtil.createPartsNotInMs(17); + Set<PartitionResult> partsNotInMs = createPartsNotInMs(17); IMetaStoreClient spyDb = spy(db); doThrow(MetaException.class).when(spyDb) .add_partitions(any(), anyBoolean(), anyBoolean()); diff --git a/ql/src/test/org/apache/hadoop/hive/ql/exec/TestMsckDropPartitionsInBatches.java b/ql/src/test/org/apache/hadoop/hive/ql/exec/TestMsckDropPartitionsInBatches.java index a6281653701..a61e066266a 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/exec/TestMsckDropPartitionsInBatches.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/exec/TestMsckDropPartitionsInBatches.java @@ -25,10 +25,17 @@ import org.apache.hadoop.hive.metastore.HiveMetaStoreClient; import org.apache.hadoop.hive.metastore.IMetaStoreClient; import org.apache.hadoop.hive.metastore.Msck; import org.apache.hadoop.hive.metastore.PartitionDropOptions; +import org.apache.hadoop.hive.metastore.api.FieldSchema; import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.hadoop.hive.metastore.api.SerDeInfo; +import org.apache.hadoop.hive.metastore.api.StorageDescriptor; import org.apache.hadoop.hive.metastore.api.Table; import org.apache.hadoop.hive.metastore.utils.RetryUtilities; +import org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat; import org.apache.hadoop.hive.ql.session.SessionState; +import org.apache.hadoop.hive.ql.stats.StatsUtils; +import org.apache.hadoop.mapred.TextInputFormat; +import org.apache.hadoop.util.StringUtils; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -37,11 +44,13 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.eq; @@ -77,14 +86,49 @@ public class TestMsckDropPartitionsInBatches { @Before public void before() throws Exception { - PartitionUtil.createPartitionedTable(db, catName, dbName, tableName); + createPartitionedTable(catName, dbName, tableName); table = db.getTable(catName, dbName, tableName); repairOutput = new ArrayList<String>(); } @After public void after() throws Exception { - PartitionUtil.cleanUpTableQuietly(db, catName, dbName, tableName); + cleanUpTableQuietly(catName, dbName, tableName); + } + + private Table createPartitionedTable(String catName, String dbName, String tableName) throws Exception { + try { + db.dropTable(catName, dbName, tableName); + Table table = new Table(); + table.setCatName(catName); + table.setDbName(dbName); + table.setTableName(tableName); + FieldSchema col1 = new FieldSchema("key", "string", ""); + FieldSchema col2 = new FieldSchema("value", "int", ""); + FieldSchema col3 = new FieldSchema("city", "string", ""); + StorageDescriptor sd = new StorageDescriptor(); + sd.setSerdeInfo(new SerDeInfo()); + sd.setInputFormat(TextInputFormat.class.getCanonicalName()); + sd.setOutputFormat(HiveIgnoreKeyTextOutputFormat.class.getCanonicalName()); + sd.setCols(Arrays.asList(col1, col2)); + table.setPartitionKeys(Arrays.asList(col3)); + table.setSd(sd); + db.createTable(table); + return db.getTable(catName, dbName, tableName); + } catch (Exception exception) { + fail("Unable to drop and create table " + StatsUtils + .getFullyQualifiedTableName(dbName, tableName) + " because " + StringUtils + .stringifyException(exception)); + throw exception; + } + } + + private void cleanUpTableQuietly(String catName, String dbName, String tableName) { + try { + db.dropTable(catName, dbName, tableName, true, true, true); + } catch (Exception exception) { + fail("Unexpected exception: " + StringUtils.stringifyException(exception)); + } } private Set<PartitionResult> dropPartsNotInFs(int numOfParts) { diff --git a/ql/src/test/results/clientpositive/llap/temp_table_add_part_multiple.q.out b/ql/src/test/results/clientpositive/llap/temp_table_add_part_multiple.q.out index 657ba88e6ca..ac040e8509b 100644 --- a/ql/src/test/results/clientpositive/llap/temp_table_add_part_multiple.q.out +++ b/ql/src/test/results/clientpositive/llap/temp_table_add_part_multiple.q.out @@ -115,5 +115,5 @@ POSTHOOK: Input: default@add_part_test_n1_temp@ds=2010-04-01 #### A masked pattern was here #### 100 100 2010-01-01 200 200 2010-02-01 -400 300 2010-03-01 500 400 2010-04-01 +400 300 2010-03-01 diff --git a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java index 96dca0cb738..4e0c136fb5d 100644 --- a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java +++ b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java @@ -1174,14 +1174,6 @@ public class MetastoreConf { "command should handle partition retention. If enabled, and if a specific partition's age exceeded\n" + "retention period the partition will be dropped along with data"), - GETPARTITIONS_BATCH_MAX_RETRIES("metastore.getpartitions.batch.max.retries", - "hive.getpartitions.batch.max.retries", 5, - "Maximum number of retries for the Hive.GetAllPartitionsOf() when getting partitions in batches.\n " - + "If the value is greater than zero it will retry getting partitions until the maximum\n" - + "number of attempts is reached or batch size is reduced to 0, whichever is earlier.\n" - + "In each retry attempt it will reduce the batch size by a factor of 2 until it reaches zero.\n" - + "If the value is set to zero it will retry until the batch size becomes zero as described above."), - // Partition management task params PARTITION_MANAGEMENT_TASK_FREQUENCY("metastore.partition.management.task.frequency",
