weizuo93 commented on a change in pull request #5143:
URL: https://github.com/apache/incubator-doris/pull/5143#discussion_r549195382



##########
File path: be/src/olap/data_dir.cpp
##########
@@ -1018,4 +1018,163 @@ void DataDir::disks_compaction_score_increment(int64_t 
delta) {
 void DataDir::disks_compaction_num_increment(int64_t delta) {
     disks_compaction_num->increment(delta);
 }
+
+void DataDir::init_compaction_heap() {
+    for (std::set<TabletInfo>::iterator it = _tablet_set.begin(); it != 
_tablet_set.end(); it++) {
+        TabletSharedPtr tablet = 
StorageEngine::instance()->tablet_manager()->get_tablet(
+                it->tablet_id, it->schema_hash);
+        if (tablet != nullptr) {
+            push_tablet_into_compaction_heap(CompactionType::BASE_COMPACTION, 
tablet);
+            
push_tablet_into_compaction_heap(CompactionType::CUMULATIVE_COMPACTION, tablet);
+        }
+    }
+}
+
+void DataDir::push_tablet_into_compaction_heap(CompactionType compaction_type,
+                                               TabletSharedPtr tablet) {
+    OlapStopWatch watch;
+    if (compaction_type == CompactionType::BASE_COMPACTION) {
+        std::unique_lock<std::mutex> lock(_base_compaction_heap_mutex);
+        std::vector<TabletSharedPtr>::iterator it =
+                find(_base_compaction_heap.begin(), 
_base_compaction_heap.end(), tablet);
+        if (it == _base_compaction_heap.end()) {
+            _base_compaction_heap.push_back(tablet);
+        }
+        std::make_heap(_base_compaction_heap.begin(), 
_base_compaction_heap.end(),
+                       TabletScoreComparator(CompactionType::BASE_COMPACTION));

Review comment:
       @morningman 
   Because the `priority_queue` only supports pushing element through the rear 
of queue and popping element through the head of queue, but we need to pop an 
element through the `queue head` when selecting a tablet for compaction and pop 
an element through the `queue rear` when sacrificing a tablet. Thus 
`priority_queue`is not enough.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to