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::ExternalFileCache Class Reference
Collaboration diagram for duckdb::ExternalFileCache:

Classes

struct  CachedFileRange
 Cached reads (immutable). More...
struct  CachedFile
 Cached files. More...

Public Types

enum class  CachedFileRangeOverlap { NONE , PARTIAL , FULL }

Public Member Functions

 ExternalFileCache (DatabaseInstance &db, bool enable)
bool IsEnabled () const
void SetEnabled (bool enable)
vector< CachedFileInformation > GetCachedFileInformation () const
BufferManager & GetBufferManager () const
CachedFile & GetOrCreateCachedFile (const string &path)
 Gets the cached file, or creates it if is not yet present.

Static Public Member Functions

static ExternalFileCache & Get (DatabaseInstance &db)
static ExternalFileCache & Get (ClientContext &context)
static DUCKDB_API bool IsValid (bool validate, const string &cached_version_tag, timestamp_t cached_last_modified, const string &current_version_tag, timestamp_t current_last_modified)

Private Attributes

BufferManager & buffer_manager
 The BufferManager used to cache files.
atomic< bool > enable
 Whether or not file caching is enabled.
unordered_map< string, unique_ptr< CachedFile > > cached_files
 Mapping from file path to cached file with cached ranges.
mutex lock
 Lock for accessing the cached files.

Member Enumeration Documentation

◆ CachedFileRangeOverlap

enum class duckdb::ExternalFileCache::CachedFileRangeOverlap
strong
144591{ NONE, PARTIAL, FULL };

Constructor & Destructor Documentation

◆ ExternalFileCache()

duckdb::ExternalFileCache::ExternalFileCache ( DatabaseInstance & db,
bool enable )
413366 : buffer_manager(BufferManager::GetBufferManager(db)), enable(enable_p) {
413367}
atomic< bool > enable
Whether or not file caching is enabled.
Definition duckdb.cpp:144674
BufferManager & buffer_manager
The BufferManager used to cache files.
Definition duckdb.cpp:144672

Member Function Documentation

◆ Get() [1/2]

ExternalFileCache & duckdb::ExternalFileCache::Get ( DatabaseInstance & db)
static
413395 {
413396 return db.GetExternalFileCache();
413397}
db

◆ Get() [2/2]

ExternalFileCache & duckdb::ExternalFileCache::Get ( ClientContext & context)
static
413399 {
413400 return context.db->GetExternalFileCache();
413401}

◆ IsEnabled()

bool duckdb::ExternalFileCache::IsEnabled ( ) const
413369 {
413370 return enable;
413371}

◆ SetEnabled()

void duckdb::ExternalFileCache::SetEnabled ( bool enable)
413373 {
413374 lock_guard<mutex> guard(lock);
413375 enable = enable_p;
413376 if (!enable) {
413377 cached_files.clear();
413378 }
413379}
unordered_map< string, unique_ptr< CachedFile > > cached_files
Mapping from file path to cached file with cached ranges.
Definition duckdb.cpp:144676
mutex lock
Lock for accessing the cached files.
Definition duckdb.cpp:144678

◆ GetCachedFileInformation()

vector< CachedFileInformation > duckdb::ExternalFileCache::GetCachedFileInformation ( ) const
413381 {
413382 unique_lock<mutex> files_guard(lock);
413383 vector<CachedFileInformation> result;
413384 for (const auto &file : cached_files) {
413385 auto ranges_guard = file.second->lock.GetSharedLock();
413386 for (const auto &range_entry : file.second->Ranges(ranges_guard)) {
413387 const auto &range = *range_entry.second;
413388 result.push_back(
413389 {file.first, range.nr_bytes, range.location, !range.block_handle->GetMemory().IsUnloaded()});
413390 }
413391 }
413392 return result;
413393}

◆ GetBufferManager()

BufferManager & duckdb::ExternalFileCache::GetBufferManager ( ) const
413403 {
413404 return buffer_manager;
413405}

◆ GetOrCreateCachedFile()

ExternalFileCache::CachedFile & duckdb::ExternalFileCache::GetOrCreateCachedFile ( const string & path)

Gets the cached file, or creates it if is not yet present.

413407 {
413408 lock_guard<mutex> guard(lock);
413409 auto &entry = cached_files[path];
413410 if (!entry) {
413411 entry = make_uniq<CachedFile>(path);
413412 }
413413 return *entry;
413414}

◆ IsValid()

bool duckdb::ExternalFileCache::IsValid ( bool validate,
const string & cached_version_tag,
timestamp_t cached_last_modified,
const string & current_version_tag,
timestamp_t current_last_modified )
static
413310 {
413311 if (!validate) {
413312 return true; // Assume valid
413313 }
413314 if (!current_version_tag.empty() || !cached_version_tag.empty()) {
413315 return cached_version_tag == current_version_tag; // Validity checked by version tag (httpfs)
413316 }
413317 if (cached_last_modified != current_last_modified) {
413318 return false; // The file has certainly been modified
413319 }
413320 // The last modified time matches. However, we cannot blindly trust this,
413321 // because some file systems use a low resolution clock to set the last modified time.
413322 // So, we will require that the last modified time is more than 10 seconds ago.
413323 static constexpr int64_t LAST_MODIFIED_THRESHOLD = 10LL * 1000LL * 1000LL;
413324 const auto access_time = Timestamp::GetCurrentTimestamp();
413325 if (access_time < current_last_modified) {
413326 return false; // Last modified in the future?
413327 }
413328 return access_time - current_last_modified > LAST_MODIFIED_THRESHOLD;
413329}
static DUCKDB_API timestamp_t GetCurrentTimestamp()
Returns current timestamp.
Definition duckdb.cpp:129836
::int64_t int64_t

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