diff options
author | Andrew Chow <achow101-github@achow101.com> | 2021-04-07 20:55:09 -0400 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2021-04-12 19:29:03 -0400 |
commit | 41f891da508114f1fd4df30b4068073ec30abc2a (patch) | |
tree | 1b3e171dfbc7eadf4d503659e4c973dcc93c3d9d /src/wallet/sqlite.cpp | |
parent | cb79cabdd9d9a6d183cf09575dd46925f2c9cb3b (diff) | |
download | bitcoin-41f891da508114f1fd4df30b4068073ec30abc2a.tar.xz |
tests: Skip SQLite fsyncs while testing
Since we want tests to run quickly, and since tests do a lot more db
operations than expected we expect to see in actual usage, we disable
sqlite's syncing behavior to make db operations run much faster. This
syncing behavior is necessary for normal operation as it helps guarantee
that data won't become lost or corrupted, but in tests, we don't care
about that.
Diffstat (limited to 'src/wallet/sqlite.cpp')
-rw-r--r-- | src/wallet/sqlite.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/wallet/sqlite.cpp b/src/wallet/sqlite.cpp index 91891c5fc2..e245a277e4 100644 --- a/src/wallet/sqlite.cpp +++ b/src/wallet/sqlite.cpp @@ -233,6 +233,15 @@ void SQLiteDatabase::Open() throw std::runtime_error(strprintf("SQLiteDatabase: Failed to enable fullfsync: %s\n", sqlite3_errstr(ret))); } + if (gArgs.GetBoolArg("-unsafesqlitesync", false)) { + // Use normal synchronous mode for the journal + LogPrintf("WARNING SQLite is configured to not wait for data to be flushed to disk. Data loss and corruption may occur.\n"); + ret = sqlite3_exec(m_db, "PRAGMA synchronous = OFF", nullptr, nullptr, nullptr); + if (ret != SQLITE_OK) { + throw std::runtime_error(strprintf("SQLiteDatabase: Failed to set synchronous mode to OFF: %s\n", sqlite3_errstr(ret))); + } + } + // Make the table for our key-value pairs // First check that the main table exists sqlite3_stmt* check_main_stmt{nullptr}; |