• rlarocque@chromium.org's avatar
    Check node references during sync DB init · b4031e8a
    rlarocque@chromium.org authored
    This commit adds a check to verify that the NEXT_ID, PREV_ID and
    PARENT_ID fields of nodes in the database point to the IDs of other
    existing nodes.  The syncable::Database code assumes that this invariant
    always holds and seems to do a good job of maintaining it.  This change
    ensures that the invariant holds at the time the data is loaded from
    disk.
    
    There exist some corrupt databases that cause the directory to behave
    unpredictably, since the code assumes the databsae is correct when it is
    read from disk.  We can't do anything to fix those databases now that
    they've been written, but we can detect the corruption and recreate the
    affected databases.
    
    This check is implemented using a set of hash maps, so the cost of the
    check should scale well with the number of nodes (it's O(n)).  The
    per-node cost of this check also seems cheap compared to the disc
    access.  In release mode, loading 5000 nodes from a (probably in-cache)
    sqlite database took 53ms, while the check took 9 ms.
    
    BUG=101048
    TEST=Manual.  Corrupted the database with external sqlite tool, verified
    that the database was deleted and re-created next time Chrome was loaded.
    
    Review URL: http://codereview.chromium.org/8475017
    
    git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111033 0039d316-1c4b-4281-b951-d872f2087c98
    b4031e8a
syncable_id.h 3.81 KB