Skip to content

Commit

Permalink
fix(hdfs): do not call hdfsDisconnect() after jvm exited (XiaoMi#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyifan27 committed Jan 26, 2021
1 parent fb504e7 commit df16164
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
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

0 comments on commit df16164

Please sign in to comment.