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

Handle exceptions when flushing WAL #3283

Merged
merged 1 commit into from
Apr 16, 2024
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
4 changes: 3 additions & 1 deletion src/common/file_system/local_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ void LocalFileSystem::syncFile(const FileInfo& fileInfo) const {
#if defined(_WIN32)
// Note that `FlushFileBuffers` returns 0 when fail, while `fsync` returns 0 when succeed.
if (FlushFileBuffers((HANDLE)localFileInfo.handle) == 0) {
throw IOException(stringFormat("Failed to sync file {}.", fileInfo.path));
auto error = GetLastError();
throw IOException(stringFormat("Failed to sync file {}. Error {}: {}", fileInfo.path, error,
std::system_category().message(error)));
}
#else
if (fsync(localFileInfo.fd) != 0) {
Expand Down
8 changes: 7 additions & 1 deletion src/storage/wal/wal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

#include <fcntl.h>

#include "common/exception/io.h"
#include "common/file_system/file_info.h"
#include "common/file_system/virtual_file_system.h"
#include "common/serializer/buffered_file.h"
#include "common/serializer/deserializer.h"
#include "common/serializer/serializer.h"
#include "spdlog/spdlog.h"
#include "storage/storage_utils.h"

using namespace kuzu::common;
Expand All @@ -31,7 +33,11 @@ WAL::WAL(const std::string& directory, bool readOnly, BufferManager& bufferManag
}

WAL::~WAL() {
flushAllPages();
try {
flushAllPages();
} catch (IOException& e) {
spdlog::error("Failed to flush WAL: {}", e.what());
}
}

page_idx_t WAL::logPageUpdateRecord(DBFileID dbFileID, page_idx_t pageIdxInOriginalFile) {
Expand Down
5 changes: 2 additions & 3 deletions tools/rust_api/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ mod tests {

#[test]
fn create_database_failure() {
let result: Error = Database::new("", SystemConfig::default())
.expect_err("An empty string should not be a valid database path!")
.into();
Database::new("", SystemConfig::default())
.expect_err("An empty string should not be a valid database path!");
}

#[test]
Expand Down
Loading