Skip to content

Commit 8061168

Browse files
authored
Prevent get_or_insert from adding all entries to hot (#95)
1 parent bce276c commit 8061168

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/shard.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ impl<
816816
enter_state = ResidentState::Hot;
817817
}
818818
Entry::Placeholder(ph) => {
819-
referenced = 1; // Pretend it's a newly insereted Resident
819+
referenced = 1; // Pretend it's a newly inserted Resident
820820
enter_state = ph.hot;
821821
}
822822
}
@@ -933,12 +933,14 @@ impl<
933933
if weight > self.weight_target_hot && !self.lifecycle.is_pinned(&key, &value) {
934934
self.lifecycle.before_evict(lcs, &key, &mut value);
935935
weight = self.weighter.weight(&key, &value);
936+
// check again, it could have changed weight
936937
if weight > self.weight_target_hot {
937938
return self.handle_overweight_replace_placeholder(lcs, placeholder, key, value);
938939
}
939940
}
940941

941-
if self.weight_hot + self.weight_cold + weight <= self.weight_capacity {
942+
// cache is filling up, admit as hot if possible
943+
if self.weight_hot + weight <= self.weight_target_hot {
942944
placeholder_hot = ResidentState::Hot;
943945
}
944946
*entry = Entry::Resident(Resident {
@@ -995,6 +997,7 @@ impl<
995997
if weight > self.weight_target_hot && !self.lifecycle.is_pinned(&key, &value) {
996998
self.lifecycle.before_evict(lcs, &key, &mut value);
997999
weight = self.weighter.weight(&key, &value);
1000+
// check again, it could have changed weight
9981001
if weight > self.weight_target_hot {
9991002
return self.handle_insert_overweight(lcs, hash, key, value, strategy);
10001003
}

0 commit comments

Comments
 (0)