Skip to content
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
1 change: 1 addition & 0 deletions csdb/include/csdb/database_berkeleydb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class DatabaseBerkeleyDB : public Database {
bool updateContractData(const cs::Bytes& key, const cs::Bytes& data) override;
bool getContractData(const cs::Bytes& key, cs::Bytes& data) override;
bool compact() override;
bool flush() override;

void logfile_routine();

Expand Down
15 changes: 15 additions & 0 deletions csdb/src/database_berkeleydb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ void DatabaseBerkeleyDB::logfile_routine() {
}
}

// Commits run with DB_TXN_NOSYNC, so their log records may still sit in the in-process log buffer.
// Write and sync the log, or a checkpoint saved after this call could name blocks that a killed
// process never put on disk, and the next start would refuse the database.
bool DatabaseBerkeleyDB::flush() {
try {
const int status = env_.log_flush(nullptr);
set_last_error_from_berkeleydb(status);
return status == 0;
}
catch (const DbException& e) {
set_last_error_from_berkeleydb(e.get_errno());
return false;
}
}

void DatabaseBerkeleyDB::set_last_error_from_berkeleydb(int status) {
Error err = UnknownError;
if (status == 0) {
Expand Down
Loading