0
Commit Graph

722 Commits

Author SHA1 Message Date
Vikram Pasupathy
73c6039154 sql: Use updated SQLite name for LAST_ERRNO
SQLite now uses SQLITE_FCNTL_LAST_ERRNO to get the LastErrno, so we
should update the Chromium SQL code to use this now, since the previous
name is a deprecated name.

Also update the comment in the header to refer reader to implementation
rather than documentation since documentation is nonexistent.

Bug: 40272342
Change-Id: I6f63f0bb8fcde1cfa32db705b5b76667dd1cef17
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5414914
Reviewed-by: Evan Stade <estade@chromium.org>
Commit-Queue: Vikram Pasupathy <vpasupathy@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1281428}
2024-04-02 20:51:31 +00:00
Evan Stade
339502a4b9 SQL: handle failure during recovery more gracefully.
When attempting a recovery, if the meta table is corrupted then the
`key` column can be missing, leading to errors like:

    SQL compilation error: table meta has no column named key.
    Statement: INSERT OR REPLACE INTO meta(key,value) VALUES(?,?)

Current code goes on to attempt to run this statement anyway, which
leads to a fatal DLOG. Intercept this problem earlier for a more
graceful exit.

Bug: 331970403
Change-Id: I3c20d0fdcdbd927df22011c9a4f6d27e96293d42
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5408209
Reviewed-by: Nathan Memmott <memmott@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1280898}
2024-04-01 22:15:09 +00:00
Md Hasibul Hasan
52ffeca692 Convert StringPiece to std::string_view in //sql
Bug: 40506050
Change-Id: Ib65254fb3011507a1330848ffa9d3e12175ffcf6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5394490
Reviewed-by: Evan Stade <estade@chromium.org>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1278487}
2024-03-26 18:23:18 +00:00
Evan Stade
4c7d6b3b77 SQL: recovery cleanup - rename BuiltInRecovery and delete dead code.
Bug: 40061775
Change-Id: I62aea84fccbeb735029a54bff4a652816c4e41b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5328615
Reviewed-by: Austin Sullivan <asully@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: Cait Phillips <caitkp@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1271620}
2024-03-12 16:50:27 +00:00
Arthur Sonzogni
5bc3326c91 Cleanup: Format <optional> include order.
This is an automated patch. Please avoid assigning unrelated bug.
 #cleanup

This is a follow-up to @thestig comment:
https://chromium-review.googlesource.com/c/chromium/src/+/5009410/7/pdf/accessibility_helper.cc#11

Several developers, including myself rewrote optional without properly
reordering the #includes at the beginning.
This patches automatically fixes it.

Script:
-------

```
function replace {
  echo "Replacing $1 by $2"
  git grep -l "$1" \
    | cut -f1 -d: \
    | grep -v \
      -e "*win*" \
      -e "third_party/*" \
      -e "tools/*" \
    | grep \
      -e "\.h" \
      -e "\.cc" \
    | sort \
    | uniq \
    | xargs sed -i "s/$1/$2/g"
}

replace "#include <optional>" ""
git add -u
git commit -m "remove optional"
git revert HEAD --no-commit
git add -u
echo "Formatting":
echo "IncludeBlocks: Regroup" >> ".clang-format"
echo "IncludeIsMainRegex: \"(_(android|apple|chromeos|freebsd|fuchsia|fuzzer|ios|linux|mac|nacl|openbsd|posix|stubs?|win))?(_(unit|browser|perf)?tests?)?$\"" >> ".clang-format"
git add -u
git cl format --upstream=HEAD
git checkout origin/main -- ".clang-format"
git add -u
git commit -m "revert with format"
git reset --soft origin/main
git add -u
git commit -m "Automated format"
```

cleanup: This is a no-op patch formatting includes.
Bug: 40288126
Change-Id: I5f61b1207c097a4c6b20a034f9d1b323975b1851
AX-Relnotes: n/a.
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5335142
Owners-Override: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1267143}
2024-02-29 19:39:05 +00:00
Dan McArdle
ba44e47beb SQL: Add test for Database::DetachFromSequence()
I wanted to write a DCHECK death test where the Database is destroyed on
an unexpected sequence, but had trouble getting EXPECT_DCHECK_DEATH_WITH
to capture the crash.

Bug: 326498393
Change-Id: Ie28624addfe329d7867446806a01957c321cd81e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5333056
Commit-Queue: Dan McArdle <dmcardle@chromium.org>
Reviewed-by: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1267050}
2024-02-29 17:12:18 +00:00
Dan McArdle
44d62a1ac5 SQL: Make sql::Transaction hold WeakPtr<Database>
Now, Transaction checks whether the Database has been destroyed before
using it.

