Merge issue-47-sqlite-wal: WAL frame admission and rollback reporting (closes #47)
This commit is contained in:
commit
a535f352d6
5 files changed
+364
-28
No files matched your search
@@ -140,6 +140,12 @@ namespace Void::Sqlite
|
||||
}
|
||||
return Void::Result::fail(std::move(c).error());
|
||||
}
|
||||
} else if (tx->state() != TransactionState::Committed) {
|
||||
// SQLite may end the transaction on its own (FULL, interrupt,
|
||||
// IO error). Never report the callback's success as durable.
|
||||
return Void::Result::fail(make_sqlite_error(
|
||||
SqliteErrorCode::misuse,
|
||||
"AsyncPool: transaction ended before commit (automatically rolled back)"));
|
||||
}
|
||||
return res;
|
||||
},
|
||||
|
||||
@@ -181,7 +181,8 @@ namespace Void::Sqlite
|
||||
};
|
||||
|
||||
/// RAII transaction retaining shared ConnectionState. Never marks Committed
|
||||
/// before COMMIT succeeds; inspects sqlite3_get_autocommit on error.
|
||||
/// before COMMIT succeeds; inspects sqlite3_get_autocommit on error and after
|
||||
/// statements so an automatic rollback is reported as RolledBack.
|
||||
class Transaction
|
||||
{
|
||||
public:
|
||||
@@ -192,11 +193,11 @@ namespace Void::Sqlite
|
||||
Transaction(const Transaction&) = delete;
|
||||
Transaction& operator=(const Transaction&) = delete;
|
||||
|
||||
[[nodiscard]] TransactionState state() const noexcept { return m_state; }
|
||||
[[nodiscard]] bool is_active() const noexcept
|
||||
{
|
||||
return m_state == TransactionState::Active;
|
||||
}
|
||||
/// Observes the native autocommit state; returns RolledBack when SQLite
|
||||
/// already ended this transaction (for example SQLITE_FULL or an
|
||||
/// interrupt inside the transaction).
|
||||
[[nodiscard]] TransactionState state() const noexcept;
|
||||
[[nodiscard]] bool is_active() const noexcept;
|
||||
|
||||
Result<void> commit();
|
||||
[[nodiscard]] Result<void> rollback_checked();
|
||||
@@ -204,10 +205,13 @@ namespace Void::Sqlite
|
||||
|
||||
private:
|
||||
friend class Database;
|
||||
explicit Transaction(std::shared_ptr<detail::ConnectionState> conn) noexcept;
|
||||
explicit Transaction(std::shared_ptr<detail::ConnectionState> conn,
|
||||
std::uint64_t id) noexcept;
|
||||
void refresh_state() const noexcept;
|
||||
|
||||
std::shared_ptr<detail::ConnectionState> m_conn{};
|
||||
TransactionState m_state{TransactionState::RolledBack};
|
||||
std::uint64_t m_id{0};
|
||||
mutable TransactionState m_state{TransactionState::RolledBack};
|
||||
};
|
||||
|
||||
/// Separately owned nested savepoint scope.
|
||||
|
||||
@@ -177,6 +177,8 @@ namespace Void::Sqlite
|
||||
std::size_t max_cached_statements{64};
|
||||
std::size_t max_cache_bytes{8ULL * 1024ULL * 1024ULL};
|
||||
std::chrono::milliseconds busy_timeout{5000};
|
||||
/// WAL thresholds are measured in un-checkpointed frames (converted to
|
||||
/// bytes with the database page size), not the raw on-disk WAL size.
|
||||
std::uint64_t wal_checkpoint_threshold_bytes{16ULL * 1024ULL * 1024ULL};
|
||||
std::uint64_t wal_warn_threshold_bytes{64ULL * 1024ULL * 1024ULL};
|
||||
std::uint64_t wal_stop_writes_threshold_bytes{256ULL * 1024ULL * 1024ULL};
|
||||
@@ -335,6 +337,8 @@ namespace Void::Sqlite
|
||||
struct CheckpointReport {
|
||||
int log_frames{0};
|
||||
int checkpointed_frames{0};
|
||||
/// Frames written to the WAL but not yet copied back into the database.
|
||||
int uncheckpointed_frames{0};
|
||||
bool busy{false};
|
||||
std::uint64_t wal_size_bytes{0};
|
||||
};
|
||||
@@ -364,6 +368,14 @@ namespace Void::Sqlite
|
||||
bool active_transaction{false};
|
||||
std::size_t open_savepoints{0};
|
||||
std::uint64_t wal_size_bytes{0};
|
||||
/// Whether the frame counts below were obtained from the WAL index. When
|
||||
/// false, `wal_uncheckpointed_bytes` is a conservative upper bound (the
|
||||
/// on-disk WAL size) and the frame counts are zero.
|
||||
bool wal_frames_known{false};
|
||||
int wal_log_frames{0};
|
||||
int wal_checkpointed_frames{0};
|
||||
int wal_uncheckpointed_frames{0};
|
||||
std::uint64_t wal_uncheckpointed_bytes{0};
|
||||
bool wal_checkpoint_recommended{false};
|
||||
bool wal_warn_exceeded{false};
|
||||
bool wal_write_admission_blocked{false};
|
||||
|
||||
Reference in new issue
Block a user