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

refactor: simplify nfs client and nfs server #771

Merged
merged 5 commits into from
Mar 3, 2021
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
130 changes: 0 additions & 130 deletions src/nfs/nfs_client.h

This file was deleted.

45 changes: 20 additions & 25 deletions src/nfs/nfs_client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,12 @@ void nfs_client_impl::begin_remote_copy(std::shared_ptr<remote_copy_request> &rc
req->nfs_task = nfs_task;
req->is_finished = false;

get_file_size(req->file_size_req,
[=](error_code err, get_file_size_response &&resp) {
end_get_file_size(err, std::move(resp), req);
},
std::chrono::milliseconds(FLAGS_rpc_timeout_ms),
0,
0,
0,
req->file_size_req.source);
async_nfs_get_file_size(req->file_size_req,
[=](error_code err, get_file_size_response &&resp) {
end_get_file_size(err, std::move(resp), req);
},
std::chrono::milliseconds(FLAGS_rpc_timeout_ms),
req->file_size_req.source);
}

void nfs_client_impl::end_get_file_size(::dsn::error_code err,
Expand Down Expand Up @@ -284,22 +281,20 @@ void nfs_client_impl::continue_copy()
copy_req.source_dir = ureq->file_size_req.source_dir;
copy_req.overwrite = ureq->file_size_req.overwrite;
copy_req.is_last = req->is_last;
req->remote_copy_task = copy(copy_req,
[=](error_code err, copy_response &&resp) {
end_copy(err, std::move(resp), req);
// reset task to release memory quickly.
// should do this after end_copy() done.
if (req->is_ready_for_write) {
::dsn::task_ptr tsk;
zauto_lock l(req->lock);
tsk = std::move(req->remote_copy_task);
}
},
std::chrono::milliseconds(FLAGS_rpc_timeout_ms),
0,
0,
0,
req->file_ctx->user_req->file_size_req.source);
req->remote_copy_task =
async_nfs_copy(copy_req,
[=](error_code err, copy_response &&resp) {
end_copy(err, std::move(resp), req);
// reset task to release memory quickly.
// should do this after end_copy() done.
if (req->is_ready_for_write) {
::dsn::task_ptr tsk;
zauto_lock l(req->lock);
tsk = std::move(req->remote_copy_task);
}
},
std::chrono::milliseconds(FLAGS_rpc_timeout_ms),
req->file_ctx->user_req->file_size_req.source);
} else {
--ureq->concurrent_copy_count;
--_concurrent_copy_request_count;
Expand Down
41 changes: 31 additions & 10 deletions src/nfs/nfs_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,53 @@
* THE SOFTWARE.
*/

/*
* Description:
* What is this file about?
*
* Revision history:
* xxxx-xx-xx, author, first version
* xxxx-xx-xx, author, fix bug about xxx
*/
#pragma once

#include <vector>
#include <deque>
#include <iostream>
#include <dsn/tool-api/task_tracker.h>
#include <dsn/tool-api/zlocks.h>
#include <dsn/perf_counter/perf_counter_wrapper.h>
#include <dsn/dist/nfs_node.h>
#include <dsn/utility/defer.h>
#include <dsn/utility/TokenBucket.h>
#include <dsn/utility/flags.h>
#include "nfs_client.h"
#include <dsn/tool-api/async_calls.h>

#include "nfs_types.h"
#include "nfs_code_definition.h"

namespace dsn {
namespace service {

using TokenBucket = folly::BasicTokenBucket<std::chrono::steady_clock>;

class nfs_client_impl : public ::dsn::service::nfs_client
template <typename TCallback>
task_ptr async_nfs_get_file_size(const get_file_size_request &request,
TCallback &&callback,
std::chrono::milliseconds timeout,
rpc_address server_addr)
{
return rpc::call(server_addr,
RPC_NFS_GET_FILE_SIZE,
request,
nullptr,
std::forward<TCallback>(callback),
timeout);
}

template <typename TCallback>
task_ptr async_nfs_copy(const copy_request &request,
TCallback &&callback,
std::chrono::milliseconds timeout,
rpc_address server_addr)
{
return rpc::call(
server_addr, RPC_NFS_COPY, request, nullptr, std::forward<TCallback>(callback), timeout);
}

foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
class nfs_client_impl
{
public:
struct user_request;
Expand Down
75 changes: 0 additions & 75 deletions src/nfs/nfs_server.h

This file was deleted.

30 changes: 19 additions & 11 deletions src/nfs/nfs_server_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,38 @@
* THE SOFTWARE.
*/

/*
* Description:
* What is this file about?
*
* Revision history:
* xxxx-xx-xx, author, first version
* xxxx-xx-xx, author, fix bug about xxx
*/
#pragma once
#include <dsn/tool-api/task_tracker.h>
#include <dsn/perf_counter/perf_counter_wrapper.h>
#include <iostream>
#include <dsn/cpp/serverlet.h>
#include <dsn/utility/flags.h>

#include "nfs_server.h"
#include "nfs_code_definition.h"
#include "nfs_types.h"
#include "nfs_client_impl.h"

namespace dsn {
namespace service {
class nfs_service_impl : public ::dsn::service::nfs_service,
public ::dsn::serverlet<nfs_service_impl>
class nfs_service_impl : public ::dsn::serverlet<nfs_service_impl>
{
public:
nfs_service_impl();
virtual ~nfs_service_impl() { _tracker.cancel_outstanding_tasks(); }

void open_service()
{
register_async_rpc_handler(RPC_NFS_COPY, "copy", &nfs_service_impl::on_copy);
register_async_rpc_handler(
RPC_NFS_GET_FILE_SIZE, "get_file_size", &nfs_service_impl::on_get_file_size);
}

void close_service()
{
unregister_rpc_handler(RPC_NFS_COPY);
unregister_rpc_handler(RPC_NFS_GET_FILE_SIZE);
}

protected:
// RPC_NFS_V2_NFS_COPY
virtual void on_copy(const copy_request &request, ::dsn::rpc_replier<copy_response> &reply);
Expand Down