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

Public Member Functions

BufferPool & GetBufferPool () const
DUCKDB_API SecretManager & GetSecretManager ()
DUCKDB_API BufferManager & GetBufferManager ()
DUCKDB_API const BufferManager & GetBufferManager () const
DUCKDB_API DatabaseManager & GetDatabaseManager ()
DUCKDB_API FileSystem & GetFileSystem ()
DUCKDB_API ExternalFileCache & GetExternalFileCache ()
DUCKDB_API ResultSetManager & GetResultSetManager ()
DUCKDB_API TaskScheduler & GetScheduler ()
DUCKDB_API ObjectCache & GetObjectCache ()
DUCKDB_API ConnectionManager & GetConnectionManager ()
DUCKDB_API ExtensionManager & GetExtensionManager ()
DUCKDB_API ValidChecker & GetValidChecker ()
DUCKDB_API LogManager & GetLogManager () const
DUCKDB_API const duckdb_ext_api_v1 GetExtensionAPIV1 ()
idx_t NumberOfThreads ()
DUCKDB_API bool ExtensionIsLoaded (const string &name)
DUCKDB_API SettingLookupResult TryGetCurrentSetting (const string &key, Value &result) const
DUCKDB_API shared_ptr< EncryptionUtil > GetEncryptionUtil (bool read_only=false)
shared_ptr< EncryptionUtil > GetMbedTLSUtil (bool force_mbedtls) const
shared_ptr< AttachedDatabase > CreateAttachedDatabase (ClientContext &context, AttachInfo &info, AttachOptions &options)
Public Member Functions inherited from duckdb::enable_shared_from_this< DatabaseInstance >
shared_ptr< DatabaseInstance > shared_from_this ()

Static Public Member Functions

static DUCKDB_API DatabaseInstance & GetDatabase (ClientContext &context)
static DUCKDB_API const DatabaseInstance & GetDatabase (const ClientContext &context)

Public Attributes

DBConfig config

Private Member Functions

void Initialize (const char *path, DBConfig *config)
void LoadExtensionSettings ()
void CreateMainDatabase ()
void Configure (DBConfig &config, const char *path)

Private Attributes

shared_ptr< BufferManager > buffer_manager
unique_ptr< DatabaseManager > db_manager
unique_ptr< TaskScheduler > scheduler
unique_ptr< ObjectCache > object_cache
unique_ptr< ConnectionManager > connection_manager
unique_ptr< ExtensionManager > extension_manager
ValidChecker db_validity
unique_ptr< DatabaseFileSystem > db_file_system
unique_ptr< LogManager > log_manager
unique_ptr< ExternalFileCache > external_file_cache
unique_ptr< ResultSetManager > result_set_manager
duckdb_ext_api_v1(* create_api_v1 )()

Friends

class DuckDB

Additional Inherited Members

Protected Member Functions inherited from duckdb::enable_shared_from_this< DatabaseInstance >
enable_shared_from_this & operator= (enable_shared_from_this const &) noexcept

Constructor & Destructor Documentation

◆ DatabaseInstance()

duckdb::DatabaseInstance::DatabaseInstance ( )
276808 : db_validity(*this) {
276809 config.is_user_config = false;
276810 create_api_v1 = nullptr;
276811}

◆ ~DatabaseInstance()

duckdb::DatabaseInstance::~DatabaseInstance ( )
276813 {
276814 // destroy all attached databases
276815 if (db_manager) {
276816 db_manager->ResetDatabases();
276817 }
276818 // destroy child elements
276819 connection_manager.reset();
276820 object_cache.reset();
276821 scheduler.reset();
276822 db_manager.reset();
276823
276824 // stop the log manager, after this point Logger calls are unsafe.
276825 log_manager.reset();
276826
276827 external_file_cache.reset();
276828 result_set_manager.reset();
276829
276830 buffer_manager.reset();
276831
276832 // flush allocations and disable the background thread
276833 config.block_allocator->FlushAll();
276834 Allocator::SetBackgroundThreads(false);
276835 // after all destruction is complete clear the cache entry
276836 config.db_cache_entry.reset();
276837}

Member Function Documentation

◆ GetBufferPool()

BufferPool & duckdb::DatabaseInstance::GetBufferPool ( ) const
277097 {
277098 return *config.buffer_pool;
277099}

◆ GetSecretManager()

SecretManager & duckdb::DatabaseInstance::GetSecretManager ( )
277085 {
277086 return *config.secret_manager;
277087}

