| 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) { |
| 900 | if (UNLIKELY(trace_replay_)) { |
| 901 | DCHECK(buffer == nullptr); |
| 902 | DCHECK(cache_file == nullptr); |
| 903 | } |
| 904 | DCHECK_EQ(insertion_offset % PAGE_SIZE, 0); |
| 905 | const int64_t charge_len = BitUtil::RoundUp(buffer_len, PAGE_SIZE); |
| 906 | |
| 907 | // Allocate a cache handle |
| 908 | Cache::UniquePendingHandle pending_handle( |
| 909 | meta_cache_->Allocate(key, sizeof(CacheEntry), charge_len)); |
| 910 | if (UNLIKELY(pending_handle.get() == nullptr)) return false; |
| 911 | |
| 912 | int64_t checksum = 0; |
| 913 | // Trace replays have no data and cannot do checksums |
| 914 | if (LIKELY(!trace_replay_)) { |
| 915 | // Compute checksum if necessary. |
| 916 | checksum = FLAGS_data_cache_checksum ? Checksum(buffer, buffer_len) : 0; |
| 917 | |
| 918 | // Write to backing file. |
| 919 | VLOG(3) << Substitute("Storing file $0 offset $1 len $2 checksum $3 ", |
| 920 | cache_file->path(), insertion_offset, buffer_len, checksum); |
| 921 | bool write_success; |
| 922 | { |
| 923 | ScopedHistogramTimer write_timer(write_latency_); |
| 924 | write_success = cache_file->Write(insertion_offset, buffer, buffer_len); |
| 925 | } |
| 926 | if (UNLIKELY(!write_success)) { |
| 927 | return false; |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | // IMPALA-10971: These metrics need to be incremented prior to the Insert(), because |
| 932 | // the Insert() can fail and instantly evict the entry. When that happens, |
| 933 | // the total bytes and num entries are decremented. Without this corresponding |
| 934 | // increment, the counts will be incorrect. |
| 935 | // Trace replays do not keep metrics |
| 936 | if (LIKELY(!trace_replay_)) { |
| 937 | ImpaladMetrics::IO_MGR_REMOTE_DATA_CACHE_TOTAL_BYTES->Increment(charge_len); |
| 938 | ImpaladMetrics::IO_MGR_REMOTE_DATA_CACHE_NUM_ENTRIES->Increment(1); |
| 939 | ImpaladMetrics::IO_MGR_REMOTE_DATA_CACHE_NUM_WRITES->Increment(1); |
| 940 | } |
| 941 | |
| 942 | // Insert the new entry into the cache. |
| 943 | CacheEntry entry(cache_file, insertion_offset, buffer_len, checksum); |
| 944 | memcpy(meta_cache_->MutableValue(&pending_handle), &entry, sizeof(CacheEntry)); |
| 945 | Cache::UniqueHandle handle(meta_cache_->Insert(std::move(pending_handle), this)); |
| 946 | // Check for failure of Insert(), which means the entry was evicted during Insert() |
| 947 | if (UNLIKELY(handle.get() == nullptr)){ |
| 948 | // Trace replays do not keep metrics |
| 949 | if (LIKELY(!trace_replay_)) { |
| 950 | // EvictedEntry() already ran and decremented the other counters. |
| 951 | ImpaladMetrics::IO_MGR_REMOTE_DATA_CACHE_INSTANT_EVICTIONS->Increment(1); |
| 952 | } |
| 953 | return false; |
| 954 | } |
| 955 | return true; |
nothing calls this directly
no test coverage detected