| 875 | } |
| 876 | |
| 877 | bool DataCache::Partition::HandleExistingEntry(const Slice& key, |
| 878 | const Cache::UniqueHandle& handle, const uint8_t* buffer, int64_t buffer_len) { |
| 879 | // Unpack the cache entry. |
| 880 | CacheEntry entry(meta_cache_->Value(handle)); |
| 881 | |
| 882 | // Trace replays have no data and cannot do checksums. |
| 883 | if (LIKELY(!trace_replay_)) { |
| 884 | // Try verifying the checksum of the new buffer matches that of the existing entry. |
| 885 | // On checksum mismatch, delete the existing entry and don't install the new entry |
| 886 | // as it's unclear which one is right. |
| 887 | if (FLAGS_data_cache_checksum && buffer_len >= entry.len()) { |
| 888 | if (!VerifyChecksum("write", entry, buffer, buffer_len)) { |
| 889 | meta_cache_->Erase(key); |
| 890 | return true; |
| 891 | } |
| 892 | } |
| 893 | } |
| 894 | // If the new entry is not any longer than the existing entry, no work to do. |
| 895 | return entry.len() >= buffer_len; |
| 896 | } |
| 897 | |
| 898 | bool DataCache::Partition::InsertIntoCache(const Slice& key, CacheFile* cache_file, |
| 899 | int64_t insertion_offset, const uint8_t* buffer, int64_t buffer_len) { |