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::DatabaseFilePathManager Class Reference

The DatabaseFilePathManager is used to ensure we only ever open a single database file once. More...

#include <duckdb.hpp>

Public Member Functions

idx_t ApproxDatabaseCount () const
InsertDatabasePathResult InsertDatabasePath (DatabaseManager &manager, const string &path, const string &name, OnCreateConflict on_conflict, AttachOptions &options)
void EraseDatabasePath (const string &path)
 Erase a database path - indicating we are done with using it.
void DetachDatabase (DatabaseManager &manager, const string &path)
 Called when a database is detached, but before it is fully finished being used.

Private Attributes

mutex db_paths_lock
 The lock to add entries to the db_paths map.
unordered_map< string, DatabasePathInfo > db_paths
 A set containing all attached database path This allows to attach many databases efficiently, and to avoid attaching the same file path twice.

Detailed Description

The DatabaseFilePathManager is used to ensure we only ever open a single database file once.

Member Function Documentation

◆ ApproxDatabaseCount()

idx_t duckdb::DatabaseFilePathManager::ApproxDatabaseCount ( ) const
277343 {
277344 lock_guard<mutex> path_lock(db_paths_lock);
277345 return db_paths.size();
277346}
mutex db_paths_lock
The lock to add entries to the db_paths map.
Definition duckdb.hpp:40734
unordered_map< string, DatabasePathInfo > db_paths
A set containing all attached database path This allows to attach many databases efficiently,...
Definition duckdb.hpp:40741

◆ InsertDatabasePath()

InsertDatabasePathResult duckdb::DatabaseFilePathManager::InsertDatabasePath ( DatabaseManager & manager,
const string & path,
const string & name,
OnCreateConflict on_conflict,
AttachOptions & options )
277350 {
277351 if (path.empty() || path == IN_MEMORY_PATH) {
277352 throw InternalException("DatabaseFilePathManager::InsertDatabasePath - cannot insert in-memory database");
277353 }
277354 lock_guard<mutex> path_lock(db_paths_lock);
277355 auto entry = db_paths.emplace(path, DatabasePathInfo(manager, name, options.access_mode));
277356 if (!entry.second) {
277357 auto &existing = entry.first->second;
277358 bool already_exists = false;
277359 bool attached_in_this_system = false;
277360 if (on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT && existing.name == name) {
277361 already_exists = true;
277362 attached_in_this_system = existing.attached_databases.find(manager) != existing.attached_databases.end();
277363 }
277364 if (options.access_mode == AccessMode::READ_ONLY && existing.access_mode == AccessMode::READ_ONLY) {
277365 if (attached_in_this_system) {
277366 return InsertDatabasePathResult::ALREADY_EXISTS;
277367 }
277368 // all attaches are in read-only mode - there is no conflict, just increase the reference count
277369 existing.attached_databases.insert(manager);
277370 existing.reference_count++;
277371 } else {
277372 if (already_exists) {
277373 if (attached_in_this_system) {
277374 return InsertDatabasePathResult::ALREADY_EXISTS;
277375 }
277376 throw BinderException(
277377 "Unique file handle conflict: Cannot attach \"%s\" - the database file \"%s\" is in "
277378 "the process of being detached",
277379 name, path);
277380 }
277381 throw BinderException(
277382 "Unique file handle conflict: Cannot attach \"%s\" - the database file \"%s\" is already "
277383 "attached by database \"%s\"",
277384 name, path, existing.name);
277385 }
277386 }
277387 options.stored_database_path = make_uniq<StoredDatabasePath>(manager, *this, path, name);
277388 return InsertDatabasePathResult::SUCCESS;
277389}

◆ EraseDatabasePath()

void duckdb::DatabaseFilePathManager::EraseDatabasePath ( const string & path)

Erase a database path - indicating we are done with using it.

277391 {
277392 if (path.empty() || path == IN_MEMORY_PATH) {
277393 return;
277394 }
277395 lock_guard<mutex> path_lock(db_paths_lock);
277396 auto entry = db_paths.find(path);
277397 if (entry != db_paths.end()) {
277398 if (entry->second.reference_count <= 1) {
277399 db_paths.erase(entry);
277400 } else {
277401 entry->second.reference_count--;
277402 }
277403 }
277404}

◆ DetachDatabase()

void duckdb::DatabaseFilePathManager::DetachDatabase ( DatabaseManager & manager,
const string & path )

Called when a database is detached, but before it is fully finished being used.

277406 {
277407 if (path.empty() || path == IN_MEMORY_PATH) {
277408 return;
277409 }
277410 lock_guard<mutex> path_lock(db_paths_lock);
277411 auto entry = db_paths.find(path);
277412 if (entry != db_paths.end()) {
277413 entry->second.attached_databases.erase(manager);
277414 }
277415}

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