| 247 | #endif |
| 248 | |
| 249 | int |
| 250 | RamCacheCLFUS::get(CryptoHash *key, Ptr<IOBufferData> *ret_data, uint64_t auxkey) |
| 251 | { |
| 252 | if (!this->_max_bytes) { |
| 253 | return 0; |
| 254 | } |
| 255 | int64_t i = key->slice32(3) % this->_nbuckets; |
| 256 | RamCacheCLFUSEntry *e = this->_bucket[i].head; |
| 257 | char *b = nullptr; |
| 258 | while (e) { |
| 259 | if (e->key == *key && e->auxkey == auxkey) { |
| 260 | this->_move_compressed(e); |
| 261 | if (!e->flag_bits.lru) { // in memory |
| 262 | if (CACHE_VALUE(e) > this->_average_value) { |
| 263 | this->_lru[e->flag_bits.lru].remove(e); |
| 264 | this->_lru[e->flag_bits.lru].enqueue(e); |
| 265 | } |
| 266 | e->hits++; |
| 267 | uint32_t ram_hit_state = RAM_HIT_COMPRESS_NONE; |
| 268 | if (e->flag_bits.compressed) { |
| 269 | b = static_cast<char *>(ats_malloc(e->len)); |
| 270 | switch (e->flag_bits.compressed) { |
| 271 | default: |
| 272 | goto Lfailed; |
| 273 | case CACHE_COMPRESSION_FASTLZ: { |
| 274 | int l = static_cast<int>(e->len); |
| 275 | if ((l != fastlz_decompress(e->data->data(), e->compressed_len, b, l))) { |
| 276 | goto Lfailed; |
| 277 | } |
| 278 | ram_hit_state = RAM_HIT_COMPRESS_FASTLZ; |
| 279 | break; |
| 280 | } |
| 281 | case CACHE_COMPRESSION_LIBZ: { |
| 282 | uLongf l = e->len; |
| 283 | if (Z_OK != |
| 284 | uncompress(reinterpret_cast<Bytef *>(b), &l, reinterpret_cast<Bytef *>(e->data->data()), e->compressed_len)) { |
| 285 | goto Lfailed; |
| 286 | } |
| 287 | ram_hit_state = RAM_HIT_COMPRESS_LIBZ; |
| 288 | break; |
| 289 | } |
| 290 | #ifdef HAVE_LZMA_H |
| 291 | case CACHE_COMPRESSION_LIBLZMA: { |
| 292 | size_t l = static_cast<size_t>(e->len), ipos = 0, opos = 0; |
| 293 | uint64_t memlimit = e->len * 2 + LZMA_BASE_MEMLIMIT; |
| 294 | if (LZMA_OK != lzma_stream_buffer_decode(&memlimit, 0, nullptr, reinterpret_cast<uint8_t *>(e->data->data()), &ipos, |
| 295 | e->compressed_len, reinterpret_cast<uint8_t *>(b), &opos, l)) { |
| 296 | goto Lfailed; |
| 297 | } |
| 298 | ram_hit_state = RAM_HIT_COMPRESS_LIBLZMA; |
| 299 | break; |
| 300 | } |
| 301 | #endif |
| 302 | } |
| 303 | IOBufferData *data = new_xmalloc_IOBufferData(b, e->len); |
| 304 | data->_mem_type = DEFAULT_ALLOC; |
| 305 | if (!e->flag_bits.copy) { // don't bother if we have to copy anyway |
| 306 | int64_t delta = (static_cast<int64_t>(e->compressed_len)) - static_cast<int64_t>(e->size); |
nothing calls this directly
no test coverage detected