pub struct TransactionalEventWriter { /* private fields */ }
Expand description

Write events to a stream transactionally.

Events that are written to the transaction can be committed atomically, which means that reader cannot see any writes prior to committing and will not see any writes if the transaction is aborted.

§Example

use tokio;
use pravega_client_shared::{Timestamp, ScopedStream, Scope, Stream, WriterId, PravegaNodeUri};
use pravega_client::client_factory::ClientFactory;
use pravega_client_config::ClientConfigBuilder;

#[tokio::main]
async fn main() {
    let scope_name = Scope::from("txnScope".to_owned());
    let stream_name = Stream::from("txnStream".to_owned());
    let scoped_stream = ScopedStream {
         scope: scope_name.clone(),
         stream: stream_name.clone(),
     };
    // omit the step to create scope and stream in Pravega

    let config = ClientConfigBuilder::default()
        .controller_uri(PravegaNodeUri::from("tcp://127.0.0.2:9091".to_string()))
        .build()
        .expect("creating config");
    let client_factory = ClientFactory::new(config);
    let mut writer = client_factory
        .create_transactional_event_writer(scoped_stream.clone(), WriterId(0))
        .await;

    // start a transaction
    let mut transaction = writer.begin().await.expect("begin transaction");

    // do something with it
    transaction.write_event(None, String::from("hello").into_bytes()).await.unwrap();

    // commit the transaction
    transaction.commit(Timestamp(0u64)).await;
}

Implementations§

source§

impl TransactionalEventWriter

source

pub async fn begin( &mut self ) -> Result<Transaction, TransactionalEventWriterError>

This method opens a transaction by sending a request to Pravega controller.

source

pub async fn get_txn( &self, txn_id: TxId ) -> Result<Transaction, TransactionalEventWriterError>

This method returns the Transaction based on the given transaction id. If the current transaction is not in open status, meaning it has been committed or aborted, this method will create a closed transaction that only contains the meta data of this transaction.

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.

§

impl<T> Instrument for T

§

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

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
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