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

fix(hdfs): do not call hdfsDisconnect() after jvm exited #736

Merged
merged 1 commit into from
Jan 25, 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
30 changes: 22 additions & 8 deletions src/block_service/hdfs/hdfs_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ hdfs_service::hdfs_service() { _read_token_bucket.reset(new folly::DynamicTokenB

hdfs_service::~hdfs_service()
{
ddebug("Try to disconnect hdfs.");
int result = hdfsDisconnect(_fs);
if (result == -1) {
derror_f("Fail to disconnect from the hdfs file system, error: {}.",
utils::safe_strerror(errno));
}
// Even if there is an error, the resources associated with the hdfsFS will be freed.
_fs = nullptr;
// We should not call hdfsDisconnect() here if jvm has exited.
// And there is no simple, safe way to call hdfsDisconnect()
// when process terminates (the proper solution is likely to create a
// signal handler to detect when the process is killed, but we would still
// leak when pegasus crashes).
//
// close();
}

error_code hdfs_service::initialize(const std::vector<std::string> &args)
Expand Down Expand Up @@ -95,6 +94,21 @@ error_code hdfs_service::create_fs()
return ERR_OK;
}

void hdfs_service::close()
{
// This method should be carefully called.
// Calls to hdfsDisconnect() by individual threads would terminate
// all other connections handed out via hdfsConnect() to the same URI.
ddebug("Try to disconnect hdfs.");
int result = hdfsDisconnect(_fs);
if (result == -1) {
derror_f("Fail to disconnect from the hdfs file system, error: {}.",
utils::safe_strerror(errno));
}
// Even if there is an error, the resources associated with the hdfsFS will be freed.
_fs = nullptr;
}

std::string hdfs_service::get_hdfs_entry_name(const std::string &hdfs_path)
{
// get exact file name from an hdfs path.
Expand Down
1 change: 1 addition & 0 deletions src/block_service/hdfs/hdfs_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class hdfs_service : public block_filesystem
dsn::task_code code,
const remove_path_callback &cb,
dsn::task_tracker *tracker) override;
void close();

static std::string get_hdfs_entry_name(const std::string &hdfs_path);

Expand Down