Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] Update SQLite schema with WAL journal mode and normal sync #5796

Merged
merged 2 commits into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions platform/default/mbgl/storage/offline_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ void OfflineDatabase::ensureSchema() {
case 0: break; // cache-only database; ok to delete
case 1: break; // cache-only database; ok to delete
case 2: migrateToVersion3(); // fall through
case 3: return;
case 3: migrateToVersion4(); // fall through
case 4: return;
default: throw std::runtime_error("unknown schema version");
}

Expand Down Expand Up @@ -79,8 +80,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(schema);
db->exec("PRAGMA user_version = 3");
db->exec("PRAGMA user_version = 4");
} catch (...) {
Log::Error(Event::Database, "Unexpected error creating database schema: %s", util::toString(std::current_exception()).c_str());
throw;
Expand Down Expand Up @@ -111,6 +114,12 @@ void OfflineDatabase::migrateToVersion3() {
db->exec("PRAGMA user_version = 3");
}

void OfflineDatabase::migrateToVersion4() {
db->exec("PRAGMA synchronous = NORMAL");
db->exec("PRAGMA journal_mode = WAL");
db->exec("PRAGMA user_version = 4");
}

OfflineDatabase::Statement OfflineDatabase::getStatement(const char * sql) {
auto it = statements.find(sql);

Expand Down
1 change: 1 addition & 0 deletions platform/default/mbgl/storage/offline_database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class OfflineDatabase : private util::noncopyable {
void ensureSchema();
void removeExisting();
void migrateToVersion3();
void migrateToVersion4();

class Statement {
public:
Expand Down
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
### Other changes

* Fixed a crash that sometimes occurred when initializing an MGLMapView. ([#5932](https://github.com/mapbox/mapbox-gl-native/pull/5932))
* Improved offline and ambient cache database performance. ([#5796](https://github.com/mapbox/mapbox-gl-native/pull/5796))
* As the user zooms in, tiles from lower zoom levels are scaled up until tiles for higher zoom levels are loaded. ([#5143](https://github.com/mapbox/mapbox-gl-native/pull/5143))
* MGLMapDebugOverdrawVisualizationMask no longer has any effect in Release builds of the SDK. This debug mask has been disabled for performance reasons. ([#5555](https://github.com/mapbox/mapbox-gl-native/pull/5555))
* Fixed a typo in the documentation for the MGLCompassDirectionFormatter class. ([#5879](https://github.com/mapbox/mapbox-gl-native/pull/5879))
Expand Down
1 change: 1 addition & 0 deletions platform/macos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Fixed an issue causing code signing failures and bloating the framework. ([#5850](https://github.com/mapbox/mapbox-gl-native/pull/5850))
* Xcode 7.3 or higher is now required for using this SDK. ([#6059](https://github.com/mapbox/mapbox-gl-native/issues/6059))
* A new runtime styling API allows you to adjust the style and content of the base map dynamically. All the options available in [Mapbox Studio](https://www.mapbox.com/studio/) are now exposed via MGLStyle and subclasses of MGLStyleLayer and MGLSource. ([#5727](https://github.com/mapbox/mapbox-gl-native/pull/5727))
* Improved offline and ambient cache database performance. ([#5796](https://github.com/mapbox/mapbox-gl-native/pull/5796))
* Added `showAnnotations:animated:` and `showAnnotations:edgePadding:animated:`, which moves the map viewport to show the specified annotations. ([#5749](https://github.com/mapbox/mapbox-gl-native/pull/5749))
* To make an MGLPolyline or MGLPolygon span the antimeridian, specify coordinates with longitudes greater than 180° or less than −180°. ([#6088](https://github.com/mapbox/mapbox-gl-native/pull/6088))
* MGLMapView’s `styleURL` property can now be set to an absolute file URL. ([#6026](https://github.com/mapbox/mapbox-gl-native/pull/6026))
Expand Down
10 changes: 5 additions & 5 deletions test/storage/offline_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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/v3.db");
writeFile("test/fixtures/offline_database/v3.db", util::read_file("test/fixtures/offline_database/v2.db"));
deleteFile("test/fixtures/offline_database/v4.db");
writeFile("test/fixtures/offline_database/v4.db", util::read_file("test/fixtures/offline_database/v2.db"));

{
OfflineDatabase db("test/fixtures/offline_database/v3.db", 0);
OfflineDatabase db("test/fixtures/offline_database/v4.db", 0);
auto regions = db.listRegions();
for (auto& region : regions) {
db.deleteRegion(std::move(region));
}
}

EXPECT_EQ(3, databaseUserVersion("test/fixtures/offline_database/v3.db"));
EXPECT_LT(databasePageCount("test/fixtures/offline_database/v3.db"),
EXPECT_EQ(4, databaseUserVersion("test/fixtures/offline_database/v4.db"));
EXPECT_LT(databasePageCount("test/fixtures/offline_database/v4.db"),
databasePageCount("test/fixtures/offline_database/v2.db"));
}