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

refactor(block_service): remove rebundant functions #630

Merged
merged 2 commits into from
Sep 23, 2020
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
74 changes: 0 additions & 74 deletions include/dsn/dist/block_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,56 +88,6 @@ typedef std::function<void(const create_file_response &)> create_file_callback;
typedef future_task<create_file_response> create_file_future;
typedef dsn::ref_ptr<create_file_future> create_file_future_ptr;

/**
* @brief The delete_file_request struct, use to delete a file
* file_name: a valid absolute path string, which "/" as splitter
*/
struct delete_file_request
{
std::string file_name;
};

/**
* @brief The delete_file_response struct
* err: ERR_OK: delete file succeed
* ERR_OBJECT_NOT_FOUND: the file doesn't exist
* ERR_TIMEOUT: request timeout
* ERR_FS_INTERNAL: an internal error occured in the service implementation
* which we can't handle
*/
struct delete_file_response
{
dsn::error_code err;
};
typedef std::function<void(const delete_file_response &)> delete_file_callback;
typedef future_task<delete_file_response> delete_file_future;
typedef dsn::ref_ptr<delete_file_future> delete_file_future_ptr;

/**
* @brief The exist_request struct
* path: a valid absolute path string, which point to file or directory, which "/" as splitter
*/
struct exist_request
{
std::string path;
};

/**
* @brief The exist_response struct
* err: ERR_OK: request succeed, path is exist
* ERR_OBJECT_NOT_FOUND, request succeed, path is not exist
* ERR_TIMEOUT: request timeout
* ERR_FS_INTERNAL: an internal error occured in the service implementation
* which we can't handle
*/
struct exist_response
{
dsn::error_code err;
};
typedef std::function<void(const exist_response &)> exist_callback;
typedef future_task<exist_response> exist_future;
typedef dsn::ref_ptr<exist_future> exist_future_ptr;

/**
* @brief The remove_path_request struct
* path: a valid absolute path string, which point to file or directory, which "/" as splitter
Expand Down Expand Up @@ -331,30 +281,6 @@ class block_filesystem
const create_file_callback &cb,
dsn::task_tracker *tracker = nullptr) = 0;

/**
* @brief delete_file
* @param req, ref {@link #delete_file_request}
* @param code, a task_code, describe how the callback executed
* @param callback, called when get the list result
* @param tracker
* @return a task which represent the async operation
*/
virtual dsn::task_ptr delete_file(const delete_file_request &req,
dsn::task_code code,
const delete_file_callback &cb,
dsn::task_tracker *tracker = nullptr) = 0;
/**
* @brief exist
* @param req, ref {@link #exist_request}
* @param code, a task_code, describe how the callback executed
* @param callback, called when get the list result
* @param tracker
* @return a task which represent the async operation
*/
virtual dsn::task_ptr exist(const exist_request &req,
dsn::task_code code,
const exist_callback &cb,
dsn::task_tracker *tracker = nullptr) = 0;
/**
* @brief remove_path
* @param req, ref {@link #remove_path_request}
Expand Down
81 changes: 0 additions & 81 deletions src/block_service/fds/fds_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,87 +306,6 @@ dsn::task_ptr fds_service::create_file(const create_file_request &req,
return t;
}

dsn::task_ptr fds_service::delete_file(const delete_file_request &req,
task_code code,
const delete_file_callback &cb,
dsn::task_tracker *tracker)
{
delete_file_future_ptr t(new delete_file_future(code, cb, 0));
t->set_tracker(tracker);
auto delete_file_in_background = [this, req, t]() {
std::string fds_path = utils::path_to_fds(req.file_name, false);
delete_file_response resp;
try {
_client->deleteObject(_bucket_name, fds_path, false);
resp.err = ERR_OK;
} catch (const galaxy::fds::GalaxyFDSClientException &ex) {
if (ex.code() == Poco::Net::HTTPResponse::HTTP_NOT_FOUND) {
derror("fds deleteObject failed: file not found, parameter(%s)",
req.file_name.c_str());
resp.err = ERR_OBJECT_NOT_FOUND;
} else {
derror("fds deleteObject failed: parameter(%s), code(%d), msg(%s)",
req.file_name.c_str(),
ex.code(),
ex.what());
resp.err = ERR_FS_INTERNAL;
}
}
FDS_EXCEPTION_HANDLE(resp.err, "deleteObject", req.file_name.c_str());
t->enqueue_with(resp);
};

dsn::tasking::enqueue(LPC_FDS_CALL, nullptr, delete_file_in_background);
return t;
}

// FDS don't have the concept of directory, so if no file(req.path/***/file) exist
// then the path isn't exist, otherwise we think path is exist
//
// Attention: using listObjects to implement, if req.path is an non-empty dir, and these is many
// file under req.path, then this function may consume much time
//
dsn::task_ptr fds_service::exist(const exist_request &req,
dsn::task_code code,
const exist_callback &cb,
dsn::task_tracker *tracker)
{
exist_future_ptr callback(new exist_future(code, cb, 0));
callback->set_tracker(tracker);
auto exist_in_background = [this, req, callback]() {
exist_response resp;
std::string fds_path = utils::path_to_fds(req.path, true);
try {
std::shared_ptr<galaxy::fds::FDSObjectListing> result =
_client->listObjects(_bucket_name, fds_path);
const std::vector<galaxy::fds::FDSObjectSummary> &objs = result->objectSummaries();
const std::vector<std::string> &common_prefix = result->commonPrefixes();

if (!objs.empty() || !common_prefix.empty()) {
// path is a non-empty directory
resp.err = ERR_OK;
} else {
if (_client->doesObjectExist(_bucket_name, utils::path_to_fds(req.path, false))) {
resp.err = ERR_OK;
} else {
derror("fds exist failed: path not found, parameter(%s)", req.path.c_str());
resp.err = ERR_OBJECT_NOT_FOUND;
}
}
} catch (const galaxy::fds::GalaxyFDSClientException &ex) {
derror("fds exist failed: parameter(%s), code(%d), msg(%s)",
req.path.c_str(),
ex.code(),
ex.what());
resp.err = ERR_FS_INTERNAL;
}
FDS_EXCEPTION_HANDLE(resp.err, "exist", req.path.c_str());
callback->enqueue_with(resp);
};
tasking::enqueue(LPC_FDS_CALL, nullptr, std::move(exist_in_background));
return callback;
}

