Commit Graph

494 Commits

Author SHA1 Message Date
Joshua Baxter
b3c20232f1 docs: fixed typo
am: 3639e2f929

Change-Id: I6f7381045bb25fdcc9f86e3e2dd0d7b8c4eda853
2018-03-27 17:34:53 +00:00
Joshua Baxter
3639e2f929 docs: fixed typo
Test: make ds-docs

Bug: 36941741

Change-Id: I451d8095bcc5d30dbefe3503441d718a69d821ca
2018-03-26 18:17:08 -07:00
Fyodor Kupolov
681ec3128e Include additional information in the dumpsys
Test: adb shell dumpsys dbinfo system
Bug: 64262688
Change-Id: I43d76e505e4d5598994c9af3e615c572017f120c
2018-03-20 18:50:07 -07:00
Fyodor Kupolov
692573b1b2 Introduced DISABLE_COMPATIBILITY_WAL flag
If set, Compatibility WAL will not be used.
Currently this flag is set if SQLiteOpenHelper.setWriteAheadLogging(false)
is called before opening the database. Previously this call was ignored
since ENABLE_WRITE_AHEAD_LOGGING flag is only set when setWriteAheadLogging(true)

Test: CtsDatabaseTestCases
Bug: 74116447
Change-Id: Ic486e178b9da5d747840be739303a2685b91f35b
2018-03-06 13:31:30 -08:00
Fyodor Kupolov
ab05b143ba Added SQLiteOpenHelper.setOpenParams
Using the new constructor can be difficult as it requires an app to
make a decision which version of constructor to use before instantiating
the object. By adding setOpenParams method, apps can keep the old
structure of the code and only add API level check after instantiating
a helper object.

Test: SQLiteOpenHelperTest
Bug: 70863722
Change-Id: I1705dd790e3549d0d8e75eb33b1d9b5bdadcb3c9
2018-02-12 15:33:13 -08:00
Andreas Gampe
3f24e69dbe Frameworks: Annotate trivial @GuardedBy in core/java
Add @GuardedBy for simple functions that require a single lock
and are named XYZLocked.

Bug: 73000847
Test: m
Test: m javac-check-framework RUN_ERROR_PRONE=true
Change-Id: Icb5114fea2ff2385e1cc7511121026099e05c0ee
2018-02-08 02:19:42 -08:00
Fyodor Kupolov
a17858d072 Merge "Fix JavaDoc for enableWriteAheadLogging" 2018-02-07 01:51:57 +00:00
Jeff Sharkey
ad357d1839 Pass in the user defined by Context.
The majority of Manager-style classes already use Context.getUserId()
when making calls into the OS, so clean up the remaining callers to
unify behind this strategy.

This gives @SystemApi developers a nice clean interface to interact
across user boundaries, instead of manually adding "AsUser" or
"ForUser" method variants, which would quickly become unsustainable.

Test: builds, boots
Bug: 72863821
Exempt-From-Owner-Approval: trivial changes
Change-Id: Ib772ec4438e57a2ad4950821b9432f9842998451
2018-02-03 02:11:45 +00:00
Fyodor Kupolov
4b5c35984c Fix JavaDoc for enableWriteAheadLogging
Test: build
Bug: 65206410
Bug: 64262688
Change-Id: I92e27b048ae8717c5007ac39d6a6de7b59dc7072
2018-02-02 14:57:50 -08:00
Chris Craik
0834e3561e @FastNative for CursorWindow
Test: adb install -r $OUT/data/app/CorePerfTests/CorePerfTests.apk && adb shell cmd package compile -m speed -f com.android.perftests.core && adb shell am instrument -w -e class android.database.CursorWindowPerfTest com.android.perftests.core/android.support.test.runner.AndroidJUnitRunner

Change-Id: I4d2f8846592426b993ca44a187ac0e2de7313170
2018-01-26 15:03:49 -08:00
Fyodor Kupolov
2abd2a4976 Clarify usage of context in the JavaDoc
The context is only used for resolving database paths.

Test: build
Bug: 70863722
Change-Id: I675dcd35da9d73b57dbd0bf3e357bfffdf485168
2018-01-18 01:39:10 +00:00
Fyodor Kupolov
7fcd659705 Enabled SQLiteCompatibilityWalFlags class
In system_server, it should be deactivated until InstallSystemProviders
is finished.

