This is an automated email from the ASF dual-hosted git repository. morrysnow pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push: new 1363d7c32c1 [minor](stats) Throw error when sync analyze failed (#27846) 1363d7c32c1 is described below commit 1363d7c32c1ac012933d086e8585ad6d68c7b6a2 Author: AKIRA <33112463+kikyou1...@users.noreply.github.com> AuthorDate: Fri Dec 1 16:55:19 2023 +0800 [minor](stats) Throw error when sync analyze failed (#27846) pick from master #27845 --- .../org/apache/doris/statistics/AnalysisJob.java | 25 ++++++---------------- .../apache/doris/statistics/BaseAnalysisTask.java | 4 ++-- .../apache/doris/statistics/StatisticsCleaner.java | 17 +++++++++++---- .../apache/doris/statistics/AnalysisJobTest.java | 4 ++-- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisJob.java b/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisJob.java index 5b1ca430409..b5dc2cceb9b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisJob.java +++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisJob.java @@ -119,7 +119,7 @@ public class AnalysisJob { if (killed) { return; } - // buf could be empty when nothing need to do, for example user submit an analysis task for table with no data + // buf could be empty when nothing need to do,r for example user submit an analysis task for table with no data // change if (!buf.isEmpty()) { String insertStmt = "INSERT INTO " + StatisticConstants.FULL_QUALIFIED_STATS_TBL_NAME + " VALUES "; @@ -128,28 +128,17 @@ public class AnalysisJob { values.add(data.toSQL(true)); } insertStmt += values.toString(); - int retryTimes = 0; - while (retryTimes < StatisticConstants.ANALYZE_TASK_RETRY_TIMES) { - if (killed) { - return; - } - try (AutoCloseConnectContext r = StatisticsUtil.buildConnectContext(false)) { - stmtExecutor = new StmtExecutor(r.connectContext, insertStmt); - executeWithExceptionOnFail(stmtExecutor); - break; - } catch (Exception t) { - LOG.warn("Failed to write buf: " + insertStmt, t); - retryTimes++; - if (retryTimes >= StatisticConstants.ANALYZE_TASK_RETRY_TIMES) { - updateTaskState(AnalysisState.FAILED, t.getMessage()); - return; - } - } + try (AutoCloseConnectContext r = StatisticsUtil.buildConnectContext(false)) { + stmtExecutor = new StmtExecutor(r.connectContext, insertStmt); + executeWithExceptionOnFail(stmtExecutor); + } catch (Exception t) { + throw new RuntimeException("Failed to analyze: " + t.getMessage()); } } updateTaskState(AnalysisState.FINISHED, ""); syncLoadStats(); queryFinished.clear(); + buf.clear(); } protected void executeWithExceptionOnFail(StmtExecutor stmtExecutor) throws Exception { diff --git a/fe/fe-core/src/main/java/org/apache/doris/statistics/BaseAnalysisTask.java b/fe/fe-core/src/main/java/org/apache/doris/statistics/BaseAnalysisTask.java index 449a6fc15e5..cdd5c3fc69f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/statistics/BaseAnalysisTask.java +++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/BaseAnalysisTask.java @@ -181,7 +181,7 @@ public abstract class BaseAnalysisTask { protected void executeWithRetry() { int retriedTimes = 0; - while (retriedTimes <= StatisticConstants.ANALYZE_TASK_RETRY_TIMES) { + while (retriedTimes < StatisticConstants.ANALYZE_TASK_RETRY_TIMES) { if (killed) { break; } @@ -193,7 +193,7 @@ public abstract class BaseAnalysisTask { throw new RuntimeException(t); } LOG.warn("Failed to execute analysis task, retried times: {}", retriedTimes++, t); - if (retriedTimes > StatisticConstants.ANALYZE_TASK_RETRY_TIMES) { + if (retriedTimes >= StatisticConstants.ANALYZE_TASK_RETRY_TIMES) { job.taskFailed(this, t.getMessage()); throw new RuntimeException(t); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCleaner.java b/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCleaner.java index 88fa098e57b..21deb44c0a4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCleaner.java +++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCleaner.java @@ -75,11 +75,20 @@ public class StatisticsCleaner extends MasterDaemon { } public synchronized void clear() { - if (!init()) { - return; + try { + if (!init()) { + return; + } + clearStats(colStatsTbl); + clearStats(histStatsTbl); + } finally { + colStatsTbl = null; + histStatsTbl = null; + idToCatalog = null; + idToDb = null; + idToTbl = null; + idToMVIdx = null; } - clearStats(colStatsTbl); - clearStats(histStatsTbl); } private void clearStats(OlapTable statsTbl) { diff --git a/fe/fe-core/src/test/java/org/apache/doris/statistics/AnalysisJobTest.java b/fe/fe-core/src/test/java/org/apache/doris/statistics/AnalysisJobTest.java index bca05d8299c..255ab7106aa 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/statistics/AnalysisJobTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/statistics/AnalysisJobTest.java @@ -206,7 +206,7 @@ public class AnalysisJobTest { @Mock protected void executeWithExceptionOnFail(StmtExecutor stmtExecutor) throws Exception { - throw new RuntimeException(); + // DO NOTHING } @Mock @@ -218,7 +218,7 @@ public class AnalysisJobTest { job.queryFinished = new HashSet<>(); job.queryFinished.add(task2); job.writeBuf(); - Assertions.assertEquals(1, job.queryFinished.size()); + Assertions.assertEquals(0, job.queryFinished.size()); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org