pingora icon indicating copy to clipboard operation
pingora copied to clipboard

A counting problem of `used_weight` data field in `LruUnit<T>`.

Open JiajunDu opened this issue 1 year ago • 2 comments

Describe the bug

In the pingora-lru crate, the structure LruUnit<T> and related functions are implemented. The structure LruUnit<T> contains a data domain name used_weight, which should be equal to the sum of the weights of all elements stored in the structure.

I found that in the related functions of LruUnit<T>, the two functions remove and insert_tail did not handle changes in used_weight. Instead, corresponding processing is carried out in the admit and evict functions. Therefore, the result is that if the structure is operated by remove or insert_tail, used_weight will be inconsistent with the expected effect.

Therefore, I modified the remove and insert_tail functions of LruUnit<T>, and added tests for these two functions(remove and insert_tail). If possible, I can submit these codes in the form of a PR.

Pingora info

Pingora version: commit hash is 0de54eb9071a9c4baccc6bad7acad11e9c54186f Rust version: cargo 1.77.0 (3fe68eabf 2024-02-29) Operating system version: Ubuntu 20.04

JiajunDu avatar Mar 28 '24 03:03 JiajunDu

Thanks for your investigation, do you mind opening a PR for this?

andrewhavck avatar Mar 29 '24 17:03 andrewhavck

Thanks for your investigation, do you mind opening a PR for this?

I don't mind opening a PR for this issue. I will open one later.

JiajunDu avatar Mar 30 '24 03:03 JiajunDu

Fixed with commit 59b60f2.

gumpt avatar Apr 19 '24 22:04 gumpt