cloudflare / pingora

A library for building fast, reliable and evolvable network services.
Apache License 2.0
20.28k stars 1.1k forks source link

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

Closed JiajunDu closed 2 months ago

JiajunDu commented 3 months ago

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, 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

andrewhavck commented 3 months ago

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

JiajunDu commented 3 months ago

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.

gumpt commented 2 months ago

Fixed with commit 59b60f2.