pub struct Node { /* private fields */ }Expand description
A single TCP connection to a VoltDB server node.
Node represents a persistent, stateful TCP connection used to execute
stored procedures and queries against a VoltDB cluster. Each Node
maintains its own socket and spawns a dedicated background thread to
asynchronously receive and dispatch responses from the server.
§Concurrency
Node is safe to use concurrently and supports multiple in-flight requests
over the same connection. For automatic reconnection, load balancing, or
managing multiple connections, use crate::Pool.
§Example
use voltdb_client_rust::{Node, NodeOpt, IpPort, block_for_result};
let opt = NodeOpt {
ip_port: IpPort::new("localhost".to_string(), 21212),
user: None,
pass: None,
connect_timeout: None,
read_timeout: None,
};
let node = Node::new(opt)?;
let rx = node.query("SELECT * FROM my_table")?;
let table = block_for_result(&rx)?;Implementations§
Source§impl Node
impl Node
Sourcepub fn new(opt: NodeOpt) -> Result<Node, VoltError>
pub fn new(opt: NodeOpt) -> Result<Node, VoltError>
Creates a new connection to a VoltDB server node.
This method establishes a TCP connection to the specified host/port, performs authentication, and spawns a background listener thread for receiving asynchronous responses.
§Arguments
opt- Connection options including host, port, credentials, and timeouts.
§Timeouts
connect_timeout- If set, limits how long the connection attempt will wait. If not set, the connection attempt blocks indefinitely.read_timeout- If set, socket read operations will timeout after this duration. This affects both the authentication phase and the background listener thread.
§Errors
Returns VoltError if:
- The connection cannot be established (network error or timeout)
- DNS resolution fails
- Authentication fails
- The server rejects the connection
§Example
use voltdb_client_rust::{Node, NodeOpt, IpPort};
use std::time::Duration;
let opt = NodeOpt {
ip_port: IpPort::new("localhost".to_string(), 21212),
user: None,
pass: None,
connect_timeout: Some(Duration::from_secs(5)),
read_timeout: Some(Duration::from_secs(30)),
};
let node = Node::new(opt)?;Sourcepub fn get_sequence(&self) -> i64
pub fn get_sequence(&self) -> i64
Returns the next unique sequence number for request tracking.
Each request to VoltDB uses a unique handle (sequence number) for matching responses to requests.
Sourcepub fn list_procedures(&self) -> Result<Receiver<VoltTable>, VoltError>
pub fn list_procedures(&self) -> Result<Receiver<VoltTable>, VoltError>
Lists all stored procedures available in the VoltDB database.
This calls the @SystemCatalog system procedure with “PROCEDURES” argument.
§Returns
A receiver that will yield a VoltTable containing procedure metadata.
Sourcepub fn call_sp(
&self,
query: &str,
param: Vec<&dyn Value>,
) -> Result<Receiver<VoltTable>, VoltError>
pub fn call_sp( &self, query: &str, param: Vec<&dyn Value>, ) -> Result<Receiver<VoltTable>, VoltError>
Executes a stored procedure with the given parameters.
§Arguments
query- The name of the stored procedure (e.g., “@AdHoc”, “MyProcedure”)param- Vector of parameter values. Usevolt_param!macro for convenience.
§Returns
A receiver that will yield the result VoltTable when available.
§Example
use voltdb_client_rust::{Node, NodeOpt, IpPort, Value, block_for_result, volt_param};
let node = Node::new(opt)?;
let id = 1i32;
let name = "test".to_string();
let rx = node.call_sp("MyProcedure", volt_param![id, name])?;
let result = block_for_result(&rx)?;Sourcepub fn upload_jar(&self, bs: Vec<u8>) -> Result<Receiver<VoltTable>, VoltError>
pub fn upload_jar(&self, bs: Vec<u8>) -> Result<Receiver<VoltTable>, VoltError>
Uploads a JAR file containing stored procedure classes to VoltDB.
This calls the @UpdateClasses system procedure to deploy new classes.
§Arguments
bs- The JAR file contents as bytes
Sourcepub fn query(&self, sql: &str) -> Result<Receiver<VoltTable>, VoltError>
pub fn query(&self, sql: &str) -> Result<Receiver<VoltTable>, VoltError>
Executes an ad-hoc SQL query.
This is a convenience method that calls the @AdHoc system procedure.
§Arguments
sql- The SQL query string to execute
§Returns
A receiver that will yield the result VoltTable when available.
§Example
use voltdb_client_rust::{Node, NodeOpt, IpPort, block_for_result};
let node = Node::new(opt)?;
let rx = node.query("SELECT COUNT(*) FROM users")?;
let result = block_for_result(&rx)?;