pub struct Client { /* private fields */ }
Expand description
Client holds the underlying connection to hdfs clusters.
The connection will be disconnected while Drop
, so their is no need to terminate it manually.
Note
Hadoop will have it’s own filesystem logic which may return the same filesystem instance while
hdfsConnect
. If we call hdfsDisconnect
, all clients that hold this filesystem instance will
meet java.io.IOException: Filesystem closed
during I/O operations.
So it’s better for us to not call hdfsDisconnect
manually.
Aka, don’t implement Drop
to disconnect the connection.
Reference: IOException: Filesystem closed exception when running oozie workflo
Examples
use hdrs::Client;
let fs = Client::connect("default");
Implementations§
source§impl Client
impl Client
sourcepub fn connect(name_node: &str) -> Result<Self>
pub fn connect(name_node: &str) -> Result<Self>
Connect to a name node with port
Returns an io::Result
if any error happens.
Examples
use hdrs::Client;
let fs = Client::connect("default");
sourcepub fn connect_as_user(name_node: &str, user: &str) -> Result<Self>
pub fn connect_as_user(name_node: &str, user: &str) -> Result<Self>
Connect to a name node with port as specified user
Returns an io::Result
if any error happens.
Examples
use hdrs::Client;
let fs = Client::connect_as_user("default", "user");
sourcepub fn open_file(&self) -> OpenOptions
pub fn open_file(&self) -> OpenOptions
Open will create a stream builder for later IO operations.
Examples
use hdrs::Client;
let fs = Client::connect("default").expect("client connect succeed");
let open_options = fs.open_file();
sourcepub fn remove_file(&self, path: &str) -> Result<()>
pub fn remove_file(&self, path: &str) -> Result<()>
Delete a file.
Examples
use hdrs::Client;
let fs = Client::connect("default").expect("client connect succeed");
let _ = fs.remove_file("/tmp/hello.txt");
sourcepub fn rename_file(&self, old_path: &str, new_path: &str) -> Result<()>
pub fn rename_file(&self, old_path: &str, new_path: &str) -> Result<()>
Rename a file.
ATTENTION: the destination directory must exist.
Examples
use hdrs::Client;
let fs = Client::connect("default").expect("client connect succeed");
let _ = fs.rename_file("/tmp/hello.txt._COPY_", "/tmp/hello.txt");
sourcepub fn remove_dir(&self, path: &str) -> Result<()>
pub fn remove_dir(&self, path: &str) -> Result<()>
Delete a dir.
Examples
use hdrs::Client;
let fs = Client::connect("default").expect("client connect succeed");
let _ = fs.remove_dir("/tmp/xxx");
sourcepub fn remove_dir_all(&self, path: &str) -> Result<()>
pub fn remove_dir_all(&self, path: &str) -> Result<()>
Delete a dir recursively.
Examples
use hdrs::Client;
let fs = Client::connect("default").expect("client connect succeed");
let _ = fs.remove_dir_all("/tmp/xxx/");
sourcepub fn metadata(&self, path: &str) -> Result<Metadata>
pub fn metadata(&self, path: &str) -> Result<Metadata>
Stat a path to get file info.
Examples
Stat a path to file info
use hdrs::Client;
let fs = Client::connect("default").expect("client connect succeed");
let fi = fs.metadata("/tmp/hello.txt");
Stat a non-exist path
use std::io;
use hdrs::Client;
let fs = Client::connect("default").expect("client connect succeed");
let fi = fs.metadata("/tmp/not-exist.txt");
assert!(fi.is_err());
assert_eq!(fi.unwrap_err().kind(), io::ErrorKind::NotFound)
Trait Implementations§
impl Send for Client
HDFS’s client handle is thread safe.