hello-stephen commented on code in PR #70916:
URL: https://github.com/apache/doris/pull/70916#discussion_r4766075377
##########
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:
[P1] Preserve the acknowledged prefix when a later WAL append tears
With `group_commit_wal_sync_before_ack=true`, A can be synced/ACKed here
while the internal transaction is still open and another producer appends B. A
power failure on a filesystem without safe append (e.g. [ext4
`data=writeback`](https://www.kernel.org/doc/html/v6.9/admin-guide/ext4.html#options))
can preserve the enlarged file size but leave B's length word zero.
`WalFileReader::read_block()` then returns `DATA_QUALITY_ERROR`;
`WalTable::_handle_stream_load()` exits on the failed future before committing
A, and `_relay_wal_one_by_one()` treats that error as success and deletes the
entire WAL. A is therefore lost despite its successful durable ACK.
`_wal_synced_offset` only exists in memory, and the updated tail test covers
physical truncation of a finalized file. Preserve a recoverable durable
boundary (or isolate durable prefixes) before ACK and cover a synced A followed
by an extended zero/malformed B tail.
--
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]