This CL also adds stricter sequence checking to Database, which found a
few places that Database was passed between sequences:

(1) storage::DatabaseTracker was using and destroying sql::Database on
    different sequences. Now, it simply destroys the Database instance
    in storage::DatabaseTracker::Shutdown(), which already runs on the
    correct sequence.

(1) history::InMemoryDatabase was "slurping" data from disk on one
    sequence, then querying the data on a different sequence. To support
    this use case, we added added sql:Database::DetachFromSequence().
    Now, InMemoryDatabase effectively annotates the cut point where the
    Database is handed off to another sequence.

Bug: 326498393
Change-Id: I866061feaf08d48607d97731a512bc02ce497f71
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5320373
Reviewed-by: manuk hovanesian <manukh@chromium.org>
Commit-Queue: Dan McArdle <dmcardle@chromium.org>
Reviewed-by: Evan Stade <estade@chromium.org>
Auto-Submit: Dan McArdle <dmcardle@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1267047}
2024-02-29 17:08:14 +00:00
danakj
85a24d73e8 Apply spans to writing big-endian bytes.
WriteBigEndian() is converted to the byte_conversions functions
in base::numerics or into a BigEndianWriter.

BigEndianWriter now uses a span internally, and can be constructed
from a span.

Bug: 1490484
Change-Id: I4d6726651e4c6eece2cb8d8c74bdf766d86a8beb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5202348
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Owners-Override: danakj <danakj@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1266703}
2024-02-28 23:15:00 +00:00
Evan Stade
1d80896e25 SQL: allow AttachDatabase usage from client code.
Bug: 327244264
Change-Id: If0470516933f7ddd4d4178665e9392e3e727fac4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5327504
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: Austin Sullivan <asully@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1266540}
2024-02-28 18:40:26 +00:00
Clark DuVall
8ecfcfa893 Allow using POSIX_FADV_SEQUENTIAL in base::PreReadFile()
For some uses cases, POSIX_FADV_SEQUENTIAL is substantially faster than
POSIX_FADV_WILLNEED. This change adds an option to base::PreReadFile()
to hint at sequential file reading. This was not added as the default
since it looks like other callers may not be doing sequential reads
(e.g. database files).

Bug: 326240401
Change-Id: I578b277afc99f2bd1725a79161609e0471800cfa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5325390
Reviewed-by: Evan Stade <estade@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Reviewed-by: Adam Rice <ricea@chromium.org>
Reviewed-by: John Rummell <jrummell@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1266208}
2024-02-28 02:02:50 +00:00
Evan Stade
b3be6371d9 SQL: remove legacy recovery code.
Built-in recovery has been launched to stable for all databases
that use recovery (in M122).

-12KB binary size on Android.

Bug: 40061775
Change-Id: I5ddf318112f989d34988410092114ed1a0737863
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5319793
Reviewed-by: John Delaney <johnidel@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Justin Donnelly <jdonnelly@chromium.org>
Reviewed-by: Austin Sullivan <asully@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: Bo Liu <boliu@chromium.org>
Reviewed-by: Guido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1266061}
2024-02-27 21:11:09 +00:00
Dan McArdle
c948198df5 SQL: Drop explicit rollback in Database::Poison()
With this CL, Database::Poison() relies on the implicit rollback of
transactions that occurs when closing the database connection, rather
than explicitly issuing a "ROLLBACK" statement.

This addresses a post-merge comment on a prior CL:
https://chromium-review.googlesource.com/c/chromium/src/+/5321958/comment/4c088549_9a0e5e08/

Fixed: 326498384
Change-Id: Ia422e230ff44794e7407156178078766f838867b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5323382
Reviewed-by: Evan Stade <estade@chromium.org>
Commit-Queue: Dan McArdle <dmcardle@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1265867}
2024-02-27 17:18:54 +00:00
Lei Zhang
7816ff59a2 Remove base::PreReadFile() fallback on Windows
Now that Windows 10 is the minimum requirement, PrefetchVirtualMemory()
is always available. Thus there is no need for the PreReadFileSlow()
fallback on Windows. Make the PreReadFileSlow() fallback POSIX-only, and
remove the Windows-specific bits within its implementation.

Update the comments for one of the PreReadFile() callers to stop
mentioning Windows 7.

