alvarotuso commented on code in PR #70916:
URL: https://github.com/apache/doris/pull/70916#discussion_r4787505675
##########
be/src/load/group_commit/group_commit_mgr.cpp:
##########
@@ -799,6 +895,11 @@ GroupCommitMgr::GroupCommitMgr(ExecEnv* exec_env) :
_exec_env(exec_env) {
.set_min_threads(1)
.set_max_threads(config::group_commit_insert_threads)
.build(&_thread_pool));
+ CHECK(ThreadPoolBuilder("GroupCommitWalSync")
+ .set_min_threads(0)
+ .set_max_threads(2)
Review Comment:
Could we make this configurable? A BE getting a lot of requests may starve
other tables and since these threads are mostly waiting for fsync they will be
cheap
##########
be/src/load/group_commit/group_commit_mgr.cpp:
##########
@@ -241,10 +333,14 @@ void LoadBlockQueue::cancel(const Status& st) {
}
void LoadBlockQueue::_cancel_without_lock(const Status& st) {
+ if (!status.ok()) {
+ return; // Preserve the first error for callers and pending ACKs.
+ }
LOG(INFO) << "cancel group_commit, instance_id=" << load_instance_id << ",
label=" << label
<< ", status=" << st.to_string();
status =
Status::Cancelled("cancel group_commit, label=" + label + ",
status=" + st.to_string());
+ _complete_wal_acks();
Review Comment:
Pending ACKs can fail even though their rows are durable and will be replayed
`_cancel_without_lock` fails every pending ACK through
`_complete_wal_acks()`. Many cancellations are unrelated to WAL durability:
- another producer’s write_wal failing,
- the internal load fragment being cancelled or timing out (get_block),
- the internal load failing in _finish_group_commit_load.
In each case the failed batch goes to `add_recover_wal`, so replay still
commits these producers’ rows.
Example: A reaches EOS and registers an ACK, and the worker starts fdatasync
covering A. Before it returns, the internal load fails and the queue is
cancelled, so A gets an error. The sync then succeeds, but the ACK list is
already empty. A’s rows are durable and are committed by replay. If A’s client
retries after the error, the rows land twice. Without this PR, A would have
been acknowledged after its append and replay would have delivered the rows
exactly once, so this is a new duplicate path when
`group_commit_wal_sync_before_ack=true`.
Suggestion: decide each ACK from the WAL sync result alone. On a
cancellation that isn’t a sync failure, keep the pending ACKs. Let the running
or a final sync (for example in close_wal(), which already waits for the
worker) complete them with OK. Fail them only when the sync itself fails, or
when the WAL won’t be replayed.
##########
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:
Our internal review also flagged this ^
--
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]