Transaction

TWO_PHASE = 1

The two phase commit is separated in 2 parts. First it tries to execute the prepare; if there are any conflicts, the prepare will fail. Once the prepare has succeeded, the commit (writing the changes) can be executed.

Hazelcast also provides three phase transaction by automatically copying the backlog to another member so that in case of failure during a commit, another member can continue the commit from backup.

ONE_PHASE = 2

The one phase transaction executes a transaction using a single step at the end; committing the changes. There is no prepare of the transactions, so conflicts are not detected. If there is a conflict, then when the transaction commits the changes, some of the changes are written and others are not; leaving the system in a potentially permanent inconsistent state.

class TransactionManager(context)[source]

Bases: object

Manages the execution of client transactions and provides Transaction objects.

new_transaction(timeout: float, durability: int, transaction_type: int) Transaction[source]

Creates a Transaction object with given timeout, durability and transaction type.

Parameters
  • timeout – The timeout in seconds determines the maximum lifespan of a transaction.

  • durability – The durability is the number of machines that can take over if a member fails during a transaction commit or rollback.

  • transaction_type – the transaction type which can be hazelcast.transaction.TWO_PHASE or hazelcast.transaction.ONE_PHASE.

Returns

New created Transaction.

class Transaction(context, connection, timeout, durability, transaction_type)[source]

Bases: object

Provides transactional operations: beginning/committing transactions, but also retrieving transactional data-structures like the TransactionalMap.

state = 'not_started'
id: Optional[UUID] = None
start_time: Optional[float] = None
thread_id: Optional[int] = None
begin() None[source]

Begins this transaction.

commit() None[source]

Commits this transaction.

rollback() None[source]

Rollback of this current transaction.

get_list(name: str) TransactionalList[source]

Returns the transactional list instance with the specified name.

Parameters

name – The specified name.

Returns

The instance of Transactional List with the specified name.

get_map(name: str) TransactionalMap[source]

Returns the transactional map instance with the specified name.

Parameters

name – The specified name.

Returns

The instance of Transactional Map with the specified name.

get_multi_map(name: str) TransactionalMultiMap[source]

Returns the transactional multimap instance with the specified name.

Parameters

name – The specified name.

Returns

The instance of Transactional MultiMap with the specified name.

get_queue(name: str) TransactionalQueue[source]

Returns the transactional queue instance with the specified name.

Parameters

name – The specified name.

Returns

The instance of Transactional Queue with the specified name.

get_set(name: str) TransactionalSet[source]

Returns the transactional set instance with the specified name.

Parameters

name – The specified name.

Returns

The instance of Transactional Set with the specified name.