Repository: phoenix Updated Branches: refs/heads/txn 46eb25c14 -> 35bcb3246
Support rollback over indexes on immutable tables Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/35bcb324 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/35bcb324 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/35bcb324 Branch: refs/heads/txn Commit: 35bcb32467b5026128496e4eff632a85cac562b6 Parents: 46eb25c Author: James Taylor <[email protected]> Authored: Wed May 20 15:54:40 2015 -0700 Committer: James Taylor <[email protected]> Committed: Wed May 20 15:54:40 2015 -0700 ---------------------------------------------------------------------- .../end2end/index/TxImmutableIndexIT.java | 33 +++++++++++++++++++- .../apache/phoenix/index/PhoenixIndexCodec.java | 2 +- .../index/PhoenixTransactionalIndexer.java | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/35bcb324/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/TxImmutableIndexIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/TxImmutableIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/TxImmutableIndexIT.java index 4c77ea3..2a5bd69 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/TxImmutableIndexIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/TxImmutableIndexIT.java @@ -55,7 +55,7 @@ public class TxImmutableIndexIT extends ImmutableIndexIT { } @Test - public void testRollbackOfUncommittedIndexChange() throws Exception { + public void testRollbackOfUncommittedKeyValueIndexChange() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); conn.setAutoCommit(false); @@ -84,4 +84,35 @@ public class TxImmutableIndexIT extends ImmutableIndexIT { conn.close(); } } + + @Test + public void testRollbackOfUncommittedRowKeyIndexChange() throws Exception { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + conn.setAutoCommit(false); + try { + Statement stmt = conn.createStatement(); + stmt.execute("CREATE TABLE DEMO(v1 VARCHAR, v2 VARCHAR, v3 VARCHAR, CONSTRAINT pk PRIMARY KEY (v1, v2)) IMMUTABLE_ROWS=true"); + stmt.execute("CREATE INDEX DEMO_idx ON DEMO (v2, v1)"); + + stmt.executeUpdate("upsert into DEMO values('x', 'y', 'a')"); + + //assert values in data table + ResultSet rs = stmt.executeQuery("select v1, v2, v3 from DEMO"); + assertTrue(rs.next()); + assertEquals("x", rs.getString(1)); + assertEquals("y", rs.getString(2)); + assertEquals("a", rs.getString(3)); + assertFalse(rs.next()); + + conn.rollback(); + + //assert values in data table + rs = stmt.executeQuery("select v1, v2, v3 from DEMO"); + assertFalse(rs.next()); + + } finally { + conn.close(); + } + } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/35bcb324/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexCodec.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexCodec.java b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexCodec.java index 109de84..e78df56 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexCodec.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexCodec.java @@ -86,7 +86,7 @@ public class PhoenixIndexCodec extends BaseIndexCodec { ptr.set(state.getCurrentRowKey()); List<IndexUpdate> indexUpdates = Lists.newArrayList(); for (IndexMaintainer maintainer : indexMaintainers) { - if (maintainer.isImmutableRows()) { + if (maintainer.isImmutableRows() && maintainer.isLocalIndex()) { continue; } Pair<ValueGetter, IndexUpdate> statePair = state.getIndexUpdateState(maintainer.getAllColumns()); http://git-wip-us.apache.org/repos/asf/phoenix/blob/35bcb324/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java index cfe0058..dad93e3 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixTransactionalIndexer.java @@ -213,7 +213,7 @@ public class PhoenixTransactionalIndexer extends BaseRegionObserver { List<IndexMaintainer> indexMaintainers = indexMetaData.getIndexMaintainers(); Set<ColumnReference> mutableColumns = Sets.newHashSetWithExpectedSize(indexMaintainers.size() * 10); for (IndexMaintainer indexMaintainer : indexMaintainers) { - if (!indexMaintainer.isImmutableRows()) { + if (!indexMaintainer.isImmutableRows() || !indexMaintainer.isLocalIndex()) { mutableColumns.addAll(indexMaintainer.getAllColumns()); } }
