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 2018/10/05 14:35:01 UTC
[1/4] phoenix git commit: PHOENIX-4731 Make running transactional
unit tests for a given provider optional
Repository: phoenix
Updated Branches:
refs/heads/4.x-HBase-1.3 20000d956 -> fd9af912f
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index d4f4ae3..f77ed75 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -1179,14 +1179,12 @@ public class MetaDataClient {
// If the table is a view, then we will end up calling update stats
// here for all the view indexes on it. We take care of local indexes later.
if (index.getIndexType() != IndexType.LOCAL) {
- if (index.getIndexType() != IndexType.LOCAL) {
- if (table.getType() != PTableType.VIEW) {
- rowCount += updateStatisticsInternal(index.getPhysicalName(), index,
- updateStatisticsStmt.getProps(), true);
- } else {
- rowCount += updateStatisticsInternal(table.getPhysicalName(), index,
- updateStatisticsStmt.getProps(), true);
- }
+ if (table.getType() != PTableType.VIEW) {
+ rowCount += updateStatisticsInternal(index.getPhysicalName(), index,
+ updateStatisticsStmt.getProps(), true);
+ } else {
+ rowCount += updateStatisticsInternal(table.getPhysicalName(), index,
+ updateStatisticsStmt.getProps(), true);
}
}
}
@@ -1548,6 +1546,11 @@ public class MetaDataClient {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CREATE_INDEX_ON_MUTABLE_TABLE_WITH_ROWTIMESTAMP).setTableName(indexTableName.getTableName()).build().buildException();
}
}
+ if (dataTable.isTransactional()
+ && isLocalIndex
+ && dataTable.getTransactionProvider().getTransactionProvider().isUnsupported(PhoenixTransactionProvider.Feature.ALLOW_LOCAL_INDEX)) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CREATE_LOCAL_INDEX_FOR_TXN_TABLE).setMessage(dataTable.getTransactionProvider().name()).setTableName(indexTableName.getTableName()).build().buildException();
+ }
int posOffset = 0;
List<PColumn> pkColumns = dataTable.getPKColumns();
Set<RowKeyColumnExpression> unusedPkColumns;
@@ -2128,10 +2131,20 @@ public class MetaDataClient {
.setSchemaName(schemaName).setTableName(tableName)
.build().buildException();
}
+ if (TableProperty.TTL.getValue(commonFamilyProps) != null
+ && transactionProvider != null
+ && transactionProvider.getTransactionProvider().isUnsupported(PhoenixTransactionProvider.Feature.SET_TTL)) {
+ throw new SQLExceptionInfo.Builder(PhoenixTransactionProvider.Feature.SET_TTL.getCode())
+ .setMessage(transactionProvider.name())
+ .setSchemaName(schemaName)
+ .setTableName(tableName)
+ .build()
+ .buildException();
+ }
// Put potentially inferred value into tableProps as it's used by the createTable call below
// to determine which coprocessors to install on the new table.
- tableProps.put(PhoenixDatabaseMetaData.TRANSACTIONAL, transactionProvider != null);
+ tableProps.put(PhoenixDatabaseMetaData.TRANSACTION_PROVIDER, transactionProvider);
if (transactionProvider != null) {
// TODO: for Omid
// If TTL set, use Tephra TTL property name instead
@@ -2355,32 +2368,61 @@ public class MetaDataClient {
} else {
Byte encodingSchemeSerializedByte = (Byte) TableProperty.COLUMN_ENCODED_BYTES.getValue(tableProps);
if (encodingSchemeSerializedByte == null) {
- encodingSchemeSerializedByte = (byte)connection.getQueryServices().getProps().getInt(QueryServices.DEFAULT_COLUMN_ENCODED_BYTES_ATRRIB, QueryServicesOptions.DEFAULT_COLUMN_ENCODED_BYTES);
- }
- encodingScheme = QualifierEncodingScheme.fromSerializedValue(encodingSchemeSerializedByte);
+ // Ignore default if transactional and column encoding is not supported (as with OMID)
+ if (transactionProvider == null || !transactionProvider.getTransactionProvider().isUnsupported(PhoenixTransactionProvider.Feature.COLUMN_ENCODING) ) {
+ encodingSchemeSerializedByte = (byte)connection.getQueryServices().getProps().getInt(QueryServices.DEFAULT_COLUMN_ENCODED_BYTES_ATRRIB,
+ QueryServicesOptions.DEFAULT_COLUMN_ENCODED_BYTES);
+ encodingScheme = QualifierEncodingScheme.fromSerializedValue(encodingSchemeSerializedByte);
+ }
+ } else {
+ encodingScheme = QualifierEncodingScheme.fromSerializedValue(encodingSchemeSerializedByte);
+ if (encodingScheme != NON_ENCODED_QUALIFIERS && transactionProvider != null && transactionProvider.getTransactionProvider().isUnsupported(PhoenixTransactionProvider.Feature.COLUMN_ENCODING) ) {
+ throw new SQLExceptionInfo.Builder(
+ SQLExceptionCode.UNSUPPORTED_COLUMN_ENCODING_FOR_TXN_PROVIDER)
+ .setSchemaName(schemaName).setTableName(tableName)
+ .setMessage(transactionProvider.name())
+ .build()
+ .buildException();
+ }
+ }
if (isImmutableRows) {
- immutableStorageScheme =
+ ImmutableStorageScheme immutableStorageSchemeProp =
(ImmutableStorageScheme) TableProperty.IMMUTABLE_STORAGE_SCHEME
.getValue(tableProps);
- if (immutableStorageScheme == null) {
- if (multiTenant) {
- immutableStorageScheme =
- ImmutableStorageScheme
- .valueOf(connection
- .getQueryServices()
- .getProps()
- .get(
- QueryServices.DEFAULT_MULTITENANT_IMMUTABLE_STORAGE_SCHEME_ATTRIB,
- QueryServicesOptions.DEFAULT_MULTITENANT_IMMUTABLE_STORAGE_SCHEME));
- } else {
- immutableStorageScheme =
- ImmutableStorageScheme
- .valueOf(connection
- .getQueryServices()
- .getProps()
- .get(
- QueryServices.DEFAULT_IMMUTABLE_STORAGE_SCHEME_ATTRIB,
- QueryServicesOptions.DEFAULT_IMMUTABLE_STORAGE_SCHEME));
+ if (immutableStorageSchemeProp == null) {
+ // Ignore default if transactional and column encoding is not supported
+ if (transactionProvider == null ||
+ !transactionProvider.getTransactionProvider().isUnsupported(
+ PhoenixTransactionProvider.Feature.COLUMN_ENCODING) ) {
+ if (multiTenant) {
+ immutableStorageScheme =
+ ImmutableStorageScheme
+ .valueOf(connection
+ .getQueryServices()
+ .getProps()
+ .get(
+ QueryServices.DEFAULT_MULTITENANT_IMMUTABLE_STORAGE_SCHEME_ATTRIB,
+ QueryServicesOptions.DEFAULT_MULTITENANT_IMMUTABLE_STORAGE_SCHEME));
+ } else {
+ immutableStorageScheme =
+ ImmutableStorageScheme
+ .valueOf(connection
+ .getQueryServices()
+ .getProps()
+ .get(
+ QueryServices.DEFAULT_IMMUTABLE_STORAGE_SCHEME_ATTRIB,
+ QueryServicesOptions.DEFAULT_IMMUTABLE_STORAGE_SCHEME));
+ }
+ }
+ } else {
+ immutableStorageScheme = immutableStorageSchemeProp;
+ if (immutableStorageScheme != ONE_CELL_PER_COLUMN && transactionProvider != null && transactionProvider.getTransactionProvider().isUnsupported(PhoenixTransactionProvider.Feature.COLUMN_ENCODING) ) {
+ throw new SQLExceptionInfo.Builder(
+ SQLExceptionCode.UNSUPPORTED_STORAGE_FORMAT_FOR_TXN_PROVIDER)
+ .setSchemaName(schemaName).setTableName(tableName)
+ .setMessage(transactionProvider.name())
+ .build()
+ .buildException();
}
}
if (immutableStorageScheme != ONE_CELL_PER_COLUMN
@@ -3135,6 +3177,7 @@ public class MetaDataClient {
throws SQLException {
return incrementTableSeqNum(table, expectedType, columnCountDelta,
metaPropertiesEvaluated.getIsTransactional(),
+ metaPropertiesEvaluated.getTransactionProvider(),
metaPropertiesEvaluated.getUpdateCacheFrequency(),
metaPropertiesEvaluated.getIsImmutableRows(),
metaPropertiesEvaluated.getDisableWAL(),
@@ -3147,13 +3190,14 @@ public class MetaDataClient {
}
private long incrementTableSeqNum(PTable table, PTableType expectedType, int columnCountDelta, Boolean isTransactional, Long updateCacheFrequency) throws SQLException {
- return incrementTableSeqNum(table, expectedType, columnCountDelta, isTransactional, updateCacheFrequency, null, null, null, null, -1L, null, null, null);
+ return incrementTableSeqNum(table, expectedType, columnCountDelta, isTransactional, null, updateCacheFrequency, null, null, null, null, -1L, null, null, null);
}
private long incrementTableSeqNum(PTable table, PTableType expectedType, int columnCountDelta,
- Boolean isTransactional, Long updateCacheFrequency, Boolean isImmutableRows, Boolean disableWAL,
- Boolean isMultiTenant, Boolean storeNulls, Long guidePostWidth, Boolean appendOnlySchema, ImmutableStorageScheme immutableStorageScheme
- , Boolean useStatsForParallelization)
+ Boolean isTransactional, TransactionFactory.Provider transactionProvider,
+ Long updateCacheFrequency, Boolean isImmutableRows, Boolean disableWAL,
+ Boolean isMultiTenant, Boolean storeNulls, Long guidePostWidth, Boolean appendOnlySchema,
+ ImmutableStorageScheme immutableStorageScheme, Boolean useStatsForParallelization)
throws SQLException {
String schemaName = table.getSchemaName().getString();
String tableName = table.getTableName().getString();
@@ -3188,6 +3232,9 @@ public class MetaDataClient {
if (isTransactional != null) {
mutateBooleanProperty(tenantId, schemaName, tableName, TRANSACTIONAL, isTransactional);
}
+ if (transactionProvider !=null) {
+ mutateByteProperty(tenantId, schemaName, tableName, TRANSACTION_PROVIDER, transactionProvider.getCode());
+ }
if (updateCacheFrequency != null) {
mutateLongProperty(tenantId, schemaName, tableName, UPDATE_CACHE_FREQUENCY, updateCacheFrequency);
}
@@ -3244,6 +3291,27 @@ public class MetaDataClient {
}
}
+ private void mutateByteProperty(String tenantId, String schemaName, String tableName,
+ String propertyName, Byte propertyValue) throws SQLException {
+ String updatePropertySql = "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
+ TENANT_ID + "," +
+ TABLE_SCHEM + "," +
+ TABLE_NAME + "," +
+ propertyName +
+ ") VALUES (?, ?, ?, ?)";
+ try (PreparedStatement tableBoolUpsert = connection.prepareStatement(updatePropertySql)) {
+ tableBoolUpsert.setString(1, tenantId);
+ tableBoolUpsert.setString(2, schemaName);
+ tableBoolUpsert.setString(3, tableName);
+ if (propertyValue == null) {
+ tableBoolUpsert.setNull(4, Types.TINYINT);
+ } else {
+ tableBoolUpsert.setByte(4, propertyValue);
+ }
+ tableBoolUpsert.execute();
+ }
+ }
+
private void mutateStringProperty(String tenantId, String schemaName, String tableName,
String propertyName, String propertyValue) throws SQLException {
String updatePropertySql = "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
@@ -3728,7 +3796,7 @@ public class MetaDataClient {
*/
private static byte[] getNewEmptyColumnFamilyOrNull (PTable table, PColumn columnToDrop) {
if (table.getType() != PTableType.VIEW && !SchemaUtil.isPKColumn(columnToDrop) && table.getColumnFamilies().get(0).getName().equals(columnToDrop.getFamilyName()) && table.getColumnFamilies().get(0).getColumns().size() == 1) {
- return SchemaUtil.getEmptyColumnFamily(table.getDefaultFamilyName(), table.getColumnFamilies().subList(1, table.getColumnFamilies().size()));
+ return SchemaUtil.getEmptyColumnFamily(table.getDefaultFamilyName(), table.getColumnFamilies().subList(1, table.getColumnFamilies().size()), table.getIndexType() == IndexType.LOCAL);
}
// If unchanged, return null
return null;
@@ -4533,8 +4601,8 @@ public class MetaDataClient {
connection.getQueryServices().getProps().get(
QueryServices.DEFAULT_TRANSACTION_PROVIDER_ATTRIB,
QueryServicesOptions.DEFAULT_TRANSACTION_PROVIDER));
- metaPropertiesEvaluated.setTransactionProvider(provider);
}
+ metaPropertiesEvaluated.setTransactionProvider(provider);
if (provider.getTransactionProvider().isUnsupported(PhoenixTransactionProvider.Feature.ALTER_NONTX_TO_TX)) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_ALTER_TABLE_FROM_NON_TXN_TO_TXNL)
.setMessage(provider.name() + ". ")
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionContext.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionContext.java b/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionContext.java
index d235d4b..9edc58b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionContext.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionContext.java
@@ -19,122 +19,111 @@ package org.apache.phoenix.transaction;
import java.sql.SQLException;
-import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.hadoop.hbase.client.Table;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.transaction.TransactionFactory.Provider;
+import com.google.protobuf.InvalidProtocolBufferException;
+//import org.apache.omid.tso.TSOMockModule;
+
public class OmidTransactionContext implements PhoenixTransactionContext {
+ public OmidTransactionContext() {
+ }
+
+ public OmidTransactionContext(PhoenixConnection connection) throws SQLException {
+ }
+
+ public OmidTransactionContext(byte[] txnBytes) throws InvalidProtocolBufferException {
+ }
+
+ public OmidTransactionContext(PhoenixTransactionContext ctx, boolean subTask) {
+ }
+
@Override
public void begin() throws SQLException {
- // TODO Auto-generated method stub
-
}
@Override
public void commit() throws SQLException {
- // TODO Auto-generated method stub
-
}
@Override
public void abort() throws SQLException {
- // TODO Auto-generated method stub
-
}
@Override
public void checkpoint(boolean hasUncommittedData) throws SQLException {
- // TODO Auto-generated method stub
-
}
@Override
public void commitDDLFence(PTable dataTable) throws SQLException {
- // TODO Auto-generated method stub
-
}
@Override
public void join(PhoenixTransactionContext ctx) {
- // TODO Auto-generated method stub
-
}
@Override
public boolean isTransactionRunning() {
- // TODO Auto-generated method stub
return false;
}
@Override
public void reset() {
- // TODO Auto-generated method stub
-
}
@Override
public long getTransactionId() {
- // TODO Auto-generated method stub
return 0;
}
@Override
public long getReadPointer() {
- // TODO Auto-generated method stub
return 0;
}
@Override
public long getWritePointer() {
- // TODO Auto-generated method stub
return 0;
}
@Override
public PhoenixVisibilityLevel getVisibilityLevel() {
- // TODO Auto-generated method stub
return null;
}
@Override
public void setVisibilityLevel(PhoenixVisibilityLevel visibilityLevel) {
- // TODO Auto-generated method stub
-
}
@Override
public byte[] encodeTransaction() throws SQLException {
- // TODO Auto-generated method stub
return null;
}
@Override
public Provider getProvider() {
- return Provider.OMID;
+ return TransactionFactory.Provider.OMID;
}
@Override
- public PhoenixTransactionContext newTransactionContext(PhoenixTransactionContext contex, boolean subTask) {
+ public PhoenixTransactionContext newTransactionContext(PhoenixTransactionContext context, boolean subTask) {
return null;
}
@Override
public void markDMLFence(PTable dataTable) {
- // TODO Auto-generated method stub
-
}
@Override
- public HTableInterface getTransactionalTable(HTableInterface htable, boolean isImmutable) {
- // TODO Auto-generated method stub
- return null;
+ public Table getTransactionalTable(Table htable, boolean isConflictFree) throws SQLException {
+ return new OmidTransactionTable(this, htable, isConflictFree);
}
@Override
- public HTableInterface getTransactionalTableWriter(PhoenixConnection connection, PTable table, HTableInterface htable, boolean isIndex) {
- // TODO Auto-generated method stub
- return null;
+ public Table getTransactionalTableWriter(PhoenixConnection connection, PTable table, Table htable, boolean isIndex) throws SQLException {
+ return new OmidTransactionTable(this, htable, table.isImmutableRows() || isIndex);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java b/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java
index c211661..c53215c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java
@@ -18,15 +18,25 @@
package org.apache.phoenix.transaction;
import java.io.IOException;
+import java.sql.SQLException;
+import java.util.Arrays;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.coprocessor.RegionObserver;
+import org.apache.phoenix.coprocessor.OmidGCProcessor;
+import org.apache.phoenix.coprocessor.OmidTransactionalProcessor;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo;
import org.apache.phoenix.transaction.TransactionFactory.Provider;
public class OmidTransactionProvider implements PhoenixTransactionProvider {
private static final OmidTransactionProvider INSTANCE = new OmidTransactionProvider();
+ public static final String OMID_TSO_PORT = "phoenix.omid.tso.port";
+ public static final String OMID_TSO_CONFLICT_MAP_SIZE = "phoenix.omid.tso.conflict.map.size";
+ public static final String OMID_TSO_TIMESTAMP_TYPE = "phoenix.omid.tso.timestamp.type";
+ public static final int DEFAULT_OMID_TSO_CONFLICT_MAP_SIZE = 1000;
+ public static final String DEFAULT_OMID_TSO_TIMESTAMP_TYPE = "WORLD_TIME";
public static final OmidTransactionProvider getInstance() {
return INSTANCE;
@@ -36,33 +46,54 @@ public class OmidTransactionProvider implements PhoenixTransactionProvider {
}
@Override
+ public String toString() {
+ return getProvider().toString();
+ }
+
+ @Override
public PhoenixTransactionContext getTransactionContext(byte[] txnBytes) throws IOException {
- //return new OmidTransactionContext(txnBytes);
- return null;
+ // Remove last byte (which is used to identify transaction provider)
+ return new OmidTransactionContext(Arrays.copyOf(txnBytes,txnBytes.length-1));
}
@Override
- public PhoenixTransactionContext getTransactionContext(PhoenixConnection connection) {
- //return new OmidTransactionContext(connection);
- return null;
+ public PhoenixTransactionContext getTransactionContext(PhoenixConnection connection) throws SQLException {
+ return new OmidTransactionContext(connection);
}
@Override
- public PhoenixTransactionClient getTransactionClient(Configuration config, ConnectionInfo connectionInfo) {
- // TODO Auto-generated method stub
- return null;
+ public PhoenixTransactionClient getTransactionClient(Configuration config, ConnectionInfo connectionInfo) throws SQLException{
+ return new OmidTransactionClient();
+ }
+
+ static class OmidTransactionClient implements PhoenixTransactionClient {
+ @Override
+ public void close() throws IOException {}
}
@Override
- public PhoenixTransactionService getTransactionService(Configuration config, ConnectionInfo connectionInfo) {
- // TODO Auto-generated method stub
- return null;
+ public PhoenixTransactionService getTransactionService(Configuration config, ConnectionInfo connectionInfo) throws SQLException{
+ return new OmidTransactionService();
+ }
+
+ static class OmidTransactionService implements PhoenixTransactionService {
+
+ public void start() {
+ }
+
+ @Override
+ public void close() throws IOException {
+ }
}
@Override
public Class<? extends RegionObserver> getCoprocessor() {
- // TODO Auto-generated method stub
- return null;
+ return OmidTransactionalProcessor.class;
+ }
+
+ @Override
+ public Class<? extends RegionObserver> getGCCoprocessor() {
+ return OmidGCProcessor.class;
}
@Override
@@ -72,13 +103,11 @@ public class OmidTransactionProvider implements PhoenixTransactionProvider {
@Override
public boolean isUnsupported(Feature feature) {
- // FIXME: if we initialize a Set with the unsupported features
- // and check for containment, we run into a test failure
- // in SetPropertyOnEncodedTableIT.testSpecifyingColumnFamilyForTTLFails()
- // due to TableProperty.colFamSpecifiedException being null
- // (though it's set in the constructor). I suspect some
- // mysterious class loader issue. The below works fine
- // as a workaround.
- return (feature == Feature.ALTER_NONTX_TO_TX);
+ return true;
+ }
+
+ @Override
+ public Put markPutAsCommitted(Put put, long timestamp, long commitTimestamp) {
+ return put;
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionTable.java b/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionTable.java
new file mode 100644
index 0000000..a2afcc9
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionTable.java
@@ -0,0 +1,280 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.transaction;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Append;
+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.Increment;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Row;
+import org.apache.hadoop.hbase.client.RowMutations;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.client.coprocessor.Batch.Call;
+import org.apache.hadoop.hbase.client.coprocessor.Batch.Callback;
+import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
+import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel;
+
+import com.google.protobuf.Descriptors.MethodDescriptor;
+import com.google.protobuf.Message;
+import com.google.protobuf.Service;
+import com.google.protobuf.ServiceException;
+
+public class OmidTransactionTable implements Table {
+
+ public OmidTransactionTable() throws SQLException {
+ }
+
+ public OmidTransactionTable(PhoenixTransactionContext ctx, Table hTable) throws SQLException {
+ }
+
+ public OmidTransactionTable(PhoenixTransactionContext ctx, Table hTable, boolean isConflictFree) throws SQLException {
+ }
+
+ @Override
+ public Result get(Get get) throws IOException {
+ return null;
+ }
+
+ @Override
+ public void put(Put put) throws IOException {
+ }
+
+ @Override
+ public void delete(Delete delete) throws IOException {
+ }
+
+ @Override
+ public ResultScanner getScanner(Scan scan) throws IOException {
+ return null;
+ }
+
+ @Override
+ public Configuration getConfiguration() {
+ return null;
+ }
+
+ @Override
+ public HTableDescriptor getTableDescriptor() throws IOException {
+ return null;
+ }
+
+ @Override
+ public boolean exists(Get get) throws IOException {
+ return false;
+ }
+
+ @Override
+ public Result[] get(List<Get> gets) throws IOException {
+ return null;
+ }
+
+ @Override
+ public ResultScanner getScanner(byte[] family) throws IOException {
+ return null;
+ }
+
+ @Override
+ public ResultScanner getScanner(byte[] family, byte[] qualifier)
+ throws IOException {
+ return null;
+ }
+
+ @Override
+ public void put(List<Put> puts) throws IOException {
+ }
+
+ @Override
+ public void delete(List<Delete> deletes) throws IOException {
+ }
+
+ @Override
+ public void close() throws IOException {
+ }
+
+ @Override
+ public TableName getName() {
+ return null;
+ }
+
+ @Override
+ public boolean[] existsAll(List<Get> gets) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void batch(List<? extends Row> actions, Object[] results)
+ throws IOException, InterruptedException {
+ }
+
+ @Override
+ public Object[] batch(List<? extends Row> actions) throws IOException,
+ InterruptedException {
+ return null;
+ }
+
+ @Override
+ public <R> void batchCallback(List<? extends Row> actions,
+ Object[] results, Callback<R> callback) throws IOException,
+ InterruptedException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <R> Object[] batchCallback(List<? extends Row> actions,
+ Callback<R> callback) throws IOException, InterruptedException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
+ byte[] value, Put put) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
+ CompareOp compareOp, byte[] value, Put put) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
+ byte[] value, Delete delete) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
+ CompareOp compareOp, byte[] value, Delete delete)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void mutateRow(RowMutations rm) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Result append(Append append) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Result increment(Increment increment) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long incrementColumnValue(byte[] row, byte[] family,
+ byte[] qualifier, long amount) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long incrementColumnValue(byte[] row, byte[] family,
+ byte[] qualifier, long amount, Durability durability)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public CoprocessorRpcChannel coprocessorService(byte[] row) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <T extends Service, R> Map<byte[], R> coprocessorService(
+ Class<T> service, byte[] startKey, byte[] endKey,
+ Call<T, R> callable) throws ServiceException, Throwable {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <T extends Service, R> void coprocessorService(Class<T> service,
+ byte[] startKey, byte[] endKey, Call<T, R> callable,
+ Callback<R> callback) throws ServiceException, Throwable {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <R extends Message> Map<byte[], R> batchCoprocessorService(
+ MethodDescriptor methodDescriptor, Message request,
+ byte[] startKey, byte[] endKey, R responsePrototype)
+ throws ServiceException, Throwable {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <R extends Message> void batchCoprocessorService(
+ MethodDescriptor methodDescriptor, Message request,
+ byte[] startKey, byte[] endKey, R responsePrototype,
+ Callback<R> callback) throws ServiceException, Throwable {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
+ CompareOp compareOp, byte[] value, RowMutations mutation)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getOperationTimeout() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getRpcTimeout() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setOperationTimeout(int arg0) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setRpcTimeout(int arg0) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getWriteBufferSize() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setWriteBufferSize(long writeBufferSize) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/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 dfa35be..1882004 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
@@ -20,7 +20,7 @@ package org.apache.phoenix.transaction;
import java.sql.SQLException;
import java.util.concurrent.TimeoutException;
-import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.hadoop.hbase.client.Table;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.transaction.TransactionFactory.Provider;
@@ -106,12 +106,12 @@ public interface PhoenixTransactionContext {
}
@Override
- public HTableInterface getTransactionalTable(HTableInterface htable, boolean isImmutable) {
+ public Table getTransactionalTable(Table htable, boolean isConflictFree) {
return null;
}
@Override
- public HTableInterface getTransactionalTableWriter(PhoenixConnection connection, PTable table, HTableInterface htable, boolean isIndex) {
+ public Table getTransactionalTableWriter(PhoenixConnection connection, PTable table, Table htable, boolean isIndex) {
return null;
}
};
@@ -230,6 +230,6 @@ public interface PhoenixTransactionContext {
public Provider getProvider();
public PhoenixTransactionContext newTransactionContext(PhoenixTransactionContext contex, boolean subTask);
- public HTableInterface getTransactionalTable(HTableInterface htable, boolean isImmutable);
- public HTableInterface getTransactionalTableWriter(PhoenixConnection connection, PTable table, HTableInterface htable, boolean isIndex) throws SQLException;
+ public Table getTransactionalTable(Table htable, boolean isConflictFree) throws SQLException;
+ public Table getTransactionalTableWriter(PhoenixConnection connection, PTable table, Table htable, boolean isIndex) throws SQLException;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java b/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java
index cdc6058..b7f660e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java
@@ -18,8 +18,10 @@
package org.apache.phoenix.transaction;
import java.io.IOException;
+import java.sql.SQLException;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.coprocessor.RegionObserver;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.jdbc.PhoenixConnection;
@@ -27,7 +29,12 @@ import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo;
public interface PhoenixTransactionProvider {
public enum Feature {
- ALTER_NONTX_TO_TX(SQLExceptionCode.CANNOT_ALTER_TABLE_FROM_NON_TXN_TO_TXNL);
+ ALTER_NONTX_TO_TX(SQLExceptionCode.CANNOT_ALTER_TABLE_FROM_NON_TXN_TO_TXNL),
+ COLUMN_ENCODING(SQLExceptionCode.UNSUPPORTED_COLUMN_ENCODING_FOR_TXN_PROVIDER),
+ MAINTAIN_LOCAL_INDEX_ON_SERVER(null),
+ SET_TTL(SQLExceptionCode.TTL_UNSUPPORTED_FOR_TXN_TABLE),
+ ALLOW_LOCAL_INDEX(SQLExceptionCode.CANNOT_CREATE_LOCAL_INDEX_FOR_TXN_TABLE)
+ ;
private final SQLExceptionCode code;
@@ -40,12 +47,23 @@ public interface PhoenixTransactionProvider {
}
}
public PhoenixTransactionContext getTransactionContext(byte[] txnBytes) throws IOException;
- public PhoenixTransactionContext getTransactionContext(PhoenixConnection connection);
-
- public PhoenixTransactionClient getTransactionClient(Configuration config, ConnectionInfo connectionInfo);
- public PhoenixTransactionService getTransactionService(Configuration config, ConnectionInfo connectionInfo);
+ public PhoenixTransactionContext getTransactionContext(PhoenixConnection connection) throws SQLException;
+
+ public PhoenixTransactionClient getTransactionClient(Configuration config, ConnectionInfo connectionInfo) throws SQLException;
+ public PhoenixTransactionService getTransactionService(Configuration config, ConnectionInfo connectionInfo) throws SQLException;
public Class<? extends RegionObserver> getCoprocessor();
-
+ public Class<? extends RegionObserver> getGCCoprocessor();
+
public TransactionFactory.Provider getProvider();
public boolean isUnsupported(Feature feature);
+
+ /**
+ * Converts put operation to autocommit operation
+ * @param put put operation
+ * @param timestamp - start timestamp
+ * @param commitTimestamp - commit timestamp
+ * @return put operation with metadata
+ * @throws IOException
+ */
+ public Put markPutAsCommitted(Put put, long timestamp, long commitTimestamp);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/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 5b3c9b8..18a05ce 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
@@ -30,6 +30,7 @@ import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Mutation;
+import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
@@ -82,7 +83,7 @@ public class TephraTransactionContext implements PhoenixTransactionContext {
this.tx = CODEC.decode(txnBytes);
}
- public TephraTransactionContext(PhoenixConnection connection) {
+ public TephraTransactionContext(PhoenixConnection connection) throws SQLException {
PhoenixTransactionClient client = connection.getQueryServices().initTransactionClient(getProvider());
assert (client instanceof TephraTransactionClient);
this.txServiceClient = ((TephraTransactionClient)client).getTransactionClient();
@@ -222,6 +223,12 @@ public class TephraTransactionContext implements PhoenixTransactionContext {
.setSchemaName(dataTable.getSchemaName().getString())
.setTableName(dataTable.getTableName().getString()).build()
.buildException();
+ } finally {
+ // The client expects a transaction to be in progress on the txContext while the
+ // VisibilityFence.prepareWait() starts a new tx and finishes/aborts it. After it's
+ // finished, we start a new one here.
+ // TODO: seems like an autonomous tx capability in Tephra would be useful here.
+ this.begin();
}
}
@@ -403,14 +410,14 @@ public class TephraTransactionContext implements PhoenixTransactionContext {
}
@Override
- public HTableInterface getTransactionalTable(HTableInterface htable, boolean isImmutable) {
- TransactionAwareHTable transactionAwareHTable = new TransactionAwareHTable(htable, isImmutable ? TxConstants.ConflictDetection.NONE : TxConstants.ConflictDetection.ROW);
+ public Table getTransactionalTable(Table htable, boolean isConflictFree) {
+ TransactionAwareHTable transactionAwareHTable = new TransactionAwareHTable(htable, isConflictFree ? TxConstants.ConflictDetection.NONE : TxConstants.ConflictDetection.ROW);
this.addTransactionAware(transactionAwareHTable);
return transactionAwareHTable;
}
@Override
- public HTableInterface getTransactionalTableWriter(PhoenixConnection connection, PTable table, HTableInterface htable, boolean isIndex) throws SQLException {
+ public Table getTransactionalTableWriter(PhoenixConnection connection, PTable table, Table htable, boolean isIndex) throws SQLException {
// If we have indexes, wrap the HTable in a delegate HTable that
// will attach the necessary index meta data in the event of a
// rollback
@@ -444,7 +451,7 @@ public class TephraTransactionContext implements PhoenixTransactionContext {
private final PTable table;
private final PhoenixConnection connection;
- private RollbackHookHTableWrapper(HTableInterface delegate, PTable table, PhoenixConnection connection) {
+ private RollbackHookHTableWrapper(Table delegate, PTable table, PhoenixConnection connection) {
super(delegate);
this.table = table;
this.connection = connection;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionProvider.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionProvider.java b/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionProvider.java
index 2e52efa..70937cf 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionProvider.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionProvider.java
@@ -18,10 +18,12 @@
package org.apache.phoenix.transaction;
import java.io.IOException;
+import java.sql.SQLException;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.coprocessor.RegionObserver;
import org.apache.phoenix.coprocessor.TephraTransactionalProcessor;
import org.apache.phoenix.jdbc.PhoenixConnection;
@@ -59,12 +61,17 @@ public class TephraTransactionProvider implements PhoenixTransactionProvider {
}
@Override
+ public String toString() {
+ return getProvider().toString();
+ }
+
+ @Override
public PhoenixTransactionContext getTransactionContext(byte[] txnBytes) throws IOException {
return new TephraTransactionContext(txnBytes);
}
@Override
- public PhoenixTransactionContext getTransactionContext(PhoenixConnection connection) {
+ public PhoenixTransactionContext getTransactionContext(PhoenixConnection connection) throws SQLException {
return new TephraTransactionContext(connection);
}
@@ -185,6 +192,9 @@ public class TephraTransactionProvider implements PhoenixTransactionProvider {
}
@Override
+ public Class<? extends RegionObserver> getGCCoprocessor() {return null;}
+
+ @Override
public Provider getProvider() {
return TransactionFactory.Provider.TEPHRA;
}
@@ -194,4 +204,8 @@ public class TephraTransactionProvider implements PhoenixTransactionProvider {
return false;
}
+ @Override
+ public Put markPutAsCommitted(Put put, long timestamp, long commitTimestamp) {
+ return put;
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/transaction/TransactionFactory.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/transaction/TransactionFactory.java b/phoenix-core/src/main/java/org/apache/phoenix/transaction/TransactionFactory.java
index 67c4bc1..d1d531a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/transaction/TransactionFactory.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/transaction/TransactionFactory.java
@@ -25,15 +25,17 @@ import org.apache.phoenix.coprocessor.MetaDataProtocol;
public class TransactionFactory {
public enum Provider {
- TEPHRA((byte)1, TephraTransactionProvider.getInstance()),
- OMID((byte)2, OmidTransactionProvider.getInstance());
+ TEPHRA((byte)1, TephraTransactionProvider.getInstance(), true),
+ OMID((byte)2, OmidTransactionProvider.getInstance(), false);
private final byte code;
private final PhoenixTransactionProvider provider;
+ private final boolean runTests;
- Provider(byte code, PhoenixTransactionProvider provider) {
+ Provider(byte code, PhoenixTransactionProvider provider, boolean runTests) {
this.code = code;
this.provider = provider;
+ this.runTests = runTests;
}
public byte getCode() {
@@ -54,19 +56,31 @@ public class TransactionFactory {
public PhoenixTransactionProvider getTransactionProvider() {
return provider;
}
+
+ public boolean runTests() {
+ return runTests;
+ }
}
public static PhoenixTransactionProvider getTransactionProvider(Provider provider) {
return provider.getTransactionProvider();
}
- public static PhoenixTransactionContext getTransactionContext(byte[] txState, int clientVersion) throws IOException {
+ public static PhoenixTransactionProvider getTransactionProvider(byte[] txState, int clientVersion) {
if (txState == null || txState.length == 0) {
return null;
}
Provider provider = (clientVersion < MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_14_0)
- ? Provider.OMID
+ ? Provider.TEPHRA
: Provider.fromCode(txState[txState.length-1]);
- return provider.getTransactionProvider().getTransactionContext(txState);
+ return provider.getTransactionProvider();
+ }
+
+ public static PhoenixTransactionContext getTransactionContext(byte[] txState, int clientVersion) throws IOException {
+ PhoenixTransactionProvider provider = getTransactionProvider(txState, clientVersion);
+ if (provider == null) {
+ return null;
+ }
+ return provider.getTransactionContext(txState);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/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 b63b053..9010f5f 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
@@ -119,6 +119,7 @@ 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.PhoenixTransactionProvider.Feature;
import com.google.common.collect.Lists;
@@ -834,8 +835,11 @@ public class IndexUtil {
public static List<PTable> getClientMaintainedIndexes(PTable table) {
Iterator<PTable> indexIterator = // Only maintain tables with immutable rows through this client-side mechanism
- (table.isImmutableRows() || table.isTransactional()) ? IndexMaintainer.maintainedGlobalIndexes(table
- .getIndexes().iterator()) : Collections.<PTable> emptyIterator();
+ (table.isTransactional() && table.getTransactionProvider().getTransactionProvider().isUnsupported(Feature.MAINTAIN_LOCAL_INDEX_ON_SERVER)) ?
+ IndexMaintainer.maintainedIndexes(table.getIndexes().iterator()) :
+ (table.isImmutableRows() || table.isTransactional()) ?
+ IndexMaintainer.maintainedGlobalIndexes(table.getIndexes().iterator()) :
+ Collections.<PTable>emptyIterator();
return Lists.newArrayList(indexIterator);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
index 48d2a5c..ec2eb14 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
@@ -500,23 +500,23 @@ public class SchemaUtil {
return isString ? ("'" + type.toObject(value).toString() + "'") : type.toObject(value, offset, length).toString();
}
- public static byte[] getEmptyColumnFamily(PName defaultColumnFamily, List<PColumnFamily> families) {
- return families.isEmpty() ? defaultColumnFamily == null ? QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES : defaultColumnFamily.getBytes() : families.get(0).getName().getBytes();
+ public static byte[] getEmptyColumnFamily(PName defaultColumnFamily, List<PColumnFamily> families, boolean isLocalIndex) {
+ return families.isEmpty() ? defaultColumnFamily == null ? (isLocalIndex ? QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES : QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES) : defaultColumnFamily.getBytes() : families.get(0).getName().getBytes();
}
public static byte[] getEmptyColumnFamily(PTable table) {
List<PColumnFamily> families = table.getColumnFamilies();
- return families.isEmpty() ? table.getDefaultFamilyName() == null ? QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES : table.getDefaultFamilyName().getBytes() : families.get(0).getName().getBytes();
+ return families.isEmpty() ? table.getDefaultFamilyName() == null ? (table.getIndexType() == IndexType.LOCAL ? QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES : QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES) : table.getDefaultFamilyName().getBytes() : families.get(0).getName().getBytes();
}
public static String getEmptyColumnFamilyAsString(PTable table) {
List<PColumnFamily> families = table.getColumnFamilies();
- return families.isEmpty() ? table.getDefaultFamilyName() == null ? QueryConstants.DEFAULT_COLUMN_FAMILY : table.getDefaultFamilyName().getString() : families.get(0).getName().getString();
+ return families.isEmpty() ? table.getDefaultFamilyName() == null ? (table.getIndexType() == IndexType.LOCAL ? QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY : QueryConstants.DEFAULT_COLUMN_FAMILY) : table.getDefaultFamilyName().getString() : families.get(0).getName().getString();
}
public static ImmutableBytesPtr getEmptyColumnFamilyPtr(PTable table) {
List<PColumnFamily> families = table.getColumnFamilies();
- return families.isEmpty() ? table.getDefaultFamilyName() == null ? QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES_PTR : table.getDefaultFamilyName().getBytesPtr() : families.get(0)
+ return families.isEmpty() ? table.getDefaultFamilyName() == null ? (table.getIndexType() == IndexType.LOCAL ? QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES_PTR : QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES_PTR) : table.getDefaultFamilyName().getBytesPtr() : families.get(0)
.getName().getBytesPtr();
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/CoveredColumnIndexCodec.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/CoveredColumnIndexCodec.java b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/CoveredColumnIndexCodec.java
index 83d05f3..1825f04 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/CoveredColumnIndexCodec.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/CoveredColumnIndexCodec.java
@@ -52,12 +52,12 @@ public class CoveredColumnIndexCodec extends BaseIndexCodec {
}
@Override
- public void initialize(Configuration conf, byte[] regionStartKey, byte[] regionEndKey, byte[] tableName) {
+ public void initialize(Configuration conf, byte[] tableName) {
groups = CoveredColumnIndexSpecifierBuilder.getColumns(conf);
}
@Override
- public Iterable<IndexUpdate> getIndexUpserts(TableState state, IndexMetaData indexMetaData) {
+ public Iterable<IndexUpdate> getIndexUpserts(TableState state, IndexMetaData indexMetaData, byte[] regionStartKey, byte[] regionEndKey) {
List<IndexUpdate> updates = new ArrayList<IndexUpdate>(groups.size());
for (ColumnGroup group : groups) {
IndexUpdate update = getIndexUpdateForGroup(group, state, indexMetaData);
@@ -111,7 +111,7 @@ public class CoveredColumnIndexCodec extends BaseIndexCodec {
}
@Override
- public Iterable<IndexUpdate> getIndexDeletes(TableState state, IndexMetaData context) {
+ public Iterable<IndexUpdate> getIndexDeletes(TableState state, IndexMetaData context, byte[] regionStartKey, byte[] regionEndKey) {
List<IndexUpdate> deletes = new ArrayList<IndexUpdate>(groups.size());
for (ColumnGroup group : groups) {
deletes.add(getDeleteForGroup(group, state, context));
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/CoveredIndexCodecForTesting.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/CoveredIndexCodecForTesting.java b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/CoveredIndexCodecForTesting.java
index 204b1a0..665d2bf 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/CoveredIndexCodecForTesting.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/CoveredIndexCodecForTesting.java
@@ -48,17 +48,17 @@ public class CoveredIndexCodecForTesting extends BaseIndexCodec {
}
@Override
- public Iterable<IndexUpdate> getIndexDeletes(TableState state, IndexMetaData context) {
+ public Iterable<IndexUpdate> getIndexDeletes(TableState state, IndexMetaData context, byte[] regionStartKey, byte[] regionEndKey) {
return this.deletes;
}
@Override
- public Iterable<IndexUpdate> getIndexUpserts(TableState state, IndexMetaData context) {
+ public Iterable<IndexUpdate> getIndexUpserts(TableState state, IndexMetaData context, byte[] regionStartKey, byte[] regionEndKey) {
return this.updates;
}
@Override
- public void initialize(Configuration conf, byte[] regionStartKey, byte[] regionEndKey, byte[] tableName) {
+ public void initialize(Configuration conf, byte[] tableName) {
// noop
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/TestCoveredColumnIndexCodec.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/TestCoveredColumnIndexCodec.java b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/TestCoveredColumnIndexCodec.java
index d63dd6b..e0a8ebe 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/TestCoveredColumnIndexCodec.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/covered/TestCoveredColumnIndexCodec.java
@@ -177,14 +177,14 @@ public class TestCoveredColumnIndexCodec {
// check the codec for deletes it should send
LocalTableState state = new LocalTableState(table, p);
- Iterable<IndexUpdate> updates = codec.getIndexDeletes(state, IndexMetaData.NULL_INDEX_META_DATA);
+ Iterable<IndexUpdate> updates = codec.getIndexDeletes(state, IndexMetaData.NULL_INDEX_META_DATA, null, null);
assertFalse("Found index updates without any existing kvs in table!", updates.iterator().next()
.isValid());
// get the updates with the pending update
state.setCurrentTimestamp(1);
state.addPendingUpdates(kvs);
- updates = codec.getIndexUpserts(state, IndexMetaData.NULL_INDEX_META_DATA);
+ updates = codec.getIndexUpserts(state, IndexMetaData.NULL_INDEX_META_DATA, null, null);
assertTrue("Didn't find index updates for pending primary table update!", updates.iterator()
.hasNext());
for (IndexUpdate update : updates) {
@@ -207,7 +207,7 @@ public class TestCoveredColumnIndexCodec {
state = new LocalTableState(table, d);
state.setCurrentTimestamp(2);
// check the cleanup of the current table, after the puts (mocking a 'next' update)
- updates = codec.getIndexDeletes(state, IndexMetaData.NULL_INDEX_META_DATA);
+ updates = codec.getIndexDeletes(state, IndexMetaData.NULL_INDEX_META_DATA, null, null);
for (IndexUpdate update : updates) {
assertTrue("Didn't have any index cleanup, even though there is current state",
update.isValid());
@@ -237,7 +237,7 @@ public class TestCoveredColumnIndexCodec {
state.setCurrentTimestamp(d.getTimeStamp());
// now we shouldn't see anything when getting the index update
state.addPendingUpdates(d.getFamilyMap().get(FAMILY));
- Iterable<IndexUpdate> updates = codec.getIndexUpserts(state, IndexMetaData.NULL_INDEX_META_DATA);
+ Iterable<IndexUpdate> updates = codec.getIndexUpserts(state, IndexMetaData.NULL_INDEX_META_DATA, null, null);
for (IndexUpdate update : updates) {
assertFalse("Had some index updates, though it should have been covered by the delete",
update.isValid());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
index e279074..841abb6 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
@@ -22,6 +22,7 @@ import static org.apache.phoenix.query.QueryServicesOptions.withDefaults;
import org.apache.curator.shaded.com.google.common.io.Files;
import org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec;
+import org.apache.phoenix.transaction.OmidTransactionProvider;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.ReadOnlyProps;
import org.apache.tephra.TxConstants;
@@ -124,7 +125,7 @@ public final class QueryServicesTestImpl extends BaseQueryServicesImpl {
.setDefaultIndexPopulationWaitTime(DEFAULT_INDEX_POPULATION_WAIT_TIME)
.setIndexRebuildTaskInitialDelay(DEFAULT_INDEX_REBUILD_TASK_INITIAL_DELAY)
.set(AGGREGATE_CHUNK_SIZE_INCREASE_ATTRIB, DEFAULT_AGGREGATE_CHUNK_SIZE_INCREASE)
- // setup default configs for Tephra
+ // setup default test configs for Tephra
.set(TxConstants.Manager.CFG_DO_PERSIST, false)
.set(TxConstants.Service.CFG_DATA_TX_CLIENT_RETRY_STRATEGY, "n-times")
.set(TxConstants.Service.CFG_DATA_TX_CLIENT_ATTEMPTS, 1)
@@ -132,6 +133,8 @@ public final class QueryServicesTestImpl extends BaseQueryServicesImpl {
.set(TxConstants.Manager.CFG_TX_SNAPSHOT_DIR, Files.createTempDir().getAbsolutePath())
.set(TxConstants.Manager.CFG_TX_TIMEOUT, DEFAULT_TXN_TIMEOUT_SECONDS)
.set(TxConstants.Manager.CFG_TX_SNAPSHOT_INTERVAL, 5L)
+ // setup default test configs for Omid
+ .set(OmidTransactionProvider.OMID_TSO_PORT, Networks.getRandomPort())
;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
index 0def76f..f0a26b9 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
@@ -63,6 +63,7 @@ import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.coprocessor.Batch;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
@@ -122,6 +123,7 @@ import org.apache.phoenix.schema.stats.GuidePostsInfo;
import org.apache.phoenix.schema.stats.GuidePostsKey;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.transaction.TransactionFactory;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
@@ -675,15 +677,6 @@ public class TestUtil {
assertEquals(rs.getDate(6), date);
}
- public static String getTableName(Boolean mutable, Boolean transactional) {
- StringBuilder tableNameBuilder = new StringBuilder(DEFAULT_DATA_TABLE_NAME);
- if (mutable!=null)
- tableNameBuilder.append(mutable ? "_MUTABLE" : "_IMMUTABLE");
- if (transactional!=null)
- tableNameBuilder.append(transactional ? "_TXN" : "_NON_TXN");
- return tableNameBuilder.toString();
- }
-
public static ClientAggregators getSingleSumAggregator(String url, Properties props) throws SQLException {
try (PhoenixConnection pconn = DriverManager.getConnection(url, props).unwrap(PhoenixConnection.class)) {
PhoenixStatement statement = new PhoenixStatement(pconn);
@@ -803,7 +796,7 @@ public class TestUtil {
if (table.isTransactional()) {
mutationState.startTransaction(table.getTransactionProvider());
}
- try (HTableInterface htable = mutationState.getHTable(table)) {
+ try (Table htable = mutationState.getHTable(table)) {
byte[] markerRowKey = Bytes.toBytes("TO_DELETE");
Put put = new Put(markerRowKey);
@@ -1088,4 +1081,28 @@ public class TestUtil {
}
assertTrue(!rs.next());
}
+
+ public static Collection<Object[]> filterTxParamData(Collection<Object[]> data, int index) {
+ boolean runAllTests = true;
+ boolean runNoTests = true;
+
+ for (TransactionFactory.Provider provider : TransactionFactory.Provider.values()) {
+ runAllTests &= provider.runTests();
+ runNoTests &= !provider.runTests();
+ }
+ if (runNoTests) {
+ return Collections.emptySet();
+ }
+ if (runAllTests) {
+ return data;
+ }
+ List<Object[]> filteredData = Lists.newArrayListWithExpectedSize(data.size());
+ for (Object[] params : data) {
+ String provider = (String)params[index];
+ if (provider == null || TransactionFactory.Provider.valueOf(provider).runTests()) {
+ filteredData.add(params);
+ }
+ }
+ return filteredData;
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4412c15..a5c3144 100644
--- a/pom.xml
+++ b/pom.xml
@@ -100,7 +100,7 @@
<joni.version>2.1.2</joni.version>
<avatica.version>1.12.0</avatica.version>
<jettyVersion>8.1.7.v20120910</jettyVersion>
- <tephra.version>0.14.0-incubating</tephra.version>
+ <tephra.version>0.15.0-incubating</tephra.version>
<spark.version>2.0.2</spark.version>
<scala.version>2.11.8</scala.version>
<scala.binary.version>2.11</scala.binary.version>
[2/4] phoenix git commit: PHOENIX-4731 Make running transactional
unit tests for a given provider optional
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 4f08846..61be561 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -109,7 +109,6 @@ import org.apache.phoenix.schema.types.PVarbinary;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.ExpressionUtil;
import org.apache.phoenix.util.IndexUtil;
-import org.apache.phoenix.util.MetaDataUtil;
import org.apache.phoenix.util.ScanUtil;
import org.apache.phoenix.util.SchemaUtil;
@@ -541,7 +540,11 @@ public class UpsertCompiler {
// Disable running upsert select on server side if a table has global mutable secondary indexes on it
boolean hasGlobalMutableIndexes = SchemaUtil.hasGlobalIndex(table) && !table.isImmutableRows();
boolean hasWhereSubquery = select.getWhere() != null && select.getWhere().hasSubquery();
- runOnServer = (sameTable || (serverUpsertSelectEnabled && !hasGlobalMutableIndexes)) && isAutoCommit && !table.isTransactional()
+ runOnServer = (sameTable || (serverUpsertSelectEnabled && !hasGlobalMutableIndexes)) && isAutoCommit
+ // We can run the upsert select for initial index population on server side for transactional
+ // tables since the writes do not need to be done transactionally, since we gate the index
+ // usage on successfully writing all data rows.
+ && (!table.isTransactional() || table.getType() == PTableType.INDEX)
&& !(table.isImmutableRows() && !table.getIndexes().isEmpty())
&& !select.isJoin() && !hasWhereSubquery && table.getRowTimestampColPos() == -1;
}
@@ -1039,12 +1042,15 @@ public class UpsertCompiler {
byte[] txState = table.isTransactional() ?
connection.getMutationState().encodeTransaction() : ByteUtil.EMPTY_BYTE_ARRAY;
+ ScanUtil.setClientVersion(scan, MetaDataProtocol.PHOENIX_VERSION);
+ if (aggPlan.getTableRef().getTable().isTransactional()
+ || (table.getType() == PTableType.INDEX && table.isTransactional())) {
+ scan.setAttribute(BaseScannerRegionObserver.TX_STATE, txState);
+ }
if (ptr.getLength() > 0) {
byte[] uuidValue = ServerCacheClient.generateId();
scan.setAttribute(PhoenixIndexCodec.INDEX_UUID, uuidValue);
scan.setAttribute(PhoenixIndexCodec.INDEX_PROTO_MD, ptr.get());
- scan.setAttribute(BaseScannerRegionObserver.TX_STATE, txState);
- ScanUtil.setClientVersion(scan, MetaDataProtocol.PHOENIX_VERSION);
}
ResultIterator iterator = aggPlan.iterator();
try {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/OmidGCProcessor.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/OmidGCProcessor.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/OmidGCProcessor.java
new file mode 100644
index 0000000..70658fb
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/OmidGCProcessor.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.coprocessor;
+
+import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
+
+
+public class OmidGCProcessor extends DelegateRegionObserver {
+
+ public OmidGCProcessor() {
+ super(new BaseRegionObserver());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/OmidTransactionalProcessor.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/OmidTransactionalProcessor.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/OmidTransactionalProcessor.java
new file mode 100644
index 0000000..fc246d4
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/OmidTransactionalProcessor.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.coprocessor;
+
+import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
+
+
+public class OmidTransactionalProcessor extends DelegateRegionObserver {
+
+ public OmidTransactionalProcessor() {
+ super(new BaseRegionObserver());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
index c325d70..a667316 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
@@ -130,6 +130,8 @@ import org.apache.phoenix.schema.types.PDouble;
import org.apache.phoenix.schema.types.PFloat;
import org.apache.phoenix.schema.types.PLong;
import org.apache.phoenix.transaction.PhoenixTransactionContext;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider;
+import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.EncodedColumnsUtil;
import org.apache.phoenix.util.EnvironmentEdgeManager;
@@ -429,6 +431,12 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
byte[] replayMutations = scan.getAttribute(BaseScannerRegionObserver.REPLAY_WRITES);
byte[] indexUUID = scan.getAttribute(PhoenixIndexCodec.INDEX_UUID);
byte[] txState = scan.getAttribute(BaseScannerRegionObserver.TX_STATE);
+ byte[] clientVersionBytes = scan.getAttribute(BaseScannerRegionObserver.CLIENT_VERSION);
+ PhoenixTransactionProvider txnProvider = null;
+ if (txState != null) {
+ int clientVersion = clientVersionBytes == null ? ScanUtil.UNKNOWN_CLIENT_VERSION : Bytes.toInt(clientVersionBytes);
+ txnProvider = TransactionFactory.getTransactionProvider(txState, clientVersion);
+ }
List<Expression> selectExpressions = null;
byte[] upsertSelectTable = scan.getAttribute(BaseScannerRegionObserver.UPSERT_SELECT_TABLE);
boolean isUpsert = false;
@@ -535,7 +543,6 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
useIndexProto = false;
}
- byte[] clientVersionBytes = scan.getAttribute(BaseScannerRegionObserver.CLIENT_VERSION);
if(needToWrite) {
synchronized (lock) {
if (isRegionClosingOrSplitting) {
@@ -658,6 +665,10 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
valueGetter, ptr, results.get(0).getTimestamp(),
env.getRegion().getRegionInfo().getStartKey(),
env.getRegion().getRegionInfo().getEndKey());
+
+ if (txnProvider != null) {
+ put = txnProvider.markPutAsCommitted(put, ts, ts);
+ }
indexMutations.add(put);
}
}
@@ -725,6 +736,8 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
for (Mutation mutation : row.toRowMutations()) {
if (replayMutations != null) {
mutation.setAttribute(REPLAY_WRITES, replayMutations);
+ } else if (txnProvider != null && projectedTable.getType() == PTableType.INDEX) {
+ mutation = txnProvider.markPutAsCommitted((Put)mutation, ts, ts);
}
mutations.add(mutation);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
index d6a70f2..c0a81ec 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
@@ -297,7 +297,12 @@ public enum SQLExceptionCode {
UNKNOWN_TRANSACTION_PROVIDER(1089,"44A20", "Unknown TRANSACTION_PROVIDER: "),
CANNOT_START_TXN_IF_TXN_DISABLED(1091, "44A22", "Cannot start transaction if transactions are disabled."),
CANNOT_MIX_TXN_PROVIDERS(1092, "44A23", "Cannot mix transaction providers: "),
- CANNOT_ALTER_TABLE_FROM_NON_TXN_TO_TXNL(1093, "44A24", "Cannot alter table from non transactional to transactional for "),
+ CANNOT_ALTER_TABLE_FROM_NON_TXN_TO_TXNL(1093, "44A24", "Cannot alter table from non transactional to transactional for"),
+ UNSUPPORTED_COLUMN_ENCODING_FOR_TXN_PROVIDER(1094, "44A25", "Column encoding is not supported for"),
+ UNSUPPORTED_STORAGE_FORMAT_FOR_TXN_PROVIDER(1095, "44A26", "Only ONE_CELL_PER_COLUMN storage scheme is supported for"),
+ CANNOT_SWITCH_TXN_PROVIDERS(1096, "44A27", "Cannot switch transaction providers."),
+ TTL_UNSUPPORTED_FOR_TXN_TABLE(10947, "44A28", "TTL is not supported for"),
+ CANNOT_CREATE_LOCAL_INDEX_FOR_TXN_TABLE(10948, "44A29", "Local indexes cannot be created for"),
/** Sequence related */
SEQUENCE_ALREADY_EXIST(1200, "42Z00", "Sequence already exists.", new Factory() {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateHTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateHTable.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateHTable.java
index f45b356..0618945 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateHTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateHTable.java
@@ -28,7 +28,6 @@ import org.apache.hadoop.hbase.client.Append;
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;
import org.apache.hadoop.hbase.client.Increment;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
@@ -36,6 +35,7 @@ import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Row;
import org.apache.hadoop.hbase.client.RowMutations;
import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.coprocessor.Batch.Call;
import org.apache.hadoop.hbase.client.coprocessor.Batch.Callback;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
@@ -46,19 +46,14 @@ import com.google.protobuf.Message;
import com.google.protobuf.Service;
import com.google.protobuf.ServiceException;
-public class DelegateHTable implements HTableInterface {
- protected final HTableInterface delegate;
+public class DelegateHTable implements Table {
+ protected final Table delegate;
- public DelegateHTable(HTableInterface delegate) {
+ public DelegateHTable(Table delegate) {
this.delegate = delegate;
}
@Override
- public byte[] getTableName() {
- return delegate.getTableName();
- }
-
- @Override
public TableName getName() {
return delegate.getName();
}
@@ -79,11 +74,6 @@ public class DelegateHTable implements HTableInterface {
}
@Override
- public Boolean[] exists(List<Get> gets) throws IOException {
- return delegate.exists(gets);
- }
-
- @Override
public void batch(List<? extends Row> actions, Object[] results) throws IOException, InterruptedException {
delegate.batch(actions, results);
}
@@ -117,12 +107,6 @@ public class DelegateHTable implements HTableInterface {
return delegate.get(gets);
}
- @SuppressWarnings("deprecation")
- @Override
- public Result getRowOrBefore(byte[] row, byte[] family) throws IOException {
- return delegate.getRowOrBefore(row, family);
- }
-
@Override
public ResultScanner getScanner(Scan scan) throws IOException {
return delegate.getScanner(scan);
@@ -195,23 +179,6 @@ public class DelegateHTable implements HTableInterface {
return delegate.incrementColumnValue(row, family, qualifier, amount, durability);
}
- @SuppressWarnings("deprecation")
- @Override
- public long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount, boolean writeToWAL)
- throws IOException {
- return delegate.incrementColumnValue(row, family, qualifier, amount, writeToWAL);
- }
-
- @Override
- public boolean isAutoFlush() {
- return delegate.isAutoFlush();
- }
-
- @Override
- public void flushCommits() throws IOException {
- delegate.flushCommits();
- }
-
@Override
public void close() throws IOException {
delegate.close();
@@ -234,22 +201,6 @@ public class DelegateHTable implements HTableInterface {
delegate.coprocessorService(service, startKey, endKey, callable, callback);
}
- @SuppressWarnings("deprecation")
- @Override
- public void setAutoFlush(boolean autoFlush) {
- delegate.setAutoFlush(autoFlush);
- }
-
- @Override
- public void setAutoFlush(boolean autoFlush, boolean clearBufferOnFail) {
- delegate.setAutoFlush(autoFlush, clearBufferOnFail);
- }
-
- @Override
- public void setAutoFlushTo(boolean autoFlush) {
- delegate.setAutoFlushTo(autoFlush);
- }
-
@Override
public long getWriteBufferSize() {
return delegate.getWriteBufferSize();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/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 d2d1eea..14f13b3 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
@@ -39,15 +39,13 @@ import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import org.apache.hadoop.hbase.HConstants;
-import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Mutation;
+import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.htrace.Span;
import org.apache.htrace.TraceScope;
-import org.apache.phoenix.cache.IndexMetaDataCache;
-import org.apache.phoenix.cache.ServerCacheClient;
import org.apache.phoenix.cache.ServerCacheClient.ServerCache;
import org.apache.phoenix.compile.MutationPlan;
import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
@@ -294,10 +292,11 @@ public class MutationState implements SQLCloseable {
// the Transaction outside of MutationState, this seems reasonable, as the member variables
// would not change as these threads are running. We also clone mutationState to ensure that
// the transaction context won't change due to a commit when auto commit is true.
- public HTableInterface getHTable(PTable table) throws SQLException {
- HTableInterface htable = this.getConnection().getQueryServices().getTable(table.getPhysicalName().getBytes());
+ public Table getHTable(PTable table) throws SQLException {
+ Table htable = this.getConnection().getQueryServices().getTable(table.getPhysicalName().getBytes());
if (table.isTransactional() && phoenixTransactionContext.isTransactionRunning()) {
- htable = phoenixTransactionContext.getTransactionalTable(htable, table.isImmutableRows());
+ // We're only using this table for reading, so we want it wrapped even if it's an index
+ htable = phoenixTransactionContext.getTransactionalTable(htable, table.isImmutableRows() || table.getType() == PTableType.INDEX);
}
return htable;
}
@@ -533,7 +532,7 @@ public class MutationState implements SQLCloseable {
if (indexMutationsMap == null) {
PhoenixTxIndexMutationGenerator generator = PhoenixTxIndexMutationGenerator.newGenerator(connection, table,
indexList, mutationsPertainingToIndex.get(0).getAttributesMap());
- try (HTableInterface htable = connection.getQueryServices().getTable(
+ try (Table htable = connection.getQueryServices().getTable(
table.getPhysicalName().getBytes())) {
Collection<Pair<Mutation, byte[]>> allMutations = generator.getIndexUpdates(htable,
mutationsPertainingToIndex.iterator());
@@ -562,8 +561,7 @@ public class MutationState implements SQLCloseable {
MultiRowMutationState multiRowMutationState = mutations.remove(key);
if (multiRowMutationState != null) {
final List<Mutation> deleteMutations = Lists.newArrayList();
- generateMutations(tableRef, mutationTimestamp, serverTimestamp, multiRowMutationState,
- deleteMutations, null);
+ generateMutations(key, mutationTimestamp, serverTimestamp, multiRowMutationState, deleteMutations, null);
if (indexMutations == null) {
indexMutations = deleteMutations;
} else {
@@ -960,7 +958,7 @@ public class MutationState implements SQLCloseable {
// region servers.
shouldRetry = cache != null;
SQLException sqlE = null;
- HTableInterface hTable = connection.getQueryServices().getTable(htableName);
+ Table hTable = connection.getQueryServices().getTable(htableName);
try {
if (table.isTransactional()) {
// Track tables to which we've sent uncommitted data
@@ -968,7 +966,12 @@ public class MutationState implements SQLCloseable {
uncommittedPhysicalNames.add(table.getPhysicalName().getString());
phoenixTransactionContext.markDMLFence(table);
}
- hTable = phoenixTransactionContext.getTransactionalTableWriter(connection, table, hTable, !tableInfo.isDataTable());
+ // Only pass true for last argument if the index is being written to on it's own (i.e. initial
+ // index population), not if it's being written to for normal maintenance due to writes to
+ // the data table. This case is different because the initial index population does not need
+ // to be done transactionally since the index is only made active after all writes have
+ // occurred successfully.
+ hTable = phoenixTransactionContext.getTransactionalTableWriter(connection, table, hTable, tableInfo.isDataTable() && table.getType() == PTableType.INDEX);
}
numMutations = mutationList.size();
GLOBAL_MUTATION_BATCH_SIZE.update(numMutations);
@@ -981,7 +984,7 @@ public class MutationState implements SQLCloseable {
for (final List<Mutation> mutationBatch : mutationBatchList) {
if (shouldRetryIndexedMutation) {
// if there was an index write failure, retry the mutation in a loop
- final HTableInterface finalHTable = hTable;
+ final Table finalHTable = hTable;
PhoenixIndexFailurePolicy.doBatchWithRetries(new MutateCommand() {
@Override
public void doMutation() throws IOException {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/execute/PhoenixTxIndexMutationGenerator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/PhoenixTxIndexMutationGenerator.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/PhoenixTxIndexMutationGenerator.java
index 877c939..8a94314 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/PhoenixTxIndexMutationGenerator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/PhoenixTxIndexMutationGenerator.java
@@ -34,9 +34,9 @@ import java.util.Set;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellScanner;
+import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueUtil;
-import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Mutation;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
@@ -62,6 +62,7 @@ import org.apache.phoenix.index.IndexMaintainer;
import org.apache.phoenix.index.PhoenixIndexCodec;
import org.apache.phoenix.index.PhoenixIndexMetaData;
import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.query.ConnectionQueryServices;
import org.apache.phoenix.query.KeyRange;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.types.PVarbinary;
@@ -79,14 +80,26 @@ import com.google.common.primitives.Longs;
public class PhoenixTxIndexMutationGenerator {
private final PhoenixIndexCodec codec;
private final PhoenixIndexMetaData indexMetaData;
+ private final ConnectionQueryServices services;
+ private final byte[] regionStartKey;
+ private final byte[] regionEndKey;
+ private final byte[] tableName;
- public PhoenixTxIndexMutationGenerator(Configuration conf, PhoenixIndexMetaData indexMetaData, byte[] tableName, byte[] regionStartKey, byte[] regionEndKey) {
+ private PhoenixTxIndexMutationGenerator(ConnectionQueryServices services, Configuration conf, PhoenixIndexMetaData indexMetaData, byte[] tableName, byte[] regionStartKey, byte[] regionEndKey) {
+ this.services = services;
this.indexMetaData = indexMetaData;
- this.codec = new PhoenixIndexCodec(conf, regionStartKey, regionEndKey, tableName);
+ this.regionStartKey = regionStartKey;
+ this.regionEndKey = regionEndKey;
+ this.tableName = tableName;
+ this.codec = new PhoenixIndexCodec(conf, tableName);
}
- public PhoenixTxIndexMutationGenerator(Configuration conf, PhoenixIndexMetaData indexMetaData, byte[] tableName) {
- this(conf, indexMetaData, tableName, null, null);
+ public PhoenixTxIndexMutationGenerator(Configuration conf, PhoenixIndexMetaData indexMetaData, byte[] tableName, byte[] regionStartKey, byte[] regionEndKey) {
+ this(null, conf, indexMetaData, tableName, regionStartKey, regionEndKey);
+ }
+
+ public PhoenixTxIndexMutationGenerator(ConnectionQueryServices services, PhoenixIndexMetaData indexMetaData, byte[] tableName) {
+ this(services, services.getConfiguration(), indexMetaData, tableName, null, null);
}
private static void addMutation(Map<ImmutableBytesPtr, MultiMutation> mutations, ImmutableBytesPtr row, Mutation m) {
@@ -99,7 +112,7 @@ public class PhoenixTxIndexMutationGenerator {
stored.addAll(m);
}
- public Collection<Pair<Mutation, byte[]>> getIndexUpdates(HTableInterface htable, Iterator<? extends Mutation> mutationIterator) throws IOException, SQLException {
+ public Collection<Pair<Mutation, byte[]>> getIndexUpdates(Table htable, Iterator<? extends Mutation> mutationIterator) throws IOException, SQLException {
if (!mutationIterator.hasNext()) {
return Collections.emptyList();
@@ -179,7 +192,7 @@ public class PhoenixTxIndexMutationGenerator {
scan.addColumn(indexMaintainers.get(0).getDataEmptyKeyValueCF(), emptyKeyValueQualifier);
ScanRanges scanRanges = ScanRanges.create(SchemaUtil.VAR_BINARY_SCHEMA, Collections.singletonList(keys), ScanUtil.SINGLE_COLUMN_SLOT_SPAN, null, true, -1);
scanRanges.initializeScan(scan);
- Table txTable = indexMetaData.getTransactionContext().getTransactionalTable(htable, isImmutable);
+ Table txTable = indexMetaData.getTransactionContext().getTransactionalTable(htable, true);
// For rollback, we need to see all versions, including
// the last committed version as there may be multiple
// checkpointed versions.
@@ -313,7 +326,18 @@ public class PhoenixTxIndexMutationGenerator {
private void generateDeletes(PhoenixIndexMetaData indexMetaData,
Collection<Pair<Mutation, byte[]>> indexUpdates,
byte[] attribValue, TxTableState state) throws IOException {
- Iterable<IndexUpdate> deletes = codec.getIndexDeletes(state, indexMetaData);
+ byte[] regionStartKey = this.regionStartKey;
+ byte[] regionEndKey = this.regionEndKey;
+ if (services != null && indexMetaData.hasLocalIndexes()) {
+ try {
+ HRegionLocation tableRegionLocation = services.getTableRegionLocation(tableName, state.getCurrentRowKey());
+ regionStartKey = tableRegionLocation.getRegionInfo().getStartKey();
+ regionEndKey = tableRegionLocation.getRegionInfo().getEndKey();
+ } catch (SQLException e) {
+ throw new IOException(e);
+ }
+ }
+ Iterable<IndexUpdate> deletes = codec.getIndexDeletes(state, indexMetaData, regionStartKey, regionEndKey);
for (IndexUpdate delete : deletes) {
if (delete.isValid()) {
delete.getUpdate().setAttribute(PhoenixTransactionContext.TX_ROLLBACK_ATTRIBUTE_KEY, attribValue);
@@ -328,7 +352,18 @@ public class PhoenixTxIndexMutationGenerator {
TxTableState state)
throws IOException {
state.applyMutation();
- Iterable<IndexUpdate> puts = codec.getIndexUpserts(state, indexMetaData);
+ byte[] regionStartKey = this.regionStartKey;
+ byte[] regionEndKey = this.regionEndKey;
+ if (services != null && indexMetaData.hasLocalIndexes()) {
+ try {
+ HRegionLocation tableRegionLocation = services.getTableRegionLocation(tableName, state.getCurrentRowKey());
+ regionStartKey = tableRegionLocation.getRegionInfo().getStartKey();
+ regionEndKey = tableRegionLocation.getRegionInfo().getEndKey();
+ } catch (SQLException e) {
+ throw new IOException(e);
+ }
+ }
+ Iterable<IndexUpdate> puts = codec.getIndexUpserts(state, indexMetaData, regionStartKey, regionEndKey);
boolean validPut = false;
for (IndexUpdate put : puts) {
if (put.isValid()) {
@@ -476,8 +511,8 @@ public class PhoenixTxIndexMutationGenerator {
};
try {
PhoenixIndexMetaData indexMetaData = new PhoenixIndexMetaData(indexMetaDataCache, attributes);
- return new PhoenixTxIndexMutationGenerator(connection.getQueryServices().getConfiguration(), indexMetaData,
- table.getPhysicalName().getBytes());
+ return new PhoenixTxIndexMutationGenerator(connection.getQueryServices(),connection.getQueryServices().getConfiguration(), indexMetaData,
+ table.getPhysicalName().getBytes(), null, null);
} catch (IOException e) {
throw new RuntimeException(e); // Impossible
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/builder/BaseIndexBuilder.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/builder/BaseIndexBuilder.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/builder/BaseIndexBuilder.java
index f13e97a..0ff83ca 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/builder/BaseIndexBuilder.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/builder/BaseIndexBuilder.java
@@ -58,7 +58,7 @@ public abstract class BaseIndexBuilder implements IndexBuilder {
Constructor<? extends IndexCodec> meth = codecClass.getDeclaredConstructor(new Class[0]);
meth.setAccessible(true);
this.codec = meth.newInstance();
- this.codec.initialize(conf, env.getRegionInfo().getStartKey(), env.getRegionInfo().getEndKey(), env.getRegion().getRegionInfo().getTable().getName());
+ this.codec.initialize(conf, env.getRegion().getRegionInfo().getTable().getName());
} catch (Exception e) {
throw new IOException(e);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/IndexCodec.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/IndexCodec.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/IndexCodec.java
index 7dde941..0b70de3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/IndexCodec.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/IndexCodec.java
@@ -39,10 +39,12 @@ public interface IndexCodec {
* the current state of the table that needs to be cleaned up. Generally, you only care about the latest
* column values, for each column you are indexing for each index table.
* @param context TODO
+ * @param regionStartKey TODO
+ * @param regionEndKey TODO
* @return the pairs of (deletes, index table name) that should be applied.
* @throws IOException
*/
- public Iterable<IndexUpdate> getIndexDeletes(TableState state, IndexMetaData context) throws IOException;
+ public Iterable<IndexUpdate> getIndexDeletes(TableState state, IndexMetaData context, byte[] regionStartKey, byte[] regionEndKey) throws IOException;
// table state has the pending update already applied, before calling
// get the new index entries
@@ -59,10 +61,12 @@ public interface IndexCodec {
* the current state of the table that needs to an index update Generally, you only care about the latest
* column values, for each column you are indexing for each index table.
* @param context TODO
+ * @param regionStartKey TODO
+ * @param regionEndKey TODO
* @return the pairs of (updates,index table name) that should be applied.
* @throws IOException
*/
- public Iterable<IndexUpdate> getIndexUpserts(TableState state, IndexMetaData context) throws IOException;
+ public Iterable<IndexUpdate> getIndexUpserts(TableState state, IndexMetaData context, byte[] regionStartKey, byte[] regionEndKey) throws IOException;
/**
* This allows the codec to dynamically change whether or not indexing should take place for a table. If it doesn't
@@ -80,5 +84,5 @@ public interface IndexCodec {
*/
public boolean isEnabled(Mutation m) throws IOException;
- public void initialize(Configuration conf, byte[] startKey, byte[] endKey, byte[] tableName);
+ public void initialize(Configuration conf, byte[] tableName);
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/LocalTableState.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/LocalTableState.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/LocalTableState.java
index 4f65416..8a069f8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/LocalTableState.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/LocalTableState.java
@@ -136,7 +136,7 @@ public class LocalTableState implements TableState {
* state for any of the columns you are indexing.
* <p>
* <i>NOTE:</i> This method should <b>not</b> be used during
- * {@link IndexCodec#getIndexDeletes(TableState, BatchState)} as the pending update will not yet have been
+ * {@link IndexCodec#getIndexDeletes(TableState, BatchState, byte[], byte[])} as the pending update will not yet have been
* applied - you are merely attempting to cleanup the current state and therefore do <i>not</i>
* need to track the indexed columns.
* <p>
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java
index 97ac30d..820a475 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/NonTxIndexBuilder.java
@@ -186,7 +186,7 @@ public class NonTxIndexBuilder extends BaseIndexBuilder {
throws IOException {
// get the index updates for this current batch
- Iterable<IndexUpdate> upserts = codec.getIndexUpserts(state, indexMetaData);
+ Iterable<IndexUpdate> upserts = codec.getIndexUpserts(state, indexMetaData, env.getRegionInfo().getStartKey(), env.getRegionInfo().getEndKey());
state.resetTrackedColumns();
/*
@@ -224,7 +224,7 @@ public class NonTxIndexBuilder extends BaseIndexBuilder {
}
/**
- * Get the index deletes from the codec {@link IndexCodec#getIndexDeletes(TableState, IndexMetaData)} and then add them to the
+ * Get the index deletes from the codec {@link IndexCodec#getIndexDeletes(TableState, IndexMetaData, byte[], byte[])} and then add them to the
* update map.
* <p>
* Expects the {@link LocalTableState} to already be correctly setup (correct timestamp, updates applied, etc).
@@ -234,7 +234,7 @@ public class NonTxIndexBuilder extends BaseIndexBuilder {
*/
protected void addDeleteUpdatesToMap(IndexUpdateManager updateMap, LocalTableState state, long ts, IndexMetaData indexMetaData)
throws IOException {
- Iterable<IndexUpdate> cleanup = codec.getIndexDeletes(state, indexMetaData);
+ Iterable<IndexUpdate> cleanup = codec.getIndexDeletes(state, indexMetaData, env.getRegionInfo().getStartKey(), env.getRegionInfo().getEndKey());
if (cleanup != null) {
for (IndexUpdate d : cleanup) {
if (!d.isValid()) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
index 140c304..d1da5f1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
@@ -101,7 +101,7 @@ import org.apache.phoenix.schema.ValueSchema.Field;
import org.apache.phoenix.schema.tuple.BaseTuple;
import org.apache.phoenix.schema.tuple.ValueGetterTuple;
import org.apache.phoenix.schema.types.PDataType;
-import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider.Feature;
import org.apache.phoenix.util.BitSet;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.EncodedColumnsUtil;
@@ -184,9 +184,24 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
*/
public static void serialize(PTable dataTable, ImmutableBytesWritable ptr, PhoenixConnection connection) {
List<PTable> indexes = dataTable.getIndexes();
- serialize(dataTable, ptr, indexes, connection);
+ serializeServerMaintainedIndexes(dataTable, ptr, indexes, connection);
}
+ public static void serializeServerMaintainedIndexes(PTable dataTable, ImmutableBytesWritable ptr,
+ List<PTable> indexes, PhoenixConnection connection) {
+ Iterator<PTable> indexesItr = Collections.emptyListIterator();
+ boolean onlyLocalIndexes = dataTable.isImmutableRows() || dataTable.isTransactional();
+ if (onlyLocalIndexes) {
+ if (!dataTable.isTransactional()
+ || !dataTable.getTransactionProvider().getTransactionProvider().isUnsupported(Feature.MAINTAIN_LOCAL_INDEX_ON_SERVER)) {
+ indexesItr = maintainedLocalIndexes(indexes.iterator());
+ }
+ } else {
+ indexesItr = maintainedIndexes(indexes.iterator());
+ }
+
+ serialize(dataTable, ptr, Lists.newArrayList(indexesItr), connection);
+ }
/**
* For client-side to serialize all IndexMaintainers for a given table
* @param dataTable data table
@@ -195,22 +210,11 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
*/
public static void serialize(PTable dataTable, ImmutableBytesWritable ptr,
List<PTable> indexes, PhoenixConnection connection) {
- Iterator<PTable> indexesItr;
- boolean onlyLocalIndexes = dataTable.isImmutableRows() || dataTable.isTransactional();
- if (onlyLocalIndexes) {
- indexesItr = maintainedLocalIndexes(indexes.iterator());
- } else {
- indexesItr = maintainedIndexes(indexes.iterator());
- }
- if (!indexesItr.hasNext()) {
+ if (indexes.isEmpty()) {
ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
return;
}
- int nIndexes = 0;
- while (indexesItr.hasNext()) {
- nIndexes++;
- indexesItr.next();
- }
+ int nIndexes = indexes.size();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(stream);
try {
@@ -218,11 +222,8 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
WritableUtils.writeVInt(output, nIndexes * (dataTable.getBucketNum() == null ? 1 : -1));
// Write out data row key schema once, since it's the same for all index maintainers
dataTable.getRowKeySchema().write(output);
- indexesItr = onlyLocalIndexes
- ? maintainedLocalIndexes(indexes.iterator())
- : maintainedIndexes(indexes.iterator());
- while (indexesItr.hasNext()) {
- org.apache.phoenix.coprocessor.generated.ServerCachingProtos.IndexMaintainer proto = IndexMaintainer.toProto(indexesItr.next().getIndexMaintainer(dataTable, connection));
+ for (PTable index : indexes) {
+ org.apache.phoenix.coprocessor.generated.ServerCachingProtos.IndexMaintainer proto = IndexMaintainer.toProto(index.getIndexMaintainer(dataTable, connection));
byte[] protoBytes = proto.toByteArray();
WritableUtils.writeVInt(output, protoBytes.length);
output.write(protoBytes);
@@ -285,31 +286,33 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference> {
}
private static List<IndexMaintainer> deserialize(byte[] buf, int offset, int length, boolean useProtoForIndexMaintainer) {
- ByteArrayInputStream stream = new ByteArrayInputStream(buf, offset, length);
- DataInput input = new DataInputStream(stream);
List<IndexMaintainer> maintainers = Collections.emptyList();
- try {
- int size = WritableUtils.readVInt(input);
- boolean isDataTableSalted = size < 0;
- size = Math.abs(size);
- RowKeySchema rowKeySchema = new RowKeySchema();
- rowKeySchema.readFields(input);
- maintainers = Lists.newArrayListWithExpectedSize(size);
- for (int i = 0; i < size; i++) {
- if (useProtoForIndexMaintainer) {
- int protoSize = WritableUtils.readVInt(input);
- byte[] b = new byte[protoSize];
- input.readFully(b);
- org.apache.phoenix.coprocessor.generated.ServerCachingProtos.IndexMaintainer proto = ServerCachingProtos.IndexMaintainer.parseFrom(b);
- maintainers.add(IndexMaintainer.fromProto(proto, rowKeySchema, isDataTableSalted));
- } else {
- IndexMaintainer maintainer = new IndexMaintainer(rowKeySchema, isDataTableSalted);
- maintainer.readFields(input);
- maintainers.add(maintainer);
+ if (length > 0) {
+ ByteArrayInputStream stream = new ByteArrayInputStream(buf, offset, length);
+ DataInput input = new DataInputStream(stream);
+ try {
+ int size = WritableUtils.readVInt(input);
+ boolean isDataTableSalted = size < 0;
+ size = Math.abs(size);
+ RowKeySchema rowKeySchema = new RowKeySchema();
+ rowKeySchema.readFields(input);
+ maintainers = Lists.newArrayListWithExpectedSize(size);
+ for (int i = 0; i < size; i++) {
+ if (useProtoForIndexMaintainer) {
+ int protoSize = WritableUtils.readVInt(input);
+ byte[] b = new byte[protoSize];
+ input.readFully(b);
+ org.apache.phoenix.coprocessor.generated.ServerCachingProtos.IndexMaintainer proto = ServerCachingProtos.IndexMaintainer.parseFrom(b);
+ maintainers.add(IndexMaintainer.fromProto(proto, rowKeySchema, isDataTableSalted));
+ } else {
+ IndexMaintainer maintainer = new IndexMaintainer(rowKeySchema, isDataTableSalted);
+ maintainer.readFields(input);
+ maintainers.add(maintainer);
+ }
}
+ } catch (IOException e) {
+ throw new RuntimeException(e); // Impossible
}
- } catch (IOException e) {
- throw new RuntimeException(e); // Impossible
}
return maintainers;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/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 d33e3fe..eb911e1 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
@@ -36,8 +36,8 @@ import com.google.common.collect.Sets;
/**
* Phoenix-based {@link IndexCodec}. Manages all the logic of how to cleanup an index (
- * {@link #getIndexDeletes(TableState, IndexMetaData)}) as well as what the new index state should be (
- * {@link #getIndexUpserts(TableState, IndexMetaData)}).
+ * {@link #getIndexDeletes(TableState, IndexMetaData, byte[], byte[])}) as well as what the new index state should be (
+ * {@link #getIndexUpserts(TableState, IndexMetaData, byte[], byte[])}).
*/
public class PhoenixIndexCodec extends BaseIndexCodec {
public static final String INDEX_MD = "IdxMD";
@@ -46,23 +46,19 @@ public class PhoenixIndexCodec extends BaseIndexCodec {
public static final String INDEX_MAINTAINERS = "IndexMaintainers";
public static KeyValueBuilder KV_BUILDER = GenericKeyValueBuilder.INSTANCE;
- private byte[] regionStartKey;
- private byte[] regionEndKey;
private byte[] tableName;
public PhoenixIndexCodec() {
}
- public PhoenixIndexCodec(Configuration conf, byte[] regionStartKey, byte[] regionEndKey, byte[] tableName) {
- initialize(conf, regionStartKey, regionEndKey, tableName);
+ public PhoenixIndexCodec(Configuration conf, byte[] tableName) {
+ initialize(conf, tableName);
}
@Override
- public void initialize(Configuration conf, byte[] regionStartKey, byte[] regionEndKey, byte[] tableName) {
- this.regionStartKey = regionStartKey;
- this.regionEndKey = regionEndKey;
+ public void initialize(Configuration conf, byte[] tableName) {
this.tableName = tableName;
}
@@ -74,7 +70,7 @@ public class PhoenixIndexCodec extends BaseIndexCodec {
}
@Override
- public Iterable<IndexUpdate> getIndexUpserts(TableState state, IndexMetaData context) throws IOException {
+ public Iterable<IndexUpdate> getIndexUpserts(TableState state, IndexMetaData context, byte[] regionStartKey, byte[] regionEndKey) throws IOException {
PhoenixIndexMetaData metaData = (PhoenixIndexMetaData)context;
List<IndexMaintainer> indexMaintainers = metaData.getIndexMaintainers();
if (indexMaintainers.get(0).isRowDeleted(state.getPendingUpdate())) {
@@ -97,7 +93,7 @@ public class PhoenixIndexCodec extends BaseIndexCodec {
}
@Override
- public Iterable<IndexUpdate> getIndexDeletes(TableState state, IndexMetaData context) throws IOException {
+ public Iterable<IndexUpdate> getIndexDeletes(TableState state, IndexMetaData context, byte[] regionStartKey, byte[] regionEndKey) throws IOException {
PhoenixIndexMetaData metaData = (PhoenixIndexMetaData)context;
List<IndexMaintainer> indexMaintainers = metaData.getIndexMaintainers();
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/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 56db39b..3543da8 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
@@ -94,7 +94,7 @@ public class PhoenixTransactionalIndexer extends BaseRegionObserver {
final RegionCoprocessorEnvironment env = (RegionCoprocessorEnvironment)e;
Configuration conf = e.getConfiguration();
String serverName = env.getRegionServerServices().getServerName().getServerName();
- codec = new PhoenixIndexCodec(conf, env.getRegion().getRegionInfo().getStartKey(), env.getRegion().getRegionInfo().getEndKey(), env.getRegionInfo().getTable().getName());
+ codec = new PhoenixIndexCodec(conf, env.getRegionInfo().getTable().getName());
DelegateRegionCoprocessorEnvironment indexWriterEnv = new DelegateRegionCoprocessorEnvironment(env, ConnectionType.INDEX_WRITER_CONNECTION);
// setup the actual index writer
// For transactional tables, we keep the index active upon a write failure
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
index 9a31238..f02e9d3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ScanningResultIterator.java
@@ -38,6 +38,7 @@ import java.util.Map;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
import org.apache.phoenix.monitoring.CombinableMetric;
import org.apache.phoenix.monitoring.ScanMetricsHolder;
import org.apache.phoenix.schema.tuple.ResultTuple;
@@ -89,7 +90,11 @@ public class ScanningResultIterator implements ResultIterator {
private void getScanMetrics() {
if (!scanMetricsUpdated && scanMetricsEnabled) {
- Map<String, Long> scanMetricsMap = scan.getScanMetrics().getMetricsMap();
+ ScanMetrics scanMetrics = scan.getScanMetrics();
+ if (scanMetrics == null) {
+ return;
+ }
+ Map<String, Long> scanMetricsMap = scanMetrics.getMetricsMap();
if(scanMetricsMap == null) {
return;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/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 e6b94fb..cc99ae4 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
@@ -37,8 +37,8 @@ import java.util.concurrent.locks.ReentrantLock;
import javax.annotation.concurrent.GuardedBy;
import org.apache.hadoop.hbase.client.AbstractClientScanner;
-import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.cache.ServerCacheClient.ServerCache;
@@ -51,7 +51,6 @@ import org.apache.phoenix.join.HashCacheClient;
import org.apache.phoenix.monitoring.ScanMetricsHolder;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PTable;
-import org.apache.phoenix.schema.StaleRegionBoundaryCacheException;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.Closeables;
@@ -74,7 +73,7 @@ import com.google.common.annotations.VisibleForTesting;
*/
public class TableResultIterator implements ResultIterator {
private final Scan scan;
- private final HTableInterface htable;
+ private final Table htable;
private final ScanMetricsHolder scanMetricsHolder;
private static final ResultIterator UNINITIALIZED_SCANNER = ResultIterator.EMPTY_ITERATOR;
private final long renewLeaseThreshold;
@@ -187,13 +186,13 @@ public class TableResultIterator implements ResultIterator {
newScan.setStartRow(ByteUtil.nextKey(startRowSuffix));
}
}
- plan.getContext().getConnection().getQueryServices().clearTableRegionCache(htable.getTableName());
+ plan.getContext().getConnection().getQueryServices().clearTableRegionCache(htable.getName().getName());
logger.debug(
"Retrying when Hash Join cache is not found on the server ,by sending the cache again");
if (retry <= 0) {
throw e1;
}
- Long cacheId = ((HashJoinCacheNotFoundException) e1).getCacheId();
+ Long cacheId = e1.getCacheId();
retry--;
try {
ServerCache cache = caches == null ? null :
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/DirectHTableWriter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/DirectHTableWriter.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/DirectHTableWriter.java
index 59b26b2..1230f25 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/DirectHTableWriter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/DirectHTableWriter.java
@@ -24,10 +24,16 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Mutation;
+import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.mapreduce.TableOutputFormat;
+import org.apache.phoenix.mapreduce.util.PhoenixConfigurationUtil;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider;
+import org.apache.phoenix.transaction.TransactionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.collect.Lists;
+
/**
* Writes mutations directly to HBase using HBase front-door APIs.
*/
@@ -62,7 +68,24 @@ public class DirectHTableWriter {
public void write(List<Mutation> mutations) throws IOException, InterruptedException {
Object[] results = new Object[mutations.size()];
- table.batch(mutations, results);
+ String txnIdStr = conf.get(PhoenixConfigurationUtil.TX_SCN_VALUE);
+ if (txnIdStr == null) {
+ table.batch(mutations, results);
+ } else {
+ long ts = Long.parseLong(txnIdStr);
+ PhoenixTransactionProvider provider = TransactionFactory.Provider.getDefault().getTransactionProvider();
+ String txnProviderStr = conf.get(PhoenixConfigurationUtil.TX_PROVIDER);
+ if (txnProviderStr != null) {
+ provider = TransactionFactory.Provider.valueOf(txnProviderStr).getTransactionProvider();
+ }
+ List<Mutation> shadowedMutations = Lists.newArrayListWithExpectedSize(mutations.size());
+ for (Mutation m : mutations) {
+ if (m instanceof Put) {
+ shadowedMutations.add(provider.markPutAsCommitted((Put)m, ts, ts));
+ }
+ }
+ table.batch(shadowedMutations, results);
+ }
}
protected Configuration getConf() {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexTool.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexTool.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexTool.java
index 15d41ea..f2f4cdb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexTool.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexTool.java
@@ -381,6 +381,7 @@ public class IndexTool extends Configured implements Tool {
if (pdataTable.isTransactional()) {
configuration.set(PhoenixConfigurationUtil.TX_SCN_VALUE,
Long.toString(TransactionUtil.convertToNanoseconds(maxTimeRange)));
+ configuration.set(PhoenixConfigurationUtil.TX_PROVIDER, pdataTable.getTransactionProvider().name());
}
configuration.set(PhoenixConfigurationUtil.CURRENT_SCN_VALUE,
Long.toString(maxTimeRange));
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportMapper.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportMapper.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportMapper.java
index 9e0d629..353de7a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportMapper.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportMapper.java
@@ -21,26 +21,37 @@ import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.KeyValueUtil;
+import org.apache.hadoop.hbase.client.Mutation;
+import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Mapper;
+import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.mapreduce.ImportPreUpsertKeyValueProcessor;
import org.apache.phoenix.mapreduce.PhoenixJobCounters;
import org.apache.phoenix.mapreduce.util.ConnectionUtil;
import org.apache.phoenix.mapreduce.util.PhoenixConfigurationUtil;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider;
+import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.ColumnInfo;
import org.apache.phoenix.util.PhoenixRuntime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.collect.Lists;
+
/**
* Mapper that hands over rows from data table to the index table.
*
@@ -93,6 +104,18 @@ public class PhoenixIndexImportMapper extends Mapper<NullWritable, PhoenixIndexD
context.getCounter(PhoenixJobCounters.INPUT_RECORDS).increment(1);
+ PhoenixTransactionProvider provider = null;
+ Configuration conf = context.getConfiguration();
+ long ts = HConstants.LATEST_TIMESTAMP;
+ String txnIdStr = conf.get(PhoenixConfigurationUtil.TX_SCN_VALUE);
+ if (txnIdStr != null) {
+ ts = Long.parseLong(txnIdStr);
+ provider = TransactionFactory.Provider.getDefault().getTransactionProvider();
+ String txnProviderStr = conf.get(PhoenixConfigurationUtil.TX_PROVIDER);
+ if (txnProviderStr != null) {
+ provider = TransactionFactory.Provider.valueOf(txnProviderStr).getTransactionProvider();
+ }
+ }
try {
final ImmutableBytesWritable outputKey = new ImmutableBytesWritable();
final List<Object> values = record.getValues();
@@ -100,16 +123,30 @@ public class PhoenixIndexImportMapper extends Mapper<NullWritable, PhoenixIndexD
indxWritable.write(this.pStatement);
this.pStatement.execute();
- final Iterator<Pair<byte[], List<KeyValue>>> uncommittedDataIterator = PhoenixRuntime.getUncommittedDataIterator(connection, true);
- while (uncommittedDataIterator.hasNext()) {
- Pair<byte[], List<KeyValue>> kvPair = uncommittedDataIterator.next();
- if (Bytes.compareTo(Bytes.toBytes(indexTableName), kvPair.getFirst()) != 0) {
+ PhoenixConnection pconn = connection.unwrap(PhoenixConnection.class);
+ final Iterator<Pair<byte[],List<Mutation>>> iterator = pconn.getMutationState().toMutations(true);
+ while (iterator.hasNext()) {
+ Pair<byte[], List<Mutation>> pair = iterator.next();
+ if (Bytes.compareTo(Bytes.toBytes(indexTableName), pair.getFirst()) != 0) {
// skip edits for other tables
continue;
}
- List<KeyValue> keyValueList = kvPair.getSecond();
- keyValueList = preUpdateProcessor.preUpsert(kvPair.getFirst(), keyValueList);
- for (KeyValue kv : keyValueList) {
+ List<KeyValue> keyValues = Lists.newArrayListWithExpectedSize(pair.getSecond().size() * 5); // Guess-timate 5 key values per row
+ for (Mutation mutation : pair.getSecond()) {
+ if (mutation instanceof Put) {
+ if (provider != null) {
+ mutation = provider.markPutAsCommitted((Put)mutation, ts, ts);
+ }
+ for (List<Cell> cellList : mutation.getFamilyCellMap().values()) {
+ List<KeyValue>keyValueList = preUpdateProcessor.preUpsert(mutation.getRow(), KeyValueUtil.ensureKeyValues(cellList));
+ for (KeyValue keyValue : keyValueList) {
+ keyValues.add(keyValue);
+ }
+ }
+ }
+ }
+ Collections.sort(keyValues, pconn.getKeyValueBuilder().getKeyValueComparator());
+ for (KeyValue kv : keyValues) {
outputKey.set(kv.getRowArray(), kv.getRowOffset(), kv.getRowLength());
context.write(outputKey, kv);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtil.java
index 3b63f66..2f552ea 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtil.java
@@ -105,6 +105,8 @@ public final class PhoenixConfigurationUtil {
public static final String TX_SCN_VALUE = "phoenix.mr.txscn.value";
+ public static final String TX_PROVIDER = "phoenix.mr.txprovider";
+
/** Configuration key for the class name of an ImportPreUpsertKeyValueProcessor */
public static final String UPSERT_HOOK_CLASS_CONFKEY = "phoenix.mapreduce.import.kvprocessor";
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java
index 0820232..d5a5199 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServices.java
@@ -168,7 +168,7 @@ public interface ConnectionQueryServices extends QueryServices, MetaDataMutated
public QueryLoggerDisruptor getQueryDisruptor();
- public PhoenixTransactionClient initTransactionClient(TransactionFactory.Provider provider);
+ public PhoenixTransactionClient initTransactionClient(TransactionFactory.Provider provider) throws SQLException;
/**
* Writes a cell to SYSTEM.MUTEX using checkAndPut to ensure only a single client can execute a
@@ -183,4 +183,4 @@ public interface ConnectionQueryServices extends QueryServices, MetaDataMutated
*/
public void deleteMutexCell(String tenantId, String schemaName, String tableName,
String columnName, String familyName) throws SQLException;
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index dbfd461..ab4678a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -147,7 +147,6 @@ import org.apache.phoenix.coprocessor.MetaDataRegionObserver;
import org.apache.phoenix.coprocessor.ScanRegionObserver;
import org.apache.phoenix.coprocessor.SequenceRegionObserver;
import org.apache.phoenix.coprocessor.ServerCachingEndpointImpl;
-import org.apache.phoenix.coprocessor.TephraTransactionalProcessor;
import org.apache.phoenix.coprocessor.UngroupedAggregateRegionObserver;
import org.apache.phoenix.coprocessor.generated.MetaDataProtos;
import org.apache.phoenix.coprocessor.generated.MetaDataProtos.AddColumnRequest;
@@ -237,6 +236,7 @@ import org.apache.phoenix.schema.types.PVarbinary;
import org.apache.phoenix.schema.types.PVarchar;
import org.apache.phoenix.transaction.PhoenixTransactionClient;
import org.apache.phoenix.transaction.PhoenixTransactionContext;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider;
import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.transaction.TransactionFactory.Provider;
import org.apache.phoenix.util.ByteUtil;
@@ -860,10 +860,8 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
if (!descriptor.hasCoprocessor(ServerCachingEndpointImpl.class.getName())) {
descriptor.addCoprocessor(ServerCachingEndpointImpl.class.getName(), null, priority, null);
}
- // For ALTER TABLE
- boolean nonTxToTx = Boolean.TRUE.equals(tableProps.get(PhoenixTransactionContext.READ_NON_TX_DATA));
- boolean isTransactional =
- Boolean.TRUE.equals(tableProps.get(TableProperty.TRANSACTIONAL.name())) || nonTxToTx;
+ TransactionFactory.Provider provider = getTransactionProvider(tableProps);
+ boolean isTransactional = (provider != null);
// TODO: better encapsulation for this
// Since indexes can't have indexes, don't install our indexing coprocessor for indexes.
// Also don't install on the SYSTEM.CATALOG and SYSTEM.STATS table because we use
@@ -926,22 +924,27 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
}
if (isTransactional) {
- TransactionFactory.Provider provider = (TransactionFactory.Provider)TableProperty.TRANSACTION_PROVIDER.getValue(tableProps);
- if (provider == null) {
- String providerValue = this.props.get(QueryServices.DEFAULT_TRANSACTION_PROVIDER_ATTRIB, QueryServicesOptions.DEFAULT_TRANSACTION_PROVIDER);
- provider = (TransactionFactory.Provider)TableProperty.TRANSACTION_PROVIDER.getValue(providerValue);
- }
Class<? extends RegionObserver> coprocessorClass = provider.getTransactionProvider().getCoprocessor();
if (!descriptor.hasCoprocessor(coprocessorClass.getName())) {
descriptor.addCoprocessor(coprocessorClass.getName(), null, priority - 10, null);
}
+ Class<? extends RegionObserver> coprocessorGCClass = provider.getTransactionProvider().getGCCoprocessor();
+ if (coprocessorGCClass != null) {
+ if (!descriptor.hasCoprocessor(coprocessorGCClass.getName())) {
+ descriptor.addCoprocessor(coprocessorGCClass.getName(), null, priority - 10, null);
+ }
+ }
} else {
// Remove all potential transactional coprocessors
- for (TransactionFactory.Provider provider : TransactionFactory.Provider.values()) {
- Class<? extends RegionObserver> coprocessorClass = provider.getTransactionProvider().getCoprocessor();
+ for (TransactionFactory.Provider aprovider : TransactionFactory.Provider.values()) {
+ Class<? extends RegionObserver> coprocessorClass = aprovider.getTransactionProvider().getCoprocessor();
+ Class<? extends RegionObserver> coprocessorGCClass = aprovider.getTransactionProvider().getGCCoprocessor();
if (coprocessorClass != null && descriptor.hasCoprocessor(coprocessorClass.getName())) {
descriptor.removeCoprocessor(coprocessorClass.getName());
}
+ if (coprocessorGCClass != null && descriptor.hasCoprocessor(coprocessorGCClass.getName())) {
+ descriptor.removeCoprocessor(coprocessorGCClass.getName());
+ }
}
}
} catch (IOException e) {
@@ -949,6 +952,11 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
}
}
+ private TransactionFactory.Provider getTransactionProvider(Map<String,Object> tableProps) {
+ TransactionFactory.Provider provider = (TransactionFactory.Provider)TableProperty.TRANSACTION_PROVIDER.getValue(tableProps);
+ return provider;
+ }
+
private static interface RetriableOperation {
boolean checkForCompletion() throws TimeoutException, IOException;
String getOperationName();
@@ -1171,15 +1179,30 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
if (!modifyExistingMetaData) {
return existingDesc; // Caller already knows that no metadata was changed
}
- boolean willBeTx = Boolean.TRUE.equals(props.get(TableProperty.TRANSACTIONAL.name()));
+ TransactionFactory.Provider provider = getTransactionProvider(props);
+ boolean willBeTx = provider != null;
// If mapping an existing table as transactional, set property so that existing
// data is correctly read.
if (willBeTx) {
- newDesc.setValue(PhoenixTransactionContext.READ_NON_TX_DATA, Boolean.TRUE.toString());
+ if (!equalTxCoprocessor(provider, existingDesc, newDesc)) {
+ // Cannot switch between different providers
+ if (hasTxCoprocessor(existingDesc)) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_SWITCH_TXN_PROVIDERS)
+ .setSchemaName(SchemaUtil.getSchemaNameFromFullName(physicalTableName))
+ .setTableName(SchemaUtil.getTableNameFromFullName(physicalTableName)).build().buildException();
+ }
+ if (provider.getTransactionProvider().isUnsupported(PhoenixTransactionProvider.Feature.ALTER_NONTX_TO_TX)) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_ALTER_TABLE_FROM_NON_TXN_TO_TXNL)
+ .setMessage(provider.name())
+ .setSchemaName(SchemaUtil.getSchemaNameFromFullName(physicalTableName))
+ .setTableName(SchemaUtil.getTableNameFromFullName(physicalTableName)).build().buildException();
+ }
+ newDesc.setValue(PhoenixTransactionContext.READ_NON_TX_DATA, Boolean.TRUE.toString());
+ }
} else {
// If we think we're creating a non transactional table when it's already
// transactional, don't allow.
- if (existingDesc.hasCoprocessor(TephraTransactionalProcessor.class.getName())) {
+ if (hasTxCoprocessor(existingDesc)) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.TX_MAY_NOT_SWITCH_TO_NON_TX)
.setSchemaName(SchemaUtil.getSchemaNameFromFullName(physicalTableName))
.setTableName(SchemaUtil.getTableNameFromFullName(physicalTableName)).build().buildException();
@@ -1212,6 +1235,21 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
}
return null; // will never make it here
}
+
+ private static boolean hasTxCoprocessor(HTableDescriptor descriptor) {
+ for (TransactionFactory.Provider provider : TransactionFactory.Provider.values()) {
+ Class<? extends RegionObserver> coprocessorClass = provider.getTransactionProvider().getCoprocessor();
+ if (coprocessorClass != null && descriptor.hasCoprocessor(coprocessorClass.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static boolean equalTxCoprocessor(TransactionFactory.Provider provider, HTableDescriptor existingDesc, HTableDescriptor newDesc) {
+ Class<? extends RegionObserver> coprocessorClass = provider.getTransactionProvider().getCoprocessor();
+ return (coprocessorClass != null && existingDesc.hasCoprocessor(coprocessorClass.getName()) && newDesc.hasCoprocessor(coprocessorClass.getName()));
+}
private void modifyTable(byte[] tableName, HTableDescriptor newDesc, boolean shouldPoll) throws IOException,
InterruptedException, TimeoutException, SQLException {
@@ -1936,6 +1974,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
} else {
indexTableProps = Maps.newHashMapWithExpectedSize(1);
indexTableProps.put(PhoenixTransactionContext.READ_NON_TX_DATA, Boolean.valueOf(txValue));
+ indexTableProps.put(PhoenixDatabaseMetaData.TRANSACTION_PROVIDER, tableProps.get(PhoenixDatabaseMetaData.TRANSACTION_PROVIDER));
}
for (PTable index : table.getIndexes()) {
HTableDescriptor indexDescriptor = admin.getTableDescriptor(index.getPhysicalName().getBytes());
@@ -2046,6 +2085,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
boolean willBeTransactional = false;
boolean isOrWillBeTransactional = isTransactional;
Integer newTTL = null;
+ TransactionFactory.Provider txProvider = null;
for (String family : properties.keySet()) {
List<Pair<String, Object>> propsList = properties.get(family);
if (propsList != null && propsList.size() > 0) {
@@ -2056,20 +2096,27 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
if ((MetaDataUtil.isHTableProperty(propName) || TableProperty.isPhoenixTableProperty(propName)) && addingColumns) {
// setting HTable and PhoenixTable properties while adding a column is not allowed.
throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_SET_TABLE_PROPERTY_ADD_COLUMN)
- .setMessage("Property: " + propName).build()
+ .setMessage("Property: " + propName)
+ .setSchemaName(table.getSchemaName().getString())
+ .setTableName(table.getTableName().getString())
+ .build()
.buildException();
}
if (MetaDataUtil.isHTableProperty(propName)) {
// Can't have a column family name for a property that's an HTableProperty
if (!family.equals(QueryConstants.ALL_FAMILY_PROPERTIES_KEY)) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY)
- .setMessage("Column Family: " + family + ", Property: " + propName).build()
+ .setMessage("Column Family: " + family + ", Property: " + propName)
+ .setSchemaName(table.getSchemaName().getString())
+ .setTableName(table.getTableName().getString())
+ .build()
.buildException();
}
tableProps.put(propName, propValue);
} else {
if (TableProperty.isPhoenixTableProperty(propName)) {
- TableProperty.valueOf(propName).validate(true, !family.equals(QueryConstants.ALL_FAMILY_PROPERTIES_KEY), table.getType());
+ TableProperty tableProp = TableProperty.valueOf(propName);
+ tableProp.validate(true, !family.equals(QueryConstants.ALL_FAMILY_PROPERTIES_KEY), table.getType());
if (propName.equals(TTL)) {
newTTL = ((Number)prop.getSecond()).intValue();
// Even though TTL is really a HColumnProperty we treat it specially.
@@ -2078,6 +2125,11 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
} else if (propName.equals(PhoenixDatabaseMetaData.TRANSACTIONAL) && Boolean.TRUE.equals(propValue)) {
willBeTransactional = isOrWillBeTransactional = true;
tableProps.put(PhoenixTransactionContext.READ_NON_TX_DATA, propValue);
+ } else if (propName.equals(PhoenixDatabaseMetaData.TRANSACTION_PROVIDER) && propValue != null) {
+ willBeTransactional = isOrWillBeTransactional = true;
+ tableProps.put(PhoenixTransactionContext.READ_NON_TX_DATA, Boolean.TRUE);
+ txProvider = (Provider)TableProperty.TRANSACTION_PROVIDER.getValue(propValue);
+ tableProps.put(PhoenixDatabaseMetaData.TRANSACTION_PROVIDER, txProvider);
}
} else {
if (MetaDataUtil.isHColumnProperty(propName)) {
@@ -2091,12 +2143,26 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
// FIXME: This isn't getting triggered as currently a property gets evaluated
// as HTableProp if its neither HColumnProp or PhoenixTableProp.
throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_ALTER_PROPERTY)
- .setMessage("Column Family: " + family + ", Property: " + propName).build()
+ .setMessage("Column Family: " + family + ", Property: " + propName)
+ .setSchemaName(table.getSchemaName().getString())
+ .setTableName(table.getTableName().getString())
+ .build()
.buildException();
}
}
}
}
+ if (isOrWillBeTransactional && newTTL != null) {
+ TransactionFactory.Provider isOrWillBeTransactionProvider = txProvider == null ? table.getTransactionProvider() : txProvider;
+ if (isOrWillBeTransactionProvider.getTransactionProvider().isUnsupported(PhoenixTransactionProvider.Feature.SET_TTL)) {
+ throw new SQLExceptionInfo.Builder(PhoenixTransactionProvider.Feature.SET_TTL.getCode())
+ .setMessage(isOrWillBeTransactionProvider.name())
+ .setSchemaName(table.getSchemaName().getString())
+ .setTableName(table.getTableName().getString())
+ .build()
+ .buildException();
+ }
+ }
if (!colFamilyPropsMap.isEmpty()) {
stmtFamiliesPropsMap.put(family, colFamilyPropsMap);
}
@@ -4728,7 +4794,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
}
@Override
- public synchronized PhoenixTransactionClient initTransactionClient(Provider provider) {
+ public synchronized PhoenixTransactionClient initTransactionClient(Provider provider) throws SQLException {
PhoenixTransactionClient client = txClients[provider.ordinal()];
if (client == null) {
client = txClients[provider.ordinal()] = provider.getTransactionProvider().getTransactionClient(config, connectionInfo);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java b/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
index 147e873..4be4af8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/DelegateConnectionQueryServices.java
@@ -367,7 +367,7 @@ public class DelegateConnectionQueryServices extends DelegateQueryServices imple
}
@Override
- public PhoenixTransactionClient initTransactionClient(Provider provider) {
+ public PhoenixTransactionClient initTransactionClient(Provider provider) throws SQLException {
return getDelegate().initTransactionClient(provider);
}
[4/4] phoenix git commit: PHOENIX-4731 Make running transactional
unit tests for a given provider optional
Posted by ja...@apache.org.
PHOENIX-4731 Make running transactional unit tests for a given provider optional
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/fd9af912
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/fd9af912
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/fd9af912
Branch: refs/heads/4.x-HBase-1.3
Commit: fd9af912fe640b5085fb09e5be3b3c19a3f7d40b
Parents: 20000d9
Author: James Taylor <ja...@apache.org>
Authored: Thu Oct 4 08:19:37 2018 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Fri Oct 5 07:32:38 2018 -0700
----------------------------------------------------------------------
.gitignore | 1 +
.../apache/phoenix/end2end/AlterTableIT.java | 4 +
.../phoenix/end2end/AlterTableWithViewsIT.java | 17 +-
.../org/apache/phoenix/end2end/BaseViewIT.java | 17 +-
...mnEncodedImmutableNonTxStatsCollectorIT.java | 12 +-
...olumnEncodedImmutableTxStatsCollectorIT.java | 16 +-
...lumnEncodedMutableNonTxStatsCollectorIT.java | 10 +-
.../ColumnEncodedMutableTxStatsCollectorIT.java | 15 +-
.../ConnectionQueryServicesTestImpl.java | 2 +-
.../apache/phoenix/end2end/IndexExtendedIT.java | 1 -
.../org/apache/phoenix/end2end/IndexToolIT.java | 21 +-
...mnEncodedImmutableNonTxStatsCollectorIT.java | 10 +-
...olumnEncodedImmutableTxStatsCollectorIT.java | 16 +-
.../phoenix/end2end/SqrtFunctionEnd2EndIT.java | 1 -
...SysTableNamespaceMappedStatsCollectorIT.java | 16 +-
.../phoenix/end2end/TransactionalViewIT.java | 23 +-
.../java/org/apache/phoenix/end2end/ViewIT.java | 21 +-
.../phoenix/end2end/index/BaseIndexIT.java | 101 +++++--
.../index/GlobalImmutableNonTxIndexIT.java | 12 +-
.../end2end/index/GlobalImmutableTxIndexIT.java | 17 +-
.../index/GlobalMutableNonTxIndexIT.java | 12 +-
.../end2end/index/GlobalMutableTxIndexIT.java | 17 +-
.../phoenix/end2end/index/ImmutableIndexIT.java | 38 ++-
.../index/LocalImmutableNonTxIndexIT.java | 12 +-
.../end2end/index/LocalImmutableTxIndexIT.java | 16 +-
.../end2end/index/LocalMutableNonTxIndexIT.java | 12 +-
.../end2end/index/LocalMutableTxIndexIT.java | 16 +-
.../end2end/index/MutableIndexFailureIT.java | 67 +++--
.../MutableIndexFailureWithNamespaceIT.java | 28 +-
.../phoenix/end2end/index/MutableIndexIT.java | 9 +-
.../end2end/index/txn/MutableRollbackIT.java | 46 +--
.../phoenix/end2end/index/txn/RollbackIT.java | 28 +-
.../end2end/index/txn/TxWriteFailureIT.java | 25 +-
.../apache/phoenix/execute/PartialCommitIT.java | 202 ++++++-------
.../org/apache/phoenix/rpc/UpdateCacheIT.java | 17 +-
.../phoenix/schema/stats/StatsCollectorIT.java | 26 +-
.../phoenix/tx/FlappingTransactionIT.java | 55 ++--
.../phoenix/tx/ParameterizedTransactionIT.java | 92 ++++--
.../org/apache/phoenix/tx/TransactionIT.java | 174 +++++++++++-
.../org/apache/phoenix/tx/TxCheckpointIT.java | 46 +--
.../apache/phoenix/compile/DeleteCompiler.java | 5 +-
.../compile/PostLocalIndexDDLCompiler.java | 3 +
.../apache/phoenix/compile/UpsertCompiler.java | 14 +-
.../phoenix/coprocessor/OmidGCProcessor.java | 29 ++
.../coprocessor/OmidTransactionalProcessor.java | 29 ++
.../UngroupedAggregateRegionObserver.java | 15 +-
.../phoenix/exception/SQLExceptionCode.java | 7 +-
.../apache/phoenix/execute/DelegateHTable.java | 57 +---
.../apache/phoenix/execute/MutationState.java | 27 +-
.../PhoenixTxIndexMutationGenerator.java | 57 +++-
.../hbase/index/builder/BaseIndexBuilder.java | 2 +-
.../phoenix/hbase/index/covered/IndexCodec.java | 10 +-
.../hbase/index/covered/LocalTableState.java | 2 +-
.../hbase/index/covered/NonTxIndexBuilder.java | 6 +-
.../apache/phoenix/index/IndexMaintainer.java | 87 +++---
.../apache/phoenix/index/PhoenixIndexCodec.java | 18 +-
.../index/PhoenixTransactionalIndexer.java | 2 +-
.../phoenix/iterate/ScanningResultIterator.java | 7 +-
.../phoenix/iterate/TableResultIterator.java | 9 +-
.../mapreduce/index/DirectHTableWriter.java | 25 +-
.../phoenix/mapreduce/index/IndexTool.java | 1 +
.../index/PhoenixIndexImportMapper.java | 51 +++-
.../util/PhoenixConfigurationUtil.java | 2 +
.../phoenix/query/ConnectionQueryServices.java | 4 +-
.../query/ConnectionQueryServicesImpl.java | 106 +++++--
.../query/DelegateConnectionQueryServices.java | 2 +-
.../apache/phoenix/schema/MetaDataClient.java | 144 +++++++---
.../transaction/OmidTransactionContext.java | 55 ++--
.../transaction/OmidTransactionProvider.java | 71 +++--
.../transaction/OmidTransactionTable.java | 280 +++++++++++++++++++
.../transaction/PhoenixTransactionContext.java | 10 +-
.../transaction/PhoenixTransactionProvider.java | 30 +-
.../transaction/TephraTransactionContext.java | 17 +-
.../transaction/TephraTransactionProvider.java | 16 +-
.../phoenix/transaction/TransactionFactory.java | 26 +-
.../java/org/apache/phoenix/util/IndexUtil.java | 8 +-
.../org/apache/phoenix/util/SchemaUtil.java | 10 +-
.../index/covered/CoveredColumnIndexCodec.java | 6 +-
.../covered/CoveredIndexCodecForTesting.java | 6 +-
.../covered/TestCoveredColumnIndexCodec.java | 8 +-
.../phoenix/query/QueryServicesTestImpl.java | 5 +-
.../java/org/apache/phoenix/util/TestUtil.java | 37 ++-
pom.xml | 2 +-
83 files changed, 1785 insertions(+), 794 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 33d40ea..2f47957 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,4 +26,5 @@ target/
release/
RESULTS/
CSV_EXPORT/
+.DS_Store
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
index 295b5d7..2cac1a6 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
@@ -61,6 +61,7 @@ import org.apache.phoenix.schema.PTable.EncodedCQCounter;
import org.apache.phoenix.schema.PTable.QualifierEncodingScheme;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.TableNotFoundException;
+import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.SchemaUtil;
@@ -1073,6 +1074,9 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
@Test
public void testCreatingTxnTableFailsIfTxnsDisabled() throws Exception {
+ if (!TransactionFactory.Provider.getDefault().runTests()) {
+ return;
+ }
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
props.setProperty(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(false));
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
index b1f0fce..9e7aaa2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableWithViewsIT.java
@@ -36,6 +36,7 @@ import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
+import java.util.Properties;
import org.apache.commons.lang.ArrayUtils;
import org.apache.hadoop.hbase.client.HTable;
@@ -49,6 +50,7 @@ import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.ColumnNotFoundException;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PName;
@@ -57,9 +59,12 @@ import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.TableNotFoundException;
+import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.TestUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -907,7 +912,12 @@ public class AlterTableWithViewsIT extends SplitSystemCatalogIT {
@Test
public void testMakeBaseTableTransactional() throws Exception {
- try (Connection conn = DriverManager.getConnection(getUrl());
+ if (!TransactionFactory.Provider.TEPHRA.runTests()) {
+ return;
+ }
+ Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+ props.setProperty(QueryServices.TRANSACTIONS_ENABLED, Boolean.TRUE.toString());
+ try (Connection conn = DriverManager.getConnection(getUrl(), props);
Connection viewConn = isMultiTenant ? DriverManager.getConnection(TENANT_SPECIFIC_URL1) : conn ) {
String baseTableName = SchemaUtil.getTableName(SCHEMA1, generateUniqueName());
String viewOfTable = SchemaUtil.getTableName(SCHEMA2, generateUniqueName());
@@ -931,8 +941,9 @@ public class AlterTableWithViewsIT extends SplitSystemCatalogIT {
assertFalse(phoenixConn.getTable(new PTableKey(null, baseTableName)).isTransactional());
assertFalse(viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable)).isTransactional());
- // make the base table transactional
- conn.createStatement().execute("ALTER TABLE " + baseTableName + " SET TRANSACTIONAL=true");
+ // make the base table transactional and explicitly set TEPHRA as provider since only it
+ // supports transitioning from non transactional to transactional
+ conn.createStatement().execute("ALTER TABLE " + baseTableName + " SET TRANSACTIONAL=true, TRANSACTION_PROVIDER='TEPHRA'");
// query the view to force the table cache to be updated
viewConn.createStatement().execute("SELECT * FROM " + viewOfTable);
htable = phoenixConn.getQueryServices().getTable(Bytes.toBytes(baseTableName));
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
index c3d553a..c074b32 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
@@ -46,6 +46,7 @@ import org.apache.phoenix.util.MetaDataUtil;
import org.apache.phoenix.util.QueryUtil;
import org.apache.phoenix.util.ScanUtil;
import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.TestUtil;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@@ -57,13 +58,13 @@ public abstract class BaseViewIT extends ParallelStatsEnabledIT {
protected String schemaName;
protected String fullTableName;
protected String tableDDLOptions;
- protected boolean transactional;
+ protected String txProvider;
- public BaseViewIT( boolean transactional) {
+ public BaseViewIT( String txProvider) {
StringBuilder optionBuilder = new StringBuilder();
- this.transactional = transactional;
- if (transactional) {
- optionBuilder.append(" TRANSACTIONAL=true ");
+ this.txProvider = txProvider;
+ if (txProvider != null) {
+ optionBuilder.append(" TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + txProvider + "'");
}
this.schemaName = "S_" + generateUniqueName();
this.tableDDLOptions = optionBuilder.toString();
@@ -71,9 +72,9 @@ public abstract class BaseViewIT extends ParallelStatsEnabledIT {
this.fullTableName = SchemaUtil.getTableName(schemaName, tableName);
}
- @Parameters(name="transactional = {0}")
- public static Collection<Boolean> data() {
- return Arrays.asList(new Boolean[] { false, true });
+ @Parameters(name="transactionProvider={0}")
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(new Object[][] { {"TEPHRA"}, {"OMID"}, {null} }), 0);
}
protected void testUpdatableViewWithIndex(Integer saltBuckets, boolean localIndex) throws Exception {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedImmutableNonTxStatsCollectorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedImmutableNonTxStatsCollectorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedImmutableNonTxStatsCollectorIT.java
index eb01e89..0481ba5 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedImmutableNonTxStatsCollectorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedImmutableNonTxStatsCollectorIT.java
@@ -25,15 +25,15 @@ import org.junit.runners.Parameterized.Parameters;
public class ColumnEncodedImmutableNonTxStatsCollectorIT extends StatsCollectorIT {
- public ColumnEncodedImmutableNonTxStatsCollectorIT(boolean mutable, boolean transactional,
+ public ColumnEncodedImmutableNonTxStatsCollectorIT(boolean mutable, String transactionProvider,
boolean userTableNamespaceMapped, boolean columnEncoded) {
- super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
+ super(mutable, transactionProvider, userTableNamespaceMapped, columnEncoded);
}
- @Parameters(name = "mutable = {0}, transactional = {1}, isUserTableNamespaceMapped = {2}, columnEncoded = {3}")
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { false, false, false, true }, { false, false, true, true }
+ @Parameters(name = "mutable={0},transactionProvider={1},isUserTableNamespaceMapped={2},columnEncoded={3}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ { false, null, false, true }, { false, null, true, true }
});
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedImmutableTxStatsCollectorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedImmutableTxStatsCollectorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedImmutableTxStatsCollectorIT.java
index 4e90d70..073dc07 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedImmutableTxStatsCollectorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedImmutableTxStatsCollectorIT.java
@@ -21,18 +21,22 @@ import java.util.Arrays;
import java.util.Collection;
import org.apache.phoenix.schema.stats.StatsCollectorIT;
+import org.apache.phoenix.util.TestUtil;
import org.junit.runners.Parameterized.Parameters;
public class ColumnEncodedImmutableTxStatsCollectorIT extends StatsCollectorIT {
- public ColumnEncodedImmutableTxStatsCollectorIT(boolean mutable, boolean transactional,
+ public ColumnEncodedImmutableTxStatsCollectorIT(boolean mutable, String transactionProvider,
boolean userTableNamespaceMapped, boolean columnEncoded) {
- super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
+ super(mutable, transactionProvider, userTableNamespaceMapped, columnEncoded);
}
- @Parameters(name = "mutable = {0}, transactional = {1}, isUserTableNamespaceMapped = {2}, columnEncoded = {3}")
- public static Collection<Boolean[]> data() {
- return Arrays.asList(
- new Boolean[][] { { false, true, false, true }, { false, true, true, true }, });
+ @Parameters(name = "mutable={0},transactionProvider={1},isUserTableNamespaceMapped={2},columnEncoded={3}")
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(
+ Arrays.asList(
+ new Object[][] {
+ { false, "TEPHRA", false, true },
+ { false, "TEPHRA", true, true }, }), 1);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedMutableNonTxStatsCollectorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedMutableNonTxStatsCollectorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedMutableNonTxStatsCollectorIT.java
index 2a560db..248f6fb 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedMutableNonTxStatsCollectorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedMutableNonTxStatsCollectorIT.java
@@ -25,14 +25,14 @@ import org.junit.runners.Parameterized.Parameters;
public class ColumnEncodedMutableNonTxStatsCollectorIT extends StatsCollectorIT {
- public ColumnEncodedMutableNonTxStatsCollectorIT(boolean mutable, boolean transactional,
+ public ColumnEncodedMutableNonTxStatsCollectorIT(boolean mutable, String transactionProvider,
boolean userTableNamespaceMapped, boolean columnEncoded) {
- super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
+ super(mutable, transactionProvider, userTableNamespaceMapped, columnEncoded);
}
- @Parameters(name = "mutable = {0}, transactional = {1}, isUserTableNamespaceMapped = {2}, columnEncoded = {3}")
- public static Collection<Boolean[]> data() {
+ @Parameters(name = "mutable={0},transactionProvider={1},isUserTableNamespaceMapped={2},columnEncoded={3}")
+ public static Collection<Object[]> data() {
return Arrays.asList(
- new Boolean[][] { { true, false, false, true }, { true, false, true, true } });
+ new Object[][] { { true, null, false, true }, { true, null, true, true } });
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedMutableTxStatsCollectorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedMutableTxStatsCollectorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedMutableTxStatsCollectorIT.java
index 01fa2b5..29e000e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedMutableTxStatsCollectorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnEncodedMutableTxStatsCollectorIT.java
@@ -21,18 +21,21 @@ import java.util.Arrays;
import java.util.Collection;
import org.apache.phoenix.schema.stats.StatsCollectorIT;
+import org.apache.phoenix.util.TestUtil;
import org.junit.runners.Parameterized.Parameters;
public class ColumnEncodedMutableTxStatsCollectorIT extends StatsCollectorIT {
- public ColumnEncodedMutableTxStatsCollectorIT(boolean mutable, boolean transactional,
+ public ColumnEncodedMutableTxStatsCollectorIT(boolean mutable, String transactionProvider,
boolean userTableNamespaceMapped, boolean columnEncoded) {
- super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
+ super(mutable, transactionProvider, userTableNamespaceMapped, columnEncoded);
}
- @Parameters(name = "mutable = {0}, transactional = {1}, isUserTableNamespaceMapped = {2}, columnEncoded = {3}")
- public static Collection<Boolean[]> data() {
- return Arrays.asList(
- new Boolean[][] { { true, true, false, true }, { true, true, true, true } });
+ @Parameters(name = "mutable={0},transactionProvider={1},isUserTableNamespaceMapped={2},columnEncoded={3}")
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(
+ Arrays.asList(new Object[][] {
+ { true, "TEPHRA", false, true },
+ { true, "TEPHRA", true, true } }), 1);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
index 3db93b0..6ebaa65 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
@@ -99,7 +99,7 @@ public class ConnectionQueryServicesTestImpl extends ConnectionQueryServicesImpl
}
@Override
- public synchronized PhoenixTransactionClient initTransactionClient(Provider provider) {
+ public synchronized PhoenixTransactionClient initTransactionClient(Provider provider) throws SQLException {
PhoenixTransactionService txService = txServices[provider.ordinal()];
if (txService == null) {
txService = txServices[provider.ordinal()] = provider.getTransactionProvider().getTransactionService(config, connectionInfo);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java
index 624f3e3..6af4d78 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java
@@ -160,7 +160,6 @@ public class IndexExtendedIT extends BaseTest {
//assert we are pulling from index table.
rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
actualExplainPlan = QueryUtil.getExplainPlan(rs);
- // TODO: why is it a 1-WAY parallel scan only for !transactional && mutable && localIndex
IndexToolIT.assertExplainPlan(localIndex, actualExplainPlan, dataTableFullName, indexTableFullName);
rs = stmt.executeQuery(selectSql);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
index a120aaa..b8372c4 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
@@ -53,6 +53,7 @@ import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.QueryUtil;
import org.apache.phoenix.util.ReadOnlyProps;
import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.TestUtil;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -71,15 +72,13 @@ public class IndexToolIT extends ParallelStatsEnabledIT {
private final boolean transactional;
private final boolean directApi;
private final String tableDDLOptions;
- private final boolean mutable;
private final boolean useSnapshot;
- public IndexToolIT(boolean transactional, boolean mutable, boolean localIndex,
+ public IndexToolIT(String transactionProvider, boolean mutable, boolean localIndex,
boolean directApi, boolean useSnapshot) {
this.localIndex = localIndex;
- this.transactional = transactional;
+ this.transactional = transactionProvider != null;
this.directApi = directApi;
- this.mutable = mutable;
this.useSnapshot = useSnapshot;
StringBuilder optionBuilder = new StringBuilder();
if (!mutable) {
@@ -89,7 +88,7 @@ public class IndexToolIT extends ParallelStatsEnabledIT {
if (!(optionBuilder.length() == 0)) {
optionBuilder.append(",");
}
- optionBuilder.append(" TRANSACTIONAL=true ");
+ optionBuilder.append(" TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + transactionProvider + "'");
}
optionBuilder.append(" SPLIT ON(1,2)");
this.tableDDLOptions = optionBuilder.toString();
@@ -108,22 +107,22 @@ public class IndexToolIT extends ParallelStatsEnabledIT {
}
@Parameters(
- name = "transactional = {0} , mutable = {1} , localIndex = {2}, directApi = {3}, useSnapshot = {4}")
- public static Collection<Boolean[]> data() {
- List<Boolean[]> list = Lists.newArrayListWithExpectedSize(16);
+ name = "transactionProvider={0},mutable={1},localIndex={2},directApi={3},useSnapshot={4}")
+ public static Collection<Object[]> data() {
+ List<Object[]> list = Lists.newArrayListWithExpectedSize(48);
boolean[] Booleans = new boolean[] { false, true };
- for (boolean transactional : Booleans) {
+ for (Object transactionProvider : new String[] {"TEPHRA", "OMID", null}) {
for (boolean mutable : Booleans) {
for (boolean localIndex : Booleans) {
for (boolean directApi : Booleans) {
for (boolean useSnapshot : Booleans) {
- list.add(new Boolean[] { transactional, mutable, localIndex, directApi, useSnapshot });
+ list.add(new Object[] { transactionProvider, mutable, localIndex, directApi, useSnapshot });
}
}
}
}
}
- return list;
+ return TestUtil.filterTxParamData(list,0);
}
@Test
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/NonColumnEncodedImmutableNonTxStatsCollectorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NonColumnEncodedImmutableNonTxStatsCollectorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NonColumnEncodedImmutableNonTxStatsCollectorIT.java
index 27c6dc2..fec890e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NonColumnEncodedImmutableNonTxStatsCollectorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NonColumnEncodedImmutableNonTxStatsCollectorIT.java
@@ -25,14 +25,14 @@ import org.junit.runners.Parameterized.Parameters;
public class NonColumnEncodedImmutableNonTxStatsCollectorIT extends StatsCollectorIT {
- public NonColumnEncodedImmutableNonTxStatsCollectorIT(boolean mutable, boolean transactional,
+ public NonColumnEncodedImmutableNonTxStatsCollectorIT(boolean mutable, String transactionProvider,
boolean userTableNamespaceMapped, boolean columnEncoded) {
- super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
+ super(mutable, transactionProvider, userTableNamespaceMapped, columnEncoded);
}
- @Parameters(name = "mutable = {0}, transactional = {1}, isUserTableNamespaceMapped = {2}, columnEncoded = {3}")
- public static Collection<Boolean[]> data() {
+ @Parameters(name = "mutable={0},transactionProvider={1},isUserTableNamespaceMapped={2},columnEncoded={3}")
+ public static Collection<Object[]> data() {
return Arrays.asList(
- new Boolean[][] { { false, false, false, false }, { false, false, true, false } });
+ new Object[][] { { false, null, false, false }, { false, null, true, false } });
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/NonColumnEncodedImmutableTxStatsCollectorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NonColumnEncodedImmutableTxStatsCollectorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NonColumnEncodedImmutableTxStatsCollectorIT.java
index 0cec31a..04485c4 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NonColumnEncodedImmutableTxStatsCollectorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NonColumnEncodedImmutableTxStatsCollectorIT.java
@@ -21,18 +21,22 @@ import java.util.Arrays;
import java.util.Collection;
import org.apache.phoenix.schema.stats.StatsCollectorIT;
+import org.apache.phoenix.util.TestUtil;
import org.junit.runners.Parameterized.Parameters;
public class NonColumnEncodedImmutableTxStatsCollectorIT extends StatsCollectorIT {
- public NonColumnEncodedImmutableTxStatsCollectorIT(boolean mutable, boolean transactional,
+ public NonColumnEncodedImmutableTxStatsCollectorIT(boolean mutable, String transactionProvider,
boolean userTableNamespaceMapped, boolean columnEncoded) {
- super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
+ super(mutable,transactionProvider, userTableNamespaceMapped, columnEncoded);
}
- @Parameters(name = "mutable = {0}, transactional = {1}, isUserTableNamespaceMapped = {2}, columnEncoded = {3}")
- public static Collection<Boolean[]> data() {
- return Arrays.asList(
- new Boolean[][] { { false, true, false, false }, { false, true, true, false } });
+ @Parameters(name = "mutable={0},transactionProvider={1},isUserTableNamespaceMapped={2},columnEncoded={3}")
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(
+ new Object[][] {
+ { false, "TEPHRA", false, false }, { false, "TEPHRA", true, false },
+ { false, "OMID", false, false }, { false, "OMID", true, false },
+ }),1);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/SqrtFunctionEnd2EndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SqrtFunctionEnd2EndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SqrtFunctionEnd2EndIT.java
index 657c3fd..b9108d3 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SqrtFunctionEnd2EndIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SqrtFunctionEnd2EndIT.java
@@ -18,7 +18,6 @@
package org.apache.phoenix.end2end;
import static org.apache.phoenix.util.TestUtil.closeStmtAndConn;
-import static org.apache.phoenix.util.TestUtil.getTableName;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/SysTableNamespaceMappedStatsCollectorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SysTableNamespaceMappedStatsCollectorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SysTableNamespaceMappedStatsCollectorIT.java
index 4830189..8f0a1d8 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SysTableNamespaceMappedStatsCollectorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SysTableNamespaceMappedStatsCollectorIT.java
@@ -24,6 +24,7 @@ import java.util.Map;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.stats.StatsCollectorIT;
import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.TestUtil;
import org.junit.BeforeClass;
import org.junit.runners.Parameterized.Parameters;
@@ -31,15 +32,18 @@ import com.google.common.collect.Maps;
public class SysTableNamespaceMappedStatsCollectorIT extends StatsCollectorIT {
- public SysTableNamespaceMappedStatsCollectorIT(boolean mutable, boolean transactional,
+ public SysTableNamespaceMappedStatsCollectorIT(boolean mutable, String transactionProvider,
boolean userTableNamespaceMapped, boolean columnEncoded) {
- super(mutable, transactional, userTableNamespaceMapped, columnEncoded);
+ super(mutable, transactionProvider, userTableNamespaceMapped, columnEncoded);
}
- @Parameters(name = "mutable = {0}, transactional = {1}, isUserTableNamespaceMapped = {2}, columnEncoded = {3}")
- public static Collection<Boolean[]> data() {
- return Arrays.asList(
- new Boolean[][] { { true, true, false, false }, { true, true, false, true }, });
+ @Parameters(name = "mutable={0},transactionProvider={1},isUserTableNamespaceMapped={2},columnEncoded={3}")
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(
+ new Object[][] {
+ { true, "TEPHRA", false, false }, { true, "TEPHRA", false, true },
+ { true, "OMID", false, false },
+ }), 1);
}
@BeforeClass
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java
index b8c028b..f8910c1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java
@@ -24,6 +24,8 @@ import static org.junit.Assert.assertEquals;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
import org.apache.phoenix.query.KeyRange;
@@ -31,12 +33,27 @@ import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TestUtil;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+@RunWith(Parameterized.class)
public class TransactionalViewIT extends ParallelStatsEnabledIT {
private String fullTableName;
private String fullViewName;
-
+ private final String transactionProvider;
+
+ public TransactionalViewIT(String transactionProvider) {
+ this.transactionProvider = transactionProvider;
+ }
+
+ @Parameters(name="TransactionalViewIT_transactionProvider={0}")
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {
+ {"TEPHRA"},{"OMID"}}),0);
+ }
+
@Before
public void generateTableNames() {
String schemaName = TestUtil.DEFAULT_SCHEMA_NAME;
@@ -51,7 +68,7 @@ public class TransactionalViewIT extends ParallelStatsEnabledIT {
try (Connection conn1 = DriverManager.getConnection(getUrl());
Connection conn2 = DriverManager.getConnection(getUrl())) {
String ddl = "CREATE TABLE " + fullTableName
- + " (k INTEGER NOT NULL PRIMARY KEY, v1 DATE) TRANSACTIONAL=true";
+ + " (k INTEGER NOT NULL PRIMARY KEY, v1 DATE) TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + transactionProvider + "'";
conn1.createStatement().execute(ddl);
ddl = "CREATE VIEW " + fullViewName + " (v2 VARCHAR) AS SELECT * FROM " + fullTableName + " where k>5";
conn1.createStatement().execute(ddl);
@@ -86,7 +103,7 @@ public class TransactionalViewIT extends ParallelStatsEnabledIT {
try (Connection conn1 = DriverManager.getConnection(getUrl());
Connection conn2 = DriverManager.getConnection(getUrl())) {
String ddl = "CREATE TABLE " + fullTableName
- + " (k INTEGER NOT NULL PRIMARY KEY, v1 DATE) TRANSACTIONAL=true";
+ + " (k INTEGER NOT NULL PRIMARY KEY, v1 DATE) TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + transactionProvider + "'";
conn1.createStatement().execute(ddl);
ddl = "CREATE VIEW " + fullViewName + " (v2 VARCHAR) AS SELECT * FROM " + fullTableName + " where k>5";
conn1.createStatement().execute(ddl);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
index bfcc729..cad897f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
@@ -100,7 +100,7 @@ import com.google.common.collect.Maps;
public class ViewIT extends SplitSystemCatalogIT {
protected String tableDDLOptions;
- protected boolean transactional;
+ protected String transactionProvider;
protected boolean columnEncoded;
private static final String FAILED_VIEWNAME = SchemaUtil.getTableName(SCHEMA2, "FAILED_VIEW");
@@ -109,12 +109,12 @@ public class ViewIT extends SplitSystemCatalogIT {
private static volatile CountDownLatch latch1 = null;
private static volatile CountDownLatch latch2 = null;
- public ViewIT(boolean transactional, boolean columnEncoded) {
+ public ViewIT(String transactionProvider, boolean columnEncoded) {
StringBuilder optionBuilder = new StringBuilder();
- this.transactional = transactional;
+ this.transactionProvider = transactionProvider;
this.columnEncoded = columnEncoded;
- if (transactional) {
- optionBuilder.append(" TRANSACTIONAL=true ");
+ if (transactionProvider != null) {
+ optionBuilder.append(" TRANSACTION_PROVIDER='" + transactionProvider + "'");
}
if (!columnEncoded) {
if (optionBuilder.length()!=0)
@@ -124,11 +124,12 @@ public class ViewIT extends SplitSystemCatalogIT {
this.tableDDLOptions = optionBuilder.toString();
}
- @Parameters(name="ViewIT_transactional={0}, columnEncoded={1}") // name is used by failsafe as file name in reports
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { true, false }, { true, true },
- { false, false }, { false, true }});
+ @Parameters(name="ViewIT_transactionProvider={0}, columnEncoded={1}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {
+ { "TEPHRA", false }, { "TEPHRA", true },
+ { "OMID", false },
+ { null, false }, { null, true }}),0);
}
@BeforeClass
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseIndexIT.java
index d86037c..7c14fba 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseIndexIT.java
@@ -67,10 +67,13 @@ import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.parse.NamedTableNode;
import org.apache.phoenix.parse.TableName;
import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider.Feature;
+import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.DateUtil;
import org.apache.phoenix.util.EnvironmentEdgeManager;
import org.apache.phoenix.util.PhoenixRuntime;
@@ -90,12 +93,12 @@ public abstract class BaseIndexIT extends ParallelStatsDisabledIT {
private final boolean localIndex;
private final boolean transactional;
+ private final TransactionFactory.Provider transactionProvider;
private final boolean mutable;
private final String tableDDLOptions;
- protected BaseIndexIT(boolean localIndex, boolean mutable, boolean transactional, boolean columnEncoded) {
+ protected BaseIndexIT(boolean localIndex, boolean mutable, String transactionProvider, boolean columnEncoded) {
this.localIndex = localIndex;
- this.transactional = transactional;
this.mutable = mutable;
StringBuilder optionBuilder = new StringBuilder();
if (!columnEncoded) {
@@ -111,10 +114,14 @@ public abstract class BaseIndexIT extends ParallelStatsDisabledIT {
optionBuilder.append(",IMMUTABLE_STORAGE_SCHEME="+PTableImpl.ImmutableStorageScheme.ONE_CELL_PER_COLUMN);
}
}
+ transactional = transactionProvider != null;
if (transactional) {
if (optionBuilder.length()!=0)
optionBuilder.append(",");
- optionBuilder.append(" TRANSACTIONAL=true ");
+ optionBuilder.append(" TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + transactionProvider + "'");
+ this.transactionProvider = TransactionFactory.Provider.valueOf(transactionProvider);
+ } else {
+ this.transactionProvider = null;
}
this.tableDDLOptions = optionBuilder.toString();
}
@@ -200,7 +207,7 @@ public abstract class BaseIndexIT extends ParallelStatsDisabledIT {
ResultSet rs;
- rs = conn.createStatement().executeQuery("SELECT COUNT(*) FROM " + fullTableName);
+ rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ COUNT(*) FROM " + fullTableName);
assertTrue(rs.next());
assertEquals(3,rs.getInt(1));
rs = conn.createStatement().executeQuery("SELECT COUNT(*) FROM " + fullIndexName);
@@ -245,7 +252,8 @@ public abstract class BaseIndexIT extends ParallelStatsDisabledIT {
if (iterator.hasNext()) {
byte[] tableName = iterator.next().getFirst(); // skip data table mutations
PTable table = PhoenixRuntime.getTable(conn, Bytes.toString(tableName));
- boolean clientSideUpdate = !localIndex && (!mutable || transactional);
+ boolean clientSideUpdate = (!localIndex || (transactional && table.getTransactionProvider().getTransactionProvider().isUnsupported(Feature.MAINTAIN_LOCAL_INDEX_ON_SERVER)))
+ && (!mutable || transactional);
if (!clientSideUpdate) {
assertTrue(table.getType() == PTableType.TABLE); // should be data table
}
@@ -257,20 +265,11 @@ public abstract class BaseIndexIT extends ParallelStatsDisabledIT {
@Test
public void testCreateIndexAfterUpsertStarted() throws Exception {
- testCreateIndexAfterUpsertStarted(false,
+ testCreateIndexAfterUpsertStarted(transactional,
SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, generateUniqueName()),
SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, generateUniqueName()));
}
- @Test
- public void testCreateIndexAfterUpsertStartedTxnl() throws Exception {
- if (transactional) {
- testCreateIndexAfterUpsertStarted(true,
- SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, generateUniqueName()),
- SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, generateUniqueName()));
- }
- }
-
private void testCreateIndexAfterUpsertStarted(boolean readOwnWrites, String fullTableName, String fullIndexName) throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
try (Connection conn1 = DriverManager.getConnection(getUrl(), props)) {
@@ -934,7 +933,9 @@ public abstract class BaseIndexIT extends ParallelStatsDisabledIT {
stmt.setString(2, "y");
stmt.setString(3, "2");
stmt.execute();
- conn.commit();
+ if (!transactional) {
+ conn.commit();
+ }
query = "SELECT * FROM " + fullTableName + " WHERE \"v2\" = '1'";
rs = conn.createStatement().executeQuery("EXPLAIN " + query);
@@ -955,6 +956,18 @@ public abstract class BaseIndexIT extends ParallelStatsDisabledIT {
assertEquals("1",rs.getString("v2"));
assertFalse(rs.next());
+ // Shadow cells shouldn't exist yet since commit hasn't happened
+ if (transactional && transactionProvider == TransactionFactory.Provider.OMID) {
+ assertShadowCellsDoNotExist(conn, fullTableName, fullIndexName);
+ }
+
+ conn.commit();
+
+ // Confirm shadow cells exist after commit
+ if (transactional && transactionProvider == TransactionFactory.Provider.OMID) {
+ assertShadowCellsExist(conn, fullTableName, fullIndexName);
+ }
+
query = "SELECT \"V1\", \"V1\" as foo1, \"v2\" as foo, \"v2\" as \"Foo1\", \"v2\" FROM " + fullTableName + " ORDER BY foo";
rs = conn.createStatement().executeQuery("EXPLAIN " + query);
if(localIndex){
@@ -1040,12 +1053,22 @@ public abstract class BaseIndexIT extends ParallelStatsDisabledIT {
}
@Test
- public void testIndexWithDecimalCol() throws Exception {
+ public void testIndexWithDecimalColServerSideUpsert() throws Exception {
+ testIndexWithDecimalCol(true);
+ }
+
+ @Test
+ public void testIndexWithDecimalColClientSideUpsert() throws Exception {
+ testIndexWithDecimalCol(false);
+ }
+
+ private void testIndexWithDecimalCol(boolean enableServerSideUpsert) throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
String tableName = "TBL_" + generateUniqueName();
String indexName = "IND_" + generateUniqueName();
String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
String fullIndexName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
+ props.setProperty(QueryServices.ENABLE_SERVER_UPSERT_SELECT, Boolean.toString(enableServerSideUpsert));
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
conn.setAutoCommit(false);
String query;
@@ -1057,6 +1080,10 @@ public abstract class BaseIndexIT extends ParallelStatsDisabledIT {
String ddl = null;
ddl = "CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName + " ON " + fullTableName + " (decimal_pk) INCLUDE (decimal_col1, decimal_col2)";
conn.createStatement().execute(ddl);
+
+ if (transactional && transactionProvider == TransactionFactory.Provider.OMID) {
+ assertShadowCellsExist(conn, fullTableName, fullIndexName);
+ }
query = "SELECT decimal_pk, decimal_col1, decimal_col2 from " + fullTableName ;
rs = conn.createStatement().executeQuery("EXPLAIN " + query);
@@ -1083,6 +1110,46 @@ public abstract class BaseIndexIT extends ParallelStatsDisabledIT {
}
}
+ private static void assertShadowCellsDoNotExist(Connection conn, String fullTableName, String fullIndexName)
+ throws Exception {
+ assertShadowCells(conn, fullTableName, fullIndexName, false);
+ }
+
+ private static void assertShadowCellsExist(Connection conn, String fullTableName, String fullIndexName)
+ throws Exception {
+ assertShadowCells(conn, fullTableName, fullIndexName, true);
+ }
+
+ private static void assertShadowCells(Connection conn, String fullTableName, String fullIndexName, boolean exists)
+ throws Exception {
+ PTable ptable = conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, fullTableName));
+ int nTableKVColumns = ptable.getColumns().size() - ptable.getPKColumns().size();
+ HTableInterface hTable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(fullTableName));
+ ResultScanner tableScanner = hTable.getScanner(new Scan());
+ Result tableResult;
+ PTable pindex = conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, fullIndexName));
+ int nIndexKVColumns = pindex.getColumns().size() - pindex.getPKColumns().size();
+ HTableInterface hIndex = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(fullIndexName));
+ ResultScanner indexScanner = hIndex.getScanner(new Scan());
+ Result indexResult;
+ while ((indexResult = indexScanner.next()) != null) {
+ int nColumns = 0;
+ CellScanner scanner = indexResult.cellScanner();
+ while (scanner.advance()) {
+ nColumns++;
+ }
+ assertEquals(exists, nColumns > nIndexKVColumns * 2);
+ assertNotNull(tableResult = tableScanner.next());
+ nColumns = 0;
+ scanner = tableResult.cellScanner();
+ while (scanner.advance()) {
+ nColumns++;
+ }
+ assertEquals(exists, nColumns > nTableKVColumns * 2);
+ }
+ assertNull(tableScanner.next());
+ }
+
/**
* Ensure that HTD contains table priorities correctly.
*/
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalImmutableNonTxIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalImmutableNonTxIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalImmutableNonTxIndexIT.java
index 70ad73d..d891920 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalImmutableNonTxIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalImmutableNonTxIndexIT.java
@@ -24,14 +24,14 @@ import org.junit.runners.Parameterized.Parameters;
public class GlobalImmutableNonTxIndexIT extends BaseIndexIT {
- public GlobalImmutableNonTxIndexIT(boolean localIndex, boolean mutable, boolean transactional, boolean columnEncoded) {
- super(localIndex, mutable, transactional, columnEncoded);
+ public GlobalImmutableNonTxIndexIT(boolean localIndex, boolean mutable, String transactionProvider, boolean columnEncoded) {
+ super(localIndex, mutable, transactionProvider, columnEncoded);
}
- @Parameters(name="GlobalImmutableNonTxIndexIT_localIndex={0},mutable={1},transactional={2},columnEncoded={3}") // name is used by failsafe as file name in reports
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { false, false, false, false }, { false, false, false, true }
+ @Parameters(name="GlobalImmutableNonTxIndexIT_localIndex={0},mutable={1},transactionProvider={2},columnEncoded={3}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ { false, false, null, false }, { false, false, null, true }
});
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalImmutableTxIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalImmutableTxIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalImmutableTxIndexIT.java
index 1ba498c..76deb99 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalImmutableTxIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalImmutableTxIndexIT.java
@@ -20,19 +20,22 @@ package org.apache.phoenix.end2end.index;
import java.util.Arrays;
import java.util.Collection;
+import org.apache.phoenix.util.TestUtil;
import org.junit.runners.Parameterized.Parameters;
public class GlobalImmutableTxIndexIT extends BaseIndexIT {
- public GlobalImmutableTxIndexIT(boolean localIndex, boolean mutable, boolean transactional, boolean columnEncoded) {
- super(localIndex, mutable, transactional, columnEncoded);
+ public GlobalImmutableTxIndexIT(boolean localIndex, boolean mutable, String transactionProvider, boolean columnEncoded) {
+ super(localIndex, mutable, transactionProvider, columnEncoded);
}
- @Parameters(name="GlobalImmutableTxIndexIT_localIndex={0},mutable={1},transactional={2},columnEncoded={3}") // name is used by failsafe as file name in reports
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { false, false, true, false }, { false, false, true, true },
- });
+ @Parameters(name="GlobalImmutableTxIndexIT_localIndex={0},mutable={1},transactionProvider={2},columnEncoded={3}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(
+ Arrays.asList(new Object[][] {
+ { false, false, "TEPHRA", false }, { false, false, "TEPHRA", true },
+ { false, false, "OMID", false },
+ }), 2);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalMutableNonTxIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalMutableNonTxIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalMutableNonTxIndexIT.java
index f37182d..023bc1e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalMutableNonTxIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalMutableNonTxIndexIT.java
@@ -24,14 +24,14 @@ import org.junit.runners.Parameterized.Parameters;
public class GlobalMutableNonTxIndexIT extends BaseIndexIT {
- public GlobalMutableNonTxIndexIT(boolean localIndex, boolean mutable, boolean transactional, boolean columnEncoded) {
- super(localIndex, mutable, transactional, columnEncoded);
+ public GlobalMutableNonTxIndexIT(boolean localIndex, boolean mutable, String transactionProvider, boolean columnEncoded) {
+ super(localIndex, mutable, transactionProvider, columnEncoded);
}
- @Parameters(name="GlobalMutableNonTxIndexIT_localIndex={0},mutable={1},transactional={2},columnEncoded={3}") // name is used by failsafe as file name in reports
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { false, true, false, false }, { false, true, false, true }
+ @Parameters(name="GlobalMutableNonTxIndexIT_localIndex={0},mutable={1},transactionProvider={2},columnEncoded={3}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ { false, true, null, false }, { false, true, null, true }
});
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalMutableTxIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalMutableTxIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalMutableTxIndexIT.java
index 65ca2c5..b33cce7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalMutableTxIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalMutableTxIndexIT.java
@@ -20,19 +20,22 @@ package org.apache.phoenix.end2end.index;
import java.util.Arrays;
import java.util.Collection;
+import org.apache.phoenix.util.TestUtil;
import org.junit.runners.Parameterized.Parameters;
public class GlobalMutableTxIndexIT extends BaseIndexIT {
- public GlobalMutableTxIndexIT(boolean localIndex, boolean mutable, boolean transactional, boolean columnEncoded) {
- super(localIndex, mutable, transactional, columnEncoded);
+ public GlobalMutableTxIndexIT(boolean localIndex, boolean mutable, String transactionProvider, boolean columnEncoded) {
+ super(localIndex, mutable, transactionProvider, columnEncoded);
}
- @Parameters(name="GlobalMutableTxIndexIT_localIndex={0},mutable={1},transactional={2},columnEncoded={3}") // name is used by failsafe as file name in reports
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { false, true, true, false }, { false, true, true, true }
- });
+ @Parameters(name="GlobalMutableTxIndexIT_localIndex={0},mutable={1},transactionProvider={2},columnEncoded={3}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(
+ Arrays.asList(new Object[][] {
+ { false, true, "TEPHRA", false }, { false, true, "TEPHRA", true },
+ { false, true, "OMID", false },
+ }), 2);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
index 1db9787..d676051 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
@@ -55,6 +55,9 @@ import org.apache.phoenix.query.BaseTest;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.PIndexState;
import org.apache.phoenix.schema.PTableImpl;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider.Feature;
+import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.ReadOnlyProps;
@@ -75,7 +78,7 @@ import com.google.common.collect.Maps;
public class ImmutableIndexIT extends BaseUniqueNamesOwnClusterIT {
private final boolean localIndex;
- private final boolean transactional;
+ private final PhoenixTransactionProvider transactionProvider;
private final String tableDDLOptions;
private volatile boolean stopThreads = false;
@@ -84,17 +87,17 @@ public class ImmutableIndexIT extends BaseUniqueNamesOwnClusterIT {
private static String INDEX_DDL;
public static final AtomicInteger NUM_ROWS = new AtomicInteger(0);
- public ImmutableIndexIT(boolean localIndex, boolean transactional, boolean columnEncoded) {
+ public ImmutableIndexIT(boolean localIndex, boolean transactional, String transactionProvider, boolean columnEncoded) {
StringBuilder optionBuilder = new StringBuilder("IMMUTABLE_ROWS=true");
this.localIndex = localIndex;
- this.transactional = transactional;
if (!columnEncoded) {
- if (optionBuilder.length()!=0)
- optionBuilder.append(",");
- optionBuilder.append("COLUMN_ENCODED_BYTES=0,IMMUTABLE_STORAGE_SCHEME="+PTableImpl.ImmutableStorageScheme.ONE_CELL_PER_COLUMN);
+ optionBuilder.append(",COLUMN_ENCODED_BYTES=0,IMMUTABLE_STORAGE_SCHEME="+PTableImpl.ImmutableStorageScheme.ONE_CELL_PER_COLUMN);
}
if (transactional) {
- optionBuilder.append(", TRANSACTIONAL=true");
+ optionBuilder.append(",TRANSACTIONAL=true, TRANSACTION_PROVIDER='" + transactionProvider + "'");
+ this.transactionProvider = TransactionFactory.Provider.valueOf(transactionProvider).getTransactionProvider();
+ } else {
+ this.transactionProvider = null;
}
this.tableDDLOptions = optionBuilder.toString();
@@ -110,13 +113,16 @@ public class ImmutableIndexIT extends BaseUniqueNamesOwnClusterIT {
setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
}
- @Parameters(name="ImmutableIndexIT_localIndex={0},transactional={1},columnEncoded={2}") // name is used by failsafe as file name in reports
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { false, false, false }, { false, false, true },
- { false, true, false }, { false, true, true },
- { true, false, false }, { true, false, true },
- { true, true, false }, { true, true, true } });
+ @Parameters(name="ImmutableIndexIT_localIndex={0},transactional={1},transactionProvider={2},columnEncoded={3}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(
+ Arrays.asList(new Object[][] {
+ { false, false, null, false }, { false, false, null, true },
+ { false, true, "OMID", false },
+ { false, true, "TEPHRA", false }, { false, true, "TEPHRA", true },
+ { true, false, null, false }, { true, false, null, true },
+ { true, true, "TEPHRA", false }, { true, true, "TEPHRA", true },
+ }), 2);
}
@Test
@@ -252,7 +258,9 @@ public class ImmutableIndexIT extends BaseUniqueNamesOwnClusterIT {
Iterator<Pair<byte[], List<KeyValue>>> iterator = PhoenixRuntime.getUncommittedDataIterator(conn);
assertTrue(iterator.hasNext());
iterator.next();
- assertEquals(!localIndex, iterator.hasNext());
+ assertEquals(!localIndex ||
+ (transactionProvider != null &&
+ transactionProvider.isUnsupported(Feature.MAINTAIN_LOCAL_INDEX_ON_SERVER)), iterator.hasNext());
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableNonTxIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableNonTxIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableNonTxIndexIT.java
index 7b7c6ad..515d74c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableNonTxIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableNonTxIndexIT.java
@@ -24,14 +24,14 @@ import org.junit.runners.Parameterized.Parameters;
public class LocalImmutableNonTxIndexIT extends BaseIndexIT {
- public LocalImmutableNonTxIndexIT(boolean localIndex, boolean mutable, boolean transactional, boolean columnEncoded) {
- super(localIndex, mutable, transactional, columnEncoded);
+ public LocalImmutableNonTxIndexIT(boolean localIndex, boolean mutable, String transactionProvider, boolean columnEncoded) {
+ super(localIndex, mutable, transactionProvider, columnEncoded);
}
- @Parameters(name="LocalImmutableNonTxIndexIT_localIndex={0},mutable={1},transactional={2},columnEncoded={3}") // name is used by failsafe as file name in reports
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { true, false, false, false }, { true, false, false, true }
+ @Parameters(name="LocalImmutableNonTxIndexIT_localIndex={0},mutable={1},transactionProvider={2},columnEncoded={3}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ { true, false, null, false }, { true, false, null, true }
});
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableTxIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableTxIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableTxIndexIT.java
index 5ff6d04..176b36f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableTxIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableTxIndexIT.java
@@ -20,19 +20,21 @@ package org.apache.phoenix.end2end.index;
import java.util.Arrays;
import java.util.Collection;
+import org.apache.phoenix.util.TestUtil;
import org.junit.runners.Parameterized.Parameters;
public class LocalImmutableTxIndexIT extends BaseIndexIT {
- public LocalImmutableTxIndexIT(boolean localIndex, boolean mutable, boolean transactional, boolean columnEncoded) {
- super(localIndex, mutable, transactional, columnEncoded);
+ public LocalImmutableTxIndexIT(boolean localIndex, boolean mutable, String transactionProvider, boolean columnEncoded) {
+ super(localIndex, mutable, transactionProvider, columnEncoded);
}
- @Parameters(name="LocalImmutableTxIndexIT_localIndex={0},mutable={1},transactional={2},columnEncoded={3}") // name is used by failsafe as file name in reports
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { true, false, true, false }, { true, false, true, true }
- });
+ @Parameters(name="LocalImmutableTxIndexIT_localIndex={0},mutable={1},transactionProvider={2},columnEncoded={3}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(
+ Arrays.asList(new Object[][] {
+ { true, false, "TEPHRA", false }, { true, false, "TEPHRA", true },
+ }), 2);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableNonTxIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableNonTxIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableNonTxIndexIT.java
index 4b9688b..dd3a3bb 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableNonTxIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableNonTxIndexIT.java
@@ -24,14 +24,14 @@ import org.junit.runners.Parameterized.Parameters;
public class LocalMutableNonTxIndexIT extends BaseIndexIT {
- public LocalMutableNonTxIndexIT(boolean localIndex, boolean mutable, boolean transactional, boolean columnEncoded) {
- super(localIndex, mutable, transactional, columnEncoded);
+ public LocalMutableNonTxIndexIT(boolean localIndex, boolean mutable, String transactionProvider, boolean columnEncoded) {
+ super(localIndex, mutable, transactionProvider, columnEncoded);
}
- @Parameters(name="LocalMutableNonTxIndexIT_localIndex={0},mutable={1},transactional={2},columnEncoded={3}") // name is used by failsafe as file name in reports
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { true, true, false, false }, { true, true, false, true }
+ @Parameters(name="LocalMutableNonTxIndexIT_localIndex={0},mutable={1},transactionProvider={2},columnEncoded={3}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ { true, true, null, false }, { true, true, null, true }
});
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableTxIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableTxIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableTxIndexIT.java
index 5f5dd0f..d1b7f53 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableTxIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableTxIndexIT.java
@@ -20,18 +20,20 @@ package org.apache.phoenix.end2end.index;
import java.util.Arrays;
import java.util.Collection;
+import org.apache.phoenix.util.TestUtil;
import org.junit.runners.Parameterized.Parameters;
public class LocalMutableTxIndexIT extends BaseIndexIT {
- public LocalMutableTxIndexIT(boolean localIndex, boolean mutable, boolean transactional, boolean columnEncoded) {
- super(localIndex, mutable, transactional, columnEncoded);
+ public LocalMutableTxIndexIT(boolean localIndex, boolean mutable, String transactionProvider, boolean columnEncoded) {
+ super(localIndex, mutable, transactionProvider, columnEncoded);
}
- @Parameters(name="LocalMutableTxIndexIT_localIndex={0},mutable={1},transactional={2},columnEncoded={3}") // name is used by failsafe as file name in reports
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { true, true, true, false }, { true, true, true, true }
- });
+ @Parameters(name="LocalMutableTxIndexIT_localIndex={0},mutable={1},transactionProvider={2},columnEncoded={3}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(
+ Arrays.asList(new Object[][] {
+ { true, true, "TEPHRA", false }, { true, true, "TEPHRA", true },
+ }), 2);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
index 0611478..8be32fc 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
@@ -30,6 +30,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -65,6 +66,8 @@ import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider;
+import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.IndexScrutiny;
import org.apache.phoenix.util.MetaDataUtil;
import org.apache.phoenix.util.PhoenixRuntime;
@@ -102,6 +105,7 @@ public class MutableIndexFailureIT extends BaseTest {
private String fullIndexName;
private final boolean transactional;
+ private final PhoenixTransactionProvider transactionProvider;
private final boolean localIndex;
private final String tableDDLOptions;
private final boolean isNamespaceMapped;
@@ -115,10 +119,12 @@ public class MutableIndexFailureIT extends BaseTest {
protected static final int disableTimestampThresholdMs = 10000;
protected static final int numRpcRetries = 2;
- public MutableIndexFailureIT(boolean transactional, boolean localIndex, boolean isNamespaceMapped, Boolean disableIndexOnWriteFailure, boolean failRebuildTask, Boolean throwIndexWriteFailure) {
- this.transactional = transactional;
+ public MutableIndexFailureIT(String transactionProvider, boolean localIndex, boolean isNamespaceMapped, Boolean disableIndexOnWriteFailure, boolean failRebuildTask, Boolean throwIndexWriteFailure) {
+ this.transactional = transactionProvider != null;
+ this.transactionProvider = transactionProvider == null ? null :
+ TransactionFactory.getTransactionProvider(TransactionFactory.Provider.valueOf(transactionProvider));
this.localIndex = localIndex;
- this.tableDDLOptions = " SALT_BUCKETS=2, COLUMN_ENCODED_BYTES=NONE" + (transactional ? ", TRANSACTIONAL=true " : "")
+ this.tableDDLOptions = " SALT_BUCKETS=2, COLUMN_ENCODED_BYTES=NONE" + (transactional ? (",TRANSACTIONAL=true,TRANSACTION_PROVIDER='"+transactionProvider+"'") : "")
+ (disableIndexOnWriteFailure == null ? "" : (", " + PhoenixIndexFailurePolicy.DISABLE_INDEX_ON_WRITE_FAILURE + "=" + disableIndexOnWriteFailure))
+ (throwIndexWriteFailure == null ? "" : (", " + PhoenixIndexFailurePolicy.THROW_INDEX_WRITE_FAILURE + "=" + throwIndexWriteFailure));
this.tableName = FailingRegionObserver.FAIL_TABLE_NAME;
@@ -168,26 +174,27 @@ public class MutableIndexFailureIT extends BaseTest {
return serverProps;
}
- @Parameters(name = "MutableIndexFailureIT_transactional={0},localIndex={1},isNamespaceMapped={2},disableIndexOnWriteFailure={3},failRebuildTask={4},throwIndexWriteFailure={5}") // name is used by failsafe as file name in reports
- public static List<Object[]> data() {
- return Arrays.asList(new Object[][] {
- // note - can't disableIndexOnWriteFailure without throwIndexWriteFailure, PHOENIX-4130
- { false, false, false, false, false, false},
- { false, false, false, true, false, null},
- { true, false, false, true, false, null},
- { false, true, false, null, false, null},
- { true, true, false, true, false, null},
- { false, false, false, false, false, null},
- { false, true, false, false, false, null},
- { false, false, false, false, false, null},
- { false, false, false, true, false, null},
- { false, false, false, true, false, null},
- { false, true, false, true, false, null},
- { false, true, false, true, false, null},
- { false, false, false, true, true, null},
- { false, false, false, false, true, false},
- }
- );
+ @Parameters(name = "MutableIndexFailureIT_transactionProvider={0},localIndex={1},isNamespaceMapped={2},disableIndexOnWriteFailure={3},failRebuildTask={4},throwIndexWriteFailure={5}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(
+ Arrays.asList(new Object[][] {
+ // note - can't disableIndexOnWriteFailure without throwIndexWriteFailure, PHOENIX-4130
+ { null, false, false, false, false, false},
+ { null, false, false, true, false, null},
+ { "TEPHRA", false, false, true, false, null},
+ { "OMID", false, false, true, false, null},
+ { null, true, false, null, false, null},
+ { "TEPHRA", true, false, true, false, null},
+ { null, false, false, false, false, null},
+ { null, true, false, false, false, null},
+ { null, false, false, false, false, null},
+ { null, false, false, true, false, null},
+ { null, true, false, true, false, null},
+ { null, true, false, true, false, null},
+ { null, false, false, true, true, null},
+ { null, false, false, false, true, false},
+ }), 0);
+
}
private void runRebuildTask(Connection conn) throws InterruptedException, SQLException {
@@ -253,7 +260,10 @@ public class MutableIndexFailureIT extends BaseTest {
// Create other index which should be local/global if the other index is global/local to
// check the drop index.
conn.createStatement().execute(
- "CREATE " + (!localIndex ? "LOCAL " : "") + " INDEX " + secondIndexName + " ON " + fullTableName + " (v2) INCLUDE (v1)");
+ "CREATE " + ((!localIndex &&
+ (transactionProvider == null
+ || !transactionProvider.isUnsupported(PhoenixTransactionProvider.Feature.ALLOW_LOCAL_INDEX)))
+ ? "LOCAL " : "") + " INDEX " + secondIndexName + " ON " + fullTableName + " (v2) INCLUDE (v1)");
conn.createStatement().execute(
"CREATE " + (localIndex ? "LOCAL " : "") + " INDEX " + thirdIndexName + " ON " + fullTableName + " (v1) INCLUDE (v2)");
@@ -465,17 +475,16 @@ public class MutableIndexFailureIT extends BaseTest {
}
}
- private void validateDataWithIndex(Connection conn, String fullTableName, String fullIndexName, boolean localIndex) throws SQLException {
+ private void validateDataWithIndex(Connection conn, String fullTableName, String fullIndexName, boolean localIndex) throws Exception {
String query = "SELECT /*+ INDEX(" + fullTableName + " " + SchemaUtil.getTableNameFromFullName(fullIndexName) + ") */ k,v1 FROM " + fullTableName;
- ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
+ ResultSet rs = conn.createStatement().executeQuery(query);
String expectedPlan = " OVER "
+ (localIndex
? Bytes.toString(
SchemaUtil.getPhysicalTableName(fullTableName.getBytes(), isNamespaceMapped).getName())
: SchemaUtil.getPhysicalTableName(fullIndexName.getBytes(), isNamespaceMapped).getNameAsString());
- String explainPlan = QueryUtil.getExplainPlan(rs);
+ String explainPlan = QueryUtil.getExplainPlan(conn.createStatement().executeQuery("EXPLAIN " + query));
assertTrue(explainPlan, explainPlan.contains(expectedPlan));
- rs = conn.createStatement().executeQuery(query);
if (transactional) { // failed commit does not get retried
assertTrue(rs.next());
assertEquals("a", rs.getString(1));
@@ -507,7 +516,7 @@ public class MutableIndexFailureIT extends BaseTest {
}
}
- private void updateTable(Connection conn, boolean commitShouldFail) throws SQLException {
+ private void updateTable(Connection conn, boolean commitShouldFail) throws Exception {
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?)");
// Insert new row
stmt.setString(1, "d");
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureWithNamespaceIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureWithNamespaceIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureWithNamespaceIT.java
index 5ed9e1f..b6ec49a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureWithNamespaceIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureWithNamespaceIT.java
@@ -18,7 +18,7 @@
package org.apache.phoenix.end2end.index;
import java.util.Arrays;
-import java.util.List;
+import java.util.Collection;
import java.util.Map;
import org.apache.hadoop.hbase.HConstants;
@@ -29,6 +29,7 @@ import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.util.ReadOnlyProps;
import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.TestUtil;
import org.junit.BeforeClass;
import org.junit.runners.Parameterized.Parameters;
@@ -39,9 +40,9 @@ import com.google.common.collect.Maps;
*/
public class MutableIndexFailureWithNamespaceIT extends MutableIndexFailureIT {
- public MutableIndexFailureWithNamespaceIT(boolean transactional, boolean localIndex, boolean isNamespaceMapped,
+ public MutableIndexFailureWithNamespaceIT(String transactionProvider, boolean localIndex, boolean isNamespaceMapped,
Boolean disableIndexOnWriteFailure, boolean failRebuildTask, Boolean throwIndexWriteFailure) {
- super(transactional, localIndex, isNamespaceMapped, disableIndexOnWriteFailure, failRebuildTask,
+ super(transactionProvider, localIndex, isNamespaceMapped, disableIndexOnWriteFailure, failRebuildTask,
throwIndexWriteFailure);
}
@@ -63,18 +64,19 @@ public class MutableIndexFailureWithNamespaceIT extends MutableIndexFailureIT {
}
@Parameters(name = "MutableIndexFailureIT_transactional={0},localIndex={1},isNamespaceMapped={2},disableIndexOnWriteFailure={3},failRebuildTask={4},throwIndexWriteFailure={5}") // name is used by failsafe as file name in reports
- public static List<Object[]> data() {
- return Arrays.asList(new Object[][] {
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {
// note - can't disableIndexOnWriteFailure without throwIndexWriteFailure, PHOENIX-4130
- { false, false, true, true, false, null},
- { false, false, true, true, false, true},
- { true, false, true, true, false, null},
- { false, true, true, true, false, null},
- { true, true, true, null, false, null},
- { false, false, true, true, true, null},
- { false, false, true, false, true, false},
+ { null, false, true, true, false, null},
+ { null, false, true, true, false, true},
+ { "TEPHRA", false, true, true, false, null},
+ { "OMID", false, true, true, false, null},
+ { null, true, true, true, false, null},
+ { "TEPHRA", true, true, null, false, null},
+ { null, false, true, true, true, null},
+ { null, false, true, false, true, false},
}
- );
+ ),0);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
index 4433e12..a994094 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
@@ -106,16 +106,15 @@ public class MutableIndexIT extends ParallelStatsDisabledIT {
return getConnection(props);
}
- @Parameters(name="MutableIndexIT_localIndex={0},transactional={1},columnEncoded={2}") // name is used by failsafe as file name in reports
+ @Parameters(name="MutableIndexIT_localIndex={0},transactionProvider={1},columnEncoded={2}") // name is used by failsafe as file name in reports
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][] {
+ return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {
{ false, null, false }, { false, null, true },
{ false, "TEPHRA", false }, { false, "TEPHRA", true },
- //{ false, "OMID", false }, { false, "OMID", true },
+ { false, "OMID", false },
{ true, null, false }, { true, null, true },
{ true, "TEPHRA", false }, { true, "TEPHRA", true },
- //{ true, "OMID", false }, { true, "OMID", true },
- });
+ }),1);
}
@Test
[3/4] phoenix git commit: PHOENIX-4731 Make running transactional
unit tests for a given provider optional
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
index cbfe9a5..f807a2b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
@@ -32,10 +32,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Properties;
-import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
-import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.SchemaUtil;
@@ -49,14 +46,19 @@ import org.junit.runners.Parameterized.Parameters;
public class MutableRollbackIT extends ParallelStatsDisabledIT {
private final boolean localIndex;
+ private final String tableDDLOptions;
- public MutableRollbackIT(boolean localIndex) {
+ public MutableRollbackIT(boolean localIndex, String transactionProvider) {
this.localIndex = localIndex;
+ this.tableDDLOptions = " TRANSACTION_PROVIDER='" + transactionProvider + "'";
}
- @Parameters(name="MutableRollbackIT_localIndex={0}") // name is used by failsafe as file name in reports
- public static Collection<Boolean> data() {
- return Arrays.asList(new Boolean[] { false, true});
+ @Parameters(name="MutableRollbackIT_localIndex={0},transactionProvider={1}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {
+ { false, "TEPHRA"}, { true, "TEPHRA"},
+ { false, "OMID"},
+ }),1);
}
private static Connection getConnection() throws SQLException {
@@ -77,8 +79,8 @@ public class MutableRollbackIT extends ParallelStatsDisabledIT {
conn.setAutoCommit(false);
try {
Statement stmt = conn.createStatement();
- stmt.execute("CREATE TABLE " + fullTableName1 + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
- stmt.execute("CREATE TABLE " + fullTableName2 + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) IMMUTABLE_ROWS=true");
+ stmt.execute("CREATE TABLE " + fullTableName1 + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)" + tableDDLOptions);
+ stmt.execute("CREATE TABLE " + fullTableName2 + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) IMMUTABLE_ROWS=true,"+tableDDLOptions);
stmt.execute("CREATE "+(localIndex? " LOCAL " : "")+"INDEX " + indexName1 + " ON " + fullTableName1 + " (v1) INCLUDE(v2)");
stmt.execute("CREATE "+(localIndex? " LOCAL " : "")+"INDEX " + indexName2 + " ON " + fullTableName2 + " (v1) INCLUDE(v2)");
@@ -210,8 +212,8 @@ public class MutableRollbackIT extends ParallelStatsDisabledIT {
conn.setAutoCommit(false);
try {
Statement stmt = conn.createStatement();
- stmt.execute("CREATE TABLE " + fullTableName1 + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
- stmt.execute("CREATE TABLE " + fullTableName2 + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) IMMUTABLE_ROWS=true");
+ stmt.execute("CREATE TABLE " + fullTableName1 + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)"+tableDDLOptions);
+ stmt.execute("CREATE TABLE " + fullTableName2 + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) IMMUTABLE_ROWS=true,"+tableDDLOptions);
stmt.execute("CREATE "+(localIndex? " LOCAL " : "")+"INDEX " + indexName1 + " ON " + fullTableName1 + " (v1, k)");
stmt.execute("CREATE "+(localIndex? " LOCAL " : "")+"INDEX " + indexName2 + " ON " + fullTableName2 + " (v1, k)");
@@ -294,11 +296,6 @@ public class MutableRollbackIT extends ParallelStatsDisabledIT {
conn.rollback();
assertDataAndIndexRows(stmt, fullTableName1, fullTableName2, indexName1);
- PhoenixConnection phoenixConn = conn.unwrap(PhoenixConnection.class);
- if(localIndex) {
- dropTable(phoenixConn.getQueryServices().getAdmin(), conn, fullTableName1);
- dropTable(phoenixConn.getQueryServices().getAdmin(), conn, fullTableName2);
- }
} finally {
conn.close();
}
@@ -347,7 +344,7 @@ public class MutableRollbackIT extends ParallelStatsDisabledIT {
conn.setAutoCommit(false);
try {
Statement stmt = conn.createStatement();
- stmt.execute("CREATE TABLE " + fullTableName1 + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
+ stmt.execute("CREATE TABLE " + fullTableName1 + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)"+tableDDLOptions);
stmt.execute("CREATE "+(localIndex? " LOCAL " : "")+"INDEX " + indexName1 + " ON " + fullTableName1 + " (v1, k)");
stmt.executeUpdate("upsert into " + fullTableName1 + " values('x', 'yyyy', 'a')");
@@ -435,8 +432,6 @@ public class MutableRollbackIT extends ParallelStatsDisabledIT {
assertEquals("x", rs.getString(1));
assertEquals("yyyy", rs.getString(2));
assertFalse(rs.next());
- PhoenixConnection phoenixConn = conn.unwrap(PhoenixConnection.class);
- if(localIndex) dropTable(phoenixConn.getQueryServices().getAdmin(), conn, fullTableName1);
} finally {
conn.close();
}
@@ -451,7 +446,7 @@ public class MutableRollbackIT extends ParallelStatsDisabledIT {
conn.setAutoCommit(false);
try {
Statement stmt = conn.createStatement();
- stmt.execute("CREATE TABLE " + fullTableName1 + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
+ stmt.execute("CREATE TABLE " + fullTableName1 + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)"+tableDDLOptions);
stmt.execute("CREATE "+(localIndex? " LOCAL " : "")+"INDEX " + indexName1 + " ON " + fullTableName1 + " (v1)");
stmt.executeUpdate("upsert into " + fullTableName1 + " values('x', 'a', 'a')");
conn.commit();
@@ -501,19 +496,8 @@ public class MutableRollbackIT extends ParallelStatsDisabledIT {
assertEquals("x", rs.getString(1));
assertEquals("a", rs.getString(2));
assertFalse(rs.next());
- PhoenixConnection phoenixConn = conn.unwrap(PhoenixConnection.class);
- if(localIndex) dropTable(phoenixConn.getQueryServices().getAdmin(), conn, fullTableName1);
} finally {
conn.close();
}
}
-
- private void dropTable(HBaseAdmin admin, Connection conn, String tableName) throws SQLException, IOException {
- conn.createStatement().execute("DROP TABLE IF EXISTS "+ tableName);
- if(admin.tableExists(tableName)) {
- admin.disableTable(TableName.valueOf(tableName));
- admin.deleteTable(TableName.valueOf(tableName));
- }
- }
-
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
index 8cafcfc..ff9f14b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
@@ -45,11 +45,16 @@ import org.junit.runners.Parameterized.Parameters;
public class RollbackIT extends ParallelStatsDisabledIT {
private final boolean localIndex;
- private final boolean mutable;
+ private final String tableDDLOptions;
- public RollbackIT(boolean localIndex, boolean mutable) {
+ public RollbackIT(boolean localIndex, boolean mutable, String transactionProvider) {
this.localIndex = localIndex;
- this.mutable = mutable;
+ StringBuilder optionBuilder = new StringBuilder();
+ optionBuilder.append(" TRANSACTION_PROVIDER='" + transactionProvider + "'");
+ if (!mutable) {
+ optionBuilder.append(",IMMUTABLE_ROWS=true");
+ }
+ this.tableDDLOptions = optionBuilder.toString();
}
private static Connection getConnection() throws SQLException {
@@ -59,12 +64,13 @@ public class RollbackIT extends ParallelStatsDisabledIT {
return conn;
}
- @Parameters(name="RollbackIT_localIndex={0},mutable={1}") // name is used by failsafe as file name in reports
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { false, false }, { false, true },
- { true, false }, { true, true }
- });
+ @Parameters(name="RollbackIT_localIndex={0},mutable={1},transactionProvider={2}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {
+ { false, false, "TEPHRA" }, { false, true, "TEPHRA" },
+ { true, false, "TEPHRA" }, { true, true, "TEPHRA" },
+ { false, false, "OMID" }, { false, true, "OMID" },
+ }),2);
}
@Test
@@ -76,7 +82,7 @@ public class RollbackIT extends ParallelStatsDisabledIT {
conn.setAutoCommit(false);
try {
Statement stmt = conn.createStatement();
- stmt.execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)"+(!mutable? " IMMUTABLE_ROWS=true" : ""));
+ stmt.execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)"+tableDDLOptions);
stmt.execute("CREATE "+(localIndex? "LOCAL " : "")+"INDEX " + indexName + " ON " + fullTableName + " (v1) INCLUDE(v2)");
stmt.executeUpdate("upsert into " + fullTableName + " values('x', 'y', 'a')");
@@ -120,7 +126,7 @@ public class RollbackIT extends ParallelStatsDisabledIT {
String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
try {
Statement stmt = conn.createStatement();
- stmt.execute("CREATE TABLE " + fullTableName + "(k VARCHAR, v1 VARCHAR, v2 VARCHAR, CONSTRAINT pk PRIMARY KEY (v1, v2))"+(!mutable? " IMMUTABLE_ROWS=true" : ""));
+ stmt.execute("CREATE TABLE " + fullTableName + "(k VARCHAR, v1 VARCHAR, v2 VARCHAR, CONSTRAINT pk PRIMARY KEY (v1, v2))"+tableDDLOptions);
stmt.execute("CREATE "+(localIndex? "LOCAL " : "")+"INDEX " + indexName + " ON " + fullTableName + "(v1, k)");
stmt.executeUpdate("upsert into " + fullTableName + " values('x', 'y', 'a')");
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java
index 049611c..1ce5fc4 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java
@@ -48,6 +48,7 @@ import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.QueryUtil;
import org.apache.phoenix.util.ReadOnlyProps;
import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.TestUtil;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -68,11 +69,16 @@ public class TxWriteFailureIT extends BaseUniqueNamesOwnClusterIT {
private static final String ROW_TO_FAIL = "fail";
private final boolean localIndex;
- private final boolean mutable;
+ private final String tableDDLOptions;
- public TxWriteFailureIT(boolean localIndex, boolean mutable) {
+ public TxWriteFailureIT(boolean localIndex, boolean mutable, String transactionProvider) {
this.localIndex = localIndex;
- this.mutable = mutable;
+ StringBuilder optionBuilder = new StringBuilder();
+ optionBuilder.append(" TRANSACTION_PROVIDER='" + transactionProvider + "'");
+ if (!mutable) {
+ optionBuilder.append(",IMMUTABLE_ROWS=true");
+ }
+ this.tableDDLOptions = optionBuilder.toString();
}
@BeforeClass
@@ -87,11 +93,12 @@ public class TxWriteFailureIT extends BaseUniqueNamesOwnClusterIT {
setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
}
- @Parameters(name="TxWriteFailureIT_localIndex={0},mutable={1}") // name is used by failsafe as file name in reports
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { false, false }, { false, true }, { true, false }, { true, true }
- });
+ @Parameters(name="TxWriteFailureIT_localIndex={0},mutable={1},transactionProvider={2}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {
+ { false, false, "TEPHRA" }, { false, true, "TEPHRA" }, { true, false, "TEPHRA" }, { true, true, "TEPHRA" },
+ { false, false, "OMID" }, { false, true, "OMID" },
+ }), 2);
}
@Before
@@ -122,7 +129,7 @@ public class TxWriteFailureIT extends BaseUniqueNamesOwnClusterIT {
Connection conn = driver.connect(url, props);
conn.setAutoCommit(false);
conn.createStatement().execute(
- "CREATE TABLE " + dataTableFullName + " (k VARCHAR PRIMARY KEY, v1 VARCHAR)"+(!mutable? " IMMUTABLE_ROWS=true" : ""));
+ "CREATE TABLE " + dataTableFullName + " (k VARCHAR PRIMARY KEY, v1 VARCHAR)"+tableDDLOptions);
conn.createStatement().execute(
"CREATE "+(localIndex? "LOCAL " : "")+"INDEX " + indexName + " ON " + dataTableFullName + " (v1)");
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/execute/PartialCommitIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/execute/PartialCommitIT.java b/phoenix-core/src/it/java/org/apache/phoenix/execute/PartialCommitIT.java
index feb0ce4..c6dc312 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/execute/PartialCommitIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/execute/PartialCommitIT.java
@@ -18,7 +18,6 @@
package org.apache.phoenix.execute;
import static com.google.common.collect.Lists.newArrayList;
-import static com.google.common.collect.Sets.newHashSet;
import static java.util.Collections.singletonList;
import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_MUTATION_BATCH_FAILED_COUNT;
import static org.apache.phoenix.monitoring.MetricType.MUTATION_BATCH_FAILED_SIZE;
@@ -37,11 +36,9 @@ import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HBaseIOException;
-import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.Mutation;
@@ -51,7 +48,7 @@ import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
import org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver;
import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.end2end.BaseOwnClusterIT;
+import org.apache.phoenix.end2end.BaseUniqueNamesOwnClusterIT;
import org.apache.phoenix.execute.MutationState.MultiRowMutationState;
import org.apache.phoenix.hbase.index.Indexer;
import org.apache.phoenix.jdbc.PhoenixConnection;
@@ -61,9 +58,7 @@ import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.TableRef;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.ReadOnlyProps;
-import org.apache.phoenix.util.SchemaUtil;
-import org.junit.After;
-import org.junit.AfterClass;
+import org.apache.phoenix.util.TestUtil;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -72,27 +67,23 @@ import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@RunWith(Parameterized.class)
// Needs to extend BaseOwnClusterIT due to installation of FailingRegionObserver coprocessor
-public class PartialCommitIT extends BaseOwnClusterIT {
+public class PartialCommitIT extends BaseUniqueNamesOwnClusterIT {
- private final String A_SUCESS_TABLE;
- private final String B_FAILURE_TABLE;
- private final String C_SUCESS_TABLE;
- private final String UPSERT_TO_FAIL;
- private final String UPSERT_SELECT_TO_FAIL;
- private final String DELETE_TO_FAIL;
+ private final String aSuccessTable;
+ private final String bFailureTable;
+ private final String cSuccessTable;
+ private final String upsertToFail;
+ private final String upsertSelectToFail;
+ private final String deleteToFail;
private static final String TABLE_NAME_TO_FAIL = "B_FAILURE_TABLE";
private static final byte[] ROW_TO_FAIL_UPSERT_BYTES = Bytes.toBytes("fail me upsert");
private static final byte[] ROW_TO_FAIL_DELETE_BYTES = Bytes.toBytes("fail me delete");
- private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
- @Override
- @After
- public void cleanUpAfterTest() throws Exception {}
-
@BeforeClass
public static void doSetup() throws Exception {
Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(3);
@@ -103,144 +94,135 @@ public class PartialCommitIT extends BaseOwnClusterIT {
clientProps.put(QueryServices.TRANSACTIONS_ENABLED, "true");
clientProps.put(QueryServices.COLLECT_REQUEST_LEVEL_METRICS, String.valueOf(true));
setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
- createTablesWithABitOfData();
- }
-
- @Parameters(name="PartialCommitIT_transactional={0}") // name is used by failsafe as file name in reports
- public static Collection<Boolean> data() {
- return Arrays.asList(false, true);
}
private final boolean transactional;
+ private final String transactionProvider;
- public PartialCommitIT(boolean transactional) {
- this.transactional = transactional;
- if (transactional) {
- A_SUCESS_TABLE = "A_SUCCESS_TABLE_TXN";
- B_FAILURE_TABLE = TABLE_NAME_TO_FAIL+"_TXN";
- C_SUCESS_TABLE = "C_SUCCESS_TABLE_TXN";
- }
- else {
- A_SUCESS_TABLE = "A_SUCCESS_TABLE";
- B_FAILURE_TABLE = TABLE_NAME_TO_FAIL;
- C_SUCESS_TABLE = "C_SUCCESS_TABLE";
- }
- UPSERT_TO_FAIL = "upsert into " + B_FAILURE_TABLE + " values ('" + Bytes.toString(ROW_TO_FAIL_UPSERT_BYTES) + "', 'boom!')";
- UPSERT_SELECT_TO_FAIL = "upsert into " + B_FAILURE_TABLE + " select k, c from a_success_table";
- DELETE_TO_FAIL = "delete from " + B_FAILURE_TABLE + " where k='" + Bytes.toString(ROW_TO_FAIL_DELETE_BYTES) + "'";
+ @Parameters(name="PartialCommitIT_transactionProvider={0}")
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {
+ {"TEPHRA"},{"OMID"}}),0);
+ }
+
+ public PartialCommitIT(String transactionProvider) {
+ this.transactionProvider = transactionProvider;
+ this.transactional = transactionProvider != null;
+ aSuccessTable = generateUniqueName();
+ bFailureTable = TABLE_NAME_TO_FAIL + generateUniqueName();
+ cSuccessTable = generateUniqueName();
+ upsertToFail = "upsert into " + bFailureTable + " values ('" + Bytes.toString(ROW_TO_FAIL_UPSERT_BYTES) + "', 'boom!')";
+ upsertSelectToFail = "upsert into " + bFailureTable + " select k, c from " + aSuccessTable;
+ deleteToFail = "delete from " + bFailureTable + " where k='" + Bytes.toString(ROW_TO_FAIL_DELETE_BYTES) + "'";
}
- private static void createTablesWithABitOfData() throws Exception {
- try (Connection con = driver.connect(url, new Properties())) {
+ private void createTables() throws Exception {
+ try (Connection con = DriverManager.getConnection(getUrl())) {
Statement sta = con.createStatement();
- sta.execute("create table a_success_table (k varchar primary key, c varchar)");
- sta.execute("create table b_failure_table (k varchar primary key, c varchar)");
- sta.execute("create table c_success_table (k varchar primary key, c varchar)");
- sta.execute("create table a_success_table_txn (k varchar primary key, c varchar) TRANSACTIONAL=true");
- sta.execute("create table b_failure_table_txn (k varchar primary key, c varchar) TRANSACTIONAL=true");
- sta.execute("create table c_success_table_txn (k varchar primary key, c varchar) TRANSACTIONAL=true");
- con.commit();
+ sta.execute("create table " + aSuccessTable + " (k varchar primary key, c varchar)" + (transactional ? (" TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + transactionProvider + "'") : ""));
+ sta.execute("create table " + bFailureTable + " (k varchar primary key, c varchar)" + (transactional ? (" TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + transactionProvider + "'") : ""));
+ sta.execute("create table " + cSuccessTable + " (k varchar primary key, c varchar)" + (transactional ? (" TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + transactionProvider + "'") : ""));
}
-
- try (Connection con = driver.connect(url, new Properties())) {
+ }
+
+ private void populateTables() throws Exception {
+ try (Connection con = DriverManager.getConnection(getUrl())) {
con.setAutoCommit(false);
Statement sta = con.createStatement();
- for (String table : newHashSet("a_success_table", "b_failure_table", "c_success_table",
- "a_success_table_txn", "b_failure_table_txn", "c_success_table_txn")) {
- sta.execute("upsert into " + table + " values ('z', 'z')");
- sta.execute("upsert into " + table + " values ('zz', 'zz')");
- sta.execute("upsert into " + table + " values ('zzz', 'zzz')");
+ List<String> tableNames = Lists.newArrayList(aSuccessTable, bFailureTable, cSuccessTable);
+ for (String tableName : tableNames) {
+ sta.execute("upsert into " + tableName + " values ('z', 'z')");
+ sta.execute("upsert into " + tableName + " values ('zz', 'zz')");
+ sta.execute("upsert into " + tableName + " values ('zzz', 'zzz')");
}
con.commit();
}
}
- @AfterClass
- public static void teardownCluster() throws Exception {
- TEST_UTIL.shutdownMiniCluster();
- }
-
@Before
- public void resetGlobalMetrics() {
+ public void resetGlobalMetrics() throws Exception {
+ createTables();
+ populateTables();
for (GlobalMetric m : PhoenixRuntime.getGlobalPhoenixClientMetrics()) {
m.reset();
}
}
@Test
- public void testNoFailure() {
- testPartialCommit(singletonList("upsert into " + A_SUCESS_TABLE + " values ('testNoFailure', 'a')"), new int[0], false, singletonList("select count(*) from " + A_SUCESS_TABLE + " where k='testNoFailure'"),
+ public void testNoFailure() throws SQLException {
+ testPartialCommit(singletonList("upsert into " + aSuccessTable + " values ('testNoFailure', 'a')"), new int[0], false, singletonList("select count(*) from " + aSuccessTable + " where k='testNoFailure'"),
singletonList(new Integer(1)));
}
@Test
- public void testUpsertFailure() {
- testPartialCommit(newArrayList("upsert into " + A_SUCESS_TABLE + " values ('testUpsertFailure1', 'a')",
- UPSERT_TO_FAIL,
- "upsert into " + A_SUCESS_TABLE + " values ('testUpsertFailure2', 'b')"),
+ public void testUpsertFailure() throws SQLException {
+ testPartialCommit(newArrayList("upsert into " + aSuccessTable + " values ('testUpsertFailure1', 'a')",
+ upsertToFail,
+ "upsert into " + aSuccessTable + " values ('testUpsertFailure2', 'b')"),
transactional ? new int[] {0,1,2} : new int[]{1}, true,
- newArrayList("select count(*) from " + A_SUCESS_TABLE + " where k like 'testUpsertFailure_'",
- "select count(*) from " + B_FAILURE_TABLE + " where k = '" + Bytes.toString(ROW_TO_FAIL_UPSERT_BYTES) + "'"),
+ newArrayList("select count(*) from " + aSuccessTable + " where k like 'testUpsertFailure_'",
+ "select count(*) from " + bFailureTable + " where k = '" + Bytes.toString(ROW_TO_FAIL_UPSERT_BYTES) + "'"),
transactional ? newArrayList(new Integer(0), new Integer(0)) : newArrayList(new Integer(2), new Integer(0)));
}
@Test
public void testUpsertSelectFailure() throws SQLException {
- try (Connection con = driver.connect(url, new Properties())) {
- con.createStatement().execute("upsert into " + A_SUCESS_TABLE + " values ('" + Bytes.toString(ROW_TO_FAIL_UPSERT_BYTES) + "', 'boom!')");
+ try (Connection con = DriverManager.getConnection(getUrl())) {
+ con.createStatement().execute("upsert into " + aSuccessTable + " values ('" + Bytes.toString(ROW_TO_FAIL_UPSERT_BYTES) + "', 'boom!')");
con.commit();
}
- testPartialCommit(newArrayList("upsert into " + A_SUCESS_TABLE + " values ('testUpsertSelectFailure', 'a')",
- UPSERT_SELECT_TO_FAIL),
+ testPartialCommit(newArrayList("upsert into " + aSuccessTable + " values ('testUpsertSelectFailure', 'a')",
+ upsertSelectToFail),
transactional ? new int[] {0,1} : new int[]{1}, true,
- newArrayList("select count(*) from " + A_SUCESS_TABLE + " where k in ('testUpsertSelectFailure', '" + Bytes.toString(ROW_TO_FAIL_UPSERT_BYTES) + "')",
- "select count(*) from " + B_FAILURE_TABLE + " where k = '" + Bytes.toString(ROW_TO_FAIL_UPSERT_BYTES) + "'"),
+ newArrayList("select count(*) from " + aSuccessTable + " where k in ('testUpsertSelectFailure', '" + Bytes.toString(ROW_TO_FAIL_UPSERT_BYTES) + "')",
+ "select count(*) from " + bFailureTable + " where k = '" + Bytes.toString(ROW_TO_FAIL_UPSERT_BYTES) + "'"),
transactional ? newArrayList(new Integer(1) /* from commit above */, new Integer(0)) : newArrayList(new Integer(2), new Integer(0)));
}
@Test
- public void testDeleteFailure() {
- testPartialCommit(newArrayList("upsert into " + A_SUCESS_TABLE + " values ('testDeleteFailure1', 'a')",
- DELETE_TO_FAIL,
- "upsert into " + A_SUCESS_TABLE + " values ('testDeleteFailure2', 'b')"),
+ public void testDeleteFailure() throws SQLException {
+ testPartialCommit(newArrayList("upsert into " + aSuccessTable + " values ('testDeleteFailure1', 'a')",
+ deleteToFail,
+ "upsert into " + aSuccessTable + " values ('testDeleteFailure2', 'b')"),
transactional ? new int[] {0,1,2} : new int[]{1}, true,
- newArrayList("select count(*) from " + A_SUCESS_TABLE + " where k like 'testDeleteFailure_'",
- "select count(*) from " + B_FAILURE_TABLE + " where k = 'z'"),
+ newArrayList("select count(*) from " + aSuccessTable + " where k like 'testDeleteFailure_'",
+ "select count(*) from " + bFailureTable + " where k = 'z'"),
transactional ? newArrayList(new Integer(0), new Integer(1) /* original row */) : newArrayList(new Integer(2), new Integer(1)));
}
/**
* {@link MutationState} keeps mutations ordered lexicographically by table name.
+ * @throws SQLException
*/
@Test
- public void testOrderOfMutationsIsPredicatable() {
- testPartialCommit(newArrayList("upsert into " + C_SUCESS_TABLE + " values ('testOrderOfMutationsIsPredicatable', 'c')", // will fail because c_success_table is after b_failure_table by table sort order
- UPSERT_TO_FAIL,
- "upsert into " + A_SUCESS_TABLE + " values ('testOrderOfMutationsIsPredicatable', 'a')"), // will succeed because a_success_table is before b_failure_table by table sort order
+ public void testOrderOfMutationsIsPredicatable() throws SQLException {
+ testPartialCommit(newArrayList("upsert into " + cSuccessTable + " values ('testOrderOfMutationsIsPredicatable', 'c')", // will fail because c_success_table is after b_failure_table by table sort order
+ upsertToFail,
+ "upsert into " + aSuccessTable + " values ('testOrderOfMutationsIsPredicatable', 'a')"), // will succeed because a_success_table is before b_failure_table by table sort order
transactional ? new int[] {0,1,2} : new int[]{0,1}, true,
- newArrayList("select count(*) from " + C_SUCESS_TABLE + " where k='testOrderOfMutationsIsPredicatable'",
- "select count(*) from " + A_SUCESS_TABLE + " where k='testOrderOfMutationsIsPredicatable'",
- "select count(*) from " + B_FAILURE_TABLE + " where k = '" + Bytes.toString(ROW_TO_FAIL_UPSERT_BYTES) + "'"),
+ newArrayList("select count(*) from " + cSuccessTable + " where k='testOrderOfMutationsIsPredicatable'",
+ "select count(*) from " + aSuccessTable + " where k='testOrderOfMutationsIsPredicatable'",
+ "select count(*) from " + bFailureTable + " where k = '" + Bytes.toString(ROW_TO_FAIL_UPSERT_BYTES) + "'"),
transactional ? newArrayList(new Integer(0), new Integer(0), new Integer(0)) : newArrayList(new Integer(0), new Integer(1), new Integer(0)));
}
@Test
- public void testStatementOrderMaintainedInConnection() {
- testPartialCommit(newArrayList("upsert into " + A_SUCESS_TABLE + " values ('testStatementOrderMaintainedInConnection', 'a')",
- "upsert into " + A_SUCESS_TABLE + " select k, c from " + C_SUCESS_TABLE,
- DELETE_TO_FAIL,
- "select * from " + A_SUCESS_TABLE + "",
- UPSERT_TO_FAIL),
+ public void testStatementOrderMaintainedInConnection() throws SQLException {
+ testPartialCommit(newArrayList("upsert into " + aSuccessTable + " values ('testStatementOrderMaintainedInConnection', 'a')",
+ "upsert into " + aSuccessTable + " select k, c from " + cSuccessTable,
+ deleteToFail,
+ "select * from " + aSuccessTable + "",
+ upsertToFail),
transactional ? new int[] {0,1,2,4} : new int[]{2,4}, true,
- newArrayList("select count(*) from " + A_SUCESS_TABLE + " where k='testStatementOrderMaintainedInConnection' or k like 'z%'", // rows left: zz, zzz, checkThatAllStatementTypesMaintainOrderInConnection
- "select count(*) from " + B_FAILURE_TABLE + " where k = '" + Bytes.toString(ROW_TO_FAIL_UPSERT_BYTES) + "'",
- "select count(*) from " + B_FAILURE_TABLE + " where k = 'z'"),
+ newArrayList("select count(*) from " + aSuccessTable + " where k='testStatementOrderMaintainedInConnection' or k like 'z%'", // rows left: zz, zzz, checkThatAllStatementTypesMaintainOrderInConnection
+ "select count(*) from " + bFailureTable + " where k = '" + Bytes.toString(ROW_TO_FAIL_UPSERT_BYTES) + "'",
+ "select count(*) from " + bFailureTable + " where k = 'z'"),
transactional ? newArrayList(new Integer(3) /* original rows */, new Integer(0), new Integer(1) /* original row */) : newArrayList(new Integer(4), new Integer(0), new Integer(1)));
}
private void testPartialCommit(List<String> statements, int[] expectedUncommittedStatementIndexes, boolean willFail, List<String> countStatementsForVerification,
- List<Integer> expectedCountsForVerification) {
+ List<Integer> expectedCountsForVerification) throws SQLException {
Preconditions.checkArgument(countStatementsForVerification.size() == expectedCountsForVerification.size());
try (Connection con = getConnectionWithTableOrderPreservingMutationState()) {
@@ -264,7 +246,7 @@ public class PartialCommitIT extends BaseOwnClusterIT {
int[] uncommittedStatementIndexes = ((CommitException)sqle).getUncommittedStatementIndexes();
assertArrayEquals(expectedUncommittedStatementIndexes, uncommittedStatementIndexes);
Map<String, Map<MetricType, Long>> mutationWriteMetrics = PhoenixRuntime.getWriteMetricInfoForMutationsSinceLastReset(con);
- assertEquals(expectedUncommittedStatementIndexes.length, mutationWriteMetrics.get(B_FAILURE_TABLE).get(MUTATION_BATCH_FAILED_SIZE).intValue());
+ assertEquals(expectedUncommittedStatementIndexes.length, mutationWriteMetrics.get(bFailureTable).get(MUTATION_BATCH_FAILED_SIZE).intValue());
assertEquals(expectedUncommittedStatementIndexes.length, GLOBAL_MUTATION_BATCH_FAILED_COUNT.getMetric().getTotalSum());
}
@@ -278,22 +260,20 @@ public class PartialCommitIT extends BaseOwnClusterIT {
}
assertEquals(expectedCountsForVerification.get(i).intValue(), rs.getInt(1));
}
- } catch (SQLException e) {
- fail(e.toString());
}
}
private PhoenixConnection getConnectionWithTableOrderPreservingMutationState() throws SQLException {
- Connection con = driver.connect(url, new Properties());
- PhoenixConnection phxCon = new PhoenixConnection(con.unwrap(PhoenixConnection.class));
- final Map<TableRef, MultiRowMutationState> mutations = Maps.newTreeMap(new TableRefComparator());
- // passing a null mutation state forces the connection.newMutationState() to be used to create the MutationState
- return new PhoenixConnection(phxCon, (MutationState)null) {
- @Override
- protected MutationState newMutationState(int maxSize, int maxSizeBytes) {
- return new MutationState(maxSize, maxSizeBytes, this, mutations, false, null);
+ try (PhoenixConnection con = DriverManager.getConnection(getUrl()).unwrap(PhoenixConnection.class)) {
+ final Map<TableRef, MultiRowMutationState> mutations = Maps.newTreeMap(new TableRefComparator());
+ // passing a null mutation state forces the connection.newMutationState() to be used to create the MutationState
+ return new PhoenixConnection(con, (MutationState)null) {
+ @Override
+ protected MutationState newMutationState(int maxSize, int maxSizeBytes) {
+ return new MutationState(maxSize, maxSizeBytes, this, mutations, false, null);
+ };
};
- };
+ }
}
public static class FailingRegionObserver extends SimpleRegionObserver {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java b/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
index 2211d58..0ddbed3 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
@@ -19,7 +19,6 @@ package org.apache.phoenix.rpc;
import static org.apache.phoenix.util.TestUtil.INDEX_DATA_SCHEMA;
import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.apache.phoenix.util.TestUtil.TRANSACTIONAL_DATA_TABLE;
import static org.junit.Assert.assertFalse;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.eq;
@@ -43,6 +42,7 @@ import org.apache.phoenix.schema.MetaDataClient;
import org.apache.phoenix.schema.PName;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.TestUtil;
@@ -50,7 +50,7 @@ import org.junit.Test;
import org.mockito.Mockito;
/**
- * Verifies the number of rpcs calls from {@link MetaDataClient} updateCache()
+ * Verifies the number of RPC calls from {@link MetaDataClient} updateCache()
* for transactional and non-transactional tables.
*/
public class UpdateCacheIT extends ParallelStatsDisabledIT {
@@ -67,10 +67,15 @@ public class UpdateCacheIT extends ParallelStatsDisabledIT {
@Test
public void testUpdateCacheForTxnTable() throws Exception {
- String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + TRANSACTIONAL_DATA_TABLE;
- Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
- conn.createStatement().execute("create table " + fullTableName + TestUtil.TEST_TABLE_SCHEMA + "TRANSACTIONAL=true");
- helpTestUpdateCache(fullTableName, new int[] {1, 1});
+ for (TransactionFactory.Provider provider : TransactionFactory.Provider.values()) {
+ if (provider.runTests()) {
+ String tableName = generateUniqueName();
+ String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + tableName;
+ Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
+ conn.createStatement().execute("create table " + fullTableName + TestUtil.TEST_TABLE_SCHEMA + "TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + provider + "'");
+ helpTestUpdateCache(fullTableName, new int[] {1, 1});
+ }
+ }
}
@Test
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/schema/stats/StatsCollectorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/schema/stats/StatsCollectorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/schema/stats/StatsCollectorIT.java
index 6eb9411..8fd6d75 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/schema/stats/StatsCollectorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/schema/stats/StatsCollectorIT.java
@@ -87,27 +87,19 @@ public abstract class StatsCollectorIT extends BaseUniqueNamesOwnClusterIT {
private final boolean mutable;
private static final int defaultGuidePostWidth = 20;
- protected StatsCollectorIT(boolean mutable, boolean transactional, boolean userTableNamespaceMapped, boolean columnEncoded) {
+ protected StatsCollectorIT(boolean mutable, String transactionProvider, boolean userTableNamespaceMapped, boolean columnEncoded) {
StringBuilder sb = new StringBuilder();
- if (transactional) {
- sb.append("TRANSACTIONAL=true");
- }
- if (!columnEncoded) {
- if (sb.length()>0) {
- sb.append(",");
- }
- sb.append("COLUMN_ENCODED_BYTES=0");
+ if (columnEncoded) {
+ sb.append("COLUMN_ENCODED_BYTES=4");
} else {
- if (sb.length()>0) {
- sb.append(",");
- }
- sb.append("COLUMN_ENCODED_BYTES=4");
+ sb.append("COLUMN_ENCODED_BYTES=0");
+ }
+
+ if (transactionProvider != null) {
+ sb.append(",TRANSACTIONAL=true, TRANSACTION_PROVIDER='" + transactionProvider + "'");
}
if (!mutable) {
- if (sb.length()>0) {
- sb.append(",");
- }
- sb.append("IMMUTABLE_ROWS=true");
+ sb.append(",IMMUTABLE_ROWS=true");
if (!columnEncoded) {
sb.append(",IMMUTABLE_STORAGE_SCHEME="+PTableImpl.ImmutableStorageScheme.ONE_CELL_PER_COLUMN);
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/tx/FlappingTransactionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/FlappingTransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/FlappingTransactionIT.java
index 0323c32..5ba8dd9 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/FlappingTransactionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/FlappingTransactionIT.java
@@ -19,7 +19,6 @@ package org.apache.phoenix.tx;
import static org.apache.phoenix.util.TestUtil.INDEX_DATA_SCHEMA;
import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.apache.phoenix.util.TestUtil.createTransactionalTable;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -31,22 +30,29 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Properties;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.transaction.PhoenixTransactionContext;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider;
import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.TestUtil;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
/**
*
@@ -54,7 +60,21 @@ import org.junit.Test;
* TODO: review with Tephra community
*
*/
+@RunWith(Parameterized.class)
public class FlappingTransactionIT extends ParallelStatsDisabledIT {
+ private final String txProvider;
+
+ public FlappingTransactionIT(String provider) {
+ txProvider = provider;
+ }
+
+ @Parameters(name="FlappingTransactionIT_transactionProvider={0}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {
+ {"TEPHRA"}, {"OMID"}
+ }),0);
+ }
+
@Test
public void testDelete() throws Exception {
String transTableName = generateUniqueName();
@@ -63,7 +83,7 @@ public class FlappingTransactionIT extends ParallelStatsDisabledIT {
try (Connection conn = DriverManager.getConnection(getUrl());
Connection conn1 = DriverManager.getConnection(getUrl());
Connection conn2 = DriverManager.getConnection(getUrl())) {
- TestUtil.createTransactionalTable(conn, fullTableName);
+ TestUtil.createTransactionalTable(conn, fullTableName, "TRANSACTION_PROVIDER='"+txProvider+"'");
conn1.setAutoCommit(false);
ResultSet rs = conn1.createStatement().executeQuery(selectSQL);
assertFalse(rs.next());
@@ -103,7 +123,7 @@ public class FlappingTransactionIT extends ParallelStatsDisabledIT {
try (Connection conn = DriverManager.getConnection(getUrl());
Connection conn1 = DriverManager.getConnection(getUrl());
Connection conn2 = DriverManager.getConnection(getUrl())) {
- createTransactionalTable(conn, fullTableName);
+ TestUtil.createTransactionalTable(conn, fullTableName, "TRANSACTION_PROVIDER='"+txProvider+"'");
conn1.setAutoCommit(false);
conn2.setAutoCommit(true);
ResultSet rs = conn1.createStatement().executeQuery(selectSQL);
@@ -136,8 +156,11 @@ public class FlappingTransactionIT extends ParallelStatsDisabledIT {
rs = conn2.createStatement().executeQuery("SELECT count(*) FROM " + fullTableName + " WHERE int_col1 = 1");
assertTrue(rs.next());
assertEquals(0, rs.getInt(1));
+ // this succeeds rs = conn2.createStatement().executeQuery("SELECT int_col1 FROM " + fullTableName + " WHERE int_col1 = 1");
+ // this fails rs = conn2.createStatement().executeQuery("SELECT * FROM " + fullTableName + " WHERE int_col1 = 1");
rs = conn2.createStatement().executeQuery("SELECT * FROM " + fullTableName + " WHERE int_col1 = 1");
- assertFalse(rs.next());
+ boolean hasNext = rs.next();
+ assertFalse(hasNext);
conn1.commit();
@@ -158,7 +181,7 @@ public class FlappingTransactionIT extends ParallelStatsDisabledIT {
try (Connection conn = DriverManager.getConnection(getUrl());
Connection conn1 = DriverManager.getConnection(getUrl());
Connection conn2 = DriverManager.getConnection(getUrl())) {
- createTransactionalTable(conn, fullTableName);
+ TestUtil.createTransactionalTable(conn, fullTableName, "TRANSACTION_PROVIDER='"+txProvider+"'");
conn1.setAutoCommit(false);
conn2.setAutoCommit(true);
ResultSet rs = conn1.createStatement().executeQuery(selectSQL);
@@ -212,7 +235,7 @@ public class FlappingTransactionIT extends ParallelStatsDisabledIT {
PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
Statement stmt = conn.createStatement();
- stmt.execute("CREATE TABLE " + fullTableName + "(K VARCHAR PRIMARY KEY, V1 VARCHAR, V2 VARCHAR) TRANSACTIONAL=true");
+ stmt.execute("CREATE TABLE " + fullTableName + "(K VARCHAR PRIMARY KEY, V1 VARCHAR, V2 VARCHAR) TRANSACTIONAL=true,TRANSACTION_PROVIDER='"+txProvider+"'");
HTableInterface htable = pconn.getQueryServices().getTable(Bytes.toBytes(fullTableName));
stmt.executeUpdate("upsert into " + fullTableName + " values('x', 'a', 'a')");
conn.commit();
@@ -223,12 +246,14 @@ public class FlappingTransactionIT extends ParallelStatsDisabledIT {
assertEquals(1,rs.getInt(1));
}
- PhoenixTransactionContext txContext =
- TransactionFactory.getTransactionProvider(TransactionFactory.Provider.TEPHRA).getTransactionContext(pconn);
- HTableInterface txTable =
- txContext.getTransactionalTable(htable, false);
- txContext.begin();
+ PhoenixTransactionProvider provider = TransactionFactory.Provider.valueOf(txProvider).getTransactionProvider();
+ PhoenixTransactionContext txContext = provider.getTransactionContext(pconn);
+ // FIXME: must begin txn before getting transactional table
+ // Either set txn on all existing OmidTransactionTable or throw exception
+ // when attempting to get OmidTransactionTable if a txn is not in progress.
+ txContext.begin();
+ Table txTable = txContext.getTransactionalTable(htable, false);
// Use HBase APIs to add a new row
Put put = new Put(Bytes.toBytes("z"));
@@ -275,12 +300,10 @@ public class FlappingTransactionIT extends ParallelStatsDisabledIT {
}
// Repeat the same as above, but this time abort the transaction
- txContext =
- TransactionFactory.getTransactionProvider(TransactionFactory.Provider.TEPHRA).getTransactionContext(pconn);
- txTable =
- txContext.getTransactionalTable(htable, false);
-
+ txContext = provider.getTransactionContext(pconn);
txContext.begin();
+ txTable = txContext.getTransactionalTable(htable, false);
+
// Use HBase APIs to add a new row
put = new Put(Bytes.toBytes("j"));
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/tx/ParameterizedTransactionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/ParameterizedTransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/ParameterizedTransactionIT.java
index ec1cf3a..f94ec17 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/ParameterizedTransactionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/ParameterizedTransactionIT.java
@@ -41,6 +41,7 @@ import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.coprocessor.RegionObserver;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.coprocessor.TephraTransactionalProcessor;
import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
@@ -54,6 +55,9 @@ import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.transaction.PhoenixTransactionContext;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider.Feature;
+import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.TestUtil;
@@ -68,29 +72,39 @@ import com.google.common.collect.Lists;
public class ParameterizedTransactionIT extends ParallelStatsDisabledIT {
private final String tableDDLOptions;
+ private final String tableDDLOptionsWithoutProvider;
+ private final PhoenixTransactionProvider transactionProvider;
- public ParameterizedTransactionIT(boolean mutable, boolean columnEncoded) {
+ public ParameterizedTransactionIT(Boolean mutable, Boolean columnEncoded, String transactionProvider) {
StringBuilder optionBuilder = new StringBuilder();
+ optionBuilder.append("TRANSACTION_PROVIDER='"+transactionProvider+"',");
+ this.transactionProvider = TransactionFactory.Provider.valueOf(transactionProvider).getTransactionProvider();
+ StringBuilder optionBuilder2 = new StringBuilder();
if (!columnEncoded) {
- optionBuilder.append("COLUMN_ENCODED_BYTES=0");
+ optionBuilder2.append("COLUMN_ENCODED_BYTES=0,");
}
if (!mutable) {
- if (optionBuilder.length() > 0) {
- optionBuilder.append(",");
- }
- optionBuilder.append("IMMUTABLE_ROWS=true");
+ optionBuilder2.append("IMMUTABLE_ROWS=true,");
if (!columnEncoded) {
- optionBuilder.append(",IMMUTABLE_STORAGE_SCHEME="+PTableImpl.ImmutableStorageScheme.ONE_CELL_PER_COLUMN);
+ optionBuilder2.append("IMMUTABLE_STORAGE_SCHEME="+PTableImpl.ImmutableStorageScheme.ONE_CELL_PER_COLUMN +",");
}
}
+ if (optionBuilder2.length() > 0) {
+ optionBuilder2.setLength(optionBuilder2.length()-1);
+ optionBuilder.append(optionBuilder2);
+ } else {
+ optionBuilder.setLength(optionBuilder.length()-1);
+ }
this.tableDDLOptions = optionBuilder.toString();
+ this.tableDDLOptionsWithoutProvider = optionBuilder2.toString();
}
- @Parameters(name="TransactionIT_mutable={0},columnEncoded={1}") // name is used by failsafe as file name in reports
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- {false, false }, {false, true }, {true, false }, { true, true },
- });
+ @Parameters(name="ParameterizedTransactionIT_mutable={0},columnEncoded={1},transactionProvider={2}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {
+ {false, false, "TEPHRA" }, {false, true, "TEPHRA" }, {true, false, "TEPHRA" }, { true, true, "TEPHRA" },
+ {false, false, "OMID" }, {true, false, "OMID" },
+ }), 2);
}
@Test
@@ -134,7 +148,8 @@ public class ParameterizedTransactionIT extends ParallelStatsDisabledIT {
String fullTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + transTableName;
String selectSql = "SELECT * FROM "+fullTableName;
try (Connection conn = DriverManager.getConnection(getUrl())) {
- conn.createStatement().execute("create table " + fullTableName + TestUtil.TEST_TABLE_SCHEMA + tableDDLOptions + (tableDDLOptions.length() > 0 ? "," : "") + "TRANSACTIONAL=true");
+ String ddl = "create table " + fullTableName + TestUtil.TEST_TABLE_SCHEMA + tableDDLOptions + (tableDDLOptions.length() > 0 ? "," : "") + "TRANSACTIONAL=true";
+ conn.createStatement().execute(ddl);
conn.setAutoCommit(false);
ResultSet rs = conn.createStatement().executeQuery(selectSql);
assertFalse(rs.next());
@@ -263,7 +278,7 @@ public class ParameterizedTransactionIT extends ParallelStatsDisabledIT {
String nonTxTableName = generateUniqueName();
Connection conn = DriverManager.getConnection(getUrl());
- conn.createStatement().execute("CREATE TABLE " + nonTxTableName + "(k INTEGER PRIMARY KEY, v VARCHAR)" + tableDDLOptions);
+ conn.createStatement().execute("CREATE TABLE " + nonTxTableName + "(k INTEGER PRIMARY KEY, v VARCHAR)" + tableDDLOptionsWithoutProvider);
conn.createStatement().execute("UPSERT INTO " + nonTxTableName + " VALUES (1)");
conn.createStatement().execute("UPSERT INTO " + nonTxTableName + " VALUES (2, 'a')");
conn.createStatement().execute("UPSERT INTO " + nonTxTableName + " VALUES (3, 'b')");
@@ -279,7 +294,19 @@ public class ParameterizedTransactionIT extends ParallelStatsDisabledIT {
}
htable.put(puts);
- conn.createStatement().execute("ALTER TABLE " + nonTxTableName + " SET TRANSACTIONAL=true");
+ try {
+ conn.createStatement().execute("ALTER TABLE " + nonTxTableName + " SET TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + transactionProvider + "'");
+ if (transactionProvider.isUnsupported(Feature.ALTER_NONTX_TO_TX)) {
+ fail();
+ }
+ } catch (SQLException e) {
+ if (transactionProvider.isUnsupported(Feature.ALTER_NONTX_TO_TX)) {
+ assertEquals(SQLExceptionCode.CANNOT_ALTER_TABLE_FROM_NON_TXN_TO_TXNL.getErrorCode(), e.getErrorCode());
+ return;
+ } else {
+ throw e;
+ }
+ }
htable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes( nonTxTableName));
assertTrue(htable.getTableDescriptor().getCoprocessors().contains(TephraTransactionalProcessor.class.getName()));
@@ -328,7 +355,7 @@ public class ParameterizedTransactionIT extends ParallelStatsDisabledIT {
Connection conn = DriverManager.getConnection(getUrl());
// Put table in SYSTEM schema to prevent attempts to update the cache after we disable SYSTEM.CATALOG
- conn.createStatement().execute("CREATE TABLE \"SYSTEM\"." + nonTxTableName + "(k INTEGER PRIMARY KEY, v VARCHAR)" + tableDDLOptions);
+ conn.createStatement().execute("CREATE TABLE \"SYSTEM\"." + nonTxTableName + "(k INTEGER PRIMARY KEY, v VARCHAR)" + tableDDLOptionsWithoutProvider);
conn.createStatement().execute("UPSERT INTO \"SYSTEM\"." + nonTxTableName + " VALUES (1)");
conn.commit();
// Reset empty column value to an empty value like it is pre-transactions
@@ -343,10 +370,14 @@ public class ParameterizedTransactionIT extends ParallelStatsDisabledIT {
// This will succeed initially in updating the HBase metadata, but then will fail when
// the SYSTEM.CATALOG table is attempted to be updated, exercising the code to restore
// the coprocessors back to the non transactional ones.
- conn.createStatement().execute("ALTER TABLE \"SYSTEM\"." + nonTxTableName + " SET TRANSACTIONAL=true");
+ conn.createStatement().execute("ALTER TABLE \"SYSTEM\"." + nonTxTableName + " SET TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + transactionProvider + "'");
fail();
} catch (SQLException e) {
- assertTrue(e.getMessage().contains(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME + " is disabled"));
+ if (transactionProvider.isUnsupported(Feature.ALTER_NONTX_TO_TX)) {
+ assertEquals(SQLExceptionCode.CANNOT_ALTER_TABLE_FROM_NON_TXN_TO_TXNL.getErrorCode(), e.getErrorCode());
+ } else {
+ assertTrue(e.getMessage().contains(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME + " is disabled"));
+ }
} finally {
admin.enableTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME);
admin.close();
@@ -358,7 +389,8 @@ public class ParameterizedTransactionIT extends ParallelStatsDisabledIT {
assertFalse(rs.next());
htable = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes("SYSTEM." + nonTxTableName));
- assertFalse(htable.getTableDescriptor().getCoprocessors().contains(TephraTransactionalProcessor.class.getName()));
+ Class<? extends RegionObserver> clazz = transactionProvider.getCoprocessor();
+ assertFalse(htable.getTableDescriptor().getCoprocessors().contains(clazz.getName()));
assertEquals(1,conn.unwrap(PhoenixConnection.class).getQueryServices().
getTableDescriptor(Bytes.toBytes("SYSTEM." + nonTxTableName)).
getFamily(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES).getMaxVersions());
@@ -376,7 +408,8 @@ public class ParameterizedTransactionIT extends ParallelStatsDisabledIT {
PTable table = pconn.getTable(new PTableKey(null, t1));
HTableInterface htable = pconn.getQueryServices().getTable(Bytes.toBytes(t1));
assertTrue(table.isTransactional());
- assertTrue(htable.getTableDescriptor().getCoprocessors().contains(TephraTransactionalProcessor.class.getName()));
+ Class<? extends RegionObserver> clazz = transactionProvider.getCoprocessor();
+ assertTrue(htable.getTableDescriptor().getCoprocessors().contains(clazz.getName()));
try {
ddl = "ALTER TABLE " + t1 + " SET transactional=false";
@@ -390,8 +423,19 @@ public class ParameterizedTransactionIT extends ParallelStatsDisabledIT {
HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(t2));
desc.addFamily(new HColumnDescriptor(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES));
admin.createTable(desc);
- ddl = "CREATE TABLE " + t2 + " (k varchar primary key) transactional=true";
- conn.createStatement().execute(ddl);
+ try {
+ ddl = "CREATE TABLE " + t2 + " (k varchar primary key) transactional=true,transaction_provider='" + transactionProvider + "'";
+ conn.createStatement().execute(ddl);
+ if (transactionProvider.isUnsupported(Feature.ALTER_NONTX_TO_TX)) {
+ fail();
+ }
+ } catch (SQLException e) {
+ if (transactionProvider.isUnsupported(Feature.ALTER_NONTX_TO_TX)) {
+ assertEquals(SQLExceptionCode.CANNOT_ALTER_TABLE_FROM_NON_TXN_TO_TXNL.getErrorCode(), e.getErrorCode());
+ return;
+ }
+ throw e;
+ }
HTableDescriptor htableDescriptor = admin.getTableDescriptor(TableName.valueOf(t2));
String str = htableDescriptor.getValue(PhoenixTransactionContext.READ_NON_TX_DATA);
@@ -405,12 +449,12 @@ public class ParameterizedTransactionIT extends ParallelStatsDisabledIT {
} catch (SQLException e) {
assertEquals(SQLExceptionCode.TX_MAY_NOT_SWITCH_TO_NON_TX.getErrorCode(), e.getErrorCode());
}
- ddl += " transactional=true";
+ ddl += " transactional=true,transaction_provider='" + transactionProvider + "'";
conn.createStatement().execute(ddl);
table = pconn.getTable(new PTableKey(null, t1));
htable = pconn.getQueryServices().getTable(Bytes.toBytes(t1));
assertTrue(table.isTransactional());
- assertTrue(htable.getTableDescriptor().getCoprocessors().contains(TephraTransactionalProcessor.class.getName()));
+ assertTrue(htable.getTableDescriptor().getCoprocessors().contains(clazz.getName()));
}
@Test
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
index 12c3b7a..b1866db 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
@@ -35,13 +35,22 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
import java.util.Properties;
+import org.apache.hadoop.hbase.DoNotRetryIOException;
+import org.apache.hadoop.hbase.HBaseIOException;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.Mutation;
+import org.apache.hadoop.hbase.coprocessor.ObserverContext;
+import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+import org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver;
+import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
import org.apache.phoenix.exception.SQLExceptionCode;
@@ -52,6 +61,8 @@ import org.apache.phoenix.query.QueryServicesOptions;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.transaction.PhoenixTransactionContext;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider.Feature;
import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.EnvironmentEdgeManager;
import org.apache.phoenix.util.PhoenixRuntime;
@@ -64,6 +75,8 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
+import com.google.common.collect.Lists;
+
@RunWith(Parameterized.class)
public class TransactionIT extends ParallelStatsDisabledIT {
private final String txProvider;
@@ -75,12 +88,117 @@ public class TransactionIT extends ParallelStatsDisabledIT {
}
@Parameters(name="TransactionIT_provider={0}") // name is used by failsafe as file name in reports
- public static Collection<String[]> data() {
- return Arrays.asList(new String[][] {
- {"TEPHRA"/*,"OMID"*/}});
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {
+ {"TEPHRA"},{"OMID"}}),0);
}
@Test
+ public void testFailureToRollbackAfterDelete() throws Exception {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ String tableName = generateUniqueName();
+ conn.createStatement().execute(
+ "CREATE TABLE " + tableName + " (k VARCHAR NOT NULL PRIMARY KEY) TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + txProvider + "'");
+ conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('a')");
+ conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('b')");
+ conn.commit();
+ // Delete a in new transaction
+ conn.createStatement().execute("DELETE FROM " + tableName + " WHERE k='a'");
+ // Forces data to be written to HBase, but not yet committed
+ conn.createStatement().executeQuery("SELECT * FROM " + tableName).next();
+ // Upsert another row so commit below will fail the write (and fail subsequent attempt t o abort)
+ conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('c')");
+ TestUtil.addCoprocessor(conn, tableName, WriteFailingRegionObserver.class);
+ try {
+ conn.commit();
+ fail();
+ } catch (SQLException e) {
+ }
+ // Delete of a shouldn't be visible since commit failed, so all rows should be present
+ ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName);
+ assertTrue(rs.next());
+ assertEquals("a", rs.getString(1));
+ assertTrue(rs.next());
+ assertEquals("b", rs.getString(1));
+ assertFalse(rs.next());
+ }
+ }
+
+ public static class WriteFailingRegionObserver extends SimpleRegionObserver {
+ @Override
+ public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws HBaseIOException {
+ throw new DoNotRetryIOException();
+ }
+ }
+
+ @Test
+ public void testWithMixOfTxProviders() throws Exception {
+ // No sense in running the test with every providers, so just run it with the default one
+ if (!TransactionFactory.Provider.valueOf(txProvider).equals(TransactionFactory.Provider.getDefault())) {
+ return;
+ }
+ List<String> tableNames = Lists.newArrayList();
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ for (TransactionFactory.Provider provider : TransactionFactory.Provider.values()) {
+ if (provider.runTests()) {
+ String tableName = generateUniqueName();
+ tableNames.add(tableName);
+ conn.createStatement().execute(
+ "CREATE TABLE " + tableName + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR) TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + provider + "'");
+ }
+ }
+ if (tableNames.size() < 2) {
+ return;
+ }
+ Iterator<String> iterator = tableNames.iterator();
+ String tableName1 = iterator.next();
+ conn.createStatement().execute("UPSERT INTO " + tableName1 + " VALUES('a')");
+ String tableName2 = iterator.next();
+ try {
+ conn.createStatement().execute("UPSERT INTO " + tableName2 + " VALUES('a')");
+ fail();
+ } catch (SQLException e) {
+ assertEquals(SQLExceptionCode.CANNOT_MIX_TXN_PROVIDERS.getErrorCode(), e.getErrorCode());
+ }
+
+ conn.rollback();
+ conn.setAutoCommit(true);
+ for (String tableName : tableNames) {
+ conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('a')");
+ }
+ for (String tableName : tableNames) {
+ ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName);
+ assertTrue(rs.next());
+ assertEquals("a", rs.getString(1));
+ assertFalse(rs.next());
+ }
+ }
+ }
+
+ @Test
+ public void testPreventLocalIndexCreation() throws Exception {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ for (TransactionFactory.Provider provider : TransactionFactory.Provider.values()) {
+ if (provider.runTests() && provider.getTransactionProvider().isUnsupported(PhoenixTransactionProvider.Feature.ALLOW_LOCAL_INDEX)) {
+ String tableName = generateUniqueName();
+ conn.createStatement().execute(
+ "CREATE TABLE " + tableName + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR) TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + provider + "'");
+ String indexName = generateUniqueName();
+ try {
+ conn.createStatement().execute("CREATE LOCAL INDEX " + indexName + "_IDX ON " + tableName + " (v1) INCLUDE(v2)");
+ fail();
+ } catch (SQLException e) {
+ assertEquals(SQLExceptionCode.CANNOT_CREATE_LOCAL_INDEX_FOR_TXN_TABLE.getErrorCode(), e.getErrorCode());
+ }
+ }
+ }
+ }
+ }
+
+ @Test
public void testQueryWithSCN() throws Exception {
String tableName = generateUniqueName();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
@@ -102,7 +220,7 @@ public class TransactionIT extends ParallelStatsDisabledIT {
}
@Test
- public void testReCreateTxnTableAfterDroppingExistingNonTxnTable() throws SQLException {
+ public void testReCreateTxnTableAfterDroppingExistingNonTxnTable() throws Exception {
String tableName = generateUniqueName();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
@@ -110,6 +228,10 @@ public class TransactionIT extends ParallelStatsDisabledIT {
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE " + tableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
stmt.execute("DROP TABLE " + tableName);
+ // Must drop metadata as Omid does not allow creating a transactional table from a non transactional one
+ Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+ admin.disableTable(TableName.valueOf(tableName));
+ admin.deleteTable(TableName.valueOf(tableName));
stmt.execute("CREATE TABLE " + tableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) TRANSACTIONAL=true," + tableDDLOptions);
stmt.execute("CREATE INDEX " + tableName + "_IDX ON " + tableName + " (v1) INCLUDE(v2)");
assertTrue(conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, tableName)).isTransactional());
@@ -210,11 +332,11 @@ public class TransactionIT extends ParallelStatsDisabledIT {
try {
conn.createStatement().execute("ALTER TABLE " + nonTxTableName + "1 SET TRANSACTIONAL=true," + tableDDLOptions);
- if (TransactionFactory.Provider.OMID.name().equals(txProvider)) {
- fail("Omid shouldn't allow converting a non transactional table to be transactional");
+ if (TransactionFactory.Provider.valueOf(txProvider).getTransactionProvider().isUnsupported(Feature.ALTER_NONTX_TO_TX)) {
+ fail(txProvider + " should not allow converting a non transactional table to be transactional");
}
} catch (SQLException e) { // Should fail for Omid, but not Tephra
- if (TransactionFactory.Provider.TEPHRA.name().equals(txProvider)) {
+ if (!TransactionFactory.Provider.valueOf(txProvider).getTransactionProvider().isUnsupported(Feature.ALTER_NONTX_TO_TX)) {
throw e;
}
assertEquals(SQLExceptionCode.CANNOT_ALTER_TABLE_FROM_NON_TXN_TO_TXNL.getErrorCode(), e.getErrorCode());
@@ -247,7 +369,7 @@ public class TransactionIT extends ParallelStatsDisabledIT {
}
conn.createStatement().execute("CREATE TABLE " + nonTxTableName + "2(k INTEGER PRIMARY KEY, a.v VARCHAR, b.v VARCHAR, c.v VARCHAR)");
- conn.createStatement().execute("ALTER TABLE " + nonTxTableName + "2 SET TRANSACTIONAL=true, VERSIONS=10");
+ conn.createStatement().execute("ALTER TABLE " + nonTxTableName + "2 SET TRANSACTIONAL=true, VERSIONS=10, " + tableDDLOptions);
desc = conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes( nonTxTableName + "2"));
for (HColumnDescriptor colDesc : desc.getFamilies()) {
assertEquals(10, colDesc.getMaxVersions());
@@ -376,6 +498,7 @@ public class TransactionIT extends ParallelStatsDisabledIT {
}
}
+
private static void assertTTL(Admin admin, String tableName, int ttl) throws TableNotFoundException, IOException {
HTableDescriptor tableDesc = admin.getTableDescriptor(TableName.valueOf(tableName));
for (HColumnDescriptor colDesc : tableDesc.getFamilies()) {
@@ -388,16 +511,39 @@ public class TransactionIT extends ParallelStatsDisabledIT {
public void testSetTTL() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
TransactionFactory.Provider txProvider = TransactionFactory.Provider.valueOf(this.txProvider);
- try (Connection conn = DriverManager.getConnection(getUrl(), props); Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
+ try (Connection conn = DriverManager.getConnection(getUrl(), props);
+ Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
String tableName = generateUniqueName();
- conn.createStatement().execute("CREATE TABLE " + tableName +
- "(K VARCHAR PRIMARY KEY) TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + txProvider + "',TTL=100");
- assertTTL(admin, tableName, 100);
+ try {
+ conn.createStatement().execute("CREATE TABLE " + tableName +
+ "(K VARCHAR PRIMARY KEY) TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + txProvider + "',TTL=100");
+ if (txProvider.getTransactionProvider().isUnsupported(Feature.SET_TTL)) {
+ fail();
+ }
+ assertTTL(admin, tableName, 100);
+ } catch (SQLException e) {
+ if (txProvider.getTransactionProvider().isUnsupported(Feature.SET_TTL)) {
+ assertEquals(SQLExceptionCode.TTL_UNSUPPORTED_FOR_TXN_TABLE.getErrorCode(), e.getErrorCode());
+ } else {
+ throw e;
+ }
+ }
tableName = generateUniqueName();
conn.createStatement().execute("CREATE TABLE " + tableName +
"(K VARCHAR PRIMARY KEY) TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + txProvider + "'");
- conn.createStatement().execute("ALTER TABLE " + tableName + " SET TTL=" + 200);
- assertTTL(admin, tableName, 200);
+ try {
+ conn.createStatement().execute("ALTER TABLE " + tableName + " SET TTL=" + 200);
+ if (txProvider.getTransactionProvider().isUnsupported(Feature.SET_TTL)) {
+ fail();
+ }
+ assertTTL(admin, tableName, 200);
+ } catch (SQLException e) {
+ if (txProvider.getTransactionProvider().isUnsupported(Feature.SET_TTL)) {
+ assertEquals(SQLExceptionCode.TTL_UNSUPPORTED_FOR_TXN_TABLE.getErrorCode(), e.getErrorCode());
+ } else {
+ throw e;
+ }
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
index 42e2102..f8946e5 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
@@ -38,9 +38,9 @@ import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.transaction.PhoenixTransactionContext.PhoenixVisibilityLevel;
-import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.TestUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -52,18 +52,15 @@ public class TxCheckpointIT extends ParallelStatsDisabledIT {
private final boolean localIndex;
private final String tableDDLOptions;
- public TxCheckpointIT(boolean localIndex, boolean mutable, boolean columnEncoded) {
+ public TxCheckpointIT(boolean localIndex, boolean mutable, boolean columnEncoded, String transactionProvider) {
StringBuilder optionBuilder = new StringBuilder();
+ optionBuilder.append("TRANSACTION_PROVIDER='" + transactionProvider + "'");
this.localIndex = localIndex;
if (!columnEncoded) {
- if (optionBuilder.length()!=0)
- optionBuilder.append(",");
- optionBuilder.append("COLUMN_ENCODED_BYTES=0");
+ optionBuilder.append(",COLUMN_ENCODED_BYTES=0");
}
if (!mutable) {
- if (optionBuilder.length()!=0)
- optionBuilder.append(",");
- optionBuilder.append("IMMUTABLE_ROWS=true");
+ optionBuilder.append(",IMMUTABLE_ROWS=true");
if (!columnEncoded) {
optionBuilder.append(",IMMUTABLE_STORAGE_SCHEME="+PTableImpl.ImmutableStorageScheme.ONE_CELL_PER_COLUMN);
}
@@ -81,12 +78,13 @@ public class TxCheckpointIT extends ParallelStatsDisabledIT {
return conn;
}
- @Parameters(name="TxCheckpointIT_localIndex={0},mutable={1},columnEncoded={2}") // name is used by failsafe as file name in reports
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { false, false, false }, { false, false, true }, { false, true, false }, { false, true, true },
- { true, false, false }, { true, false, true }, { true, true, false }, { true, true, true }
- });
+ @Parameters(name="TxCheckpointIT_localIndex={0},mutable={1},columnEncoded={2},transactionProvider={3}") // name is used by failsafe as file name in reports
+ public static Collection<Object[]> data() {
+ return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {
+ { false, false, false, "TEPHRA" }, { false, false, true, "TEPHRA" }, { false, true, false, "TEPHRA" }, { false, true, true, "TEPHRA" },
+ { true, false, false, "TEPHRA" }, { true, false, true, "TEPHRA" }, { true, true, false, "TEPHRA" }, { true, true, true, "TEPHRA" },
+ { false, false, false, "OMID" }, { false, true, false, "OMID" },
+ }),3);
}
@Test
@@ -133,7 +131,6 @@ public class TxCheckpointIT extends ParallelStatsDisabledIT {
}
private void testRollbackOfUncommittedDelete(String indexDDL, String fullTableName) throws Exception {
- Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = getConnection();
conn.setAutoCommit(false);
try {
@@ -179,7 +176,15 @@ public class TxCheckpointIT extends ParallelStatsDisabledIT {
assertEquals("a2", rs.getString(3));
assertFalse(rs.next());
- //assert row is delete in index table
+ // assert row is deleted in data table
+ rs = stmt.executeQuery("select k, v1, v2 from " + fullTableName + " ORDER BY k");
+ assertTrue(rs.next());
+ assertEquals("x2", rs.getString(1));
+ assertEquals("y2", rs.getString(2));
+ assertEquals("a2", rs.getString(3));
+ assertFalse(rs.next());
+
+ // assert row is deleted in index table
rs = stmt.executeQuery("select k, v1, v2 from " + fullTableName + " ORDER BY v1");
assertTrue(rs.next());
assertEquals("x2", rs.getString(1));
@@ -189,7 +194,7 @@ public class TxCheckpointIT extends ParallelStatsDisabledIT {
conn.rollback();
- //assert two rows in data table
+ // assert two rows in data table
rs = stmt.executeQuery("select k, v1, v2 from " + fullTableName + " ORDER BY k");
assertTrue(rs.next());
assertEquals("x1", rs.getString(1));
@@ -201,7 +206,7 @@ public class TxCheckpointIT extends ParallelStatsDisabledIT {
assertEquals("a2", rs.getString(3));
assertFalse(rs.next());
- //assert two rows in index table
+ // assert two rows in index table
rs = stmt.executeQuery("select k, v1, v2 from " + fullTableName + " ORDER BY v1");
assertTrue(rs.next());
assertEquals("x1", rs.getString(1)); // fails here
@@ -266,7 +271,7 @@ public class TxCheckpointIT extends ParallelStatsDisabledIT {
ResultSet rs;
MutationState state = conn.unwrap(PhoenixConnection.class)
.getMutationState();
- state.startTransaction(TransactionFactory.Provider.TEPHRA);
+ conn.createStatement().executeQuery("select 1 from " + fullTableName + " LIMIT 1").next();
long wp = state.getWritePointer();
conn.createStatement().execute(
"upsert into " + fullTableName + " select max(id)+1, 'a4', 'b4' from " + fullTableName + "");
@@ -330,7 +335,8 @@ public class TxCheckpointIT extends ParallelStatsDisabledIT {
conn.commit();
MutationState state = conn.unwrap(PhoenixConnection.class).getMutationState();
- state.startTransaction(TransactionFactory.Provider.TEPHRA);
+ // Start a new transaction
+ stmt.executeQuery("select 1 from " + fullTableName + "1 LIMIT 1").next();
long wp = state.getWritePointer();
conn.createStatement().execute("delete from " + fullTableName + "1 where id1=fk1b AND fk1b=id1");
assertEquals(PhoenixVisibilityLevel.SNAPSHOT, state.getVisibilityLevel());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
index c2dfeab..583085e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
@@ -86,6 +86,7 @@ import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.TableRef;
import org.apache.phoenix.schema.tuple.Tuple;
import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider.Feature;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.IndexUtil;
import org.apache.phoenix.util.MetaDataUtil;
@@ -974,7 +975,9 @@ public class DeleteCompiler {
private static boolean isMaintainedOnClient(PTable table) {
// Test for not being local (rather than being GLOBAL) so that this doesn't fail
// when tested with our projected table.
- return table.getIndexType() != IndexType.LOCAL && (table.isImmutableRows() || table.isTransactional());
+ return (table.getIndexType() != IndexType.LOCAL && (table.isTransactional() || table.isImmutableRows())) ||
+ (table.getIndexType() == IndexType.LOCAL && (table.isTransactional() &&
+ table.getTransactionProvider().getTransactionProvider().isUnsupported(Feature.MAINTAIN_LOCAL_INDEX_ON_SERVER) ) );
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/fd9af912/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java
index f34c5a3..ba6d10c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostLocalIndexDDLCompiler.java
@@ -89,6 +89,9 @@ public class PostLocalIndexDDLCompiler {
scan.addColumn(columnRef.getFamily(), columnRef.getQualifier());
}
}
+ if (dataTable.isTransactional()) {
+ scan.setAttribute(BaseScannerRegionObserver.TX_STATE, connection.getMutationState().encodeTransaction());
+ }
// Go through MutationPlan abstraction so that we can create local indexes
// with a connectionless connection (which makes testing easier).