Sqlite: report unknown commit outcome after WAL I/O error (VL-SQLITE-02)

- Add TransactionState::Unknown: a failed COMMIT whose outcome cannot be
  proven (WAL I/O error after the commit record may be durable) is never
  reported as RolledBack.
- Keep the transaction Active when SQLite leaves it open after the error;
  reject commit/rollback on an Unknown transaction with a clear error.
- Extend the fault guard with commit_applied_before_error to model a lost
  commit acknowledgement, and cover Unknown, Active-retry and
  rollback-journal RolledBack paths.
This commit is contained in:
faumaray committed 2026-12-03 18:17:17 +03:00
1 parent 0002e74a7d
commit 7eaa96f9da
4 files changed
+165 -11

No files matched your search

+7 -1
View File
@@ -182,7 +182,9 @@ namespace Void::Sqlite
/// RAII transaction retaining shared ConnectionState. Never marks Committed
/// before COMMIT succeeds; inspects sqlite3_get_autocommit on error and after
/// statements so an automatic rollback is reported as RolledBack.
/// statements so an automatic rollback is reported as RolledBack. A failed
/// COMMIT whose outcome cannot be proven (WAL I/O error) is reported as
/// Unknown, never as RolledBack.
class Transaction
{
public:
@@ -199,6 +201,10 @@ namespace Void::Sqlite
[[nodiscard]] TransactionState state() const noexcept;
[[nodiscard]] bool is_active() const noexcept;
/// Commits the transaction. On failure state() is Active (SQLite kept
/// the transaction open; retry or roll back), RolledBack (SQLite ended
/// it and it was not committed), or Unknown (SQLite ended it but a WAL
/// I/O error means the commit may have taken effect).
Result<void> commit();
[[nodiscard]] Result<void> rollback_checked();
void rollback() noexcept;
+17 -1
View File
@@ -49,10 +49,22 @@ namespace Void::Sqlite
};
enum class TransactionState : std::uint8_t {
/// The transaction is open; statements execute inside it.
Active,
/// COMMIT succeeded and the transaction is durable.
Committed,
/// SQLite ended the transaction without committing it (explicit or
/// automatic rollback, or the transaction never started).
RolledBack,
RecoveryRequired
/// The connection or rollback state is unusable; the application must
/// recover before continuing.
RecoveryRequired,
/// COMMIT failed and SQLite ended the transaction, but the wrapper cannot
/// prove whether the commit took effect. A WAL I/O error can be reported
/// after the commit record became durable, so this must never be treated
/// as a definite rollback: inspect the database before assuming either
/// outcome.
Unknown
};
enum class ColumnType : std::uint8_t {
@@ -394,6 +406,10 @@ namespace Void::Sqlite
/// If true along with fail_next_commit_rc, simulates SQLite
/// auto-rollback before returning the error.
bool auto_rollback_on_faulted_commit{false};
/// If true along with fail_next_commit_rc, the COMMIT is executed and
/// committed first, and the error is reported afterwards. Models a lost
/// commit acknowledgement, where the outcome is genuinely unknown.
bool commit_applied_before_error{false};
/// If non-zero, next explicit close() returns this SQLite error code.
int fail_next_close_rc{0};
};