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

application: syncfs on storage during startup #10495

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 22 additions & 0 deletions src/v/redpanda/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ int application::run(int ac, char** av) {
});
// must initialize configuration before services
hydrate_config(cfg);
sync_disks().get();
initialize();
check_environment();
check_for_crash_loop();
Expand All @@ -375,6 +376,27 @@ int application::run(int ac, char** av) {
});
}

ss::future<> application::sync_disks() {
/*
* The last running instance of redpanda might have left un-flushed
* data or metadata in the filesystem.
*
* This does not help us in the case of e.g. IO-failed fsync() calls, which
* generally mark pages as clean anyway[1], but it does provide a more
* consistent basis for reasoning about persistence of metadata changes
* that might not have been fsync'd by a previous run of Redpanda.
*
* 1. https://dl.acm.org/doi/pdf/10.1145/3450338
*/
vlog(_log.info, "Running syncfs on data directory...");
auto data_dir = co_await ss::open_directory(config::node().data_directory().as_sstring());
co_await data_dir.syncfs();

vlog(_log.info, "Running syncfs on cache directory...");
auto cache_dir = co_await ss::open_directory(config::node().cloud_storage_cache_path().string());
co_await cache_dir.syncfs();
}

void application::initialize(
std::optional<YAML::Node> proxy_cfg,
std::optional<YAML::Node> proxy_client_cfg,
Expand Down
1 change: 1 addition & 0 deletions src/v/redpanda/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class application {
public:
int run(int, char**);

ss::future<> sync_disks();
void initialize(
std::optional<YAML::Node> proxy_cfg = std::nullopt,
std::optional<YAML::Node> proxy_client_cfg = std::nullopt,
Expand Down
7 changes: 7 additions & 0 deletions src/v/utils/file_sanitizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ class file_io_sanitizer final : public ss::file_impl {
get_file_impl(_file)->flush());
}

ss::future<> syncfs() final {
assert_file_not_closed();
return with_op(
ssx::sformat("ss::future<> syncfs(void)"),
get_file_impl(_file)->syncfs());
}

ss::future<struct stat> stat() final {
assert_file_not_closed();
return with_op(
Expand Down