Repository: phoenix Updated Branches: refs/heads/4.x-HBase-0.98 e6f9ce035 -> 5ce06a062
http://git-wip-us.apache.org/repos/asf/phoenix/blob/5ce06a06/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionContext.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionContext.java b/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionContext.java index f3ad42f..751945a 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionContext.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionContext.java @@ -108,6 +108,11 @@ public interface PhoenixTransactionContext { public HTableInterface getTransactionalTable(HTableInterface htable, boolean isImmutable) { return null; } + + @Override + public HTableInterface getTransactionalTableWriter(HTableInterface htable, PTable table) { + return null; + } }; /** * @@ -225,4 +230,5 @@ public interface PhoenixTransactionContext { public PhoenixTransactionContext newTransactionContext(PhoenixTransactionContext contex, boolean subTask); public HTableInterface getTransactionalTable(HTableInterface htable, boolean isImmutable); + public HTableInterface getTransactionalTableWriter(HTableInterface htable, PTable table); } http://git-wip-us.apache.org/repos/asf/phoenix/blob/5ce06a06/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionContext.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionContext.java b/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionContext.java index 8b16210..bc33cff 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionContext.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionContext.java @@ -397,5 +397,21 @@ public class TephraTransactionContext implements PhoenixTransactionContext { this.addTransactionAware(transactionAwareHTable); return transactionAwareHTable; } + + @Override + public HTableInterface getTransactionalTableWriter(HTableInterface htable, PTable table) { + boolean isIndex = table.getType() == PTableType.INDEX; + TransactionAwareHTable transactionAwareHTable = new TransactionAwareHTable(htable, table.isImmutableRows() || isIndex ? TxConstants.ConflictDetection.NONE : TxConstants.ConflictDetection.ROW); + // 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 (isIndex) { + transactionAwareHTable.startTx(getTransaction()); + } else { + // Even for immutable, we need to do this so that an abort has the state + // necessary to generate the rows to delete. + this.addTransactionAware(transactionAwareHTable); + } + return transactionAwareHTable; + } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/5ce06a06/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java index b4219ee..36a3c38 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java @@ -41,7 +41,6 @@ import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Durability; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.HTableInterface; @@ -115,7 +114,6 @@ import org.apache.phoenix.schema.types.PDecimal; import org.apache.phoenix.schema.types.PLong; import org.apache.phoenix.schema.types.PVarbinary; import org.apache.phoenix.schema.types.PVarchar; -import org.apache.phoenix.transaction.PhoenixTransactionContext; import com.google.common.collect.Lists; @@ -268,32 +266,6 @@ public class IndexUtil { .getLength()) == 0); } - public static List<Delete> generateDeleteIndexData(final PTable table, PTable index, - List<Delete> dataMutations, ImmutableBytesWritable ptr, final KeyValueBuilder kvBuilder, PhoenixConnection connection) - throws SQLException { - try { - IndexMaintainer maintainer = index.getIndexMaintainer(table, connection); - List<Delete> indexMutations = Lists.newArrayListWithExpectedSize(dataMutations.size()); - for (final Mutation dataMutation : dataMutations) { - long ts = MetaDataUtil.getClientTimeStamp(dataMutation); - ptr.set(dataMutation.getRow()); - byte[] regionStartKey = null; - byte[] regionEndkey = null; - if(maintainer.isLocalIndex()) { - HRegionLocation tableRegionLocation = connection.getQueryServices().getTableRegionLocation(table.getPhysicalName().getBytes(), dataMutation.getRow()); - regionStartKey = tableRegionLocation.getRegionInfo().getStartKey(); - regionEndkey = tableRegionLocation.getRegionInfo().getEndKey(); - } - Delete delete = maintainer.buildDeleteMutation(kvBuilder, null, ptr, Collections.<KeyValue>emptyList(), ts, regionStartKey, regionEndkey); - delete.setAttribute(PhoenixTransactionContext.TX_ROLLBACK_ATTRIBUTE_KEY, dataMutation.getAttribute(PhoenixTransactionContext.TX_ROLLBACK_ATTRIBUTE_KEY)); - indexMutations.add(delete); - } - return indexMutations; - } catch (IOException e) { - throw new SQLException(e); - } - } - public static List<Mutation> generateIndexData(final PTable table, PTable index, final MultiRowMutationState multiRowMutationState, List<Mutation> dataMutations, final KeyValueBuilder kvBuilder, PhoenixConnection connection) throws SQLException {