|
53 | 53 | import java.util.TreeMap; |
54 | 54 | import java.util.TreeSet; |
55 | 55 | import java.util.UUID; |
| 56 | +import java.util.concurrent.ThreadLocalRandom; |
56 | 57 | import java.util.concurrent.TimeUnit; |
57 | 58 | import java.util.concurrent.atomic.AtomicBoolean; |
58 | 59 | import java.util.function.Consumer; |
@@ -9468,17 +9469,20 @@ public Map<String, String> updateTableColumnStatistics(ColumnStatistics colStats |
9468 | 9469 | boolean committed = false; |
9469 | 9470 | List<ColumnStatisticsObj> statsObjs = colStats.getStatsObj(); |
9470 | 9471 | ColumnStatisticsDesc statsDesc = colStats.getStatsDesc(); |
9471 | | - |
| 9472 | + long start = System.currentTimeMillis(); |
| 9473 | + String catName = statsDesc.isSetCatName() ? statsDesc.getCatName() : getDefaultCatalog(conf); |
9472 | 9474 | try { |
9473 | 9475 | openTransaction(); |
9474 | 9476 | // DataNucleus objects get detached all over the place for no (real) reason. |
9475 | 9477 | // 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; |
9477 | 9481 | MTable mTable = ensureGetMTable(catName, statsDesc.getDbName(), statsDesc.getTableName()); |
9478 | 9482 | Ref<Map<String, String>> result = new Ref<>(); |
9479 | | - new RetryingExecutor(conf, () -> { |
| 9483 | + new RetryingExecutor(maxRetries, sleepInterval, () -> { |
9480 | 9484 | Ref<Exception> exceptionRef = new Ref<>(); |
9481 | | - String savePoint = "ObjectStore:updateTableColumnStatistics:" + System.nanoTime(); |
| 9485 | + String savePoint = "uts_" + ThreadLocalRandom.current().nextInt(10000) + "_" + System.nanoTime(); |
9482 | 9486 | setTransactionSavePoint(savePoint); |
9483 | 9487 | executePlainSQL( |
9484 | 9488 | sqlGenerator.addForUpdateNoWait("SELECT \"TBL_ID\" FROM \"TBLS\" WHERE \"TBL_ID\" = " + mTable.getId()), |
@@ -9542,6 +9546,9 @@ public Map<String, String> updateTableColumnStatistics(ColumnStatistics colStats |
9542 | 9546 | // TODO: similar to update...Part, this used to do "return committed;"; makes little sense. |
9543 | 9547 | return committed ? result.t : null; |
9544 | 9548 | } finally { |
| 9549 | + LOG.info("{} updateTableColumnStatistics took {}ms, success: {}", |
| 9550 | + new TableName(catName, statsDesc.getDbName(), statsDesc.getTableName()), |
| 9551 | + System.currentTimeMillis() - start, committed); |
9545 | 9552 | rollbackAndCleanup(committed, null); |
9546 | 9553 | } |
9547 | 9554 | } |
@@ -11441,21 +11448,21 @@ private void executePlainSQL(String sql, Consumer<Exception> exceptionConsumer) |
11441 | 11448 | } |
11442 | 11449 |
|
11443 | 11450 | private void lockNotificationSequenceForUpdate() throws MetaException { |
11444 | | - long maxRetries = |
| 11451 | + int maxRetries = |
11445 | 11452 | MetastoreConf.getIntVar(conf, ConfVars.NOTIFICATION_SEQUENCE_LOCK_MAX_RETRIES); |
11446 | 11453 | long sleepInterval = MetastoreConf.getTimeVar(conf, |
11447 | 11454 | ConfVars.NOTIFICATION_SEQUENCE_LOCK_RETRY_SLEEP_INTERVAL, TimeUnit.MILLISECONDS); |
11448 | 11455 | if (sqlGenerator.getDbProduct().isDERBY() && directSql != null) { |
11449 | 11456 | // Derby doesn't allow FOR UPDATE to lock the row being selected (See https://db.apache |
11450 | 11457 | // .org/derby/docs/10.1/ref/rrefsqlj31783.html) . So lock the whole table. Since there's |
11451 | 11458 | // only one row in the table, this shouldn't cause any performance degradation. |
11452 | | - new RetryingExecutor((int) maxRetries, sleepInterval, () -> { |
| 11459 | + new RetryingExecutor(maxRetries, sleepInterval, () -> { |
11453 | 11460 | directSql.lockDbTable("NOTIFICATION_SEQUENCE"); |
11454 | 11461 | }).commandName("lockNotificationSequenceForUpdate").run(); |
11455 | 11462 | } else { |
11456 | 11463 | String selectQuery = "select \"NEXT_EVENT_ID\" from \"NOTIFICATION_SEQUENCE\""; |
11457 | 11464 | String lockingQuery = sqlGenerator.addForUpdateClause(selectQuery); |
11458 | | - new RetryingExecutor((int) maxRetries, sleepInterval, () -> executePlainSQL(lockingQuery, null)) |
| 11465 | + new RetryingExecutor(maxRetries, sleepInterval, () -> executePlainSQL(lockingQuery, null)) |
11459 | 11466 | .commandName("lockNotificationSequenceForUpdate").run(); |
11460 | 11467 | } |
11461 | 11468 | } |
|
0 commit comments