Bug 1072773: Add a preference for enabling SQLite's synchronous=FULL mode in IndexedDB. r=bent

This commit is contained in:
Kyle Huey 2014-10-30 13:18:33 -07:00
parent 6c4a924701
commit bad15624f2
3 changed files with 31 additions and 0 deletions

View File

@ -2206,6 +2206,14 @@ SetDefaultPragmas(mozIStorageConnection* aConnection)
return rv;
}
if (IndexedDatabaseManager::FullSynchronous()) {
rv = aConnection->ExecuteSimpleSQL(
NS_LITERAL_CSTRING("PRAGMA synchronous = FULL;"));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
return NS_OK;
}

View File

@ -212,6 +212,7 @@ IndexedDatabaseManager::~IndexedDatabaseManager()
}
bool IndexedDatabaseManager::sIsMainProcess = false;
bool IndexedDatabaseManager::sFullSynchronousMode = false;
mozilla::Atomic<bool> IndexedDatabaseManager::sLowDiskSpaceMode(false);
// static
@ -299,6 +300,14 @@ IndexedDatabaseManager::Init()
Preferences::RegisterCallbackAndCall(TestingPrefChangedCallback,
kTestingPref);
// By default IndexedDB uses SQLite with PRAGMA synchronous = NORMAL. This
// guarantees (unlike synchronous = OFF) atomicity and consistency, but not
// necessarily durability in situations such as power loss. This preference
// allows enabling PRAGMA synchronous = FULL on SQLite, which does guarantee
// durability, but with an extra fsync() and the corresponding performance
// hit.
sFullSynchronousMode = Preferences::GetBool("dom.indexedDB.fullSynchronous");
return NS_OK;
}
@ -502,6 +511,16 @@ IndexedDatabaseManager::InTestingMode()
return gTestingMode;
}
// static
bool
IndexedDatabaseManager::FullSynchronous()
{
MOZ_ASSERT(gDBManager,
"FullSynchronous() called before indexedDB has been initialized!");
return sFullSynchronousMode;
}
already_AddRefed<FileManager>
IndexedDatabaseManager::GetFileManager(PersistenceType aPersistenceType,
const nsACString& aOrigin,

View File

@ -80,6 +80,9 @@ public:
static bool
InTestingMode();
static bool
FullSynchronous();
already_AddRefed<FileManager>
GetFileManager(PersistenceType aPersistenceType,
const nsACString& aOrigin,
@ -162,6 +165,7 @@ private:
mozilla::Mutex mFileMutex;
static bool sIsMainProcess;
static bool sFullSynchronousMode;
static mozilla::Atomic<bool> sLowDiskSpaceMode;
};