pub struct Client { /* private fields */ }Expand description
A connection to one YTsaurus cluster.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(proxy: &str) -> Self
pub fn new(proxy: &str) -> Self
Connects to proxy, with no token.
proxy may be a bare host (cluster.example.com, assumed HTTPS) or
carry a scheme (http://localhost:8000).
Sourcepub fn with_token(proxy: &str, token: impl Into<String>) -> Self
pub fn with_token(proxy: &str, token: impl Into<String>) -> Self
Connects to proxy using token for authentication.
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Connects using YT_PROXY and, if set, YT_TOKEN.
§Errors
Returns ClientError::Config if YT_PROXY is not set.
Sourcepub fn with_poll_interval(self, interval: Duration) -> Self
pub fn with_poll_interval(self, interval: Duration) -> Self
Overrides how often Client::wait_for_operation polls.
Sourcepub fn heavy_proxy(&self) -> Result<Option<String>>
pub fn heavy_proxy(&self) -> Result<Option<String>>
Returns the least-loaded heavy proxy the cluster reports, if any.
Large installations separate light and heavy proxies and answer heavy
commands on a light proxy with 503. Point a second Client at this
address to do uploads there. A local cluster returns nothing useful, and
none of this is needed for it.
§Errors
Returns ClientError if the request fails.
Sourcepub fn create(&self, node_type: &str, path: &str) -> Result<()>
pub fn create(&self, node_type: &str, path: &str) -> Result<()>
Creates a Cypress node, e.g. table, file or map_node.
Creates missing parents and succeeds if the node already exists.
§Errors
Returns ClientError if the request fails.
Sourcepub fn remove(&self, path: &str) -> Result<()>
pub fn remove(&self, path: &str) -> Result<()>
Removes a Cypress node. Succeeds if it is already absent.
§Errors
Returns ClientError if the request fails.
Sourcepub fn row_count(&self, path: &str) -> Result<i64>
pub fn row_count(&self, path: &str) -> Result<i64>
Number of rows in a table.
§Errors
Returns ClientError if the request fails or the attribute is absent.
Sourcepub fn upload_worker(&self, local: impl AsRef<Path>, remote: &str) -> Result<()>
pub fn upload_worker(&self, local: impl AsRef<Path>, remote: &str) -> Result<()>
Uploads a local file to Cypress, marking it executable.
This is what makes a worker runnable on a node: without the executable
attribute YTsaurus copies the binary but refuses to exec it, and the job
fails with a permission error that does not mention the attribute.
§Errors
Returns ClientError if the file cannot be read or the upload fails.
Sourcepub fn write_file(&self, path: &str, contents: &[u8]) -> Result<()>
pub fn write_file(&self, path: &str, contents: &[u8]) -> Result<()>
Writes raw bytes to a Cypress file, replacing its contents.
§Errors
Returns ClientError if the request fails.
Sourcepub fn write_table(&self, path: &str, rows: &[u8]) -> Result<()>
pub fn write_table(&self, path: &str, rows: &[u8]) -> Result<()>
Writes rows to a table, replacing its contents.
rows must be a binary YSON list fragment — exactly what a
ytsaurus-job worker writes.
§Errors
Returns ClientError if the request fails.
Sourcepub fn read_table(&self, path: &str) -> Result<Vec<u8>>
pub fn read_table(&self, path: &str) -> Result<Vec<u8>>
Reads a whole table as a binary YSON list fragment.
Reads it into memory: this is for results a launcher inspects, not for bulk export.
The result is checked to be a complete list fragment. That is not
pedantry — the proxy reports a mid-stream failure in a trailer this
client cannot see (see the http module), so a truncated body is the
symptom that is detectable, and returning it as success would hand the
caller a silently short table.
§Errors
Returns ClientError if the request fails or the stream is truncated.
Sourcepub fn start_map_reduce(&self, spec: &MapReduceSpec) -> Result<String>
pub fn start_map_reduce(&self, spec: &MapReduceSpec) -> Result<String>
Sourcepub fn start_operation(
&self,
kind: OperationType,
spec: &YsonValue,
) -> Result<String>
pub fn start_operation( &self, kind: OperationType, spec: &YsonValue, ) -> Result<String>
Starts an operation from a spec built by hand.
The escape hatch for anything MapSpec and MapReduceSpec do not
model; build the spec with yson_build.
§Errors
Returns ClientError if the request fails.
Sourcepub fn operation_state(&self, id: &str) -> Result<String>
pub fn operation_state(&self, id: &str) -> Result<String>
Fetches an operation’s current state, e.g. running or completed.
§Errors
Returns ClientError if the request fails.
Sourcepub fn wait_for_operation(&self, id: &str) -> Result<()>
pub fn wait_for_operation(&self, id: &str) -> Result<()>
Polls until the operation reaches a terminal state.
§Errors
Returns ClientError::OperationFailed if it ends as anything other
than completed, or ClientError if polling itself fails.