From f75c4bb15a8b4405ad478fec62743b7b6c3d5027 Mon Sep 17 00:00:00 2001 From: HeYuchen Date: Mon, 9 May 2022 16:43:22 +0800 Subject: [PATCH] fix: fix md5 lack during block service download (#1101) --- src/block_service/block_service_manager.cpp | 6 ++++-- src/block_service/fds/fds_service.cpp | 4 ++++ src/block_service/local/local_service.cpp | 1 + src/block_service/test/fds_service_test.cpp | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/block_service/block_service_manager.cpp b/src/block_service/block_service_manager.cpp index b4b8faeccc..fb63e6b976 100644 --- a/src/block_service/block_service_manager.cpp +++ b/src/block_service/block_service_manager.cpp @@ -175,8 +175,10 @@ error_code block_service_manager::download_file(const std::string &remote_dir, return resp.err; } - ddebug_f( - "download file({}) succeed, file_size = {}", local_file_name.c_str(), resp.downloaded_size); + ddebug_f("download file({}) succeed, file_size = {}, md5 = {}", + local_file_name.c_str(), + resp.downloaded_size, + resp.file_md5); download_file_size = resp.downloaded_size; download_file_md5 = resp.file_md5; return ERR_OK; diff --git a/src/block_service/fds/fds_service.cpp b/src/block_service/fds/fds_service.cpp index 95a11ebdfd..cec07e4023 100644 --- a/src/block_service/fds/fds_service.cpp +++ b/src/block_service/fds/fds_service.cpp @@ -699,6 +699,10 @@ dsn::task_ptr fds_file_object::download(const download_request &req, _fds_path, req.output_local_name); dsn::utils::filesystem::remove_path(req.output_local_name); + } else if ((resp.err = dsn::utils::filesystem::md5sum(req.output_local_name, + resp.file_md5)) != ERR_OK) { + derror_f("download failed when calculate the md5sum of local file {}", + req.output_local_name); } t->enqueue_with(resp); release_ref(); diff --git a/src/block_service/local/local_service.cpp b/src/block_service/local/local_service.cpp index f17e9783ac..e91170e123 100644 --- a/src/block_service/local/local_service.cpp +++ b/src/block_service/local/local_service.cpp @@ -548,6 +548,7 @@ dsn::task_ptr local_file_object::download(const download_request &req, target_file.c_str()); } else { _has_meta_synced = true; + resp.file_md5 = _md5_value; } } } diff --git a/src/block_service/test/fds_service_test.cpp b/src/block_service/test/fds_service_test.cpp index 96d86c6d50..0535a3f637 100644 --- a/src/block_service/test/fds_service_test.cpp +++ b/src/block_service/test/fds_service_test.cpp @@ -365,6 +365,7 @@ TEST_F(FDSClientTest, test_basic_operation) ->wait(); ASSERT_EQ(dsn::ERR_OK, d_resp.err); ASSERT_EQ(cf_resp.file_handle->get_size(), d_resp.downloaded_size); + ASSERT_EQ(cf_resp.file_handle->get_md5sum(), d_resp.file_md5); file_eq_compare(f1.filename, local_file_for_download); }