Struct hdrs::Client

source ·
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

source

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();
source

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");
source

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");
source

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");
source

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/");
source

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)
source

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/");
source

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§

source§

impl Debug for Client

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Send for Client

HDFS’s client handle is thread safe.

source§

impl Sync for Client

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more