Bug: 40246975
Change-Id: I0dbd87d17ba37303eef095534249a92acdad2990
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5321084
Reviewed-by: Will Harris <wfh@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1265553}
2024-02-27 00:21:41 +00:00
Dan McArdle
89348edf1e SQL: Handle case where DB is closed mid-transaction
Bug: 326498384
Change-Id: Idaa770a24e3059aba5839dccce10d57f8863e00f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5321958
Reviewed-by: Austin Sullivan <asully@chromium.org>
Commit-Queue: Dan McArdle <dmcardle@chromium.org>
Auto-Submit: Dan McArdle <dmcardle@chromium.org>
Commit-Queue: Austin Sullivan <asully@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1265421}
2024-02-26 20:50:08 +00:00
Evan Stade
23a8485f4c SQL: Remove browser dep on third_party/sqlite
Bug: 40219064
Change-Id: I2e5022782d4717dd24b154dcba94fa672e9c8dad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5292375
Auto-Submit: Evan Stade <estade@chromium.org>
Reviewed-by: Austin Sullivan <asully@chromium.org>
Reviewed-by: David Trainor <dtrainor@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1260846}
2024-02-15 01:57:25 +00:00
Evan Stade
a066778b6d SQL: remove dependencies on third_party/sqlite
Only //sql should depend on it.

This CL was uploaded by git cl split.

Bug: 40219064
Change-Id: Ifefab0d4ffcec0ed8ed7cf4a808a03ffa3ca9f2d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5291276
Auto-Submit: Evan Stade <estade@chromium.org>
Reviewed-by: Austin Sullivan <asully@chromium.org>
Commit-Queue: Austin Sullivan <asully@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1259918}
2024-02-13 18:14:41 +00:00
Ali Hijazi
133b2d903f Rewrite std::set<T*> into std::set<raw_ptr<T, SetExperimental>>
This patch was generated by running
./tools/clang/rewrite_templated_container_fields/rewrite-multiple-platforms.sh

AX-Relnotes: n/a.
Bug: 41486235
Change-Id: If9280b93e10508add3c9842f2b2ae190bb65c364
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5272231
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Owners-Override: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Ali Hijazi <ahijazi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1258472}
2024-02-09 14:01:52 +00:00
Dan McArdle
49be9b0414 Prevent dangling pointer in ScopedWritableSchema
Bug: 1522873
Change-Id: I71d7d178c98f2f2fc880762942fbca608d8cb81c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5245191
Reviewed-by: Evan Stade <estade@chromium.org>
Commit-Queue: Dan McArdle <dmcardle@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1257060}
2024-02-06 23:15:33 +00:00
Evan Stade
ae04e197b3 SQL: change Database::db_ to a raw_ptr
SQLite allocates this pointer via malloc which should be intercepted
by PartitionAlloc.

Change-Id: Ia4dae3e1557ed03e6753a0f1528d856850905a8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5247316
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: Keishi Hattori <keishi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1255118}
2024-02-01 17:35:53 +00:00
Dan McArdle
643e874483 Add test that closes/reopens sql::Database in error callback
Bug: 1522873
Change-Id: I3897b718608f733c56b427505093a660d95bebe6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5249272
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Evan Stade <estade@chromium.org>
Commit-Queue: Dan McArdle <dmcardle@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1254638}
2024-01-31 18:52:43 +00:00
Etienne Bergeron
6b45527336 Migrate unittests to support SQL exclusive mode
This is is fixing some issues with unittests that were not supporting
the exclusive mode.

The default Database constructor was assuming non-exclusive mode which
is not aligned with the explicit constructor.

We do recommend to use exclusive mode for performance/stability (unless there is a valid reason otherwise).

Bug: 1120969
Change-Id: I114a60c1ee290789fc8f3d2f2ea69cba2843a283
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5029223
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Reviewed-by: Andrew Paseltiner <apaseltiner@chromium.org>
Reviewed-by: Maks Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1254628}
2024-01-31 18:43:46 +00:00
Dan McArdle
2283db5cb1 Prevent dangling pointer by inlining ScopedBusyTimeout
Bug: 1522873
Change-Id: Icd6262eb23404c273fa31021cddf36bea0bb56db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5245970
Reviewed-by: Evan Stade <estade@chromium.org>
Reviewed-by: David Benjamin <davidben@chromium.org>
Commit-Queue: Dan McArdle <dmcardle@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1254220}
2024-01-30 22:20:43 +00:00
Evan Stade
a7fb27b2ec SQL: remove (pre-builtin) recovery fuzzer
The bespoke recovery code is now disabled on ToT. Although that code is
not yet fully removed in case we need to temporarily revert the
migration, the fuzzer for the old code has been ignored for some months
now and we can save bot cycles by removing it.

