Skip to content

Commit c26894e

Browse files
committed
savepoint name
1 parent 284d353 commit c26894e

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,14 @@ public enum ConfVars {
13091309
+ " seqprefix: adds a 'N_' prefix to the table name to get a unique location (table,1_table,2_table,...)\n"
13101310
+ " prohibit: do not consider alternate locations; throw error if the default is not available\n"
13111311
+ " force: use the default location even in case the directory is already available"),
1312+
METASTORE_S4U_NOWAIT_MAX_RETRIES("metastore.s4u.nowait.max.retries",
1313+
"hive.metastore.s4u.nowait.max.retries", 20,
1314+
"Number of retries required to acquire a row lock immediately without waiting."),
1315+
METASTORE_S4U_NOWAIT_RETRY_SLEEP_INTERVAL(
1316+
"metastore.s4u.nowait.retry.sleep.interval",
1317+
"hive.metastore.s4u.nowait.retry.sleep.interval", 300, TimeUnit.MILLISECONDS,
1318+
"Sleep interval between retries to acquire a row lock immediately described part of property "
1319+
+ METASTORE_S4U_NOWAIT_MAX_RETRIES.name()),
13121320

13131321
MULTITHREADED("javax.jdo.option.Multithreaded", "javax.jdo.option.Multithreaded", true,
13141322
"Set this to true if multiple threads access metastore through JDO concurrently."),

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/DatabaseProduct.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ public String addForUpdateClause(String selectStatement, boolean noWait) throws
476476
case SQLSERVER:
477477
//https://msdn.microsoft.com/en-us/library/ms189499.aspx
478478
//https://msdn.microsoft.com/en-us/library/ms187373.aspx
479-
String modifier = " with (updlock " + (noWait ? ", NOWAIT" : "") + ")";
479+
String modifier = " with (updlock" + (noWait ? ",NOWAIT" : "") + ")";
480480
int wherePos = selectStatement.toUpperCase().indexOf(" WHERE ");
481481
if (wherePos < 0) {
482482
return selectStatement + modifier;

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.util.TreeMap;
5454
import java.util.TreeSet;
5555
import java.util.UUID;
56+
import java.util.concurrent.ThreadLocalRandom;
5657
import java.util.concurrent.TimeUnit;
5758
import java.util.concurrent.atomic.AtomicBoolean;
5859
import java.util.function.Consumer;
@@ -9468,17 +9469,20 @@ public Map<String, String> updateTableColumnStatistics(ColumnStatistics colStats
94689469
boolean committed = false;
94699470
List<ColumnStatisticsObj> statsObjs = colStats.getStatsObj();
94709471
ColumnStatisticsDesc statsDesc = colStats.getStatsDesc();
9471-
9472+
long start = System.currentTimeMillis();
9473+
String catName = statsDesc.isSetCatName() ? statsDesc.getCatName() : getDefaultCatalog(conf);
94729474
try {
94739475
openTransaction();
94749476
// DataNucleus objects get detached all over the place for no (real) reason.
94759477
// So let's not use them anywhere unless absolutely necessary.
9476-
String catName = statsDesc.isSetCatName() ? statsDesc.getCatName() : getDefaultCatalog(conf);
9478+
int maxRetries = MetastoreConf.getIntVar(conf, ConfVars.METASTORE_S4U_NOWAIT_MAX_RETRIES);
9479+
long sleepInterval = ThreadLocalRandom.current().nextLong(MetastoreConf.getTimeVar(conf,
9480+
ConfVars.METASTORE_S4U_NOWAIT_RETRY_SLEEP_INTERVAL, TimeUnit.MILLISECONDS)) + 30;
94779481
MTable mTable = ensureGetMTable(catName, statsDesc.getDbName(), statsDesc.getTableName());
94789482
Ref<Map<String, String>> result = new Ref<>();
9479-
new RetryingExecutor(conf, () -> {
9483+
new RetryingExecutor(maxRetries, sleepInterval, () -> {
94809484
Ref<Exception> exceptionRef = new Ref<>();
9481-
String savePoint = "ObjectStore:updateTableColumnStatistics:" + System.nanoTime();
9485+
String savePoint = "uts_" + ThreadLocalRandom.current().nextInt(10000) + "_" + System.nanoTime();
94829486
setTransactionSavePoint(savePoint);
94839487
executePlainSQL(
94849488
sqlGenerator.addForUpdateNoWait("SELECT \"TBL_ID\" FROM \"TBLS\" WHERE \"TBL_ID\" = " + mTable.getId()),
@@ -9542,6 +9546,9 @@ public Map<String, String> updateTableColumnStatistics(ColumnStatistics colStats
95429546
// TODO: similar to update...Part, this used to do "return committed;"; makes little sense.
95439547
return committed ? result.t : null;
95449548
} finally {
9549+
LOG.info("{} updateTableColumnStatistics took {}ms, success: {}",
9550+
new TableName(catName, statsDesc.getDbName(), statsDesc.getTableName()),
9551+
System.currentTimeMillis() - start, committed);
95459552
rollbackAndCleanup(committed, null);
95469553
}
95479554
}
@@ -11441,21 +11448,21 @@ private void executePlainSQL(String sql, Consumer<Exception> exceptionConsumer)
1144111448
}
1144211449

1144311450
private void lockNotificationSequenceForUpdate() throws MetaException {
11444-
long maxRetries =
11451+
int maxRetries =
1144511452
MetastoreConf.getIntVar(conf, ConfVars.NOTIFICATION_SEQUENCE_LOCK_MAX_RETRIES);
1144611453
long sleepInterval = MetastoreConf.getTimeVar(conf,
1144711454
ConfVars.NOTIFICATION_SEQUENCE_LOCK_RETRY_SLEEP_INTERVAL, TimeUnit.MILLISECONDS);
1144811455
if (sqlGenerator.getDbProduct().isDERBY() && directSql != null) {
1144911456
// Derby doesn't allow FOR UPDATE to lock the row being selected (See https://db.apache
1145011457
// .org/derby/docs/10.1/ref/rrefsqlj31783.html) . So lock the whole table. Since there's
1145111458
// only one row in the table, this shouldn't cause any performance degradation.
11452-
new RetryingExecutor((int) maxRetries, sleepInterval, () -> {
11459+
new RetryingExecutor(maxRetries, sleepInterval, () -> {
1145311460
directSql.lockDbTable("NOTIFICATION_SEQUENCE");
1145411461
}).commandName("lockNotificationSequenceForUpdate").run();
1145511462
} else {
1145611463
String selectQuery = "select \"NEXT_EVENT_ID\" from \"NOTIFICATION_SEQUENCE\"";
1145711464
String lockingQuery = sqlGenerator.addForUpdateClause(selectQuery);
11458-
new RetryingExecutor((int) maxRetries, sleepInterval, () -> executePlainSQL(lockingQuery, null))
11465+
new RetryingExecutor(maxRetries, sleepInterval, () -> executePlainSQL(lockingQuery, null))
1145911466
.commandName("lockNotificationSequenceForUpdate").run();
1146011467
}
1146111468
}

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/utils/RetryingExecutor.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020

2121
import java.util.ArrayList;
2222
import java.util.List;
23-
import java.util.concurrent.TimeUnit;
2423

25-
import org.apache.hadoop.conf.Configuration;
2624
import org.apache.hadoop.hive.metastore.api.MetaException;
27-
import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
2825
import org.slf4j.Logger;
2926
import org.slf4j.LoggerFactory;
3027

@@ -36,9 +33,9 @@ public interface Command {
3633
private static Logger LOG = LoggerFactory.getLogger(RetryingExecutor.class);
3734
private final int maxRetries;
3835
private final long sleepInterval;
39-
private int currentRetries = 0;
4036
private final Command command;
41-
private List<Class<? extends Exception>> retriableException = new ArrayList<>();
37+
private final List<Class<? extends Exception>> retriableException = new ArrayList<>();
38+
private int currentRetries = 0;
4239
private String commandName;
4340

4441
public RetryingExecutor(int maxRetries, long sleepInterval, Command command) {
@@ -47,13 +44,6 @@ public RetryingExecutor(int maxRetries, long sleepInterval, Command command) {
4744
this.command = command;
4845
}
4946

50-
public RetryingExecutor(Configuration conf, Command command) {
51-
this.sleepInterval = MetastoreConf.getTimeVar(conf,
52-
MetastoreConf.ConfVars.HMS_HANDLER_INTERVAL, TimeUnit.MILLISECONDS);
53-
this.maxRetries = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.HMS_HANDLER_ATTEMPTS);
54-
this.command = command;
55-
}
56-
5747
public RetryingExecutor onRetry(Class<? extends Exception> ex) {
5848
this.retriableException.add(ex);
5949
return this;

standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestObjectStore.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,11 @@ public void testQueryCloseOnError() throws Exception {
13001300

13011301
@Test
13021302
public void testRetryingExecutorSleep() throws Exception {
1303-
RetryingExecutor re = new RetryingExecutor(MetastoreConf.newMetastoreConf(), null);
1303+
int maxRetries =
1304+
MetastoreConf.getIntVar(conf, ConfVars.NOTIFICATION_SEQUENCE_LOCK_MAX_RETRIES);
1305+
long sleepInterval = MetastoreConf.getTimeVar(conf,
1306+
ConfVars.NOTIFICATION_SEQUENCE_LOCK_RETRY_SLEEP_INTERVAL, TimeUnit.MILLISECONDS);
1307+
RetryingExecutor re = new RetryingExecutor(maxRetries, sleepInterval, null);
13041308
Assert.assertTrue("invalid sleep value", re.getSleepInterval() >= 0);
13051309
}
13061310

0 commit comments

Comments
 (0)