Phoenix Transactions

Phoenix Transactions

Above and beyond the row-level transactional semantics of HBase, Phoenix adds cross row and cross table transaction support with full ACID semantics by integrating with Tephra, now an Apache incubator project. Tephra provides snapshot isolation of concurrent transactions by implementing multi-versioned concurrency control.

Setting up a system to use transactions in Phoenix requires two steps:

  1. Add the following config to your client side hbase-site.xml file to enable transactions:
    <property>
  2.   <name>phoenix.transactions.enabled</name>
  3.   <value>true</value>
  4.   </property>

  5.  2   Add the following config to your server side hbase-site.xml file to configure the transaction manager: The “Transaction Server Configuration” section of Tephra describes the available configuration options.
    <property>
  6.       <name>data.tx.snapshot.dir</name>
  7.      <value>/tmp/tephra/snapshots</value>
  8.    </property>
  9.   Also set the transaction timeout (time after which open transactions become invalid) to a reasonable value.
    <property>
  10.       <name>data.tx.timeout</name>
  11.       <value>60</value> 
  12.     </property>

  13. 3   Set $HBASE_HOME and start the transaction manager:
    ./bin/tephra

The transaction manager would typically be configured to run on one or more of the master nodes in your HBase cluster

Once this setup is done, transactions may then be enabled on a table by table basis by using the TRANSACTIONAL=true property when you create your table:

CREATE TABLE my_table (k BIGINT PRIMARY KEY, v VARCHAR) TRANSACTIONAL=true;

An existing table may also be altered to be transactional, but be careful because you cannot switch a transactional table back to being non transactional:

ALTER TABLE my_other_table SET TRANSACTIONAL=true;


Limitations

  1. Starting a transaction on a connection with an SCN set is not allowed.
  2. Setting the maximum number of versions property while creating a transactional table limits the number of snapshots available for concurrent transactions.
  3. When a transaction times out or if it cannot be rolled back by the client, it is added to an invalid list. This list can potentially grow if there are a lot of failed or timed out transactions. For now, an adminstrator can manually clear transactions from this list after a major compaction has occurred. TEPHRA-35 describes ongoing work to automatically remove transactions from the invalid list once all data associated with the transaction has been removed.
  4. If adding an index asynchronously to an existing transactional table, make sure to run a major compaction before issuing the CREATE INDEX ASYNC command as otherwise invalid and/or uncommitted transactions may appear in your index PHOENIX-2154.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Transactions(事务)是指将一组数据库操作作为单个逻辑工作单元执行的过程,它要么完全执行,要么完全不执行。如果执行过程中出现故障,那么所有的更改都会回滚,以确保数据库保持一致性。 在关系型数据库中,事务通常遵循ACID(原子性、一致性、隔离性和持久性)原则,以确保数据的正确性和完整性。以下是ACID的详细解释: - 原子性(Atomicity):一个事务是原子的,即它是一个不可分割的最小工作单元。如果事务成功执行,则所有更改将提交到数据库中;如果事务失败,则所有更改将回滚到状态的起点。 - 一致性(Consistency):在事务开始之前和事务结束时,数据库必须处于一致状态。这意味着事务中的所有更改都必须满足数据库中的约束条件。 - 隔离性(Isolation):隔离性指的是并发事务之间的互相隔离性。这意味着一个事务的执行不应该影响另一个事务的执行。 - 持久性(Durability):一旦事务完成,其结果就应该是永久的。这意味着事务中的所有更改都应该保存在数据库中,并且在系统故障时也应该能够恢复。 在实际应用中,事务通常由BEGIN、COMMIT和ROLLBACK语句控制。BEGIN语句用于标识事务的开始,COMMIT语句用于标识事务的结束,并将更改保存到数据库中,而ROLLBACK语句用于回滚事务中的所有更改。 事务可以确保数据的正确性和完整性,特别是在具有高并发读写操作的应用场景下非常有用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值