Fixed: 1386218,1417151,1429058,1513310
Change-Id: I8f0cb7cae0a90b4800c537ea9c18073ed454fe81
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5244874
Reviewed-by: Austin Sullivan <asully@chromium.org>
Auto-Submit: Evan Stade <estade@chromium.org>
Commit-Queue: Austin Sullivan <asully@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1253352}
2024-01-29 17:46:37 +00:00
Dan McArdle
ff6825425c Handle fallible "PRAGMA journal_mode=TRUNCATE" while opening db
This CL adds an early return to Database::OpenInternal() in the event
that "PRAGMA journal_mode=TRUNCATE" fails. This prevents a null
dereference down the line in Database::GetSqliteVfsFile().

It also adds a comment that explains some of the historical context and
reasoning to help out future code archaeologists.

Test: Run sql_built_in_recovery_lpm_fuzzer on the fuzzer testcase
Change-Id: I50d75bcf61a4a6dde4edc098fb8434b69957eac3
Fixed: b/321842458
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5232014
Reviewed-by: Evan Stade <estade@chromium.org>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Commit-Queue: Ayu Ishii <ayui@chromium.org>
Auto-Submit: Dan McArdle <dmcardle@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1252811}
2024-01-26 19:47:28 +00:00
Dan McArdle
892f4753c8 sql_built_in_recovery_lpm_fuzzer: List contents of temp dir when non-empty
This should help debug the linked fuzzer crash. It's also a generally
useful improvement.

Bug: 1520767
Change-Id: I275bd6dc7b577f09f400cf3239c58cc65e1998d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5238393
Commit-Queue: Dan McArdle <dmcardle@chromium.org>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Reviewed-by: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1252778}
2024-01-26 19:03:25 +00:00
Evan Stade
2f6256b70d sql: Enable recovery on Fuchsia
(for non-WAL DBs only)

based on change by asully@chromium.org

Fuchsia-Binary-Size: Increase is temporary, as enabling built-in recovery module will allow removing bespoke recovery code.
Bug: 1385500
Change-Id: I99e53c5b751fbc3d3bcf484f2eb90179e00f1ae3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5238057
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: Austin Sullivan <asully@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1252631}
2024-01-26 14:58:55 +00:00
Evan Stade
a498724cc8 SQL: make wrapped VFS the default VFS
//sql uses a wrapper around the default VFS to accomplish certain
custom, OS-specific tasks (see vfs_wrapper.h). This wrapper is used
in `sql::Database::Open()` but is not used in other contexts such as
`sql::Database::Recover()` or `sql::Database::Delete()`.

This change makes that wrapper the default VFS so it's used
automatically for all SQLite library calls that don't specify a VFS
instead of just sqlite3_open_v2.

Bug: 1385500

Change-Id: I9b8fdba9897f961605914a0629beb32c1c518454
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5234121
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: Austin Sullivan <asully@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1252429}
2024-01-26 00:40:39 +00:00
Dan McArdle
cbbd39c236 sql_built_in_recovery_lpm_fuzzer: Use queries_after_open input field
The fuzzer was accidentally reusing the `queries` field of its input
protobuf and ignoring the `queries_after_open` field of
`RecoveryFuzzerTestCase` (see sql_disk_corruption.proto).

This is a behavior change and will likely cause Clusterfuzz to mark its
existing crbugs as fixed. For the ones that we care about, we can
trivially create the equivalent new test case by copying the value of
the `queries` field into the `queries_after_open` field. It's also
likely the Clusterfuzz will rediscover the same crashes because I assume
copying a field is not a complex mutation.

Bug: 1520447
Change-Id: I07ddd3fa94fd5860adb615ffe535d0b1876ea8be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5225482
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Auto-Submit: Dan McArdle <dmcardle@chromium.org>
Reviewed-by: Evan Stade <estade@chromium.org>
Commit-Queue: Ayu Ishii <ayui@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1251721}
2024-01-24 21:42:52 +00:00
Dan McArdle
7097ced305 Add LPM fuzzer for SQL recovery: sql_built_in_recovery_lpm_fuzzer
We already have sql_built_in_recovery_fuzzer, but anecdotally I never
see it reach recovery internals, e.g. Recovery::Init(). I think the main
issue is that its approach is to treat the fuzzer input as a SQLite
file.

I think there are two impediments to sql_built_in_recovery_fuzzer's
fuzzing speed and coverage:

(1) The database file must have high fidelity or else it won't exercise
    interesting paths in the recovery module.

    The new fuzzer addresses the fidelity issue by bootstrapping the
    database file with some syntactically-correct, fuzzer-generated SQL
    statements, then corrupting parts of that file with fuzzer-generated
    "mutations".

