Commit Graph

484 Commits

Author SHA1 Message Date
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
Fyodor Kupolov
1a84ad9eda Merge "Fix ContentObserver unregister issue" am: 09b6988e27 am: 481d92c517 am: aee5787b48
am: 16ff7bc82a

Change-Id: Icf006b580ff47125e992fd208a89b909dd53e639
2017-07-06 18:46:54 +00:00
Fyodor Kupolov
481d92c517 Merge "Fix ContentObserver unregister issue"
am: 09b6988e27

Change-Id: I242e87b53f603a05ba7c4069662456457a3d980a
2017-07-06 18:21:54 +00:00
daqi
2df4e144a9 Fix ContentObserver unregister issue
[Cause of Defect]
In the ContentObserver callback procedure, the binder thread
has no sync mechanism with handler thread.
The ContentObserver#onChange method can get called after
ContentResolver#unregisterContentObserver called in the
very low probability.

Bug: https://issuetracker.google.com/issues/63154326
Test: manual - check https://github.com/nanjingdaqi/ContentObserverDemo
Change-Id: I0e3831eba7a9cc1a5bf0d30abe5dd0ec8259b0d4
Signed-off-by: daqi <daqi@xiaomi.com>
2017-07-06 10:09:21 +08:00
Fyodor Kupolov
d3b0c7e7e2 Support for lookaside configuration params
Modified SQLiteDatabase to allow passing lookaside configuration to its
static initializer. Encapsulated config in OpenParams and added an
overloaded version of openDatabase with the new parameter.

Configuration is changed in SQLiteConnection::nativeOpen, immediately
after opening the database since lookaside memory configuration can only
be changed when no connection is using it.

Added SQLiteOpenHelper.setLookasideConfig method that is called from
the constructor of the subclass.

Test: bit FrameworksCoreTests:android.database.DatabaseGeneralTest
Test: bit FrameworksCoreTests:android.database.SQLiteOpenHelperTest
Bug: 38499845
Change-Id: Ifb761229b43c89c090939030fc25b8c480b9b9e2
2017-06-28 14:07:53 -07:00
Steve McKay
0b28e794de Merge "Remove support for auto-paging of cursors." into oc-dev
am: 7f0d8c8076

Change-Id: Ice100c419ce6d53721d6bbec1147bb1cc1bb7b4d
2017-04-13 18:26:43 +00:00
Steve McKay
927b01371b Remove support for auto-paging of cursors.
Auto-paging of cursors is being removed in favor of a support lib component.
Rationale:
    1) Auto-paging as implemented has potential to negatively impact system health.
    2) Similar functionality w/o system health concerns can be provided
       specific to RecyclerView.

Test: Removed. CTS coverage updated.
Bug: 30927484
Change-Id: I43e62181d8ceeeba6265d44536967a2102751320
(cherry picked from commit 4677c2b7f0)
2017-04-13 00:35:42 +00:00
Steve McKay
4677c2b7f0 Remove support for auto-paging of cursors.
Auto-paging of cursors is being removed in favor of a support lib component.
Rationale:
    1) Auto-paging as implemented has potential to negatively impact system health.
    2) Similar functionality w/o system health concerns can be provided
       specific to RecyclerView.

Test: Removed. CTS coverage updated.
Bug: 30927484
Change-Id: I43e62181d8ceeeba6265d44536967a2102751320
2017-04-12 13:51:50 -07:00
Tobias Thierer
8283da42a4 Merge "Document the fact that StatFs.restat() and ctor can throw." am: 183c93f6a0 am: e11ed001dd
am: a426851da0

Change-Id: Ife49443ed8e5e4e90723e4e46c0e8c48a6ee5547
2017-04-05 21:14:46 +00:00
Tobias Thierer
0ad48dc8aa Document the fact that StatFs.restat() and ctor can throw.
StatFs.restat() and the StatFs constructor can throw
IllegalArgumentException. This was not previously documented;
not all callers took this into account, for example:
   http://r.android.com/251290

This CL adds documentation to those methods. It also adds
comments to two of the callers.

Separately from this CL, we may in addition consider adding
new API StatFs.checkedRestat() and StatFs.checkedCreate()
or similar that throw IOException; we cannot change the
existing constructor and method since they are public.

Test: Checked that "make" still completed successfully.

Change-Id: I6a0b3cb7718939408937c61de7c3b000b948fa59
2017-04-05 20:52:04 +00:00
TreeHugger Robot
9a8eb3db62 Merge "Add honored args when auto-paging." 2017-03-28 03:26:01 +00:00