| 863 | } |
| 864 | |
| 865 | HandleBase* LIRSCacheShard::Allocate(Slice key, uint32_t hash, int val_len, |
| 866 | size_t charge) { |
| 867 | DCHECK(initialized_); |
| 868 | int key_len = key.size(); |
| 869 | DCHECK_GE(key_len, 0); |
| 870 | DCHECK_GE(val_len, 0); |
| 871 | DCHECK_GT(charge, 0); |
| 872 | if (charge == 0 || charge > protected_capacity_) { |
| 873 | return nullptr; |
| 874 | } |
| 875 | int key_len_padded = KUDU_ALIGN_UP(key_len, sizeof(void*)); |
| 876 | uint8_t* buf = new uint8_t[sizeof(LIRSHandle) |
| 877 | + key_len_padded + val_len]; // the kv_data VLA data |
| 878 | int calc_charge = |
| 879 | (charge == Cache::kAutomaticCharge) ? kudu::kudu_malloc_usable_size(buf) : charge; |
| 880 | uint8_t* kv_ptr = buf + sizeof(LIRSHandle); |
| 881 | LIRSHandle* handle = new (buf) LIRSHandle(kv_ptr, key, hash, val_len, |
| 882 | calc_charge); |
| 883 | return handle; |
| 884 | } |
| 885 | |
| 886 | void LIRSCacheShard::Free(HandleBase* handle) { |
| 887 | DCHECK(initialized_); |
nothing calls this directly
no test coverage detected