Skip to content

Commit

Permalink
Try restoring SQLite pragmas (#3338)
Browse files Browse the repository at this point in the history
(cherry picked from commit 5f51840)
  • Loading branch information
hdevalence authored and conorsch committed Dec 4, 2023
1 parent 3f209c7 commit b76e754
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/view/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,20 @@ impl Storage {
OpenFlags::default() & !OpenFlags::SQLITE_OPEN_URI,
)
.with_init(|conn| {
// "NORMAL" will be consistent, but maybe not durable -- this is fine,
// since all our data is being synced from the chain, so if we lose a dbtx,
// it's like we're resuming sync from a previous height.
conn.execute_batch("PRAGMA journal_mode=WAL; PRAGMA synchronous=NORMAL;")?;
// We use `prepare_cached` a fair amount: this is an overestimate of the number
// of cached prepared statements likely to be used.
conn.set_prepared_statement_cache_capacity(32);
Ok(())
});
Ok(r2d2::Pool::new(manager)?)
Ok(r2d2::Pool::builder()
// We set max_size=1 to avoid "database is locked" sqlite errors,
// when accessing across multiple threads.
.max_size(1)
.build(manager)?)
} else {
let manager = SqliteConnectionManager::memory();
// Max size needs to be set to 1, otherwise a new in-memory database is created for each
Expand Down

0 comments on commit b76e754

Please sign in to comment.