Test: SQLiteCompatibilityWalFlagsTest
Test: setting put global ... + verify that dumpsys dbinfo has the new flag
Bug: 70226732
Bug: 70517616
Change-Id: Iec6a5e61a5d7e4cc0ac602f2b630357c54bb4456
2017-12-15 17:34:52 -08:00
Fyodor Kupolov
ee90c03fe7 Added compatibility WAL flags for Global.Settings
Added Settings.Global.SQLITE_COMPATIBILITY_WAL_FLAGS -
configuration flags for SQLite Compatibility WAL. Encoded as a key-value
list, separated by commas. E.g.:
compatibility_wal_supported=true, wal_syncmode=OFF

SQLiteCompatibilityWalFlags caches the value of
SQLITE_COMPATIBILITY_WAL_FLAGS on first access and keeps it through
the lifetime of the process for consistent behavior across all
connections.

Test: SQLiteCompatibilityWalFlagsTest
Test: setting put global ... + verify that dumpsys dbinfo has the new flag
Bug: 70226732
Bug: 70517616
Change-Id: Ifacbf5908c83351ebe5dea676eeb716af039fb14
2017-12-14 12:21:27 -08:00
Fyodor Kupolov
f0d4810026 Added database package OWNERS
Test: N/A
Change-Id: I30993e7e20265b88d2cda246155fde50081866cb
2017-11-28 14:14:37 -08:00
Fyodor Kupolov
25095c0802 Close available secondary connections if schema changes
If DDL statement is executed on one connection, the schema change is
not always visible to other connections due to sqlite3_column_count()
API limitation. We have to close secondary connections to prevent the
issue.

Test: cts/SQLiteOpenHelperTest
Bug: 33695159
Change-Id: I862da71ecec5b1edc880dbfadf22efb2274ca10a
2017-11-17 15:22:20 -08:00
TreeHugger Robot
3c31b2f32a Merge "Allow null context in the constructor" 2017-11-16 02:52:31 +00:00
Fyodor Kupolov
9d4c3d9a50 Allow null context in the constructor
Legacy apps can use it for in-memory databases.

Test: manual
Bug:69379861
Change-Id: I989524c38d6e2ea3b2637bbe6534f2906c5b7bb6
2017-11-15 16:04:24 -08:00
TreeHugger Robot
b0ce0a8209 Merge "Fixed typo in MergeCursor" 2017-11-15 19:45:37 +00:00
Fyodor Kupolov
5c4b623d54 Fixed typo in MergeCursor
Test: n/a
Bug: 68247902
Change-Id: I484d3aa23415769b205635908f7d73d8113d866b
2017-11-15 00:05:04 +00:00
Fyodor Kupolov
d3fe8f09c8 Merge "Apps can now specify journal/synchronous mode" 2017-11-14 17:53:06 +00:00
Kevin Hufnagle
0dd496b455 Merge "Merge "docs: Added SQLite versions used on API levels 26 and 27." into oc-mr1-dev am: 9e628b60ba" into oc-mr1-dev-plus-aosp
am: be8f36d844

Change-Id: I1f64688b30ce70b66a2f07bc47fd199dc1e3dcb0
2017-11-10 17:32:10 +00:00
Kevin Hufnagle
5dfdfa0a14 docs: Added SQLite versions used on API levels 26 and 27.
The android.database.sqlite package summary page now mentions the
versions of SQLite that are available on Android devices running Oreo
(API level 26) and API level 27.

Test: make ds-docs -j16

Bug: 69106585
Change-Id: I77a323c58343fa978ade5397d613566ba25f00c2
2017-11-09 10:12:50 -08:00
Fyodor Kupolov
13a4b37e87 Apps can now specify journal/synchronous mode
Added setJournalMode/setSynchronousMode. These methods control
journal/syncrhonous mode when ENABLE_WRITE_AHEAD_LOGGING flag is not set

Bug: 33044236
Test: manual + CtsDatabaseTestCases
Change-Id: Iffef75f6941030aae5ab3e239cd65550515f5fe0
2017-11-08 16:13:40 -08:00
Fyodor Kupolov
fd22a196a6 Update wal mode of the connection when disabling WAL
Previously calling disableWriteAheadLogging wasn't updating
journal mode of the primary connection.

Test: manual + SQLiteDatabaseTest cts
Bug: 33044236
Change-Id: Ifd105dacdd10ef59b10a023aba0cc43fbb1bba97
2017-11-06 15:08:59 -08:00
TreeHugger Robot
01f5db7240 Merge "Added setFillWindowForwardOnly" 2017-11-02 02:10:46 +00:00
Fyodor Kupolov
41cadb7d31 Added setFillWindowForwardOnly
It controls fetching of rows relative to requested position

