From a5819aa9caaa8fde7f7b32105cce8b1a7fc36f89 Mon Sep 17 00:00:00 2001 From: mkaruza Date: Wed, 9 Apr 2025 14:42:28 +0200 Subject: [PATCH] feat(server): Exit process if error is report during initial load snapshot (#4907) Exit process if error is reported when we try to initially load snapshot from cloud storage or local directory. Fixes #4840 Signed-off-by: mkaruza --- src/server/server_family.cc | 6 ++++-- tests/dragonfly/snapshot_test.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/server/server_family.cc b/src/server/server_family.cc index d022a233c..73cac4598 100644 --- a/src/server/server_family.cc +++ b/src/server/server_family.cc @@ -927,9 +927,11 @@ void ServerFamily::LoadFromSnapshot() { if (std::error_code(load_path_result.error()) == std::errc::no_such_file_or_directory) { LOG(WARNING) << "Load snapshot: No snapshot found"; } else { - util::fb2::LockGuard lk{loading_stats_mu_}; + loading_stats_mu_.lock(); loading_stats_.failed_restore_count++; - LOG(ERROR) << "Failed to load snapshot: " << load_path_result.error().Format(); + loading_stats_mu_.unlock(); + LOG(ERROR) << "Failed to load snapshot with error: " << load_path_result.error().Format(); + exit(1); } } } diff --git a/tests/dragonfly/snapshot_test.py b/tests/dragonfly/snapshot_test.py index 7f34979fb..fb0e5a3e2 100644 --- a/tests/dragonfly/snapshot_test.py +++ b/tests/dragonfly/snapshot_test.py @@ -326,6 +326,24 @@ def delete_s3_objects(bucket, prefix): ) +# If DRAGONFLY_S3_BUCKET is configured, AWS credentials must also be +# configured. +@pytest.mark.skipif( + "DRAGONFLY_S3_BUCKET" not in os.environ or os.environ["DRAGONFLY_S3_BUCKET"] == "", + reason="AWS S3 snapshots bucket is not configured", +) +async def test_exit_on_s3_snapshot_load_err(df_factory): + invalid_s3_dir = "s3://{DRAGONFLY_S3_BUCKET}" + "_invalid_bucket_" + df_server = df_factory.create( + dir=invalid_s3_dir, dbfilename="db", exit_on_cloud_dir_snapshot_load_err=True + ) + df_server.start() + # Let's wait so that process exit + await asyncio.sleep(2) + with pytest.raises(Exception): + df_server._check_status() + + # If DRAGONFLY_S3_BUCKET is configured, AWS credentials must also be # configured. @pytest.mark.skipif(