(2) It doesn't even attempt recovery unless Database::Open() saw an
    egregious-enough error.

    The new fuzzer attempts recovery when *any* error occurs.

Running sql_built_in_recovery_lpm_fuzzer locally, I see ~20 exec/s,
which is admittedly slower than sql_built_in_recovery_fuzzer, which runs
at ~50 exec/s. However, I believe it's covering more code per execution.
If I add logging statements to Recovery::Init(), it finds it in just a
few seconds.

Change-Id: I49903246ea66f528f76ee2cc912623d12d700d39
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5153917
Reviewed-by: Evan Stade <estade@chromium.org>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Commit-Queue: Dan McArdle <dmcardle@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1249516}
2024-01-19 21:21:48 +00:00
Peter Boström
29c76179f7 Replace DLOG(DCHECK) with DLOG(FATAL)
DLOG(DCHECK) is just confusing, and in most cases it means DLOG(FATAL)
anyways. DLOGs are enabled in DCHECK-enabled builds.

If we wanted DLOG(DCHECK) to not be fatal, we should probably make
DLOG(FATAL) and LOG(DFATAL) non-fatal as well under the same build
conditions.

This removes the ability to use LOG(DCHECK) as well.

Bug: None
Change-Id: I7fc31ee13d7f2f57591e3caba76b26af21d819d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5201856
Commit-Queue: Peter Boström <pbos@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Owners-Override: danakj <danakj@chromium.org>
Reviewed-by: Jeremy Roman <jbroman@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Auto-Submit: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1249112}
2024-01-18 23:05:29 +00:00
Jeff Yoon
68190b3fbb [buganizer] Migrate DIR_METADATA for net/ and sql/
Migrate all metadata files for net/ and sql/ and mixins
used by metadata files under net/ and sql/.

Verify components with http://b/components/{id} or at
go/chrome-on-buganizer-prod-components.

Bug: chromium:1518875
Change-Id: I2d081a94bb40e0f1e8638582976787a4ae5fa000
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5203309
Reviewed-by: Chris Fredrickson <cfredric@chromium.org>
Reviewed-by: Adam Langley <agl@chromium.org>
Commit-Queue: Jeff Yoon <jeffyoon@google.com>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1248393}
2024-01-17 22:17:35 +00:00
Evan Stade
e5a74024a9 SQLite: sidestep Mac crash when acting on non-existent file
Chrome tries to propagate TimeMachine exclusions from the main
database file to its journal file. In some cases, the database
file doesn't exist, which causes a DCHECK. This change papers
over that by verifying the database file exists before calling
base utilities on it.

It's not clear if the existence of a -journal file without
the database file is an error case or can happen normally.
If it is an error case, then we rely on other SQLite code to
notice and error out (but not crash). If it is not an error
case, then the worst thing that will happen due to this change
is that a -journal file may not be excluded from TimeMachine.
The journal file is much smaller than the database file, so
this outcome, while not ideal, is hardly terrible.

crbug.com/25959 has the original justification for this
behavior, and in that example the journal files are less than
2% of the size of the database files.

Bug: 1493504
Change-Id: Ib15a97572b46f54c03699568cf46999cb80c78aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5187142
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: Austin Sullivan <asully@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1245920}
2024-01-11 17:18:54 +00:00
Austin Sullivan
8c040fc3eb sql: Enable exclusive locking of the recovery database
The recovery database should only be accessed by one instance of
recovery at a time

Bug: 1120969, 1385500
Change-Id: Ida82321e2c8ea291ff40000ac11a737b0a2db57b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5167016
Reviewed-by: Evan Stade <estade@chromium.org>
Commit-Queue: Austin Sullivan <asully@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1245639}
2024-01-11 01:04:54 +00:00
Austin Sullivan
bfea855fb6 sql: Test recovery using WAL mode
The legacy recovery module does not support WAL databases. We'd like to
enable WAL mode more broadly, which increases the urgency of our
migration to the new recovery module

Bug: 1385500
Change-Id: I61da303c356923e53da0f1ed4c319ee6c39edaed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5173125
Reviewed-by: Evan Stade <estade@chromium.org>
Commit-Queue: Austin Sullivan <asully@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1244889}
2024-01-09 21:40:20 +00:00
Peter Boström
8310f0f31b Replace logging::LOG_FATAL with LOGGING_
Old alias is deprecated. Will be removed in a separate CL to avoid
broader rollbacks in case I missed one or this is inadvertently used
outside src/.