Test: SQLiteCursorTest
Bug: 62550963
Change-Id: Iab651d8e3d689710b0436650c58dab86b119e296
2017-11-01 14:38:15 -07:00
Fyodor Kupolov
5bd43ad2e7 Initial version of compatibility WAL
In this mode, only database journal mode will be changed, connection pool
size will still be limited to a single connection.

If enabled, compatibility WAL mode will be used if an app hasn't explicitly
 requested journal mode, by calling disable/enableWriteAheadLogging.

Compatibility WAL mode is controlled by debug.sqlite.use_compatibility_wal
property and db_use_compatibility_wal config resource.

Impact on write performance:
On ext4, with WAL, there is approx 300% increase in speed of update operations
On f2fs, with WAL, there is approx 5% increase in speed of update operations

Impact on number of writes:
On ext4, switching to WAL reduces the number of writes by approx 50%.
On f2fs, switching to WAL increases the number of writes by approx 15%.

Test: CtsDatabaseTestCases
Test: manual, running device
Bug: 33044236
Change-Id: Iaffb5651df39d8c9f710d7dbbe174f9c0d8a3186
2017-10-26 11:21:19 -07:00
Fyodor Kupolov
6bb32a9a8b Allow creating CursorWindow of custom size
The default size is controlled by config_cursorWindowSize.

Test: SQLiteCursorTest
Bug: 62550963
Change-Id: Ic5c6550b2dd53401afc039ec257524a98bf2950e
2017-10-17 15:22:11 -07:00
Fyodor Kupolov
76dd22ff1e Dump total execution time per connection pool
Test: dumpsys dbinfo system
Bug: 64262688
Change-Id: I3e094240a2fdb27089b90a78a0dc26822e3c66e8
2017-09-18 14:33:16 -07:00
Fyodor Kupolov
28e49b7eed Merge "Allow using SQLiteGlobal for testing" into oc-mr1-dev am: 347eaf21fa
am: ac6d9d3173

Change-Id: I0819f276018c9c9d50fe51c834c6356dad02c87e
2017-09-08 00:43:44 +00:00
Fyodor Kupolov
347eaf21fa Merge "Allow using SQLiteGlobal for testing" into oc-mr1-dev 2017-09-08 00:13:51 +00:00
Fyodor Kupolov
5d53e4477f Allow using SQLiteGlobal for testing
Test: android.database.sqlite.cts.SQLiteOpenHelperTest
Bug: 63398887
Change-Id: Ic636d672a78c7b770a964bdf17c19c8ccfb6c7eb
2017-09-01 18:33:37 -07:00
Fyodor Kupolov
a816016de4 Merge "Do not close idle connections by default" into oc-mr1-dev am: 6f8afdc501
am: eb952ab3d0

Change-Id: I5b4583fc8d663afe87cdc79b32536e85a29756cd
2017-09-01 18:01:07 +00:00
Fyodor Kupolov
5356729953 Do not close idle connections by default
Otherwise it can cause issues in apps depending on transient state.

Test: manual
Bug: 63398887
Bug: 65220630
Change-Id: I0806693e05e2e61035aee0b108e31f8bcc8b1a0b
2017-08-30 18:16:31 -07:00
Fyodor Kupolov
24929cd4e4 Distinguish ROLLBACK from ROLLBACK TO
The former aborts the current transaction, the latter restores the
state to a specified savepoint.

Test: CtsDatabaseTestCases
Test: DatabaseGeneralTest
Bug: 36957161
Change-Id: Ia0b189e8aac4687f10d8fbc07143a452f5f719c9
2017-08-28 17:02:37 -07:00
Fyodor Kupolov
2c7e249b84 Keep close_idle_connections optimization for all devices
Internal compatibility testing didn't reveal any issues related to it.

Rationale to not make it specific to low-ram:
1) Consistent behavior from app perspective. close_idle_connections
   is a behavioural change and may affect apps relying on undocumented
   behavior of connection pooling. Developers can detect problems
   without testing on low-ram device
2) Closing idle connections is especially important in WAL mode.
   Disabling this feature would become an issue if more apps are
   switching to WAL and we would need to re-enable this optimization.

Test: n/a
Bug: 63398887
Change-Id: I1b431f44daa2d337aad7f12f8e1409ae3143ded0
2017-08-23 16:36:15 -07:00
Fyodor Kupolov
45be5633e9 Make SQLiteDirectCursorDriver @TestApi
Test: cts/SQLiteDatabaseTest+SQLiteOpenHelperTest
Bug: 64228388
Change-Id: Ic711069cfdc7df1affaecf26a3d01539f1a8e821
2017-08-08 16:55:03 -07:00
Fyodor Kupolov
76436c04a4 API Review update for SQLiteDatabase
SQLiteDatabase openDatabase -- should take File for first parameter
  instead of a String path

