This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 5dde910931 [feature](profile) add clean all profile sql (#17751)
5dde910931 is described below

commit 5dde91093175a6e2c841ff4179e7d8d6980b848f
Author: xueweizhang <[email protected]>
AuthorDate: Thu Mar 16 16:12:21 2023 +0800

    [feature](profile) add clean all profile sql (#17751)
    
    Signed-off-by: nextdreamblue <[email protected]>
---
 .../Load/CLEAN-PROFILE.md                          | 56 ++++++++++++++++++++
 .../Load/CLEAN-PROFILE.md                          | 60 ++++++++++++++++++++++
 fe/fe-core/src/main/cup/sql_parser.cup             |  4 ++
 .../apache/doris/analysis/CleanProfileStmt.java    | 50 ++++++++++++++++++
 .../apache/doris/common/util/ProfileManager.java   | 12 ++++-
 .../main/java/org/apache/doris/qe/DdlExecutor.java |  4 ++
 6 files changed, 185 insertions(+), 1 deletion(-)

diff --git 
a/docs/en/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Load/CLEAN-PROFILE.md
 
b/docs/en/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Load/CLEAN-PROFILE.md
new file mode 100644
index 0000000000..e6c178fd4d
--- /dev/null
+++ 
b/docs/en/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Load/CLEAN-PROFILE.md
@@ -0,0 +1,56 @@
+---
+{
+    "title": "CLEAN-PROFILE",
+    "language": "en"
+}
+---
+
+<!--
+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.
+-->
+
+## CLEAN-PROFILE
+
+### Name
+
+CLEAN PROFILE
+
+### Description
+
+For manual cleanup all of historical query or load profile.
+
+Syntax:
+
+```sql
+CLEAN ALL PROFILE;
+```
+
+### Example
+
+1. Clean all profile
+
+       ```sql
+       CLEAN ALL PROFILE;
+       ```
+
+### Keywords
+
+    CLEAN, PROFILE
+
+### Best Practice
+
diff --git 
a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Load/CLEAN-PROFILE.md
 
b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Load/CLEAN-PROFILE.md
new file mode 100644
index 0000000000..2d90c2e3a0
--- /dev/null
+++ 
b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Manipulation-Statements/Load/CLEAN-PROFILE.md
@@ -0,0 +1,60 @@
+---
+{
+    "title": "CLEAN-PROFILE",
+    "language": "zh-CN"
+}
+---
+
+<!--
+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.
+-->
+
+## CLEAN-PROFILE
+
+### Name
+
+<version since="1.2">
+
+CLEAN PROFILE
+
+</version>
+
+### Description
+
+用于手动清理所有历史query或load的profile信息。
+
+语法:
+
+```sql
+CLEAN ALL PROFILE;
+```
+
+### Example
+
+1. 清理所有profile信息。
+
+       ```sql
+       CLEAN ALL PROFILE;
+       ```
+
+### Keywords
+
+    CLEAN, PROFILE
+
+### Best Practice
+
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup 
b/fe/fe-core/src/main/cup/sql_parser.cup
index fb153f80bc..5a093025f8 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -1214,6 +1214,10 @@ clean_stmt ::=
     {:
         RESULT = new CleanLabelStmt(db, label);
     :}
+    | KW_CLEAN KW_ALL KW_PROFILE
+    {:
+        RESULT = new CleanProfileStmt();
+    :}
     ;
 
 // plugin statement
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/CleanProfileStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CleanProfileStmt.java
new file mode 100644
index 0000000000..95ff420d1e
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CleanProfileStmt.java
@@ -0,0 +1,50 @@
+// 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.doris.analysis;
+
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.UserException;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.qe.ConnectContext;
+
+/**
+ * CLEAN ALL PROFILE;
+ */
+public class CleanProfileStmt extends DdlStmt {
+    public CleanProfileStmt() {
+    }
+
+    @Override
+    public void analyze(Analyzer analyzer) throws UserException {
+        if 
(!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.ADMIN)) {
+            
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, 
"ADMIN");
+        }
+    }
+
+    @Override
+    public String toSql() {
+        return "CLEAN ALL PROFILE";
+    }
+
+    @Override
+    public RedirectStatus getRedirectStatus() {
+        return RedirectStatus.FORWARD_WITH_SYNC;
+    }
+}
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java 
b/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java
index f6b4fb06e1..6d0f575d38 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java
@@ -202,10 +202,10 @@ public class ProfileManager {
                     + "may be forget to insert 'QUERY_ID' or 'JOB_ID' column 
into infoStrings");
         }
 
+        writeLock.lock();
         // a profile may be updated multiple times in queryIdToProfileMap,
         // and only needs to be inserted into the queryIdDeque for the first 
time.
         queryIdToProfileMap.put(key, element);
-        writeLock.lock();
         try {
             if (!queryIdDeque.contains(key)) {
                 if (queryIdDeque.size() >= Config.max_query_profile_num) {
@@ -393,4 +393,14 @@ public class ProfileManager {
             profileElement.setStatsErrorEstimator(statsErrorEstimator);
         }
     }
+
+    public void cleanProfile() {
+        writeLock.lock();
+        try {
+            queryIdToProfileMap.clear();
+            queryIdDeque.clear();
+        } finally {
+            writeLock.unlock();
+        }
+    }
 }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/DdlExecutor.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/DdlExecutor.java
index e4df13fb05..857f14e652 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/DdlExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/DdlExecutor.java
@@ -50,6 +50,7 @@ import org.apache.doris.analysis.CancelBackupStmt;
 import org.apache.doris.analysis.CancelExportStmt;
 import org.apache.doris.analysis.CancelLoadStmt;
 import org.apache.doris.analysis.CleanLabelStmt;
+import org.apache.doris.analysis.CleanProfileStmt;
 import org.apache.doris.analysis.CreateCatalogStmt;
 import org.apache.doris.analysis.CreateClusterStmt;
 import org.apache.doris.analysis.CreateDataSyncJobStmt;
@@ -113,6 +114,7 @@ import org.apache.doris.analysis.UninstallPluginStmt;
 import org.apache.doris.catalog.EncryptKeyHelper;
 import org.apache.doris.catalog.Env;
 import org.apache.doris.common.DdlException;
+import org.apache.doris.common.util.ProfileManager;
 import org.apache.doris.load.sync.SyncJobManager;
 import org.apache.doris.statistics.StatisticsRepository;
 
@@ -320,6 +322,8 @@ public class DdlExecutor {
             env.getCatalogMgr().refreshCatalog((RefreshCatalogStmt) ddlStmt);
         } else if (ddlStmt instanceof AlterUserStmt) {
             env.getAuth().alterUser((AlterUserStmt) ddlStmt);
+        } else if (ddlStmt instanceof CleanProfileStmt) {
+            ProfileManager.getInstance().cleanProfile();
         } else if (ddlStmt instanceof DropTableStatsStmt) {
             // TODO: support later
         } else {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to