Bug: 849450
Change-Id: I35d0f03cd750ef5def74f9bcdf626041847e4014
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5167919
Commit-Queue: Peter Boström <pbos@chromium.org>
Owners-Override: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1243437}
2024-01-05 15:57:39 +00:00
Austin Sullivan
8acdc253b5 sql: Update docs to suggest using BuiltInRecovery for new databases
Bug: 1385500
Change-Id: I966a21040ad17a3eb2c9b723f39ca58423791dcf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5167404
Reviewed-by: Evan Stade <estade@chromium.org>
Commit-Queue: Austin Sullivan <asully@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1243090}
2024-01-04 20:36:15 +00:00
Austin Sullivan
f79ebbba93 sql: Remove kConsiderPoisonedDatabasesClosed feature flag
This flag was added in M118
https://crrev.com/6c6faa56ae799a6781ba59bb11a2c453637f1910

Fixed: 1441955
Change-Id: Id414b250f3e6d38ce9bf7108c48eef43be02a306
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5167271
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: Evan Stade <estade@chromium.org>
Auto-Submit: Austin Sullivan <asully@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1243089}
2024-01-04 20:35:22 +00:00
Vikram Pasupathy
2cd0591870 Implement new schema and time based removal into CdmStorageDatabase
A new schema is introduced into CdmStorageDatabase to add last_modified
and file_size to be able to support time-based deletion and time-based
usage calculation.

Methods were implemented to delete by time frame, by storage key, and
to calculate file size using SQL queries for time frames by storing
the file size into the CdmStorageDatabase to be a one time operation.

This CL also provides the functionality that automatically deletes the
database if a Delete function for a subset (i.e file, storage key,
time-frame) ends up removing entries such that there are no more entries
in the database.

An SQL statement is used to alter the version1 database so that we don't
run into crashes when a user that already has the CdmStorageDatabase
v1.0 in their profile runs into queries that are made for the v2.0, such
as writing into the column file_size, since file_size is only in v2.0.

Testing: unittests +

Manual Testing Steps for the Schema Alter code:
1. Build chrome on main branch.
2. Go to chrome://flags and enable kCdmStorageDatabase and
kCdmStorageDatabaseMigration.
3. Open a new profile, name it CdmStorageDatabase (or anything you want)
4. Play this website: https://integration.staging.widevine.com/player?contentUrl=https://storage.googleapis.com/wvtemp/hmchen/poc/tears_hd_cenc.mpd&proxyServerUrl=https://proxy.uat.widevine.com/proxy?video_id=GTS_CAN_PLAY_CLIENT_TOKEN%26provider=widevine_test%26full_response=true&persistentStateRequired=true
5. Log the kVersionNumber (should be 1) (I did this through LOG(ERROR)).
6. A value should be written.
7. Quit Chrome.
8. Switch your branch to these changes using git and build chrome.
9. Open chrome, verify the same flags are still enabled, and open
the same profile you used as before.
10. Play same website as step .
11. log the kVersionNumber (should be 2) (I did this through LOG(ERROR))
12. View in chrome://histograms/Media.EME that the
IncompatibleDatabaseDetected histogram was triggered.
13. Verify that playback plays continuously and Chrome does not crash.

OBSOLETE_HISTOGRAMS= Media.EME.CdmStorageManager.DeleteDatabaseError.Incognito, Media.EME.CdmStorageManager.DeleteDatabaseError.NonIncognito.

Bug: 1454512
Change-Id: I64f9dff580114545ececf5d7b4f03124b1f55192
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4994868
Reviewed-by: Evan Stade <estade@chromium.org>
Reviewed-by: Evan Liu <evliu@google.com>
Reviewed-by: John Rummell <jrummell@chromium.org>
Commit-Queue: Vikram Pasupathy <vpasupathy@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1242731}
2024-01-04 01:06:06 +00:00
Dan McArdle
4feabeb596 Handle double-error edge case in sql::Database::Open()
Currently, Database::Open() incorrectly returns true when both attempts
at opening the database fail. We're chalking this behavior up to a
simple oversight in Database::OpenInternal()'s error handling. See the
linked crbug for more details.

This CL addresses the root cause by unifying Database::Open()'s error
handling and retry logic. In doing so, it resolves a preexisting TODO.
As a side effect, Database::Open() no longer invokes the error callback
6 times in the double-error scenario, which was why I originally filed
the crbug.

Bug: 1509891
Change-Id: Ib0b2f295a2932cf8612f74763db11896d11d6227
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5141149
Reviewed-by: Nan Lin <linnan@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Dan McArdle <dmcardle@chromium.org>
Reviewed-by: Evan Stade <estade@chromium.org>
Reviewed-by: Angela Yoeurng <yoangela@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1242432}
2024-01-03 15:17:13 +00:00
Etienne Bergeron
2d13dbe466 Add a UMA metric to measure the overhead of flushes related to SQLite
This CL is adding a UMA metric that intercept calls to sync (IO flush
operations) and reports the amount of time spent in the operations.