dsn::task_ptr fds_service::remove_path(const remove_path_request &req,
dsn::task_code code,
const remove_path_callback &cb,
Expand Down
13 changes: 0 additions & 13 deletions src/block_service/fds/fds_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,6 @@ class fds_service : public block_filesystem
dsn::task_code code,
const create_file_callback &cb,
dsn::task_tracker *tracker) override;
//
// Attention:
// delete file directly on fds, will not enter trash
//
virtual dsn::task_ptr delete_file(const delete_file_request &req,
dsn::task_code code,
const delete_file_callback &cb,
dsn::task_tracker *tracker) override;

virtual dsn::task_ptr exist(const exist_request &req,
dsn::task_code code,
const exist_callback &cb,
dsn::task_tracker *tracker) override;

//
// Attention:
Expand Down
62 changes: 0 additions & 62 deletions src/block_service/local/local_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,68 +169,6 @@ dsn::task_ptr local_service::create_file(const create_file_request &req,
return tsk;
}

dsn::task_ptr local_service::delete_file(const delete_file_request &req,
dsn::task_code code,
const delete_file_callback &cb,
task_tracker *tracker)
{
delete_file_future_ptr tsk(new delete_file_future(code, cb, 0));
tsk->set_tracker(tracker);

auto delete_file_background = [this, req, tsk]() {
delete_file_response resp;
resp.err = ERR_OK;
dinfo("delete file(%s)", req.file_name.c_str());

// delete the meta data file.
std::string meta_file = utils::filesystem::path_combine(_root, get_metafile(req.file_name));
if (utils::filesystem::file_exists(meta_file)) {
if (!utils::filesystem::remove_path(meta_file)) {
resp.err = ERR_FS_INTERNAL;
}
}

// if "delete meta data file ok" or "meta data file not found", then delete the real file
if (resp.err == ERR_OK) {
std::string file = utils::filesystem::path_combine(_root, req.file_name);
if (::dsn::utils::filesystem::file_exists(file)) {
if (!::dsn::utils::filesystem::remove_path(file)) {
resp.err = ERR_FS_INTERNAL;
}
} else {
resp.err = ERR_OBJECT_NOT_FOUND;
}
}

tsk->enqueue_with(resp);
};

tasking::enqueue(LPC_LOCAL_SERVICE_CALL, nullptr, std::move(delete_file_background));
return tsk;
}

dsn::task_ptr local_service::exist(const exist_request &req,
dsn::task_code code,
const exist_callback &cb,
task_tracker *tracker)
{
exist_future_ptr tsk(new exist_future(code, cb, 0));
tsk->set_tracker(tracker);
auto exist_background = [this, req, tsk]() {
exist_response resp;
std::string meta_file = utils::filesystem::path_combine(_root, get_metafile(req.path));
if (utils::filesystem::path_exists(meta_file)) {
resp.err = ERR_OK;
} else {
resp.err = ERR_OBJECT_NOT_FOUND;
}
tsk->enqueue_with(resp);
};

tasking::enqueue(LPC_LOCAL_SERVICE_CALL, nullptr, std::move(exist_background));
return tsk;
}

dsn::task_ptr local_service::remove_path(const remove_path_request &req,
dsn::task_code code,
const remove_path_callback &cb,
Expand Down
10 changes: 0 additions & 10 deletions src/block_service/local/local_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ class local_service : public block_filesystem
const create_file_callback &cb,
dsn::task_tracker *tracker = nullptr) override;

virtual dsn::task_ptr delete_file(const delete_file_request &req,
dsn::task_code code,
const delete_file_callback &cb,
dsn::task_tracker *tracker = nullptr) override;

virtual dsn::task_ptr exist(const exist_request &req,
dsn::task_code code,
const exist_callback &cb,
dsn::task_tracker *tracker = nullptr) override;

virtual dsn::task_ptr remove_path(const remove_path_request &req,
dsn::task_code code,
const remove_path_callback &cb,
Expand Down
16 changes: 0 additions & 16 deletions src/block_service/test/block_service_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,6 @@ class block_service_mock : public block_filesystem
return task_ptr();
}

virtual dsn::task_ptr delete_file(const delete_file_request &req,
dsn::task_code code,
const delete_file_callback &cb,
dsn::task_tracker *tracker = nullptr)
{
return task_ptr();
}

dsn::task_ptr remove_path(const remove_path_request &req,
dsn::task_code code,
const remove_path_callback &cb,
Expand All @@ -195,14 +187,6 @@ class block_service_mock : public block_filesystem
return task_ptr();
}

dsn::task_ptr exist(const exist_request &req,
dsn::task_code code,
const exist_callback &cb,
dsn::task_tracker *tracker)
{
return task_ptr();
}

public:
std::map<std::string, std::vector<ls_entry>> dir_files;
std::map<std::string, std::pair<int64_t, std::string>> files;
Expand Down
Loading