chg: Enable ACID by default

This commit is contained in:
SinTan1729
2025-10-23 15:00:34 -05:00
parent 6dacbc086f
commit a575700cac
6 changed files with 18 additions and 18 deletions

View File

@@ -108,25 +108,24 @@ data loss in that case.
If this is enabled, there'll be a significant boost in performance under high load, since write will no longer block reads.
Also, automated backups of the database will be enabled. Otherwise, `DELETE` journal mode is used by default, along with
[`FULL` synchronous](https://sqlite.org/pragma.html#pragma_synchronous) pragma. In `WAL` mode, `NORMAL` synchronous pragma is
used instead. In both cases, we do technically lose Durability, but in my view, it is an acceptable compromise for this
use case. If you disagree, read on to the next configuration option.
[`EXTRA` synchronous](https://sqlite.org/pragma.html#pragma_synchronous) pragma. In `WAL` mode, `FULL` synchronous pragma is
used instead.
_Note: There might be a data loss only in case of system failure or power loss. And you should only lose the data stored
after the last sync with the database file. So, under normal loads, you shouldn't lose any data anyway. But this is a real
thing that can technically happen._
In both cases, we have full ACID compliance, but it does cost a bit of performance. If you expect to see high throughput (in the
order of hundreds of read/writes per second), take a look at the `ensure_acid` configuration option.
### `ensure_acid`
By default, the database set set up as Atomic, Consistent, and Isolated; but not Durable. If you want full
[ACID](https://www.slingacademy.com/article/acid-properties-in-sqlite-why-they-matter) compliance, set this to
`True`. Any other value will be ignored.
By default, the database is
[ACID (i.e. Atomic, Consistent, Isolated, and Durable)](https://www.slingacademy.com/article/acid-properties-in-sqlite-why-they-matter).
If you'd like to let go of durability for an increase in throughput, set this to `False`. Any other value will be ignored.
This is done by setting the [synchronous pragma](https://sqlite.org/pragma.html#pragma_synchronous) to `FULL` in `WAL`
[journal mode](https://sqlite.org/pragma.html#pragma_journal_mode), and to `EXTRA` in `DELETE` journal mode.
_Note: This will impact performance, and will only make any difference if a power loss or system crash happens. Durability
is maintained even without this option in case of an application crash._
_Note: There might be partial data loss only in case of system failure or power loss. Durability is maintained across application
crashes. If you do have data loss, you should only lose the data stored after the last sync with the database file. So, under normal
loads, you shouldn't lose any data anyway. But this is a real thing that can technically happen._
### `redirect_method` \#

View File

@@ -71,7 +71,8 @@ Password: `chhoto-url-demo-pass`
time for public instances, which might be useful.
- Allows setting the URL of your website, in case you want to conveniently
generate short links locally.
- Links are stored in an SQLite database.
- Links are stored in an SQLite database, which is configured to be ACID by default.
Options are available for tuning the database to the user's liking.
- Available as a Docker container with a provided compose file.
- Backend written in Rust using [Actix Web](https://actix.rs/), and frontend
written in plain HTML and vanilla JS, using [Pure CSS](https://purecss.io/)

View File

@@ -177,7 +177,7 @@ pub fn read() -> Config {
} else {
warn!("Using DELETE journaling mode for database. WAL mode is recommended. (Please read the docs.)");
}
let ensure_acid = var("ensure_acid").is_ok_and(|s| s.trim() == "True");
let ensure_acid = !var("ensure_acid").is_ok_and(|s| s.trim() == "False");
if ensure_acid {
let synchronous = if use_wal_mode { "FULL" } else { "EXTRA" };
info!("Ensuring ACID compliance, using synchronous pragma: {synchronous}.");

View File

@@ -16,7 +16,7 @@ DropCapability=ALL
# Environment variables
Environment=db_url=/db/urls.sqlite
Environment=use_wal_mode = True
Environment=ensure_acid = False
#Environment=ensure_acid = True
#Environment=site_url=https://www.example.com
#Environment=hash_algorithm=Argon2
Environment=password=TopSecretPass

View File

@@ -33,9 +33,9 @@ services:
# (In fact, I'd suggest that you do that so that you can keep
# a copy of your database.)
# - use_wal_mode = True
# If you'd like to enable ACID compliance, uncomment the next line.
# Note that it'll impact performance. Look at the README for more.
# - ensure_acid = True
# If you'd like to disable ACID compliance, uncomment the next line.
# Note that there are risks. Look at the README for more.
# - ensure_acid = False
# Change this if your server URL is not "http://localhost"
# This must not be surrounded by quotes. For example:

View File

@@ -28,7 +28,7 @@ allow_capital_letters: False
# custom_landing_directory: "/custom/dir/location"
# cache_control_header: "no-cache, private"
use_wal_mode: True
# ensure_acid: True
# ensure_acid: False
protocol: https
fqdn: your.short.link.url.com