R=gab@chromium.org

Bug: 1508662
Change-Id: I0d53aa170781698f0ab5e13e58824f2b455fd57a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5096415
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Reviewed-by: Evan Stade <estade@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1242070}
2024-01-02 19:13:40 +00:00
Austin Sullivan
db911aaacd sql: Use histogram tag to log per-DB recovery results
This removes the optional argument added in https://crrev.com/c/4917012
in favor of using the database's histogram tag, reusing the pattern from
https://crrev.com/c/5089633

Bug: 1385500
Change-Id: Ia2c6fbaff84f9424f3007153c048be922d479af7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5133183
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Reviewed-by: Evan Stade <estade@chromium.org>
Auto-Submit: Austin Sullivan <asully@chromium.org>
Commit-Queue: Austin Sullivan <asully@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1240114}
2023-12-21 13:44:29 +00:00
Evan Stade
5d24c4bd60 Sql: fix recovery module fuzzer issue
Convert DCHECK + crash into LOG(ERROR) + graceful failure.

Bug: 1511175
Change-Id: I3d450e5f9b195f22849c3bd5f053d0a3133a0e8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5126702
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Auto-Submit: Evan Stade <estade@chromium.org>
Commit-Queue: Ayu Ishii <ayui@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1238288}
2023-12-15 22:27:26 +00:00
Etienne Bergeron
f969727ae5 Introduce statement execution metrics based on SQLite VM Steps
This CL is an adding UMA metric for each database that represent
the amount of SQLite VM steps. This is a good proxy metrics for
estimating the overhead of database' queries.

We are using VM Steps as a proxy instead of CPU time since most
of the databases code are executed on a background sequence; which
is highly affected by Thread priority and OS scheduling. VM Steps
should be stable and comparable between databases.

Bug: 1508662
Change-Id: Ibdf419c5c2b68e5aec9130b297235612f14bdd28
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5089633
Reviewed-by: Evan Stade <estade@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1238200}
2023-12-15 19:40:34 +00:00
Evan Stade
f4cb61eec4 SQL: fix fuzzer-discovered issue in recovery module
The fix is in cursor.cc, where a page ID was directly compared to
kInvalidPageId instead of being validated by the `IsValidPageId()` fn.

The rest of the modifications in this change are:
* changing some DCHECKs to CHECKs for improved security and bug
  discovery
* application of `IsValidPageId()` rather than direct comparison in
  more places, for correctness and not out of strict necessity

Bug: 1508758
Change-Id: Ic8d344f710b2008cf7d45bab608195d1d487f681
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5101280
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1235108}
2023-12-08 18:12:43 +00:00
Etienne Bergeron
6817f4d805 SQL: Ensure CorruptSizeInHeader is using exclusive mode
The corruptSizeInHeader function is used in unittests to
corrupt the database on disk.

If the database is opened in WAL, it requires a checkpoint to
ensures the data is moved from the journal to the actual database
(a.k.a sqlite3_wal_checkpoint_v2(...)).

This CL is ensuring the database is opened in exclusive mode;
which means there is no other opened instance of that database.
If there was instances, CorruptSizeInHeader(...) will fail and
return false. The corresponding unittests will fail and should be
fixed.

Bug: 1120969
Change-Id: Id0d05aef4a7a272effc54ec637b57962f91677a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5018152
Reviewed-by: Greg Thompson <grt@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Reviewed-by: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1224931}
2023-11-15 15:06:26 +00:00
Austin Sullivan
38ce1a5b3d Remove asully@ from most Storage OWNERS files
Also adds some other folks as owners. More files will be updated to
remove asully@ in follow-up CLs

Change-Id: Iab67fa6a55ed2891e9333a8fb41a659dc2255f8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5019014
Commit-Queue: Austin Sullivan <asully@chromium.org>
Reviewed-by: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1223873}
2023-11-13 21:41:36 +00:00
David Benjamin
f4921f509e Avoid memcpy(nullptr, _, 0) in sandboxed_vfs.cc
Due to a C language bug, memcpy with nullptr is UB even when the count
is zero. sqlite3OsGetLastError calls xGetLastError with nullptr and 0.
The C++ STL functions do not have this bug, so use them instead. This
avoids a UBSan warning in some Blink test.