◆ GetBufferManager() [1/2]

BufferManager & duckdb::DatabaseInstance::GetBufferManager ( )
277089 {
277090 return *buffer_manager;
277091}

◆ GetBufferManager() [2/2]

const BufferManager & duckdb::DatabaseInstance::GetBufferManager ( ) const
277093 {
277094 return *buffer_manager;
277095}

◆ GetDatabaseManager()

DatabaseManager & duckdb::DatabaseInstance::GetDatabaseManager ( )
276847 {
276848 if (!db_manager) {
276849 throw InternalException("Missing DB manager");
276850 }
276851 return *db_manager;
276852}

◆ GetFileSystem()

FileSystem & duckdb::DatabaseInstance::GetFileSystem ( )
277117 {
277118 return *db_file_system;
277119}

◆ GetExternalFileCache()

ExternalFileCache & duckdb::DatabaseInstance::GetExternalFileCache ( )
277121 {
277122 return *external_file_cache;
277123}

◆ GetResultSetManager()

ResultSetManager & duckdb::DatabaseInstance::GetResultSetManager ( )
277125 {
277126 return *result_set_manager;
277127}

◆ GetScheduler()

TaskScheduler & duckdb::DatabaseInstance::GetScheduler ( )
277109 {
277110 return *scheduler;
277111}

◆ GetObjectCache()

ObjectCache & duckdb::DatabaseInstance::GetObjectCache ( )
277113 {
277114 return *object_cache;
277115}

◆ GetConnectionManager()

ConnectionManager & duckdb::DatabaseInstance::GetConnectionManager ( )
277129 {
277130 return *connection_manager;
277131}

◆ GetExtensionManager()

ExtensionManager & duckdb::DatabaseInstance::GetExtensionManager ( )
277133 {
277134 return *extension_manager;
277135}

◆ GetValidChecker()

ValidChecker & duckdb::DatabaseInstance::GetValidChecker ( )
277312 {
277313 return db_validity;
277314}

◆ GetLogManager()

LogManager & duckdb::DatabaseInstance::GetLogManager ( ) const
277321 {
277322 return *log_manager;
277323}

◆ GetExtensionAPIV1()

const duckdb_ext_api_v1 duckdb::DatabaseInstance::GetExtensionAPIV1 ( )
277316 {
277317 D_ASSERT(create_api_v1);
277318 return create_api_v1();
277319}

◆ NumberOfThreads()

idx_t duckdb::DatabaseInstance::NumberOfThreads ( )
277242 {
277243 return NumericCast<idx_t>(scheduler->NumberOfThreads());
277244}

◆ GetDatabase() [1/2]

DatabaseInstance & duckdb::DatabaseInstance::GetDatabase ( ClientContext & context)
static
276839 {
276840 return *context.db;
276841}

◆ GetDatabase() [2/2]

const DatabaseInstance & duckdb::DatabaseInstance::GetDatabase ( const ClientContext & context)
static
276843 {
276844 return *context.db;
276845}

◆ ExtensionIsLoaded()

bool duckdb::DatabaseInstance::ExtensionIsLoaded ( const string & name)
277250 {
277251 return extension_manager->ExtensionIsLoaded(name);
277252}

◆ TryGetCurrentSetting()

SettingLookupResult duckdb::DatabaseInstance::TryGetCurrentSetting ( const string & key,
Value & result ) const
277258 {
277259 // check the session values
277260 auto &db_config = DBConfig::GetConfig(*this);
277261 return db_config.TryGetCurrentSetting(key, result);
277262}

◆ GetEncryptionUtil()

