mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
wallet: sqlite: there is no need to have exclusive locking when mocking
For in-memory SQLite databases, exclusive locking is generally not necessary because in-memory dbs are private to the connection that created them.
This commit is contained in:
parent
ba8d151fe0
commit
72a424e60a
1 changed files with 12 additions and 9 deletions
|
@ -278,15 +278,18 @@ void SQLiteDatabase::Open()
|
|||
|
||||
// Acquire an exclusive lock on the database
|
||||
// First change the locking mode to exclusive
|
||||
SetPragma(m_db, "locking_mode", "exclusive", "Unable to change database locking mode to exclusive");
|
||||
// Now begin a transaction to acquire the exclusive lock. This lock won't be released until we close because of the exclusive locking mode.
|
||||
int ret = sqlite3_exec(m_db, "BEGIN EXCLUSIVE TRANSACTION", nullptr, nullptr, nullptr);
|
||||
if (ret != SQLITE_OK) {
|
||||
throw std::runtime_error("SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another instance of " CLIENT_NAME "?\n");
|
||||
}
|
||||
ret = sqlite3_exec(m_db, "COMMIT", nullptr, nullptr, nullptr);
|
||||
if (ret != SQLITE_OK) {
|
||||
throw std::runtime_error(strprintf("SQLiteDatabase: Unable to end exclusive lock transaction: %s\n", sqlite3_errstr(ret)));
|
||||
int ret;
|
||||
if (!m_mock) {
|
||||
SetPragma(m_db, "locking_mode", "exclusive", "Unable to change database locking mode to exclusive");
|
||||
// Now begin a transaction to acquire the exclusive lock. This lock won't be released until we close because of the exclusive locking mode.
|
||||
ret = sqlite3_exec(m_db, "BEGIN EXCLUSIVE TRANSACTION", nullptr, nullptr, nullptr);
|
||||
if (ret != SQLITE_OK) {
|
||||
throw std::runtime_error("SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another instance of " CLIENT_NAME "?\n");
|
||||
}
|
||||
ret = sqlite3_exec(m_db, "COMMIT", nullptr, nullptr, nullptr);
|
||||
if (ret != SQLITE_OK) {
|
||||
throw std::runtime_error(strprintf("SQLiteDatabase: Unable to end exclusive lock transaction: %s\n", sqlite3_errstr(ret)));
|
||||
}
|
||||
}
|
||||
|
||||
// Enable fullfsync for the platforms that use it
|
||||
|
|
Loading…
Add table
Reference in a new issue