diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-30 23:08:39 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-30 23:08:39 +0000 |
commit | 3c85b8003597b96007ed2e6a98007bb6f3c0ddb2 (patch) | |
tree | 3ad86fe254b1eb88d1d7ed22201721d9e1315f83 /net | |
parent | 10ca64313cc70fd791172d6257c607b2c80e5eff (diff) | |
download | chromium_src-3c85b8003597b96007ed2e6a98007bb6f3c0ddb2.zip chromium_src-3c85b8003597b96007ed2e6a98007bb6f3c0ddb2.tar.gz chromium_src-3c85b8003597b96007ed2e6a98007bb6f3c0ddb2.tar.bz2 |
Disk Cache: Make sure that an entry that pretends to be
"clean" is not really dirty.
If for some reason an entry is left on disk with a pointer
on the rankings node but without the dirty flag set, we now
recognize it as dirty the next time we read it from disk.
BUG=3987
TEST=DiskCacheTest.Backend_NotMarkedButDirty
Review URL: http://codereview.chromium.org/57024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12820 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/data/cache_tests/dirty_entry/contents.txt | 67 | ||||
-rw-r--r-- | net/data/cache_tests/dirty_entry/data_0 | bin | 0 -> 45056 bytes | |||
-rw-r--r-- | net/data/cache_tests/dirty_entry/data_1 | bin | 0 -> 270336 bytes | |||
-rw-r--r-- | net/data/cache_tests/dirty_entry/data_2 | bin | 0 -> 8192 bytes | |||
-rw-r--r-- | net/data/cache_tests/dirty_entry/data_3 | bin | 0 -> 8192 bytes | |||
-rw-r--r-- | net/data/cache_tests/dirty_entry/index | bin | 0 -> 262512 bytes | |||
-rw-r--r-- | net/disk_cache/backend_unittest.cc | 17 | ||||
-rw-r--r-- | net/disk_cache/entry_impl.cc | 3 |
8 files changed, 87 insertions, 0 deletions
diff --git a/net/data/cache_tests/dirty_entry/contents.txt b/net/data/cache_tests/dirty_entry/contents.txt new file mode 100644 index 0000000..6cece3e --- /dev/null +++ b/net/data/cache_tests/dirty_entry/contents.txt @@ -0,0 +1,67 @@ +Index header: +num_entries: 2 +num_bytes: 27 +this_id: 1 +table_len: 64k + +head: 0x90000001 +tail: 0x90000000 + +Address: 0xa0010002 +Address: 0xa0010003 + +------------------------------- + +entry: +Address: 0xa0010002 +hash: 0x687d1422 +next: 0 +rankings_node: 0x90000000 +key_len: 13 +long_key: 0 +data_size: 0's +data_addr: 0's +key: "the first key" + +rankings: +Address: 0x90000000 +next: 0x90000000 +prev: 0x90000001 +contents: 0xa0010002 +dirty: 0 +pointer: 0 + +------------------------------- + +entry: +Address: 0xa0010003 +hash: 0x63909ecb +next: 0 +rankings_node: 0x90000001 +key_len: 14 +long_key: 0 +data_size: 0's +data_addr: 0's +key: "some other key" + +rankings: +Address: 0x90000001 +next: 0x90000000 +prev: 0x90000001 +contents: 0xa0010003 +dirty: 0 +pointer: 0x0169dc48 <- Invalid. + +================================ + +Generated with: + +disk_cache::Entry *entry; +ASSERT_TRUE(cache_->CreateEntry("the first key", &entry)); +entry->Close(); + +ASSERT_TRUE(cache_->CreateEntry("some other key", &entry)); +entry->Close(); <---- Edit value* + +* Edit the value with the debugger before it is saved to disk (break on +the destructor of EntryImpl and skip the line that clears "pointer")
\ No newline at end of file diff --git a/net/data/cache_tests/dirty_entry/data_0 b/net/data/cache_tests/dirty_entry/data_0 Binary files differnew file mode 100644 index 0000000..1d60495 --- /dev/null +++ b/net/data/cache_tests/dirty_entry/data_0 diff --git a/net/data/cache_tests/dirty_entry/data_1 b/net/data/cache_tests/dirty_entry/data_1 Binary files differnew file mode 100644 index 0000000..446ac45 --- /dev/null +++ b/net/data/cache_tests/dirty_entry/data_1 diff --git a/net/data/cache_tests/dirty_entry/data_2 b/net/data/cache_tests/dirty_entry/data_2 Binary files differnew file mode 100644 index 0000000..c7e2eb9 --- /dev/null +++ b/net/data/cache_tests/dirty_entry/data_2 diff --git a/net/data/cache_tests/dirty_entry/data_3 b/net/data/cache_tests/dirty_entry/data_3 Binary files differnew file mode 100644 index 0000000..5eec973 --- /dev/null +++ b/net/data/cache_tests/dirty_entry/data_3 diff --git a/net/data/cache_tests/dirty_entry/index b/net/data/cache_tests/dirty_entry/index Binary files differnew file mode 100644 index 0000000..ba2b6ca --- /dev/null +++ b/net/data/cache_tests/dirty_entry/index diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc index 9851203..a13762f 100644 --- a/net/disk_cache/backend_unittest.cc +++ b/net/disk_cache/backend_unittest.cc @@ -817,6 +817,23 @@ TEST_F(DiskCacheTest, Backend_InvalidEntry) { delete cache; } +// We want to be able to deal with abnormal dirty entries. +TEST_F(DiskCacheTest, Backend_NotMarkedButDirty) { + ASSERT_TRUE(CopyTestCache(L"dirty_entry")); + std::wstring path = GetCachePath(); + disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0, + net::DISK_CACHE); + ASSERT_TRUE(NULL != cache); + + disk_cache::Entry *entry1, *entry2; + ASSERT_TRUE(cache->OpenEntry("the first key", &entry1)); + EXPECT_FALSE(cache->OpenEntry("some other key", &entry2)); + entry1->Close(); + + delete cache; + EXPECT_TRUE(CheckCacheIntegrity(path)); +} + // We want to be able to deal with messed up entries on disk. TEST_F(DiskCacheTest, Backend_InvalidRankings) { ASSERT_TRUE(CopyTestCache(L"bad_rankings")); diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc index 0173548..8ff7b21 100644 --- a/net/disk_cache/entry_impl.cc +++ b/net/disk_cache/entry_impl.cc @@ -539,6 +539,9 @@ EntryImpl* EntryImpl::Update(EntryImpl* entry) { bool EntryImpl::IsDirty(int32 current_id) { DCHECK(node_.HasData()); + if (node_.Data()->pointer && !node_.Data()->dirty) + return true; + return node_.Data()->dirty && current_id != node_.Data()->dirty; } |