[core] Revert SQLite WAL journaling

This commit is contained in:
Jason Wray
2016-09-09 10:40:03 -04:00
parent ffa8c48926
commit 4daff7f2f8
3 changed files with 18 additions and 10 deletions

View File

@@ -49,7 +49,8 @@ void OfflineDatabase::ensureSchema() {
case 1: break; // cache-only database; ok to delete
case 2: migrateToVersion3(); // fall through
case 3: migrateToVersion4(); // fall through
case 4: return;
case 4: migrateToVersion5(); // fall through
case 5: return;
default: throw std::runtime_error("unknown schema version");
}
@@ -80,10 +81,10 @@ void OfflineDatabase::ensureSchema() {
// If you change the schema you must write a migration from the previous version.
db->exec("PRAGMA auto_vacuum = INCREMENTAL");
db->exec("PRAGMA synchronous = NORMAL");
db->exec("PRAGMA journal_mode = WAL");
db->exec("PRAGMA journal_mode = DELETE");
db->exec("PRAGMA synchronous = FULL");
db->exec(schema);
db->exec("PRAGMA user_version = 4");
db->exec("PRAGMA user_version = 5");
} catch (...) {
Log::Error(Event::Database, "Unexpected error creating database schema: %s", util::toString(std::current_exception()).c_str());
throw;
@@ -115,11 +116,17 @@ void OfflineDatabase::migrateToVersion3() {
}
void OfflineDatabase::migrateToVersion4() {
db->exec("PRAGMA synchronous = NORMAL");
db->exec("PRAGMA journal_mode = WAL");
db->exec("PRAGMA synchronous = NORMAL");
db->exec("PRAGMA user_version = 4");
}
void OfflineDatabase::migrateToVersion5() {
db->exec("PRAGMA journal_mode = DELETE");
db->exec("PRAGMA synchronous = FULL");
db->exec("PRAGMA user_version = 5");
}
OfflineDatabase::Statement OfflineDatabase::getStatement(const char * sql) {
auto it = statements.find(sql);

View File

@@ -61,6 +61,7 @@ private:
void removeExisting();
void migrateToVersion3();
void migrateToVersion4();
void migrateToVersion5();
class Statement {
public:

View File

@@ -559,18 +559,18 @@ TEST(OfflineDatabase, MigrateFromV2Schema) {
// v2.db is a v2 database containing a single offline region with a small number of resources.
deleteFile("test/fixtures/offline_database/v4.db");
writeFile("test/fixtures/offline_database/v4.db", util::read_file("test/fixtures/offline_database/v2.db"));
deleteFile("test/fixtures/offline_database/v5.db");
writeFile("test/fixtures/offline_database/v5.db", util::read_file("test/fixtures/offline_database/v2.db"));
{
OfflineDatabase db("test/fixtures/offline_database/v4.db", 0);
OfflineDatabase db("test/fixtures/offline_database/v5.db", 0);
auto regions = db.listRegions();
for (auto& region : regions) {
db.deleteRegion(std::move(region));
}
}
EXPECT_EQ(4, databaseUserVersion("test/fixtures/offline_database/v4.db"));
EXPECT_LT(databasePageCount("test/fixtures/offline_database/v4.db"),
EXPECT_EQ(5, databaseUserVersion("test/fixtures/offline_database/v5.db"));
EXPECT_LT(databasePageCount("test/fixtures/offline_database/v5.db"),
databasePageCount("test/fixtures/offline_database/v2.db"));
}