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;

let fs = Client::connect("default");

Implementations§

Connect to a name node with port

Returns an io::Result if any error happens.

Examples
use hdrs::Client;

let fs = Client::connect("default");

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

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

Delete a file.

Examples
use hdrs::Client;

let fs = Client::connect("default").expect("client connect succeed");
let _ = fs.remove_file("/tmp/hello.txt");

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

Delete a dir.

Examples
use hdrs::Client;

let fs = Client::connect("default").expect("client connect succeed");
let _ = fs.remove_dir("/tmp/xxx");

Delete a dir recursively.

Examples
use hdrs::Client;

let fs = Client::connect("default").expect("client connect succeed");
let _ = fs.remove_dir_all("/tmp/xxx/");

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)

readdir will read file entries from a file.

Examples
use hdrs::Client;

let fs = Client::connect("default").expect("client connect succeed");
let fis = fs.read_dir("/tmp/hello/");

mkdir create dir and all it’s parent directories.

The behavior is similar to mkdir -p /path/to/dir.

Examples
use hdrs::Client;

let fs = Client::connect("default").expect("client connect succeed");
let _ = fs.create_dir("/tmp");

Trait Implementations§

Formats the value using the given formatter. Read more

HDFS’s client handle is thread safe.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.