Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Issue 9567022: Reinitialize the cookie database if the meta table gets corrupted. (Closed)

Created:
8 years, 9 months ago by erikwright (departed)
Modified:
5 years, 4 months ago
CC:
chromium-reviews, cbentzel+watch_chromium.org, erikwright (departed), wtc, Randy Smith (Not in Mondays), darin-cc_chromium.org, rkn
Visibility:
Public.

Description

Reinitialize the cookie database if the meta table gets corrupted. This has been shown to occur in the wild. At the moment users in this situation will simply get a failure to load or persist cookies (though cookies will work within the current session). After this change, users will see their Cookie database wiped out and reinitialized, but loading and persisting should work going forward. A histogram tracks how often this scenario is detected - it should probably spike as this is rolled out to new channels and then taper off (hopefully approaching 0). BUG=111376 TEST=unit_tests --gtest_filter=SQLitePersistentCookieStoreTest.TestInvalidMetaTableRecovery

Patch Set 1 : Extracted test refactoring into a separate CL. #

Total comments: 4

Patch Set 2 : Add histograms. #

Patch Set 3 : A more satisfying refactoring. #

Patch Set 4 : Move things around a bit for a slightly smaller diff. #

Total comments: 4
Unified diffs Side-by-side diffs Delta from patch set Stats (+146 lines, -66 lines) Patch
M chrome/browser/net/sqlite_persistent_cookie_store.cc View 1 2 3 13 chunks +101 lines, -66 lines 4 comments Download
M chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc View 1 2 2 chunks +45 lines, -0 lines 0 comments Download

Messages

Total messages: 7 (0 generated)
erikwright (departed)
PTAL. Depends on http://codereview.chromium.org/9569028/
8 years, 9 months ago (2012-03-01 21:06:46 UTC) #1
Scott Hess - ex-Googler
http://codereview.chromium.org/9567022/diff/2001/chrome/browser/net/sqlite_persistent_cookie_store.cc File chrome/browser/net/sqlite_persistent_cookie_store.cc (right): http://codereview.chromium.org/9567022/diff/2001/chrome/browser/net/sqlite_persistent_cookie_store.cc#newcode774 chrome/browser/net/sqlite_persistent_cookie_store.cc:774: if (!file_util::Delete(path_, false) || I am a small bit ...
8 years, 9 months ago (2012-03-01 22:15:15 UTC) #2
erikwright (departed)
http://codereview.chromium.org/9567022/diff/2001/chrome/browser/net/sqlite_persistent_cookie_store.cc File chrome/browser/net/sqlite_persistent_cookie_store.cc (right): http://codereview.chromium.org/9567022/diff/2001/chrome/browser/net/sqlite_persistent_cookie_store.cc#newcode774 chrome/browser/net/sqlite_persistent_cookie_store.cc:774: if (!file_util::Delete(path_, false) || On 2012/03/01 22:15:15, shess wrote: ...
8 years, 9 months ago (2012-03-02 01:04:27 UTC) #3
erikwright (departed)
Hi Scott, The latest patch is a version that is moderately refactored and more clearly ...
8 years, 9 months ago (2012-03-03 04:29:16 UTC) #4
Scott Hess - ex-Googler
I'll try to review on Monday, but I'm fine with going TBR to get some ...
8 years, 9 months ago (2012-03-04 21:33:14 UTC) #5
Scott Hess - ex-Googler
BTW, on Friday I wrote a skeleton of sqlite3_nuke(), which would effectively zero out the ...
8 years, 9 months ago (2012-03-04 21:35:14 UTC) #6
Scott Hess - ex-Googler
8 years, 9 months ago (2012-03-08 00:48:44 UTC) #7
Sorry if this review is out-dated - I kept thinking "Wait, isn't this already
in?", but then thinking "No, I don't think all of it is."

http://codereview.chromium.org/9567022/diff/7002/chrome/browser/net/sqlite_pe...
File chrome/browser/net/sqlite_persistent_cookie_store.cc (left):

http://codereview.chromium.org/9567022/diff/7002/chrome/browser/net/sqlite_pe...
chrome/browser/net/sqlite_persistent_cookie_store.cc:775: 
If the code gets to this point without cur_version getting to
kCurrentVersionNumber, that's a problem.  Just continuing anyway was clearly
wrong, unless statements are written in a way which degrades gracefully, rather
than trying to reference columns or tables which don't exist.  Can you think of
any reason not to CHECK() that the version equals the expected version?  I was
going to suggest histogramming it, but if a histogram is reported to the server
and nobody looks at it, does it exist?

http://codereview.chromium.org/9567022/diff/7002/chrome/browser/net/sqlite_pe...
File chrome/browser/net/sqlite_persistent_cookie_store.cc (right):

http://codereview.chromium.org/9567022/diff/7002/chrome/browser/net/sqlite_pe...
chrome/browser/net/sqlite_persistent_cookie_store.cc:573: // we know something
is wrong.
I don't like making these assumptions on how MetaTable works.  I'm not going to
argue for whether the existing API is the right API, but abusing it won't make
things better.  You should be calling Init() with the current version numbers,
and relying on it not populating the table if it already exists.

Since we do know that we have created databases which do contain invalidness, I
would support adding a static function to test for that case.  Something like:
  static bool MetaTable::IsTableInvalid(*db);
which returns true if the table exists but doesn't contain both versions. 
Obviously it should be documented with a short description of the problem and a
suggestion not to ever call it.  Then you can just call that before you even get
started on setting up the schema.

Another possible solution would be to add something like:
  static bool MetaTable::ReInit(*db, int* v, int* c);
It would return false if the table didn't exist or if it didn't contain both
versions.  Then you could do something like:

if (MetaTable::ReInit(db, &v, &c)) {
  return EnsureDatabaseVersion(v, c);
} else {
  if (MetaTable::DoesTableExist(db)) {
    // Nuke here.
  }
  return InitializeSchema();
}

http://codereview.chromium.org/9567022/diff/7002/chrome/browser/net/sqlite_pe...
chrome/browser/net/sqlite_persistent_cookie_store.cc:619: transaction.Commit();
I don't really care for this style, versus a bunch of if() statements, since it
only allows a narrow class of changes to be applied easily.  But I will defer to
your ownership of this code.

http://codereview.chromium.org/9567022/diff/7002/chrome/browser/net/sqlite_pe...
chrome/browser/net/sqlite_persistent_cookie_store.cc:792: " (creation_utc)") ||
If/when you get the conflict with my change to remove this index, make sure you
remove both cases.

Powered by Google App Engine
This is Rietveld 408576698