Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove DatabaseConfig #1270

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions src/include/main/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,7 @@ KUZU_API struct SystemConfig {
};

/**
* @brief Stores databasePath.
*/
KUZU_API struct DatabaseConfig {
/**
* @brief Creates a DatabaseConfig object.
* @param databasePath Path to store the database files.
*/
explicit DatabaseConfig(std::string databasePath);

std::string databasePath;
};

/**
* @brief Database class is the main class of the KuzuDB. It manages all database components.
* @brief Database class is the main class of KùzuDB. It manages all database components.
*/
class Database {
friend class EmbeddedShell;
Expand All @@ -56,17 +43,17 @@ class Database {
public:
/**
* @brief Creates a database object with default buffer pool size and max num threads.
* @param databaseConfig Database configurations(database path).
* @param databaseConfig Database path.
*/
KUZU_API explicit Database(DatabaseConfig databaseConfig);
KUZU_API explicit Database(std::string databasePath);
/**
* @brief Creates a database object.
* @param databaseConfig Database configurations(database path).
* @param systemConfig System configurations(buffer pool size and max num threads).
* @param databasePath Database path.
* @param systemConfig System configurations (buffer pool size and max num threads).
*/
KUZU_API Database(DatabaseConfig databaseConfig, SystemConfig systemConfig);
KUZU_API Database(std::string databasePath, SystemConfig systemConfig);
/**
* @brief Deconstructs the database object.
* @brief Destructs the database object.
*/
KUZU_API ~Database();

Expand Down Expand Up @@ -102,7 +89,7 @@ class Database {
void checkpointOrRollbackAndClearWAL(bool isRecovering, bool isCheckpoint);

private:
DatabaseConfig databaseConfig;
std::string databasePath;
SystemConfig systemConfig;
std::unique_ptr<storage::MemoryManager> memoryManager;
std::unique_ptr<processor::QueryProcessor> queryProcessor;
Expand Down
36 changes: 16 additions & 20 deletions src/main/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,17 @@ SystemConfig::SystemConfig(uint64_t bufferPoolSize) {
maxNumThreads = std::thread::hardware_concurrency();
}

DatabaseConfig::DatabaseConfig(std::string databasePath) : databasePath{std::move(databasePath)} {}
Database::Database(std::string databasePath) : Database{std::move(databasePath), SystemConfig()} {}

Database::Database(DatabaseConfig databaseConfig)
: Database{std::move(databaseConfig), SystemConfig()} {}

Database::Database(DatabaseConfig databaseConfig, SystemConfig systemConfig)
: databaseConfig{std::move(databaseConfig)},
Database::Database(std::string databasePath, SystemConfig systemConfig)
: databasePath{std::move(databasePath)},
systemConfig{systemConfig}, logger{LoggerUtils::getOrCreateLogger("database")} {
initLoggers();
initDBDirAndCoreFilesIfNecessary();
bufferManager = std::make_unique<BufferManager>(
this->systemConfig.defaultPageBufferPoolSize, this->systemConfig.largePageBufferPoolSize);
memoryManager = std::make_unique<MemoryManager>(bufferManager.get());
wal = std::make_unique<WAL>(this->databaseConfig.databasePath, *bufferManager);
wal = std::make_unique<WAL>(this->databasePath, *bufferManager);
recoverIfNecessary();
queryProcessor = std::make_unique<processor::QueryProcessor>(this->systemConfig.maxNumThreads);
catalog = std::make_unique<catalog::Catalog>(wal.get());
Expand All @@ -58,21 +55,20 @@ Database::Database(DatabaseConfig databaseConfig, SystemConfig systemConfig)
Database::~Database() = default;

void Database::initDBDirAndCoreFilesIfNecessary() const {
if (!FileUtils::fileOrPathExists(databaseConfig.databasePath)) {
FileUtils::createDir(databaseConfig.databasePath);
if (!FileUtils::fileOrPathExists(databasePath)) {
FileUtils::createDir(databasePath);
}
if (!FileUtils::fileOrPathExists(StorageUtils::getNodesStatisticsAndDeletedIDsFilePath(
databaseConfig.databasePath, DBFileType::ORIGINAL))) {
NodesStatisticsAndDeletedIDs::saveInitialNodesStatisticsAndDeletedIDsToFile(
databaseConfig.databasePath);
databasePath, DBFileType::ORIGINAL))) {
NodesStatisticsAndDeletedIDs::saveInitialNodesStatisticsAndDeletedIDsToFile(databasePath);
}
if (!FileUtils::fileOrPathExists(StorageUtils::getRelsStatisticsFilePath(
databaseConfig.databasePath, DBFileType::ORIGINAL))) {
RelsStatistics::saveInitialRelsStatisticsToFile(databaseConfig.databasePath);
if (!FileUtils::fileOrPathExists(
StorageUtils::getRelsStatisticsFilePath(databasePath, DBFileType::ORIGINAL))) {
RelsStatistics::saveInitialRelsStatisticsToFile(databasePath);
}
if (!FileUtils::fileOrPathExists(
StorageUtils::getCatalogFilePath(databaseConfig.databasePath, DBFileType::ORIGINAL))) {
Catalog::saveInitialCatalogToFile(databaseConfig.databasePath);
StorageUtils::getCatalogFilePath(databasePath, DBFileType::ORIGINAL))) {
Catalog::saveInitialCatalogToFile(databasePath);
}
}

Expand Down Expand Up @@ -120,19 +116,19 @@ void Database::commitAndCheckpointOrRollback(
if (nodeTableHasUpdates) {
storageManager->getNodesStore()
.getNodesStatisticsAndDeletedIDs()
.writeTablesStatisticsFileForWALRecord(databaseConfig.databasePath);
.writeTablesStatisticsFileForWALRecord(databasePath);
} else {
storageManager->getRelsStore()
.getRelsStatistics()
.writeTablesStatisticsFileForWALRecord(databaseConfig.databasePath);
.writeTablesStatisticsFileForWALRecord(databasePath);
}
}
}
if (catalog->hasUpdates()) {
wal->logCatalogRecord();
// If we are committing, we also need to write the WAL file for catalog.
if (isCommit) {
catalog->writeCatalogForWALRecord(databaseConfig.databasePath);
catalog->writeCatalogForWALRecord(databasePath);
}
}
storageManager->prepareCommitOrRollbackIfNecessary(isCommit);
Expand Down
26 changes: 12 additions & 14 deletions test/graph_test/graph_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,27 @@ void BaseGraphTest::validateListFilesExistence(
void BaseGraphTest::validateNodeColumnFilesExistence(
NodeTableSchema* nodeTableSchema, DBFileType dbFileType, bool existence) {
for (auto& property : nodeTableSchema->properties) {
validateColumnFilesExistence(
StorageUtils::getNodePropertyColumnFName(databaseConfig->databasePath,
nodeTableSchema->tableID, property.propertyID, dbFileType),
validateColumnFilesExistence(StorageUtils::getNodePropertyColumnFName(databasePath,
nodeTableSchema->tableID, property.propertyID, dbFileType),
existence, containsOverflowFile(property.dataType.typeID));
}
validateColumnFilesExistence(StorageUtils::getNodeIndexFName(databaseConfig->databasePath,
nodeTableSchema->tableID, dbFileType),
validateColumnFilesExistence(
StorageUtils::getNodeIndexFName(databasePath, nodeTableSchema->tableID, dbFileType),
existence, containsOverflowFile(nodeTableSchema->getPrimaryKey().dataType.typeID));
}

void BaseGraphTest::validateRelColumnAndListFilesExistence(
RelTableSchema* relTableSchema, DBFileType dbFileType, bool existence) {
for (auto relDirection : REL_DIRECTIONS) {
if (relTableSchema->relMultiplicity) {
validateColumnFilesExistence(
StorageUtils::getAdjColumnFName(databaseConfig->databasePath,
relTableSchema->tableID, relDirection, dbFileType),
validateColumnFilesExistence(StorageUtils::getAdjColumnFName(databasePath,
relTableSchema->tableID, relDirection, dbFileType),
existence, false /* hasOverflow */);
validateRelPropertyFiles(
relTableSchema, relDirection, true /* isColumnProperty */, dbFileType, existence);

} else {
validateListFilesExistence(StorageUtils::getAdjListsFName(databaseConfig->databasePath,
validateListFilesExistence(StorageUtils::getAdjListsFName(databasePath,
relTableSchema->tableID, relDirection, dbFileType),
existence, false /* hasOverflow */, true /* hasHeader */);
validateRelPropertyFiles(
Expand Down Expand Up @@ -100,13 +98,13 @@ void BaseGraphTest::validateRelPropertyFiles(catalog::RelTableSchema* relTableSc
auto hasOverflow = containsOverflowFile(property.dataType.typeID);
if (isColumnProperty) {
validateColumnFilesExistence(
StorageUtils::getRelPropertyColumnFName(databaseConfig->databasePath,
relTableSchema->tableID, relDirection, property.propertyID, dbFileType),
StorageUtils::getRelPropertyColumnFName(databasePath, relTableSchema->tableID,
relDirection, property.propertyID, dbFileType),
existence, hasOverflow);
} else {
validateListFilesExistence(
StorageUtils::getRelPropertyListsFName(databaseConfig->databasePath,
relTableSchema->tableID, relDirection, property.propertyID, dbFileType),
StorageUtils::getRelPropertyListsFName(databasePath, relTableSchema->tableID,
relDirection, property.propertyID, dbFileType),
existence, hasOverflow, false /* hasHeader */);
}
}
Expand Down Expand Up @@ -143,7 +141,7 @@ void BaseGraphTest::createDBAndConn() {
if (database != nullptr) {
database.reset();
}
database = std::make_unique<main::Database>(*databaseConfig, *systemConfig);
database = std::make_unique<main::Database>(databasePath, *systemConfig);
conn = std::make_unique<main::Connection>(database.get());
spdlog::set_level(spdlog::level::info);
}
Expand Down
4 changes: 2 additions & 2 deletions test/include/graph_test/graph_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BaseGraphTest : public Test {
if (common::FileUtils::fileOrPathExists(TestHelper::getTmpTestDir())) {
common::FileUtils::removeDir(TestHelper::getTmpTestDir());
}
databaseConfig = make_unique<main::DatabaseConfig>(TestHelper::getTmpTestDir());
databasePath = TestHelper::getTmpTestDir();
}

virtual std::string getInputDir() = 0;
Expand Down Expand Up @@ -138,8 +138,8 @@ class BaseGraphTest : public Test {
bool existence);

public:
std::string databasePath;
std::unique_ptr<main::SystemConfig> systemConfig;
std::unique_ptr<main::DatabaseConfig> databaseConfig;
std::unique_ptr<main::Database> database;
std::unique_ptr<main::Connection> conn;
};
Expand Down
2 changes: 1 addition & 1 deletion test/main/config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST_F(ApiTest, ClientConfig) {
TEST_F(ApiTest, DatabasePathIncorrect) {
spdlog::set_level(spdlog::level::debug);
try {
std::make_unique<Database>(DatabaseConfig("/\\0:* /? \" < > |"));
std::make_unique<Database>("0:* /? \" < > |");
FAIL();
} catch (Exception& e) {
ASSERT_TRUE(std::string(e.what()).find("Failed to create directory") != std::string::npos);
Expand Down
63 changes: 26 additions & 37 deletions test/runner/e2e_ddl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,8 @@ class TinySnbDDLTest : public DBTest {
void dropNodeTableProperty(TransactionTestType transactionTestType) {
auto propertyToDrop =
catalog->getReadOnlyVersion()->getNodeProperty(personTableID, "gender");
auto propertyFileName =
StorageUtils::getNodePropertyColumnFName(databaseConfig->databasePath, personTableID,
propertyToDrop.propertyID, DBFileType::ORIGINAL);
auto propertyFileName = StorageUtils::getNodePropertyColumnFName(
databasePath, personTableID, propertyToDrop.propertyID, DBFileType::ORIGINAL);
bool hasOverflowFile = containsOverflowFile(propertyToDrop.dataType.typeID);
executeQueryWithoutCommit("ALTER TABLE person DROP gender");
validateColumnFilesExistence(propertyFileName, true /* existence */, hasOverflowFile);
Expand Down Expand Up @@ -311,12 +310,10 @@ class TinySnbDDLTest : public DBTest {
catalog->getReadOnlyVersion()->getRelProperty(studyAtTableID, "places");
// Note: studyAt is a MANY-ONE rel table. Properties are stored as columns in the fwd
// direction and stored as lists in the bwd direction.
auto propertyFWDColumnFileName =
StorageUtils::getRelPropertyColumnFName(databaseConfig->databasePath, studyAtTableID,
RelDirection::FWD, propertyToDrop.propertyID, DBFileType::ORIGINAL);
auto propertyBWDListFileName =
StorageUtils::getRelPropertyListsFName(databaseConfig->databasePath, studyAtTableID,
RelDirection::BWD, propertyToDrop.propertyID, DBFileType::ORIGINAL);
auto propertyFWDColumnFileName = StorageUtils::getRelPropertyColumnFName(databasePath,
studyAtTableID, RelDirection::FWD, propertyToDrop.propertyID, DBFileType::ORIGINAL);
auto propertyBWDListFileName = StorageUtils::getRelPropertyListsFName(databasePath,
studyAtTableID, RelDirection::BWD, propertyToDrop.propertyID, DBFileType::ORIGINAL);
bool hasOverflowFile = containsOverflowFile(propertyToDrop.dataType.typeID);
executeQueryWithoutCommit("ALTER TABLE studyAt DROP places");
validateColumnFilesExistence(
Expand Down Expand Up @@ -392,9 +389,9 @@ class TinySnbDDLTest : public DBTest {
auto hasOverflow =
containsOverflowFile(tableSchema->getProperty(propertyID).dataType.typeID);
auto columnOriginalVersionFileName = StorageUtils::getNodePropertyColumnFName(
databaseConfig->databasePath, personTableID, propertyID, DBFileType::ORIGINAL);
databasePath, personTableID, propertyID, DBFileType::ORIGINAL);
auto columnWALVersionFileName = StorageUtils::getNodePropertyColumnFName(
databaseConfig->databasePath, personTableID, propertyID, DBFileType::WAL_VERSION);
databasePath, personTableID, propertyID, DBFileType::WAL_VERSION);
validateDatabaseFileBeforeCheckpointAddProperty(
columnOriginalVersionFileName, columnWALVersionFileName, hasOverflow);
if (transactionTestType == TransactionTestType::RECOVERY) {
Expand Down Expand Up @@ -423,9 +420,9 @@ class TinySnbDDLTest : public DBTest {
auto hasOverflow =
containsOverflowFile(tableSchema->getProperty(propertyID).dataType.typeID);
auto columnOriginalVersionFileName = StorageUtils::getNodePropertyColumnFName(
databaseConfig->databasePath, personTableID, propertyID, DBFileType::ORIGINAL);
databasePath, personTableID, propertyID, DBFileType::ORIGINAL);
auto columnWALVersionFileName = StorageUtils::getNodePropertyColumnFName(
databaseConfig->databasePath, personTableID, propertyID, DBFileType::WAL_VERSION);
databasePath, personTableID, propertyID, DBFileType::WAL_VERSION);
validateDatabaseFileBeforeCheckpointAddProperty(
columnOriginalVersionFileName, columnWALVersionFileName, hasOverflow);
// The convertResultToString function will remove the single quote around the result
Expand Down Expand Up @@ -455,18 +452,14 @@ class TinySnbDDLTest : public DBTest {
auto propertyID = tableSchema->getPropertyID("random");
auto hasOverflow =
containsOverflowFile(tableSchema->getProperty(propertyID).dataType.typeID);
auto fwdColumnOriginalVersionFileName =
StorageUtils::getRelPropertyColumnFName(databaseConfig->databasePath, studyAtTableID,
RelDirection::FWD, propertyID, DBFileType::ORIGINAL);
auto fwdColumnWALVersionFileName =
StorageUtils::getRelPropertyColumnFName(databaseConfig->databasePath, studyAtTableID,
RelDirection::FWD, propertyID, DBFileType::WAL_VERSION);
auto bwdListOriginalVersionFileName =
StorageUtils::getRelPropertyListsFName(databaseConfig->databasePath, studyAtTableID,
RelDirection::BWD, propertyID, DBFileType::ORIGINAL);
auto bwdListWALVersionFileName =
StorageUtils::getRelPropertyListsFName(databaseConfig->databasePath, studyAtTableID,
RelDirection::BWD, propertyID, DBFileType::WAL_VERSION);
auto fwdColumnOriginalVersionFileName = StorageUtils::getRelPropertyColumnFName(
databasePath, studyAtTableID, RelDirection::FWD, propertyID, DBFileType::ORIGINAL);
auto fwdColumnWALVersionFileName = StorageUtils::getRelPropertyColumnFName(
databasePath, studyAtTableID, RelDirection::FWD, propertyID, DBFileType::WAL_VERSION);
auto bwdListOriginalVersionFileName = StorageUtils::getRelPropertyListsFName(
databasePath, studyAtTableID, RelDirection::BWD, propertyID, DBFileType::ORIGINAL);
auto bwdListWALVersionFileName = StorageUtils::getRelPropertyListsFName(
databasePath, studyAtTableID, RelDirection::BWD, propertyID, DBFileType::WAL_VERSION);
validateDatabaseFileBeforeCheckpointAddProperty(
fwdColumnOriginalVersionFileName, fwdColumnWALVersionFileName, hasOverflow);
validateDatabaseFileBeforeCheckpointAddProperty(
Expand Down Expand Up @@ -501,18 +494,14 @@ class TinySnbDDLTest : public DBTest {
auto propertyID = relTableSchema->getPropertyID("random");
auto hasOverflow =
containsOverflowFile(relTableSchema->getProperty(propertyID).dataType.typeID);
auto fwdColumnOriginalVersionFileName =
StorageUtils::getRelPropertyColumnFName(databaseConfig->databasePath, studyAtTableID,
RelDirection::FWD, propertyID, DBFileType::ORIGINAL);
auto fwdColumnWALVersionFileName =
StorageUtils::getRelPropertyColumnFName(databaseConfig->databasePath, studyAtTableID,
RelDirection::FWD, propertyID, DBFileType::WAL_VERSION);
auto bwdListOriginalVersionFileName =
StorageUtils::getRelPropertyListsFName(databaseConfig->databasePath, studyAtTableID,
RelDirection::BWD, propertyID, DBFileType::ORIGINAL);
auto bwdListWALVersionFileName =
StorageUtils::getRelPropertyListsFName(databaseConfig->databasePath, studyAtTableID,
RelDirection::BWD, propertyID, DBFileType::WAL_VERSION);
auto fwdColumnOriginalVersionFileName = StorageUtils::getRelPropertyColumnFName(
databasePath, studyAtTableID, RelDirection::FWD, propertyID, DBFileType::ORIGINAL);
auto fwdColumnWALVersionFileName = StorageUtils::getRelPropertyColumnFName(
databasePath, studyAtTableID, RelDirection::FWD, propertyID, DBFileType::WAL_VERSION);
auto bwdListOriginalVersionFileName = StorageUtils::getRelPropertyListsFName(
databasePath, studyAtTableID, RelDirection::BWD, propertyID, DBFileType::ORIGINAL);
auto bwdListWALVersionFileName = StorageUtils::getRelPropertyListsFName(
databasePath, studyAtTableID, RelDirection::BWD, propertyID, DBFileType::WAL_VERSION);
validateDatabaseFileBeforeCheckpointAddProperty(
fwdColumnOriginalVersionFileName, fwdColumnWALVersionFileName, hasOverflow);
validateDatabaseFileBeforeCheckpointAddProperty(
Expand Down
3 changes: 1 addition & 2 deletions tools/benchmark/benchmark_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const std::string BENCHMARK_SUFFIX = ".benchmark";
BenchmarkRunner::BenchmarkRunner(
const std::string& datasetPath, std::unique_ptr<BenchmarkConfig> config)
: config{std::move(config)} {
database = std::make_unique<Database>(
DatabaseConfig(datasetPath), SystemConfig(this->config->bufferPoolSize));
database = std::make_unique<Database>(datasetPath, SystemConfig(this->config->bufferPoolSize));
spdlog::set_level(spdlog::level::debug);
}

Expand Down
2 changes: 1 addition & 1 deletion tools/python_api/src_cpp/py_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ PyDatabase::PyDatabase(const std::string& databasePath, uint64_t bufferPoolSize)
systemConfig.largePageBufferPoolSize =
bufferPoolSize * StorageConfig::LARGE_PAGES_BUFFER_RATIO;
}
database = std::make_unique<Database>(DatabaseConfig(databasePath), systemConfig);
database = std::make_unique<Database>(databasePath, systemConfig);
}

void PyDatabase::resizeBufferManager(uint64_t newSize) {
Expand Down
Loading