@ -17,11 +17,23 @@
namespace ROCKSDB_NAMESPACE {
namespace ROCKSDB_NAMESPACE {
// A handle for lookup result. The handle may not be immediately ready or
// A handle for lookup result. Immediately after SecondaryCache::Lookup() with
// have a valid value. The caller must call isReady() to determine if its
// wait=false (and depending on the implementation), the handle could be in any
// ready, and call Wait() in order to block until it becomes ready.
// of the below states. It must not be destroyed while in the pending state.
// The caller must call Value() after it becomes ready to determine if the
// * Pending state (IsReady() == false): result is not ready. Value() and Size()
// handle successfullly read the item.
// must not be called.
// * Ready + not found state (IsReady() == true, Value() == nullptr): the lookup
// has completed, finding no match. Or an error occurred that prevented
// normal completion of the Lookup.
// * Ready + found state (IsReady() == false, Value() != nullptr): the lookup
// has completed, finding an entry that has been loaded into an object that is
// now owned by the caller.
//
// Wait() or SecondaryCache::WaitAll() may be skipped if IsReady() happens to
// return true, but (depending on the implementation) IsReady() might never
// return true without Wait() or SecondaryCache::WaitAll(). After the handle
// is known ready, calling Value() is required to avoid a memory leak in case
// of a cache hit.
class SecondaryCacheResultHandle {
class SecondaryCacheResultHandle {
public :
public :
virtual ~ SecondaryCacheResultHandle ( ) = default ;
virtual ~ SecondaryCacheResultHandle ( ) = default ;
@ -36,7 +48,9 @@ class SecondaryCacheResultHandle {
// the lookup was unsuccessful.
// the lookup was unsuccessful.
virtual Cache : : ObjectPtr Value ( ) = 0 ;
virtual Cache : : ObjectPtr Value ( ) = 0 ;
// Return the size of value
// Return the out_charge from the helper->create_cb used to construct the
// object.
// WART: potentially confusing name
virtual size_t Size ( ) = 0 ;
virtual size_t Size ( ) = 0 ;
} ;
} ;
@ -57,24 +71,13 @@ class SecondaryCache : public Customizable {
const std : : string & id ,
const std : : string & id ,
std : : shared_ptr < SecondaryCache > * result ) ;
std : : shared_ptr < SecondaryCache > * result ) ;
// Insert the given value into this cache. Ownership of `value` is
// Suggest inserting an entry into this cache. The caller retains ownership
// transferred to the callee, who is reponsible for deleting the value
// of `obj` (also called the "value"), so is only used directly by the
// with helper->del_cb if del_cb is not nullptr. Unlike Cache::Insert(),
// SecondaryCache during Insert(). When the cache chooses to perform the
// the callee is responsible for such cleanup even in case of non-OK
// suggested insertion, it uses the size_cb and saveto_cb provided by
// Status.
// `helper` to extract the persistable data (typically an uncompressed block)
// Typically, the value is not saved directly but the implementation
// and writes it to this cache tier. OK may be returned even if the insertion
// uses the SaveToCallback provided by helper to extract value's
// is not made.
// persistable data (typically uncompressed block), which will be written
// to this tier. The implementation may or may not write it to cache
// depending on the admission control policy, even if the return status
// is success (OK).
//
// If the implementation is asynchronous or otherwise uses `value` after
// the call returns, then InsertSaved() must be overridden not to rely on
// Insert(). For example, there could be a "holding area" in memory where
// Lookup() might return the same parsed value back. But more typically, if
// the implementation only uses `value` for getting persistable data during
// the call, then the default implementation of `InsertSaved()` suffices.
virtual Status Insert ( const Slice & key , Cache : : ObjectPtr obj ,
virtual Status Insert ( const Slice & key , Cache : : ObjectPtr obj ,
const Cache : : CacheItemHelper * helper ) = 0 ;
const Cache : : CacheItemHelper * helper ) = 0 ;
@ -84,8 +87,9 @@ class SecondaryCache : public Customizable {
// may or may not write it to cache depending on the admission control
// may or may not write it to cache depending on the admission control
// policy, even if the return status is success.
// policy, even if the return status is success.
//
//
// The default implementation assumes synchronous, non-escaping Insert(),
// The default implementation only assumes the entry helper's create_cb is
// wherein `value` is not used after return of Insert(). See Insert().
// called at Lookup() time and not Insert() time, so should work for all
// foreseeable implementations.
virtual Status InsertSaved ( const Slice & key , const Slice & saved ) ;
virtual Status InsertSaved ( const Slice & key , const Slice & saved ) ;
// Lookup the data for the given key in this cache. The create_cb
// Lookup the data for the given key in this cache. The create_cb