Skip to content

Commit

Permalink
Add option force_checkpoint_on_close (kuzudb#4032)
Browse files Browse the repository at this point in the history
* add option force_checkpoint_on_close

* update test and extension version

* bump extension version

(cherry picked from commit 7feb44e)
  • Loading branch information
ray6080 authored and wangqiang committed Aug 13, 2024
1 parent 55e1023 commit 6afb2f0
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ add_subdirectory(third_party)
if(${BUILD_KUZU})
add_definitions(-DKUZU_ROOT_DIRECTORY="${PROJECT_SOURCE_DIR}")
add_definitions(-DKUZU_CMAKE_VERSION="${CMAKE_PROJECT_VERSION}")
add_definitions(-DKUZU_EXTENSION_VERSION="0.5.0")
add_definitions(-DKUZU_EXTENSION_VERSION="0.5.1.2")

include_directories(src/include)

Expand Down
1 change: 1 addition & 0 deletions src/include/main/db_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class DBConfig {
bool enableMultiWrites = false;
bool autoCheckpoint;
uint64_t checkpointThreshold;
bool forceCheckpointOnClose;
};

} // namespace main
Expand Down
12 changes: 12 additions & 0 deletions src/include/main/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,17 @@ struct AutoCheckpointSetting {
}
};

struct ForceCheckpointClosingDBSetting {
static constexpr const char* name = "force_checkpoint_on_close";
static constexpr common::LogicalTypeID inputType = common::LogicalTypeID::BOOL;
static void setContext(ClientContext* context, const common::Value& parameter) {
parameter.validateType(inputType);
context->getDBConfigUnsafe()->forceCheckpointOnClose = parameter.getValue<bool>();
}
static common::Value getSetting(ClientContext* context) {
return common::Value(context->getDBConfig()->forceCheckpointOnClose);
}
};

} // namespace main
} // namespace kuzu
5 changes: 4 additions & 1 deletion src/main/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ Database::Database(std::string_view databasePath, SystemConfig systemConfig)
}

Database::~Database() {
// TODO(Guodong): We should consider forcing checkpoint when closing the database.
if (dbConfig.forceCheckpointOnClose) {
ClientContext clientContext(this);
transactionManager->checkpoint(clientContext);
}
}

void Database::addTableFunction(std::string name, function::function_set functionSet) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/db_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ static ConfigurationOption options[] = { // NOLINT(cert-err58-cpp):
GET_CONFIGURATION(ProgressBarSetting), GET_CONFIGURATION(ProgressBarTimerSetting),
GET_CONFIGURATION(RecursivePatternSemanticSetting),
GET_CONFIGURATION(RecursivePatternFactorSetting), GET_CONFIGURATION(EnableMVCCSetting),
GET_CONFIGURATION(CheckpointThresholdSetting), GET_CONFIGURATION(AutoCheckpointSetting)};
GET_CONFIGURATION(CheckpointThresholdSetting), GET_CONFIGURATION(AutoCheckpointSetting),
GET_CONFIGURATION(ForceCheckpointClosingDBSetting)};

DBConfig::DBConfig(const SystemConfig& systemConfig) {
bufferPoolSize = systemConfig.bufferPoolSize;
Expand All @@ -30,6 +31,7 @@ DBConfig::DBConfig(const SystemConfig& systemConfig) {
maxDBSize = systemConfig.maxDBSize;
autoCheckpoint = systemConfig.autoCheckpoint;
checkpointThreshold = systemConfig.checkpointThreshold;
forceCheckpointOnClose = false;
}

ConfigurationOption* DBConfig::getOptionByName(const std::string& optionName) {
Expand Down
23 changes: 23 additions & 0 deletions test/test_files/transaction/basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,26 @@ Alice
Timeout waiting for active transactions to leave the system before checkpointing. If you have an open transaction, please close it and try again.
-STATEMENT [conn1] MATCH (a:person) WHERE a.ID=0 RETURN a.age;
---- 0

-CASE ForceCheckpointWhenClosingDB
-STATEMENT CALL auto_checkpoint=false
---- ok
-STATEMENT CREATE NODE TABLE person(ID INT64, age INT64, PRIMARY KEY(ID));
---- ok
-STATEMENT CREATE (a:person {ID: 0, age: 20});
---- ok
-STATEMENT CALL force_checkpoint_on_close=true;
---- ok
-STATEMENT CALL current_setting('force_checkpoint_on_close') RETURN *;
---- 1
True
-STATEMENT CALL storage_info('person') WHERE residency='ON_DISK' RETURN COUNT(*);
---- 1
0
-RELOADDB
-STATEMENT MATCH (a:person) WHERE a.ID=0 RETURN a.age;
---- 1
20
-STATEMENT CALL storage_info('person') WHERE residency='IN_MEMORY' RETURN COUNT(*);
---- 1
0

0 comments on commit 6afb2f0

Please sign in to comment.