You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2015/06/05 02:44:33 UTC
phoenix git commit: Set conflict detection to NONE for tables with
IMMUTABLE_ROWS=true
Repository: phoenix
Updated Branches:
refs/heads/txn 716307f41 -> 6bcbbbd73
Set conflict detection to NONE for tables with IMMUTABLE_ROWS=true
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/6bcbbbd7
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/6bcbbbd7
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/6bcbbbd7
Branch: refs/heads/txn
Commit: 6bcbbbd737abc36cf5f68187620b0ea94e77b5f6
Parents: 716307f
Author: James Taylor <ja...@apache.org>
Authored: Thu Jun 4 17:44:20 2015 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Thu Jun 4 17:44:20 2015 -0700
----------------------------------------------------------------------
.../phoenix/transactions/TransactionIT.java | 20 +++++++++++++++++---
.../apache/phoenix/execute/MutationState.java | 2 +-
.../phoenix/iterate/TableResultIterator.java | 2 +-
.../apache/phoenix/util/TransactionUtil.java | 6 ++++--
4 files changed, 23 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/6bcbbbd7/phoenix-core/src/it/java/org/apache/phoenix/transactions/TransactionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/transactions/TransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/transactions/TransactionIT.java
index a5b80bb..49e9ecb 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/transactions/TransactionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/transactions/TransactionIT.java
@@ -28,7 +28,9 @@ import java.util.Map;
import org.apache.phoenix.end2end.BaseHBaseManagedTimeIT;
import org.apache.phoenix.end2end.Shadower;
import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.util.DateUtil;
import org.apache.phoenix.util.ReadOnlyProps;
import org.apache.phoenix.util.TestUtil;
@@ -218,8 +220,7 @@ public class TransactionIT extends BaseHBaseManagedTimeIT {
}
}
- @Test
- public void testRowConflicts() throws Exception {
+ private void testRowConflicts() throws Exception {
Connection conn1 = DriverManager.getConnection(getUrl());
Connection conn2 = DriverManager.getConnection(getUrl());
try {
@@ -228,6 +229,7 @@ public class TransactionIT extends BaseHBaseManagedTimeIT {
String selectSql = "SELECT * FROM "+FULL_TABLE_NAME;
conn1.setAutoCommit(false);
ResultSet rs = conn1.createStatement().executeQuery(selectSql);
+ boolean immutableRows = conn1.unwrap(PhoenixConnection.class).getMetaDataCache().getTable(new PTableKey(null, FULL_TABLE_NAME)).isImmutableRows();
assertFalse(rs.next());
// upsert row using conn1
String upsertSql = "UPSERT INTO " + FULL_TABLE_NAME + "(varchar_pk, char_pk, int_pk, long_pk, decimal_pk, date_pk, a.int_col1) VALUES(?, ?, ?, ?, ?, ?, ?)";
@@ -246,9 +248,10 @@ public class TransactionIT extends BaseHBaseManagedTimeIT {
//second commit should fail
try {
conn2.commit();
- fail();
+ if (!immutableRows) fail();
}
catch (SQLException e) {
+ if (immutableRows) fail();
assertEquals(e.getErrorCode(), SQLExceptionCode.TRANSACTION_CONFLICT_EXCEPTION.getErrorCode());
}
}
@@ -258,4 +261,15 @@ public class TransactionIT extends BaseHBaseManagedTimeIT {
}
}
+ @Test
+ public void testRowConflictDetected() throws Exception {
+ testRowConflicts();
+ }
+
+ @Test
+ public void testNoConflictDetectionForImmutableRows() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ conn.createStatement().execute("ALTER TABLE " + FULL_TABLE_NAME + " SET IMMUTABLE_ROWS=true");
+ testRowConflicts();
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/6bcbbbd7/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
index 562d055..9695f2d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
@@ -565,7 +565,7 @@ public class MutationState implements SQLCloseable {
if (!table.getIndexes().isEmpty()) {
hTable = new MetaDataAwareHTable(hTable, tableRef);
}
- TransactionAwareHTable txnAware = TransactionUtil.getTransactionAwareHTable(hTable);
+ TransactionAwareHTable txnAware = TransactionUtil.getTransactionAwareHTable(hTable, table);
// Don't add immutable indexes (those are the only ones that would participate
// during a commit), as we don't need conflict detection for these.
if (isDataTable) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/6bcbbbd7/phoenix-core/src/main/java/org/apache/phoenix/iterate/TableResultIterator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/TableResultIterator.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/TableResultIterator.java
index ad95ef9..898c443 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/TableResultIterator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/TableResultIterator.java
@@ -89,7 +89,7 @@ public class TableResultIterator extends ExplainTable implements ResultIterator
HTableInterface htable = context.getConnection().getQueryServices().getTable(table.getPhysicalName().getBytes());
Transaction tx;
if (table.isTransactional() && (tx=context.getTransaction()) != null) {
- TransactionAwareHTable txAware = TransactionUtil.getTransactionAwareHTable(htable);
+ TransactionAwareHTable txAware = TransactionUtil.getTransactionAwareHTable(htable, table);
// Use transaction cached on context as we may have started a new transaction already
// if auto commit is true.
txAware.startTx(tx);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/6bcbbbd7/phoenix-core/src/main/java/org/apache/phoenix/util/TransactionUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/TransactionUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/TransactionUtil.java
index 061a98b..f013244 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/TransactionUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/TransactionUtil.java
@@ -30,6 +30,7 @@ import co.cask.tephra.hbase98.TransactionAwareHTable;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.SQLExceptionInfo;
+import org.apache.phoenix.schema.PTable;
public class TransactionUtil {
private TransactionUtil() {
@@ -67,7 +68,8 @@ public class TransactionUtil {
.build().buildException();
}
- public static TransactionAwareHTable getTransactionAwareHTable(HTableInterface htable) {
- return new TransactionAwareHTable(htable, TxConstants.ConflictDetection.ROW);
+ public static TransactionAwareHTable getTransactionAwareHTable(HTableInterface htable, PTable table) {
+ // Conflict detection is not needed for tables with write-once/append-only data
+ return new TransactionAwareHTable(htable, table.isImmutableRows() ? TxConstants.ConflictDetection.NONE : TxConstants.ConflictDetection.ROW);
}
}