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)

Bases: object

Manages the execution of client transactions and provides Transaction objects.

new_transaction(timeout, durability, transaction_type)

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

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

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

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

Returns

New created Transaction.

Return type

hazelcast.transaction.Transaction

class Transaction(context, connection, timeout, durability, transaction_type)

Bases: object

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

state = 'not_started'
id = None
start_time = None
thread_id = None
begin()

Begins this transaction.

commit()

Commits this transaction.

rollback()

Rollback of this current transaction.

get_list(name)

Returns the transactional list instance with the specified name.

Parameters

name (str) – The specified name.

Returns

The instance of Transactional List

with the specified name.

Return type

hazelcast.proxy.transactional_list.TransactionalList`

get_map(name)

Returns the transactional map instance with the specified name.

Parameters

name (str) – The specified name.

Returns

The instance of Transactional Map

with the specified name.

Return type

hazelcast.proxy.transactional_map.TransactionalMap

get_multi_map(name)

Returns the transactional multimap instance with the specified name.

Parameters

name (str) – The specified name.

Returns

The instance of Transactional MultiMap

with the specified name.

Return type

hazelcast.proxy.transactional_multi_map.TransactionalMultiMap

get_queue(name)

Returns the transactional queue instance with the specified name.

Parameters

name (str) – The specified name.

Returns

The instance of Transactional Queue

with the specified name.

Return type

hazelcast.proxy.transactional_queue.TransactionalQueue

get_set(name)

Returns the transactional set instance with the specified name.

Parameters

name (str) – The specified name.

Returns

The instance of Transactional Set

with the specified name.

Return type

hazelcast.proxy.transactional_set.TransactionalSet