sollhui commented on code in PR #70916:
URL: https://github.com/apache/doris/pull/70916#discussion_r4794956221


##########
be/src/load/group_commit/group_commit_mgr.cpp:
##########
@@ -199,11 +211,91 @@ Status LoadBlockQueue::get_block(RuntimeState* 
runtime_state, Block* block, bool
     return Status::OK();
 }
 
-Status LoadBlockQueue::remove_load_id(const UniqueId& load_id) {
-    std::unique_lock l(mutex);
-    if (_load_ids_to_write_dep.find(load_id) != _load_ids_to_write_dep.end()) {
-        _load_ids_to_write_dep[load_id]->set_always_ready();
-        _load_ids_to_write_dep.erase(load_id);
+Status LoadBlockQueue::finish_wal_load(const UniqueId& load_id, size_t target,
+                                       std::shared_ptr<WalSyncWaiter> waiter, 
GroupCommitMgr& mgr) {
+    std::lock_guard lock(mutex);
+    RETURN_IF_ERROR(status);
+    if (_wal_closing) {
+        return Status::Cancelled("group commit WAL is closing");
+    }
+    target = std::max(target, _wal_header_end);
+    // A cached prepared statement can reuse this ID while the old execution's 
ACK is pending.
+    // Release its producer slot at EOS. The waiter belongs only to this 
execution.
+    RETURN_IF_ERROR(_remove_load_id_without_lock(load_id));
+    if (target <= _wal_synced_offset) {
+        waiter->result = Status::OK();
+        return Status::OK();
+    }
+    _pending_wal_acks.push_back({target, waiter});
+    waiter->finish_dep->block();
+    if (!_wal_sync_in_progress) {
+        _wal_sync_in_progress = true;
+        Status st;
+        ASSIGN_STATUS_IF_CATCH_EXCEPTION(
+                st = mgr.submit_wal_sync([queue = shared_from_this()] { 
queue->_run_wal_sync(); }),
+                st);
+        if (!st.ok()) {
+            _wal_sync_in_progress = false;
+            _cancel_without_lock(st);
+            return st;
+        }
+    }
+    return Status::OK();
+}
+
+void LoadBlockQueue::_run_wal_sync() {
+    std::unique_lock lock(mutex);
+    while (!_pending_wal_acks.empty()) {
+        // Appends after this snapshot can overlap the syscall, but are only
+        // credited by a later successful sync.
+        const size_t target = _wal_appended_offset;
+        lock.unlock();
+        Status st;
+        ASSIGN_STATUS_IF_CATCH_EXCEPTION(st = _v_wal_writer->sync(), st);
+        lock.lock();
+        if (!st.ok()) {
+            _cancel_without_lock(st);
+            break;
+        }
+        _wal_synced_offset = target;

Review Comment:
   This is not a problem introduced by PR, but an existing issue. We plan to 
fix it separately in the future.



-- 
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.

To unsubscribe, e-mail: [email protected]

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