shared_ptr< EncryptionUtil > duckdb::DatabaseInstance::GetEncryptionUtil ( bool read_only = false)
277274 {
277275 auto force_mbedtls = config.options.force_mbedtls;
277276
277277 if (force_mbedtls) {
277278 // return mbedtls if setting is enabled
277279 return GetMbedTLSUtil(force_mbedtls);
277280 }
277281
277282 if (!config.encryption_util) {
277283 // No encryption_util, attempt to get a hold of httpfs
277284 if (read_only) {
277285 // load is attempted, but no install is performed
277287 } else {
277288 // load is attempted, otherwise install+load
277289 ExtensionHelper::TryAutoLoadExtension(*this, "httpfs");
277290 }
277291 }
277292
277293 if (config.encryption_util) {
277294 // already available (potentially via httpfs loading)
277295 return config.encryption_util;
277296 }
277297
277298 if (read_only) {
277299 // return mbedtls if database is read only
277300 // and OpenSSL not set
277301 return GetMbedTLSUtil(force_mbedtls);
277302 }
277303
277304 throw InvalidConfigurationException(" DuckDB currently has a read-only crypto module "
277305 "loaded. Please ensure httpfs is loaded using `LOAD httpfs`, or for DuckDB "
277306 "database files consider READONLY mode."
277307 " To write an encrypted database or parquet file that is NOT securely "
277308 "encrypted, one can use SET force_mbedtls_unsafe = "
277309 "'true'.");
277310}
static DUCKDB_API bool TryAutoLoadExtension(DatabaseInstance &db, const string &extension_name) noexcept
Autoload an extension (depending on config, potentially a nop. Returns false on failure).
Definition duckdb.cpp:278501
static DUCKDB_API bool TryAutoLoadAvailableExtension(DatabaseInstance &instance, const string &extension_name) noexcept
Autoload an extension, only if available locally.
Definition duckdb.cpp:278525

◆ GetMbedTLSUtil()

shared_ptr< EncryptionUtil > duckdb::DatabaseInstance::GetMbedTLSUtil ( bool force_mbedtls) const
277264 {
277265 auto encryption_util = make_shared_ptr<duckdb_mbedtls::MbedTlsWrapper::AESStateMBEDTLSFactory>();
277266
277267 if (force_mbedtls) {
277268 encryption_util->ForceMbedTLSUnsafe();
277269 }
277270
277271 return encryption_util;
277272}

◆ CreateAttachedDatabase()

shared_ptr< AttachedDatabase > duckdb::DatabaseInstance::CreateAttachedDatabase ( ClientContext & context,
AttachInfo & info,
AttachOptions & options )
276903 {
276904 shared_ptr<AttachedDatabase> attached_database;
276905 auto &catalog = Catalog::GetSystemCatalog(*this);
276906
276907 if (!options.db_type.empty()) {
276908 // Find the storage extension for this database file.
276909 auto extension_name = ExtensionHelper::ApplyExtensionAlias(options.db_type);
276910 auto storage_extension = StorageExtension::Find(config, extension_name);
276911 if (!storage_extension) {
276912 throw BinderException("Unrecognized storage type \"%s\"", options.db_type);
276913 }
276914
276915 if (storage_extension->attach != nullptr && storage_extension->create_transaction_manager != nullptr) {
276916 // Use the storage extension to create the initial database.
276917 attached_database = make_shared_ptr<AttachedDatabase>(*this, catalog, *storage_extension, context,
276918 info.name, info, options);
276919 return attached_database;
276920 }
276921
276922 attached_database = make_shared_ptr<AttachedDatabase>(*this, catalog, info.name, info.path, options);
276923 return attached_database;
276924 }
276925
276926 // An empty db_type defaults to a duckdb database file.
276927 attached_database = make_shared_ptr<AttachedDatabase>(*this, catalog, info.name, info.path, options);
276928 return attached_database;
276929}
static DUCKDB_API Catalog & GetSystemCatalog(ClientContext &context)
Get the SystemCatalog from the ClientContext.
Definition duckdb.cpp:7173
static string ApplyExtensionAlias(const string &extension_name)
Apply any known extension aliases, return the lowercase name.
Definition duckdb.cpp:278254

◆ Initialize()

