HDFS-10746: libhdfs++: synchronize access to working_directory and bytes_read_. Contributed by Anatoli Shein.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/b9cf0e93 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/b9cf0e93 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/b9cf0e93 Branch: refs/heads/HDFS-8707 Commit: b9cf0e932d8a56eadc9c23912590722a5d846dec Parents: cbb3e9f Author: James <[email protected]> Authored: Mon Aug 15 12:21:25 2016 -0400 Committer: James Clampffer <[email protected]> Committed: Thu Mar 22 17:19:47 2018 -0400 ---------------------------------------------------------------------- .../main/native/libhdfspp/lib/bindings/c/hdfs.cc | 17 ++++++++++++----- .../src/main/native/libhdfspp/lib/fs/filehandle.cc | 4 ++-- .../src/main/native/libhdfspp/lib/fs/filehandle.h | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/b9cf0e93/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc index 7fda4e2..4003358 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc @@ -43,18 +43,25 @@ static constexpr tPort kDefaultPort = 8020; /* Separate the handles used by the C api from the C++ API*/ struct hdfs_internal { - hdfs_internal(FileSystem *p) : filesystem_(p), working_directory("/") {} + hdfs_internal(FileSystem *p) : filesystem_(p), working_directory_("/") {} hdfs_internal(std::unique_ptr<FileSystem> p) - : filesystem_(std::move(p)), working_directory("/") {} + : filesystem_(std::move(p)), working_directory_("/") {} virtual ~hdfs_internal(){}; FileSystem *get_impl() { return filesystem_.get(); } const FileSystem *get_impl() const { return filesystem_.get(); } - std::string get_working_directory() { return working_directory; } - void set_working_directory(std::string new_directory) { working_directory = new_directory; } + std::string get_working_directory() { + std::lock_guard<std::mutex> read_guard(wd_lock_); + return working_directory_; + } + void set_working_directory(std::string new_directory) { + std::lock_guard<std::mutex> write_guard(wd_lock_); + working_directory_ = new_directory; + } private: std::unique_ptr<FileSystem> filesystem_; - std::string working_directory; //has to always start and end with '/' + std::string working_directory_; //has to always start and end with '/' + std::mutex wd_lock_; //synchronize access to the working directory }; struct hdfsFile_internal { http://git-wip-us.apache.org/repos/asf/hadoop/blob/b9cf0e93/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc index 2600944..8f1a82c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc @@ -353,8 +353,8 @@ bool FileHandle::ShouldExclude(const Status &s) { } } -uint64_t FileHandleImpl::get_bytes_read() { return bytes_read_; } +uint64_t FileHandleImpl::get_bytes_read() { return bytes_read_.load(); } -void FileHandleImpl::clear_bytes_read() { bytes_read_ = 0; } +void FileHandleImpl::clear_bytes_read() { bytes_read_.store(0); } } http://git-wip-us.apache.org/repos/asf/hadoop/blob/b9cf0e93/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.h ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.h b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.h index 03c55ff..7e7c79d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.h +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.h @@ -139,7 +139,7 @@ private: CancelHandle cancel_state_; ReaderGroup readers_; std::shared_ptr<LibhdfsEvents> event_handlers_; - uint64_t bytes_read_; + std::atomic<uint64_t> bytes_read_; }; } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
