go/zodb: LiveCache: Allow objects to be pinned / omitted from the cache
We already have LiveCacheControl and policy to keep object state in live cache. However that state is currently kept only until the object is present in the cache, and the object is there currently only until there are live pointers to the object from anywhere. If all such pointers go away, LiveCache currently discards the object. Add a way (PCachePinObject) to tell live cache that it must retain an object even if there are no other pointers to it. This is needed for Wendelin.core which semantically relies on some objects to be present in live cache, even if in ghost state, for propagating ZODB invalidations into OS pagecache: https://lab.nexedi.com/kirr/wendelin.core/blob/000bf16359/wcfs/wcfs.go#L245 For symmetry add a way (PCacheDropObject) to tell live cache that it must not retain an object. This makes sense for objects that are read in large only once to avoid needlessly evicting all other objects while making the room for what won't be soon used again. For completeness add also a way (PCacheDropState) to tell live cache that the state of this object should not be cached. This can make sense even for objects that are pinned: for example Wendelin.core pins ZBlk objects to rely on volatile metadata it attaches to them, but have to drop ZBlk state that was loaded from database: that state is propagated to be cached in OS pagecache, and keeping it also in ZODB live cache would just waste RAM. Finally add test to cover LiveCache/LiveCacheControl functionality in detail.
Showing
Please register or sign in to comment