void duckdb::DatabaseInstance::Initialize ( const char * path,
DBConfig * config )
private
277004 {
277005 DBConfig default_config;
277006 DBConfig *config_ptr = &default_config;
277007 if (user_config) {
277008 config_ptr = user_config;
277009 }
277010
277011 Configure(*config_ptr, database_path);
277012
277013 create_api_v1 = CreateAPIv1Wrapper;
277014
277015 db_file_system = make_uniq<DatabaseFileSystem>(*this);
277016 db_manager = make_uniq<DatabaseManager>(*this);
277017 if (config.buffer_manager) {
277018 buffer_manager = config.buffer_manager;
277019 } else {
277020 buffer_manager = make_uniq<StandardBufferManager>(*this, config.options.temporary_directory);
277021 }
277022
277023 log_manager = make_uniq<LogManager>(*this, LogConfig());
277024 log_manager->Initialize();
277025
277026 bool enable_external_file_cache = Settings::Get<EnableExternalFileCacheSetting>(config);
277027 external_file_cache = make_uniq<ExternalFileCache>(*this, enable_external_file_cache);
277028 result_set_manager = make_uniq<ResultSetManager>(*this);
277029
277030 scheduler = make_uniq<TaskScheduler>(*this);
277031 object_cache = make_uniq<ObjectCache>(*config.buffer_pool);
277032 config.buffer_pool->SetObjectCache(object_cache.get());
277033 connection_manager = make_uniq<ConnectionManager>();
277034 extension_manager = make_uniq<ExtensionManager>(*this);
277035
277036 // initialize the secret manager
277037 config.secret_manager->Initialize(*this);
277038
277039 // resolve the type of the database we are opening
277040 auto &fs = FileSystem::GetFileSystem(*this);
277041 DBPathAndType::ResolveDatabaseType(fs, config.options.database_path, config.options.database_type);
277042
277043 // initialize the system catalog
277044 db_manager->InitializeSystemCatalog();
277045
277046 if (!config.options.database_type.empty() && !StringUtil::CIEquals(config.options.database_type, "duckdb")) {
277047 // if we are opening an extension database - load the extension
277048 if (!config.file_system) {
277049 throw InternalException("No file system!?");
277050 }
277051 auto storage_extension = StorageExtension::Find(config, config.options.database_type);
277052 if (!storage_extension) {
277053 ExtensionHelper::LoadExternalExtension(*this, *config.file_system, config.options.database_type);
277054 }
277055 }
277056
277057 LoadExtensionSettings();
277058
277059 if (!db_manager->HasDefaultDatabase()) {
277060 CreateMainDatabase();
277061 }
277062
277063 // only increase thread count after storage init because we get races on catalog otherwise
277064 scheduler->SetThreads(config.options.maximum_threads, Settings::Get<ExternalThreadsSetting>(config));
277065 scheduler->RelaunchThreads();
277066}
static void LoadExternalExtension(ClientContext &context, const string &extension)
Load an extension.
Definition duckdb.cpp:280517
static DUCKDB_API bool CIEquals(const string &l1, const string &l2)
Case insensitive equals.
Definition duckdb.cpp:109696
static void ResolveDatabaseType(FileSystem &fs, string &path, string &db_type)
Run ExtractExtensionPrefix followed by CheckMagicBytes.
Definition duckdb.cpp:277923

◆ LoadExtensionSettings()

void duckdb::DatabaseInstance::LoadExtensionSettings ( )
private
276955 {
276956 // copy the map, to protect against modifications during
276957 auto unrecognized_options_copy = config.options.unrecognized_options;
276958
276959 if (Settings::Get<AutoloadKnownExtensionsSetting>(*this)) {
276960 if (unrecognized_options_copy.empty()) {
276961 // Nothing to do
276962 return;
276963 }
276964
276965 Connection con(*this);
276966 con.BeginTransaction();
276967
276968 vector<string> extension_options;
276969 for (auto &option : unrecognized_options_copy) {
276970 auto &name = option.first;
276971 auto &value = option.second;
276972
276973 auto extension_name = ExtensionHelper::FindExtensionInEntries(name, EXTENSION_SETTINGS);
276974 if (extension_name.empty()) {
276975 continue;
276976 }
276977 if (!ExtensionHelper::TryAutoLoadExtension(*this, extension_name)) {
276978 throw InvalidInputException(
276979 "To set the %s setting, the %s extension needs to be loaded. But it could not be autoloaded.", name,
276980 extension_name);
276981 }
276982 ExtensionOption extension_option;
276983 if (!config.TryGetExtensionOption(name, extension_option)) {
276984 throw InternalException("Extension %s did not provide the '%s' config setting", extension_name, name);
276985 }
276986 // if the extension provided the option, it should no longer be unrecognized.
276987 D_ASSERT(config.options.unrecognized_options.find(name) == config.options.unrecognized_options.end());
276988 auto &context = *con.context;
276989 PhysicalSet::SetExtensionVariable(context, extension_option, name, SetScope::GLOBAL, value);
276990 extension_options.push_back(name);
276991 }
276992
276993 con.Commit();
276994 }
276995 if (!config.options.unrecognized_options.empty()) {
276996 ThrowExtensionSetUnrecognizedOptions(config.options.unrecognized_options);
276997 }
276998}
static string FindExtensionInEntries(const string &name, const ExtensionEntry(&entries)[N])
Lookup a name in an ExtensionEntry list.
Definition duckdb.cpp:6376

◆ CreateMainDatabase()

