Kùzu C++ API
Loading...
Searching...
No Matches
database.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <mutex>
5#include <vector>
6
7#include "api.h"
9#include "kuzu_fwd.h"
10#include "db_config.h"
11
12namespace kuzu {
13namespace common {
14class FileSystem;
15enum class LogicalTypeID : uint8_t;
16} // namespace common
17
18namespace catalog {
19class CatalogEntry;
20} // namespace catalog
21
22namespace function {
23struct Function;
24} // namespace function
25
26namespace extension {
27struct ExtensionUtils;
28struct ExtensionOptions;
29} // namespace extension
30
31namespace storage {
32class StorageExtension;
33} // namespace storage
34
35namespace main {
36struct ExtensionOption;
37class DatabaseManager;
38class ClientContext;
39
65 explicit SystemConfig(uint64_t bufferPoolSize = -1u, uint64_t maxNumThreads = 0,
66 bool enableCompression = true, bool readOnly = false, uint64_t maxDBSize = -1u,
67 bool autoCheckpoint = true, uint64_t checkpointThreshold = 16777216 /* 16MB */);
68
70 uint64_t maxNumThreads;
73 uint64_t maxDBSize;
76};
77
81class Database {
82 friend class EmbeddedShell;
83 friend class ClientContext;
84 friend class Connection;
85 friend class StorageDriver;
90
91public:
98 KUZU_API explicit Database(std::string_view databasePath,
99 SystemConfig systemConfig = SystemConfig());
104
105 // TODO(Ziyi): Instead of exposing a dedicated API for adding a new function, we should consider
106 // add function through the extension module.
107 KUZU_API void addTableFunction(std::string name,
108 std::vector<std::unique_ptr<function::Function>> functionSet);
109
110 KUZU_API void addStandaloneCallFunction(std::string name,
111 std::vector<std::unique_ptr<function::Function>> functionSet);
112
113 KUZU_API void registerFileSystem(std::unique_ptr<common::FileSystem> fs);
114
115 KUZU_API void registerStorageExtension(std::string name,
116 std::unique_ptr<storage::StorageExtension> storageExtension);
117
119 common::Value defaultValue);
120
121 KUZU_API catalog::Catalog* getCatalog() { return catalog.get(); }
122
123 ExtensionOption* getExtensionOption(std::string name) const;
124
125 const DBConfig& getConfig() const { return dbConfig; }
126
129
130 uint64_t getNextQueryID();
131
132private:
133 using construct_bm_func_t =
134 std::function<std::unique_ptr<storage::BufferManager>(const Database&)>;
135
136 struct QueryIDGenerator {
137 uint64_t queryID = 0;
138 std::mutex queryIDLock;
139 };
140
141 static std::unique_ptr<storage::BufferManager> initBufferManager(const Database& db);
142 void initMembers(std::string_view dbPath, construct_bm_func_t initBmFunc = initBufferManager);
143
144 // factory method only to be used for tests
145 Database(std::string_view databasePath, SystemConfig systemConfig,
146 construct_bm_func_t constructBMFunc);
147
148 void openLockFile();
149 void initAndLockDBDir();
150
151private:
152 std::string databasePath;
153 DBConfig dbConfig;
154 std::unique_ptr<common::VirtualFileSystem> vfs;
155 std::unique_ptr<storage::BufferManager> bufferManager;
156 std::unique_ptr<storage::MemoryManager> memoryManager;
157 std::unique_ptr<processor::QueryProcessor> queryProcessor;
158 std::unique_ptr<catalog::Catalog> catalog;
159 std::unique_ptr<storage::StorageManager> storageManager;
160 std::unique_ptr<transaction::TransactionManager> transactionManager;
161 std::unique_ptr<common::FileInfo> lockFile;
162 std::unique_ptr<extension::ExtensionOptions> extensionOptions;
163 std::unique_ptr<DatabaseManager> databaseManager;
165 QueryIDGenerator queryIDGenerator;
166};
167
168} // namespace main
169} // namespace kuzu
#define KUZU_API
Definition api.h:25
Definition value.h:26
Contain client side configuration. We make profiler associated per query, so profiler is not maintain...
Definition client_context.h:61
Connection is used to interact with a Database instance. Each Connection is thread-safe....
Definition connection.h:14
Database class is the main class of KùzuDB. It manages all database components.
Definition database.h:81
KUZU_API void addExtensionOption(std::string name, common::LogicalTypeID type, common::Value defaultValue)
friend class testing::PrivateGraphTest
Definition database.h:87
KUZU_API void addStandaloneCallFunction(std::string name, std::vector< std::unique_ptr< function::Function > > functionSet)
friend struct extension::ExtensionUtils
Definition database.h:89
KUZU_API void registerStorageExtension(std::string name, std::unique_ptr< storage::StorageExtension > storageExtension)
const DBConfig & getConfig() const
Definition database.h:125
ExtensionOption * getExtensionOption(std::string name) const
common::case_insensitive_map_t< std::unique_ptr< storage::StorageExtension > > & getStorageExtensions()
friend class EmbeddedShell
Definition database.h:82
KUZU_API ~Database()
Destructs the database object.
KUZU_API void addTableFunction(std::string name, std::vector< std::unique_ptr< function::Function > > functionSet)
uint64_t getNextQueryID()
friend class testing::BaseGraphTest
Definition database.h:86
KUZU_API Database(std::string_view databasePath, SystemConfig systemConfig=SystemConfig())
Creates a database object.
KUZU_API catalog::Catalog * getCatalog()
Definition database.h:121
KUZU_API void registerFileSystem(std::unique_ptr< common::FileSystem > fs)
Definition storage_driver.h:13
Definition transaction_context.h:32
std::unordered_map< std::string, T, CaseInsensitiveStringHashFunction, CaseInsensitiveStringEquality > case_insensitive_map_t
Definition case_insensitive_map.h:22
LogicalTypeID
Definition types.h:170
Definition array_utils.h:7
Definition db_config.h:53
Definition db_config.h:44
Stores runtime configuration for creating or opening a Database.
Definition database.h:43
bool readOnly
Definition database.h:72
uint64_t maxNumThreads
Definition database.h:70
uint64_t checkpointThreshold
Definition database.h:75
bool autoCheckpoint
Definition database.h:74
uint64_t bufferPoolSize
Definition database.h:69
SystemConfig(uint64_t bufferPoolSize=-1u, uint64_t maxNumThreads=0, bool enableCompression=true, bool readOnly=false, uint64_t maxDBSize=-1u, bool autoCheckpoint=true, uint64_t checkpointThreshold=16777216)
Creates a SystemConfig object.
uint64_t maxDBSize
Definition database.h:73
bool enableCompression
Definition database.h:71