Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

feat(bulk-load): bulk load download part2 - replica download files #471

Merged
merged 9 commits into from
May 25, 2020

Conversation

hycdong
Copy link
Contributor

@hycdong hycdong commented May 21, 2020

This pull request add do_download function and its unit test. This function is used to download files from remote provider.

@hycdong hycdong changed the title feat(bulk-load): add do_download feat(bulk-load): bulk load download part2 - replica download files May 22, 2020
@hycdong hycdong marked this pull request as ready for review May 22, 2020 01:52
src/dist/replication/lib/replica_file_provider.cpp Outdated Show resolved Hide resolved
// expected to remove old local file and redownload it
create_local_file(FILE_NAME);
create_remote_file(FILE_NAME, 2333, "md5_not_match");
ASSERT_EQ(test_do_download(), ERR_OK);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After redownloaded, better to check local file is exist and md5sum matched.

Copy link
Contributor Author

@hycdong hycdong May 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used block_file_mock function here, it is a mock function, whose download function is like below:

virtual dsn::task_ptr download(const download_request &req,
dsn::task_code code,
const download_callback &cb,
dsn::task_tracker *tracker = nullptr)
{
return task_ptr();
}

It will not do actual downloading action, the local file is not existed in unit test. And the real downloading action is hard to mock.

// remove local file to mock condition that file not existed
std::string file_name = utils::filesystem::path_combine(LOCAL_DIR, FILE_NAME);
utils::filesystem::remove_path(file_name);
ASSERT_EQ(test_do_download(), ERR_OK);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After downloaded, check local file is exist and md5sum matched.

// download files from remote provider
// this function can also be used in restore
return ERR_OK;
error_code download_err = ERR_OK;
Copy link
Contributor

@neverchanje neverchanje May 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found nothing in your codes relates to the replica except for ddebug_replica. It should be moved to dist::block_service module, rather than be in replica.

struct download_options {
  std::string &remote_dir;
  std::string &local_dir;
  // TODO(): add download rate limiter here.
  // uint64_t max_download_size;
};

error_s download_remote_files(const download_options& options, dist::block_service::block_filesystem *fs, /*out*/ uint64_t &download_file_size) {
  return error_s::make();
}

Under this impl you cannt print logs in do_download, however, you can return an error with string (error_s) in failure.

error_code replica::do_download(const std::string &remote_dir,
                                const std::string &local_dir,
                                const std::string &file_name,
                                dist::block_service::block_filesystem *fs,
                                /*out*/ uint64_t &download_file_size) {
  error_s err = download_remote_files();
  if (!err.is_ok())
    derror_replica(err);
  } else {
    ddebug_replica("download succeed with total file size {}", download_file_size);
  }
}

Copy link
Contributor Author

@hycdong hycdong May 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think current implementation is during a middle stage, it is okay to leave do_download function in replica namespace.
If I move download function into block_service module, I should also move unit tests into block_service module. However, cold backup has wrote a block_file_mock in replica unit test for backup unit tests. If I move it into block_service, I should update backup unit tests code, which will be refactored in further pull request finally, it is not meaningful to refactor them currently.
In my view, we should move all functions related to file provider into block_service module, such as download files, upload files. It can be implemented after refactoring backup and restore code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discuss offline, I will refactor code in next pull request.

acelyc111
acelyc111 previously approved these changes May 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants