Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::ObjectCache Class Reference
Collaboration diagram for duckdb::ObjectCache:

Public Member Functions

 ObjectCache (BufferPool &buffer_pool_p)
 
 ObjectCache (idx_t max_memory, BufferPool &buffer_pool_p)
 
shared_ptr< ObjectCacheEntryGetObject (const string &key)
 
template<class T >
shared_ptr< T > Get (const string &key)
 
template<class T , class... ARGS>
shared_ptr< T > GetOrCreate (const string &key, ARGS &&... args)
 
void Put (string key, shared_ptr< ObjectCacheEntry > value)
 
void Delete (const string &key)
 
idx_t GetMaxMemory () const
 
idx_t GetCurrentMemory () const
 
size_t GetEntryCount () const
 
bool IsEmpty () const
 
idx_t EvictToReduceMemory (idx_t target_bytes)
 

Static Public Member Functions

static DUCKDB_API ObjectCacheGetObjectCache (ClientContext &context)
 

Static Public Attributes

static constexpr idx_t DEFAULT_MAX_MEMORY = 8ULL * 1024 * 1024 * 1024
 Default max memory 8GiB for non-evictable cache entries.
 

Private Attributes

mutex lock_mutex
 
SharedLruCache< string, ObjectCacheEntry, duckdb::BufferPoolPayloadlru_cache
 LRU cache for evictable entries.
 
unordered_map< string, shared_ptr< ObjectCacheEntry > > non_evictable_entries
 Separate storage for non-evictable entries (i.e., encryption keys)
 
BufferPool & buffer_pool
 Used to create buffer pool reservation on entries creation.
 

Constructor & Destructor Documentation

◆ ObjectCache() [1/2]

duckdb::ObjectCache::ObjectCache ( BufferPool &  buffer_pool_p)
inlineexplicit
51584 : ObjectCache(DEFAULT_MAX_MEMORY, buffer_pool_p) {
51585 }
static constexpr idx_t DEFAULT_MAX_MEMORY
Default max memory 8GiB for non-evictable cache entries.
Definition duckdb.cpp:51582

◆ ObjectCache() [2/2]

duckdb::ObjectCache::ObjectCache ( idx_t  max_memory,
BufferPool &  buffer_pool_p 
)
inline
51587 : lru_cache(max_memory), buffer_pool(buffer_pool_p) {
51588 }
BufferPool & buffer_pool
Used to create buffer pool reservation on entries creation.
Definition duckdb.cpp:51706
SharedLruCache< string, ObjectCacheEntry, duckdb::BufferPoolPayload > lru_cache
LRU cache for evictable entries.
Definition duckdb.cpp:51702

Member Function Documentation

◆ GetObject()

shared_ptr< ObjectCacheEntry > duckdb::ObjectCache::GetObject ( const string &  key)
inline
51590 {
51591 const lock_guard<mutex> lock(lock_mutex);
51592 auto non_evictable_it = non_evictable_entries.find(key);
51593 if (non_evictable_it != non_evictable_entries.end()) {
51594 return non_evictable_it->second;
51595 }
51596 return lru_cache.Get(key);
51597 }
unordered_map< string, shared_ptr< ObjectCacheEntry > > non_evictable_entries
Separate storage for non-evictable entries (i.e., encryption keys)
Definition duckdb.cpp:51704

◆ Get()

template<class T >
shared_ptr< T > duckdb::ObjectCache::Get ( const string &  key)
inline
51600 {
51601 shared_ptr<ObjectCacheEntry> object = GetObject(key);
51602 if (!object || object->GetObjectType() != T::ObjectType()) {
51603 return nullptr;
51604 }
51605 return shared_ptr_cast<ObjectCacheEntry, T>(object);
51606 }

◆ GetOrCreate()

