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

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 38c51a46bc50146026348cb4d6ef5bfd5a5ec0c3
Author: huanghaibin <284824...@qq.com>
AuthorDate: Fri Oct 13 19:51:55 2023 +0800

    [enhancement](compaction) record base compaction schedule time and status 
(#25283)
---
 be/src/olap/olap_server.cpp |  3 +++
 be/src/olap/tablet.cpp      | 11 +++++++++++
 be/src/olap/tablet.h        | 14 ++++++++++++++
 3 files changed, 28 insertions(+)

diff --git a/be/src/olap/olap_server.cpp b/be/src/olap/olap_server.cpp
index 4697bbc7939..369b0c48d87 100644
--- a/be/src/olap/olap_server.cpp
+++ b/be/src/olap/olap_server.cpp
@@ -631,6 +631,9 @@ void StorageEngine::_compaction_tasks_producer_callback() {
             /// If it is not cleaned up, the reference count of the tablet 
will always be greater than 1,
             /// thus cannot be collected by the garbage collector. 
(TabletManager::start_trash_sweep)
             for (const auto& tablet : tablets_compaction) {
+                if (compaction_type == CompactionType::BASE_COMPACTION) {
+                    
tablet->set_last_base_compaction_schedule_time(UnixMillis());
+                }
                 Status st = _submit_compaction_task(tablet, compaction_type, 
false);
                 if (!st.ok()) {
                     LOG(WARNING) << "failed to submit compaction task for 
tablet: "
diff --git a/be/src/olap/tablet.cpp b/be/src/olap/tablet.cpp
index f245e121fd9..1ce46547679 100644
--- a/be/src/olap/tablet.cpp
+++ b/be/src/olap/tablet.cpp
@@ -1447,6 +1447,15 @@ void Tablet::get_compaction_status(std::string* 
json_result) {
     format_str = 
ToStringFromUnixMillis(_last_full_compaction_success_millis.load());
     full_success_value.SetString(format_str.c_str(), format_str.length(), 
root.GetAllocator());
     root.AddMember("last full success time", full_success_value, 
root.GetAllocator());
+    rapidjson::Value base_schedule_value;
+    format_str = 
ToStringFromUnixMillis(_last_base_compaction_schedule_millis.load());
+    base_schedule_value.SetString(format_str.c_str(), format_str.length(), 
root.GetAllocator());
+    root.AddMember("last base schedule time", base_schedule_value, 
root.GetAllocator());
+    rapidjson::Value base_compaction_status_value;
+    
base_compaction_status_value.SetString(_last_base_compaction_status.c_str(),
+                                           
_last_base_compaction_status.length(),
+                                           root.GetAllocator());
+    root.AddMember("last base status", base_compaction_status_value, 
root.GetAllocator());
 
     // print all rowsets' version as an array
     rapidjson::Document versions_arr;
@@ -1762,6 +1771,7 @@ Status 
Tablet::prepare_compaction_and_calculate_permits(CompactionType compactio
         StorageEngine::instance()->create_base_compaction(tablet, 
_base_compaction);
         DorisMetrics::instance()->base_compaction_request_total->increment(1);
         Status res = _base_compaction->prepare_compact();
+        set_last_base_compaction_status(res.to_string());
         if (!res.ok()) {
             set_last_base_compaction_failure_time(UnixMillis());
             *permits = 0;
@@ -1899,6 +1909,7 @@ void Tablet::execute_compaction(CompactionType 
compaction_type) {
         });
 
         Status res = _base_compaction->execute_compact();
+        set_last_base_compaction_status(res.to_string());
         if (!res.ok()) {
             set_last_base_compaction_failure_time(UnixMillis());
             
DorisMetrics::instance()->base_compaction_request_failed->increment(1);
diff --git a/be/src/olap/tablet.h b/be/src/olap/tablet.h
index ba2b1ab587e..bbdeb411f44 100644
--- a/be/src/olap/tablet.h
+++ b/be/src/olap/tablet.h
@@ -258,6 +258,11 @@ public:
         _last_full_compaction_success_millis = millis;
     }
 
+    int64_t last_base_compaction_schedule_time() { return 
_last_base_compaction_schedule_millis; }
+    void set_last_base_compaction_schedule_time(int64_t millis) {
+        _last_base_compaction_schedule_millis = millis;
+    }
+
     void delete_all_files();
 
     void check_tablet_path_exists();
@@ -327,6 +332,12 @@ public:
         return _cumulative_compaction_policy;
     }
 
+    void set_last_base_compaction_status(std::string status) {
+        _last_base_compaction_status = status;
+    }
+
+    std::string get_last_base_compaction_status() { return 
_last_base_compaction_status; }
+
     inline bool all_beta() const {
         std::shared_lock rdlock(_meta_lock);
         return _tablet_meta->all_beta();
@@ -657,10 +668,13 @@ private:
     std::atomic<int64_t> _last_base_compaction_success_millis;
     // timestamp of last full compaction success
     std::atomic<int64_t> _last_full_compaction_success_millis;
+    // timestamp of last base compaction schedule time
+    std::atomic<int64_t> _last_base_compaction_schedule_millis;
     std::atomic<int64_t> _cumulative_point;
     std::atomic<int64_t> _cumulative_promotion_size;
     std::atomic<int32_t> _newly_created_rowset_num;
     std::atomic<int64_t> _last_checkpoint_time;
+    std::string _last_base_compaction_status;
 
     // cumulative compaction policy
     std::shared_ptr<CumulativeCompactionPolicy> _cumulative_compaction_policy;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to