void duckdb::DatabaseInstance::CreateMainDatabase ( )
private
276931 {
276932 AttachInfo info;
276933 info.name = AttachedDatabase::ExtractDatabaseName(config.options.database_path, GetFileSystem());
276934 info.path = config.options.database_path;
276935
276936 Connection con(*this);
276937 con.BeginTransaction();
276938 AttachOptions options(config.options);
276939 options.is_main_database = true;
276940 db_manager->AttachDatabase(*con.context, info, options);
276941 con.Commit();
276942}

◆ Configure()

void duckdb::DatabaseInstance::Configure ( DBConfig & config,
const char * path )
private
277153 {
277154 config.options = new_config.options;
277155 config.user_settings = new_config.user_settings;
277156
277157 if (Settings::Get<DuckDBAPISetting>(*this).empty()) {
277158 config.SetOptionByName("duckdb_api", "cpp");
277159 }
277160
277161 if (database_path) {
277162 config.options.database_path = database_path;
277163 } else {
277164 config.options.database_path.clear();
277165 }
277166
277167 if (new_config.options.temporary_directory.empty()) {
277168 config.SetDefaultTempDirectory();
277169 }
277170
277171 if (config.options.access_mode == AccessMode::UNDEFINED) {
277172 config.options.access_mode = AccessMode::READ_WRITE;
277173 }
277174 if (new_config.file_system) {
277175 config.file_system = std::move(new_config.file_system);
277176 } else {
277177 config.file_system = make_uniq<VirtualFileSystem>(FileSystem::CreateLocal());
277178 }
277179 if (database_path && !Settings::Get<EnableExternalAccessSetting>(*this)) {
277180 config.AddAllowedPath(database_path);
277181 config.AddAllowedPath(database_path + string(".wal"));
277182 config.AddAllowedPath(database_path + string(".wal.checkpoint"));
277183 config.AddAllowedPath(database_path + string(".wal.recovery"));
277184 if (!config.options.temporary_directory.empty()) {
277185 config.AddAllowedDirectory(config.options.temporary_directory);
277186 }
277187 }
277188 if (new_config.secret_manager) {
277189 config.secret_manager = std::move(new_config.secret_manager);
277190 }
277191 if (config.options.maximum_memory == DConstants::INVALID_INDEX) {
277192 config.SetDefaultMaxMemory();
277193 }
277194 if (new_config.options.maximum_threads == DConstants::INVALID_INDEX) {
277195 config.options.maximum_threads = config.GetSystemMaxThreads(*config.file_system);
277196 }
277197 config.allocator = std::move(new_config.allocator);
277198 if (!config.allocator) {
277199 config.allocator = make_uniq<Allocator>();
277200 }
277201 config.block_allocator = std::move(new_config.block_allocator);
277202 if (!config.block_allocator) {
277203 auto default_block_size = Settings::Get<DefaultBlockSizeSetting>(config);
277204 config.block_allocator = make_uniq<BlockAllocator>(
277205 *config.allocator, default_block_size, DBConfig::GetSystemAvailableMemory(*config.file_system) * 8 / 10,
277206 config.options.block_allocator_size);
277207 }
277208 config.replacement_scans = std::move(new_config.replacement_scans);
277209 if (new_config.callback_manager) {
277210 config.callback_manager = std::move(new_config.callback_manager);
277211 new_config.callback_manager = make_uniq<ExtensionCallbackManager>();
277212 }
277213 // This is used to open e.g. parquet files. See DBPathAndType::CheckMagicBytes
277214 config.callback_manager->Register("__open_file__", OpenFileStorageExtension::Create());
277215
277216 config.error_manager = std::move(new_config.error_manager);
277217 if (!config.error_manager) {
277218 config.error_manager = make_uniq<ErrorManager>();
277219 }
277220 if (!config.default_allocator) {
277221 config.default_allocator = Allocator::DefaultAllocatorReference();
277222 }
277223 if (new_config.buffer_pool) {
277224 config.buffer_pool = std::move(new_config.buffer_pool);
277225 } else {
277226 config.buffer_pool = make_shared_ptr<BufferPool>(*config.block_allocator, config.options.maximum_memory,
277227 config.options.buffer_manager_track_eviction_timestamps,
277228 config.options.allocator_bulk_deallocation_flush_threshold);
277229 }
277230 config.db_cache_entry = std::move(new_config.db_cache_entry);
277231 config.path_manager = std::move(new_config.path_manager);
277232}
static DUCKDB_API unique_ptr< FileSystem > CreateLocal()
Create a LocalFileSystem.
Definition duckdb.cpp:80214
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117

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