SQLiteDatabase.OpenParams.Builder -- make sure the javadocs says what
  the default openFlags is and default idle connection timeout

SQLiteDatabase createInMemory -- throw if it has trouble instead of
  returning null.

Test: cts/SQLiteDatabaseTest
Bug: 64331777
Bug: 64331778
Bug: 64330914

Change-Id: Ibecf4f4a6498795f9a5d12b94b77481e5745b523
2017-08-07 11:12:38 -07:00
TreeHugger Robot
2729912a35 Merge "List column names in the error message" into oc-mr1-dev 2017-08-01 00:36:49 +00:00
Fyodor Kupolov
82f289a4b4 Merge "Added setIdleConnectionTimeout method" into oc-mr1-dev 2017-07-31 23:56:02 +00:00
Fyodor Kupolov
cf97b6b7f7 Added setIdleConnectionTimeout method
It allows apps to set time SQLite connection is allowed to be idle
before it is closed and removed from the pool.

Test: manual + DatabaseGeneralTest
Bug: 63398887
Change-Id: Ie09eeb4dc2b9e52ba67d9355b1f9bd869b148613
2017-07-31 11:05:57 -07:00
Fyodor Kupolov
848485bb1c List column names in the error message
Otherwise it's not clear what is causing the issue (e.g. no columns,
case sensitivity issue or a table prefix etc.)

Bug: 62431773
Test: manual
Change-Id: I81d1f420b70a2248a9b132147cda72c2417dc46b
2017-07-28 15:46:17 -07:00
Fyodor Kupolov
0ee7495b54 Merge "Limit number of in-memory db connections to 1 per pool" into oc-mr1-dev 2017-07-27 23:20:34 +00:00
Fyodor Kupolov
3a6cded002 Limit number of in-memory db connections to 1 per pool
We should always keep pool size of 1 for in-memory databases since every
:memory: db is separate from another.

Test: com.android.providers.contacts.util.UserUtilsTest
Bug: 64039907
Change-Id: If85af3eacfb5625036e29d44f88c1bebb338f46b
2017-07-26 16:07:09 -07:00
Fyodor Kupolov
b773312982 Tests for lookaside configuration
Test: android.database.sqlite.cts.SQLiteDatabaseTest
Test: android.database.sqlite.cts.SQLiteOpenHelperTest
Bug: 63998707
Change-Id: I2e84a6e98baf889001ef7537a290f7e2aa2d709a
2017-07-24 23:33:00 +00:00
Fyodor Kupolov
fd9c4a54cf Close idle sqlite connections
Idle connections are now closed 30 seconds after being returned to the
pool. In-memory databases and databased with attached databases
 are exempt from closing idle connections.

The new behavior is enabled on all devices (temporarily).
Use "setprop persist.debug.sqlite.close_idle_connections 0" to disable

Test: manual - devices boots, no app crashes, auth(accounts.db) works
Test: database CTS tests + SQLiteConnectionPoolTest + run_newdb_perf_test.sh
Bug: 63398887
Change-Id: Idc11e49149292d219a15502c1707c40ef27e3ddb
2017-07-18 18:21:10 -07:00
Fyodor Kupolov
54538b0f85 Merge "Revert "Fix ContentObserver unregister issue"" am: 31419a4ad4 am: 8625194c19 am: cd816c1853
am: c2a76d16f0

Change-Id: I6916fbf80f86419a264b4645d29c9167777543e8
2017-07-13 04:07:09 +00:00
Fyodor Kupolov
8625194c19 Merge "Revert "Fix ContentObserver unregister issue""
am: 31419a4ad4

Change-Id: I455be72533c24ceb5ea352774ded30d0c0a2367f
2017-07-13 03:49:36 +00:00
Fyodor Kupolov
5d5f04b004 Revert "Fix ContentObserver unregister issue"
This reverts commit 2df4e144a9. 
It was causing failures in packages/apps/DocumentsUI tests

Bug: 63638102
Bug: 63154326
Change-Id: I51fb54f705f58f159f4fcc30bfed41ababcba950
2017-07-13 01:46:23 +00:00
Fyodor Kupolov
05a0f0fa4d Disable lookaside allocator on low-RAM devices
Also dump lookaside config if it's different from the default.

Test: adb shell setprop debug.force_low_ram 1
      adb shell stop/start
      adb shell dumpsys meminfo system  // no lookaside allocations
Bug: 62877322

Change-Id: I152dae9714e7e55f93af3311b7387a6ac816e8f6
2017-07-06 17:38:08 -07:00