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, ClientBuilder};
let fs = ClientBuilder::new("default")
.with_user("default")
.with_kerberos_ticket_cache_path("/tmp/krb5_111")
.connect();
Implementations§
source§impl Client
impl Client
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, ClientBuilder};
let fs = ClientBuilder::new("default")
.with_user("default")
.connect()
.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, ClientBuilder};
let fs = ClientBuilder::new("default")
.with_user("default")
.connect()
.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, ClientBuilder};
let fs = ClientBuilder::new("default")
.with_user("default")
.connect()
.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, ClientBuilder};
let fs = ClientBuilder::new("default")
.with_user("default")
.connect()
.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, ClientBuilder};
let fs = ClientBuilder::new("default")
.with_user("default")
.connect()
.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, ClientBuilder};
let fs = ClientBuilder::new("default")
.with_user("default")
.connect()
.expect("client connect succeed");
let fi = fs.metadata("/tmp/hello.txt");
§Stat a non-exist path
use std::io;
use hdrs::{Client, ClientBuilder};
let fs = ClientBuilder::new("default")
.with_user("default")
.connect()
.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)
sourcepub fn read_dir(&self, path: &str) -> Result<Readdir>
pub fn read_dir(&self, path: &str) -> Result<Readdir>
readdir will read file entries from a file.
§Examples
use hdrs::{Client, ClientBuilder};
let fs = ClientBuilder::new("default")
.with_user("default")
.connect()
.expect("client connect succeed");
let fis = fs.read_dir("/tmp/hello/");
sourcepub fn create_dir(&self, path: &str) -> Result<()>
pub fn create_dir(&self, path: &str) -> Result<()>
mkdir create dir and all it’s parent directories.
The behavior is similar to mkdir -p /path/to/dir
.
§Examples
use hdrs::{Client, ClientBuilder};
let fs = ClientBuilder::new("default")
.with_user("default")
.connect()
.expect("client connect succeed");
let _ = fs.create_dir("/tmp");
Trait Implementations§
impl Send for Client
HDFS’s client handle is thread safe.