Bug: 1394755
Change-Id: I0a5c0b98f467a48eab66c0371393896ec11d60ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5012992
Auto-Submit: David Benjamin <davidben@chromium.org>
Commit-Queue: Ayu Ishii <ayui@chromium.org>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1223759}
2023-11-13 18:52:25 +00:00
Etienne Bergeron
14c5d7191f Reland "Add unittest for re-opening DB with different journal mode"
This is a reland of commit 28f53bbf8b

Original change's description:
> Add unittest for re-opening DB with different journal mode
>
> This CL is adding a unittest to ensure the SQLite semantic about
> re-opening a database with a different journal mode (Rollback vs WAL).
>
> Bug: 1416213
> Change-Id: I9bd41a29fe401b0a580368ce10213da50a839637
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5013352
> Reviewed-by: Evan Stade <estade@chromium.org>
> Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1222516}

Bug: 1416213
Change-Id: I49c0a190c6202233c1ee705b13ac709f5ab05a98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5019145
Reviewed-by: Evan Stade <estade@chromium.org>
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1223616}
2023-11-13 15:01:15 +00:00
Victor Vianna
072bd6fd4a Revert "Add unittest for re-opening DB with different journal mode"
This reverts commit 28f53bbf8b.

Reason for revert: crbug.com/1501278

Original change's description:
> Add unittest for re-opening DB with different journal mode
>
> This CL is adding a unittest to ensure the SQLite semantic about
> re-opening a database with a different journal mode (Rollback vs WAL).
>
> Bug: 1416213
> Change-Id: I9bd41a29fe401b0a580368ce10213da50a839637
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5013352
> Reviewed-by: Evan Stade <estade@chromium.org>
> Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1222516}

Bug: 1416213
Change-Id: I0ba4df65f6fa9952dda898657937f1d7cf64b65c
Fixed: 1501278
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5018000
Auto-Submit: Victor Vianna <victorvianna@google.com>
Owners-Override: Victor Vianna <victorvianna@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Victor Vianna <victorvianna@google.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1222840}
2023-11-10 10:48:43 +00:00
Arthur Sonzogni
59ac8227c5 Rename {absl => std}::optional in minor top-level dirs
Automated patch, intended to be effectively a no-op.

This patch gather the changes for every top-level directories with less
than 150 files modified:
 #  directory
--- ---------------
150 remoting
98  gpu
87  chromecast
79  mojo
70  storage
65  fuchsia_web
46  sandbox
44  android_webview
38  google_apis
27  pdf
25  printing
20  headless
13  ipc
11  crypto
10  sql
3   dbus
2   testing
2   skia
2   gin
2   apps
1   rlz
1   codelabs

Context:
https://groups.google.com/a/chromium.org/g/cxx/c/nBD_1LaanTc/m/ghh-ZZhWAwAJ?utm_medium=email&utm_source=footer

As of https://crrev.com/1204351, absl::optional is now a type alias for
std::optional. We should migrate toward it.

Script:
```

function replace {
  echo "Replacing $1 by $2"
  git grep -l "$1" \
		| cut -f1 -d: \
		| grep \
			-e "^codelabs" \
			-e "^rlz" \
			-e "^apps" \
			-e "^gin" \
			-e "^skia" \
			-e "^testing" \
			-e "^dbus" \
			-e "^sql" \
			-e "^crypto" \
			-e "^ipc" \
			-e "^headless" \
			-e "^printing" \
			-e "^pdf" \
			-e "^google_apis" \
			-e "^android_webview" \
			-e "^sandbox" \
			-e "^fuchsia_web" \
			-e "^storage" \
			-e "^mojo" \
			-e "^chromecast" \
			-e "^gpu" \
			-e "^remoting" \
		| sort \
		| uniq \
		| grep \
			-e "\.h" \
			-e "\.cc" \
			-e "\.mm" \
			-e "\.py" \
	  | xargs sed -i "s/$1/$2/g"
}

replace "absl::make_optional" "std::make_optional"
replace "absl::optional" "std::optional"
replace "absl::nullopt" "std::nullopt"
replace "absl::in_place" "std::in_place"
replace "absl::in_place_t" "std::in_place_t"
replace "\"third_party\/abseil-cpp\/absl\/types\/optional.h\"" "<optional>"
git cl format
```

CQ_INCLUDE_TRYBOTS=luci.chrome.try:chromeos-betty-pi-arc-chrome

Bug: chromium:1500249
Change-Id: I0eca8ff96f5712ba746ac8d8da93d03a86d8292c
AX-Relnotes: n/a.
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5009410
Reviewed-by: danakj <danakj@chromium.org>
Owners-Override: danakj <danakj@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1222826}
2023-11-10 09:46:54 +00:00