aboutsummaryrefslogtreecommitdiff
path: root/crates/tor-dirserver/src/database.rs
Commit message (Collapse)AuthorAgeFilesLines
...
* tor-dirserver: Support for inserting into storeClara Engler2026-01-151-3/+215
| | | | | | | | This commit implements support for adding arbitrary documents into the store table. It is non-trivial because the relevant data has to be compressed into various formats, so it can be retrieved without delays.
* tor-dirserver: `From<Timestamp> for SystemTime`Clara Engler2026-01-151-0/+6
| | | | | | The reverse direction already exists and it will be required when we act with functions outside the crate that only accept a `SystemTime` in situations where we just have a `Timestamp`.
* tor-dirserver: Add `dir_key_published` to schemaClara Engler2026-01-151-1/+4
|
* tor-dirserver: Eliminate use of sleep in testsClara Engler2026-01-131-38/+58
| | | | | | | | | | | | This commit eliminates the use of sleep in database tests because those can be flaky, especially when the CI scheduler is overloaded, leading to potential timeout invariants not holding true anymore. We now fix this by using synchronization primitives from Rust in order for threads to communicate. Documentation has been added explaining how these tests work in greater detail. Fixes #2308
* tor-dirserver: Improve database::TimestampClara Engler2025-11-271-14/+59
| | | | | | | | | | This commit improves upon the work made in arti!3460, by establishing the `database::Timestamp` type as a general purpose type for the handling of timestamp throughout the code base. It also replaces all previous occurrences of `SystemTime` within `dirmirror::operation`, which leads to the reduction of code complexity in one particular function, namely `calculate_sync_timeout`.
* tor-dirserver: Use `saturating-time`Clara Engler2025-11-261-2/+49
| | | | | | | This commit replaces the custom implementation of `SaturatingSystemTime` with the `saturating-time` crate, additionally adding a new type to the `database` module called `Timestamp`, in order to have a convenient wrapper around `ToSql` and `FromSql`.
* Fix name of clippy lint to unchecked_time_subtraction (2)Ian Jackson2025-11-061-1/+1
| | | | Run maint/add_warning
* tor-dirserver: Ensure positive timestampsClara Engler2025-10-301-1/+5
| | | | | This commit adds `CHECK` constraints to the database schema in order to ensure all timestamps are positive.
* tor-dirserver: Small database::open() improvementsClara Engler2025-10-301-115/+58
|
* tor-dirserver: Make database full syncClara Engler2025-10-301-136/+125
| | | | | | | | | | This commit makes the entire database operations synchronous, thereby replacing deadpool with r2d2. The full motivation is outlined in a rustdoc comment at the top of the `database` module, but it can be summarized to the fact that SQLite is by design inherently synchronous due to directly interfacing with the file system.
* tor-dirserver: Implement read_tx and rw_txClara Engler2025-10-301-55/+351
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit does a large overhaul in the overall way on how we interact with SQLite. Although SQLite is a fairly straightforward tool, it has one large caveat, namely the handling of the infamous `SQLITE_BUSY` error. In WAL mode, the journaling mode we are using, the respective error may occur if there is an existing write transaction while another thread is trying to either upgrade an existing read transaction or create an exclusive transaction at the same time. In this case, SQLite will fail at the statement that either requires the write operation or at the creation of the transaction respectively. In order to tackle this problem, SQLite provides the `busy_timeout` pragma, which allows specifying a timeout in milliseconds during which SQLite will retry to obtain a write transaction or fail immediately. This only works in the latter case, that is, creating a write transaction from the beginning. To solve this issue, we introduce two new functions: 1. `database::read_tx` 2. `database::rw_tx` Both functions accept a database pool alongside a closure accepting a `Transaction` and returning an arbitrary return value. The first function creates a deferred transaction that gets rolled-back in the end, making it suitable for read-only connections. The latter function creates an exclusive transaction that gets committed in the end, making it suitable for read-write connections. This also honors the `busy_timeout`, i.e. the function retries for up to 1s to acquire a write transaction before failing ultimately.
* tor-dirmirror: Introduce the `sql!` macroClara Engler2025-10-301-2/+19
| | | | | | This commit introduces the no-op sql macro used to mark string literals as SQL statements. It is purely semantical and serves the purpose to quickly identify string literals as SQL statements.
* tor-dirserver: Don't expose rusqlite::Error in PoolClara Engler2025-10-151-2/+11
|
* tor-dirserver: Create database moduleClara Engler2025-10-151-0/+295
This commit renames the schema module to the database module in order to perform better error handling while redesigning the API.