template<class T , class... ARGS>
shared_ptr< T > duckdb::ObjectCache::GetOrCreate ( const string &  key,
ARGS &&...  args 
)
inline
51609 {
51610 const lock_guard<mutex> lock(lock_mutex);
51611
51612 // Check non-evictable entries first
51613 auto non_evictable_it = non_evictable_entries.find(key);
51614 if (non_evictable_it != non_evictable_entries.end()) {
51615 auto &existing = non_evictable_it->second;
51616 if (existing->GetObjectType() != T::ObjectType()) {
51617 return nullptr;
51618 }
51619 return shared_ptr_cast<ObjectCacheEntry, T>(existing);
51620 }
51621
51622 // Check evictable cache
51623 auto existing = lru_cache.Get(key);
51624 if (existing) {
51625 if (existing->GetObjectType() != T::ObjectType()) {
51626 return nullptr;
51627 }
51628 return shared_ptr_cast<ObjectCacheEntry, T>(existing);
51629 }
51630
51631 // Create new entry while holding lock
51632 auto value = make_shared_ptr<T>(args...);
51633 const auto estimated_memory = value->GetEstimatedCacheMemory();
51634 const bool is_evictable = estimated_memory.IsValid();
51635 if (!is_evictable) {
51636 non_evictable_entries[key] = value;
51637 return value;
51638 }
51639
51640 auto reservation =
51641 make_uniq<TempBufferPoolReservation>(MemoryTag::OBJECT_CACHE, buffer_pool, estimated_memory.GetIndex());
51642 lru_cache.Put(key, value, std::move(reservation));
51643 return value;
51644 }

◆ Put()

void duckdb::ObjectCache::Put ( string  key,
shared_ptr< ObjectCacheEntry value 
)
inline
51646 {
51647 if (!value) {
51648 return;
51649 }
51650
51651 const lock_guard<mutex> lock(lock_mutex);
51652 const auto estimated_memory = value->GetEstimatedCacheMemory();
51653 const bool is_evictable = estimated_memory.IsValid();
51654 if (!is_evictable) {
51655 non_evictable_entries[std::move(key)] = std::move(value);
51656 return;
51657 }
51658
51659 auto reservation =
51660 make_uniq<TempBufferPoolReservation>(MemoryTag::OBJECT_CACHE, buffer_pool, estimated_memory.GetIndex());
51661 lru_cache.Put(std::move(key), std::move(value), std::move(reservation));
51662 }

◆ Delete()

void duckdb::ObjectCache::Delete ( const string &  key)
inline
51664 {
51665 const lock_guard<mutex> lock(lock_mutex);
51666 auto iter = non_evictable_entries.find(key);
51667 if (iter != non_evictable_entries.end()) {
51668 non_evictable_entries.erase(iter);
51669 return;
51670 }
51671 lru_cache.Delete(key);
51672 }

◆ GetMaxMemory()

idx_t duckdb::ObjectCache::GetMaxMemory ( ) const
inline
51676 {
51677 const lock_guard<mutex> lock(lock_mutex);
51678 return lru_cache.Capacity();
51679 }

◆ GetCurrentMemory()

idx_t duckdb::ObjectCache::GetCurrentMemory ( ) const
inline
51680 {
51681 const lock_guard<mutex> lock(lock_mutex);
51682 return lru_cache.CurrentTotalWeight();
51683 }

◆ GetEntryCount()

size_t duckdb::ObjectCache::GetEntryCount ( ) const
inline
51684 {
51685 const lock_guard<mutex> lock(lock_mutex);
51686 return lru_cache.Size() + non_evictable_entries.size();
51687 }

◆ IsEmpty()

bool duckdb::ObjectCache::IsEmpty ( ) const
inline
51688 {
51689 const lock_guard<mutex> lock(lock_mutex);
51690 return lru_cache.IsEmpty() && non_evictable_entries.empty();
51691 }

◆ EvictToReduceMemory()

idx_t duckdb::ObjectCache::EvictToReduceMemory ( idx_t  target_bytes)
inline
51693 {
51694 const lock_guard<mutex> lock(lock_mutex);
51695 return lru_cache.EvictToReduceAtLeast(target_bytes);
51696 }

The documentation for this class was generated from the following file: