Commit Graph

36 Commits

Author SHA1 Message Date
Konstantin Käfer
86682f2507 [core] fix undefined access for HTTP responses that don't contain a body 2017-07-13 17:54:18 +02:00
Konstantin Käfer
62ea1f2185 [core] remove trailing whitespace, add trailing newlines, add space after // 2017-01-27 11:44:16 +01:00
Bruno de Oliveira Abinader
eb772258cf [core] Replace sqlite3.h dependency in offline database 2017-01-23 19:06:53 +02:00
Bruno de Oliveira Abinader
80d72123df [core] Move lastInsertRowId/changes to sqlite::Statement 2017-01-23 19:06:53 +02:00
Eric Wolfe
a2ceeb4a5b [core] Evict cached resources and tiles equally by access time (#7770) 2017-01-18 18:43:24 -08:00
Konstantin Käfer
e76de05402 [build] move logging to util 2016-11-22 20:58:51 +01:00
Tore Halset
a4b79ac289 [core] Optimize OfflineDownload::ensureResource (#6707)
Add `OfflineDatabase::hasRegionResource`, for use when the actual contents are not needed by the caller, avoiding IO and decompression costs.
2016-10-17 09:27:07 -07:00
Molly Lloyd
598f7c6ad5 [core] allow offline region metadata to be updated (#6338) 2016-09-20 17:43:00 +02:00
Jason Wray
0bdd968d2b [core] Remove schema v4 migration path 2016-09-14 15:49:00 -04:00
Jason Wray
4daff7f2f8 [core] Revert SQLite WAL journaling 2016-09-14 15:45:47 -04:00
Jason Wray
74f094faab [core] Update SQLite schema with WAL journal mode and normal sync
Offers 2×-4× performance, depending on device vintage.
2016-08-23 13:26:02 -04:00
Konstantin Käfer
77e7846756 [core] code style cleanups
- puts function definitions in a namespace ... {} rather than using namespace ...;
- remove trailing whitespace
- add trailing newline
- protect SQL statements from being formatted by clang-format
2016-07-01 12:38:33 +02:00
Bruno de Oliveira Abinader
4161d197fd [tidy] Check modernize-pass-by-value
Ref: http://clang.llvm.org/extra/clang-tidy/checks/modernize-pass-by-value.html
2016-06-13 23:32:05 +03:00
Konstantin Käfer
cd65a43855 [core] move from microsecond precision timestamp to integer second precision 2016-05-13 17:24:22 +02:00
Konstantin Käfer
7332ae0073 [core] retain tiles differently and remove old TileID class 2016-05-10 14:50:56 +02:00
John Firebaugh
b39f22e6b6 [core] Refactor getRegionCompletedStatus; add completedTileCount; add tests 2016-04-27 13:41:29 -07:00
Brent Whitman
a706a2a48d [ios, osx] Add a property for bytes used by offline tiles 2016-04-27 13:41:29 -07:00
John Firebaugh
18d8e80f52 [core] Demote "Unable to make space for entry" message from Warning to Debug (#4708) 2016-04-14 13:43:24 -07:00
John Firebaugh
c3bed1dab8 [core] Fix race condition that could lead to a UNIQUE constraint failure (#4677) 2016-04-11 19:46:45 -07:00
John Firebaugh
13882a31e4 [core] Set schema version to 3 after upgrading
The migration was upgrading the schema, but not the schema version. As a result, the (expensive) migration was running every time an OfflineDatabase was constructed with a v2 database.

Fixes #4501
2016-03-28 17:28:44 -07:00
John Firebaugh
90d271709f [core] Add additional logging for exceptions during database connection / creation
Refs #4382
2016-03-18 17:09:43 -07:00
John Firebaugh
5130ca8843 [core] Implement a vacuum strategy for the offline database
Enable `PRAGMA auto_vacuum = INCREMENTAL`, and perform a `PRAGMA incremental_vacuum` when deleting an offline region.
2016-03-17 14:17:59 -07:00
John Firebaugh
eb9b463841 [core] Fix offline status reporting with pre-existing tiles (#4147) 2016-03-04 15:15:09 -08:00
John Firebaugh
065cda83fa [core] Limit total number of offline Mapbox tiles 2016-02-24 13:38:14 -08:00
John Firebaugh
5cefaeb857 [core] Enforce foreign key constraints in the offline database 2016-02-24 13:38:14 -08:00
John Firebaugh
1bdeddab2c [core] Fix subtle bug in OfflineDatabase with updated resources
SQLite REPLACE is *not* UPSERT. If a conflict occurs, it first deletes the existing row, then inserts a new row. This means that AUTOINCREMENT primary keys change. This will break foreign keys to that value, which we use.

Instead we must try an UPDATE, and fall back to an INSERT if the UPDATE changes zero rows.
2016-02-24 13:38:14 -08:00
Konstantin Käfer
bd08984713 [core] return std::move() prevents copy elision 2016-02-11 12:15:40 +01:00
John Firebaugh
7e287cae1b [core] Eliminate tilesets table
This results in a ~1% increase in database size, which is worth it for reducing complexity and making the tiles and resources tables more similar in structure.
2016-02-10 16:25:44 -08:00
John Firebaugh
40ecdeb0b6 [core] Optimize offline database schema
* Under the hood, SQLite creates surrogate keys (ROWID) anyway. We may as well take advantage of this and use the surrogates for foreign keys as well, since they are simpler and more efficient than compound foreign keys.
* Create indexes for efficient eviction queries
2016-02-10 15:40:20 -08:00
John Firebaugh
a9e0c1b99a [core] Eliminate maximumCacheEntrySize
Instead, the eviction policy accounts for the actual size needed for an incoming put.
2016-02-10 15:40:20 -08:00
John Firebaugh
db3620c58f [core] Implement an eviction policy for OfflineDatabase
When inserting an cached resource, or removing a region, remove least-recently used resources and tiles, not used by offline regions, until the used database size, as calculated by multiplying the number of in-use pages by the page size, is less than the maximum cache size minus 5 times the page size.

In addition, OfflineDatabase may be configured to ignore cache puts of individual resources larger than a certain size.

This policy is similar but not identical to the former SQLiteCache policy:

* It accounts for offline, by exempting resources required by offline regions from eviction.
* It must delete from two tables (resources and tiles), rather than one. Currently the strategy is naive: evict 50 rows at a time from each table.
* It makes maximumCacheSize and maximumCacheEntrySize completely independent. The SQLiteCache implementation evicted when `usedSize > maximumCacheSize - 2 * maximumCacheEntrySize`. This evicts when `usedSize > maximumCacheSize - 5 * pageSize`.
* It uses a non-unlimited default value for maximumCacheSize: 50 MB. We should have always had a limit in place; "a cache without an eviction policy is a resource leak".
2016-02-10 15:40:20 -08:00
John Firebaugh
5910124010 [core] Reset SQLite statements after use in order to release locks 2016-02-10 15:40:20 -08:00
John Firebaugh
96e0e5252e [core] Disable SQLite busy timeouts so that multiple readers can access the same database 2016-02-10 15:40:20 -08:00
John Firebaugh
c3c4c7b9a6 [core] Interface and implementation for offline 2016-02-10 15:40:20 -08:00
John Firebaugh
e9302c797f [all] Don't interpret 404s on non-tile resources as "no content" 2016-02-10 15:40:20 -08:00
John Firebaugh
cdedb66387 [core] Reimplement existing caching within an offline-capable database schema 2016-02-10 15:40:20 -08:00