Skip to content

Commit 1a3e8e9

Browse files
committed
configurable sleep time for Litestream.verify!
When sync-interval is configured beyond the default, verify may appear to fail where it actually didn't wait long enough for replication.
1 parent f32a1bf commit 1a3e8e9

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Rails.application.configure do
106106
end
107107
```
108108

109-
However, if you need manual control over the Litestream configuration, you can manually edit the `config/litestream.yml` file. The full range of possible configurations are covered in Litestream's [configuration reference](https://litestream.io/reference/config/).
109+
However, if you need manual control over the Litestream configuration, you can manually edit the `config/litestream.yml` file. The full range of possible configurations are covered in Litestream's [configuration reference](https://litestream.io/reference/config/). NB: If you configure a longer `sync-interval`, you may need to adjust `replication_sleep` when calling `Litestream.verify!`.
110110

111111
### Replication
112112

@@ -221,7 +221,7 @@ You can verify the integrity of your backed-up databases using the gem's provide
221221
Litestream.verify! "storage/production.sqlite3"
222222
```
223223

224-
In order to verify that the backup for that database is both restorable and fresh, the method will add a new row to that database under the `_litestream_verification` table, which it will create if needed. It will then wait 10 seconds to give the Litestream utility time to replicate that change to whatever storage providers you have configured. After that, it will download the latest backup from that storage provider and ensure that this verification row is present in the backup. If the verification row is _not_ present, the method will raise a `Litestream::VerificationFailure` exception. This check ensures that the restored database file:
224+
In order to verify that the backup for that database is both restorable and fresh, the method will add a new row to that database under the `_litestream_verification` table, which it will create if needed. It will then wait `replication_sleep` seconds (defaults to 10) to give the Litestream utility time to replicate that change to whatever storage providers you have configured. After that, it will download the latest backup from that storage provider and ensure that this verification row is present in the backup. If the verification row is _not_ present, the method will raise a `Litestream::VerificationFailure` exception. This check ensures that the restored database file:
225225

226226
1. exists,
227227
2. can be opened by SQLite, and

lib/litestream.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ def initialize
3636
mattr_writer :username, :password, :queue, :replica_bucket, :replica_key_id, :replica_access_key, :systemctl_command
3737

3838
class << self
39-
def verify!(database_path)
39+
def verify!(database_path, replication_sleep: 10)
4040
database = SQLite3::Database.new(database_path)
4141
database.execute("CREATE TABLE IF NOT EXISTS _litestream_verification (id INTEGER PRIMARY KEY, uuid BLOB)")
4242
sentinel = SecureRandom.uuid
4343
database.execute("INSERT INTO _litestream_verification (uuid) VALUES (?)", [sentinel])
4444
# give the Litestream replication process time to replicate the sentinel value
45-
sleep 10
45+
sleep replication_sleep
4646

4747
backup_path = "tmp/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_#{sentinel}.sqlite3"
4848
Litestream::Commands.restore(database_path, **{"-o" => backup_path})

0 commit comments

Comments
 (0)