Skip to content

Commit

Permalink
PHOENIX-5104: breaks client backwards compatibility
Browse files Browse the repository at this point in the history
Fixing by adding a new connection property "phoenix.index.longViewIndex.enabled" which is by default false.
Clients can set this property to true to be able to use longViewIndexes on phoenix 4.x version. This feature is by default avaiable to phoenix version 5 and above.
  • Loading branch information
Mehdi Salarkia committed Jul 15, 2019
1 parent a36efb1 commit 89404a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Expand Up @@ -352,6 +352,8 @@ public interface QueryServices extends SQLCloseable {
public static final String GLOBAL_INDEX_ROW_REPAIR_COUNT_ATTRIB = "phoenix.global.index.row.repair.count.ms";
// Enable the IndexRegionObserver Coprocessor
public static final String INDEX_REGION_OBSERVER_ENABLED_ATTRIB = "phoenix.index.region.observer.enabled";
// Enable support for long view index(default is false for clients below version 4)
public static final String LONG_VIEW_INDEX_ENABLED_ATTRIB = "phoenix.index.longViewIndex.enabled";


// Before 4.15 when we created a view we included the parent table column metadata in the view
Expand Down
Expand Up @@ -97,6 +97,7 @@
import static org.apache.phoenix.query.QueryConstants.DEFAULT_COLUMN_FAMILY;
import static org.apache.phoenix.query.QueryConstants.ENCODED_CQ_COUNTER_INITIAL_VALUE;
import static org.apache.phoenix.query.QueryServices.DROP_METADATA_ATTRIB;
import static org.apache.phoenix.query.QueryServices.LONG_VIEW_INDEX_ENABLED_ATTRIB;
import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_DROP_METADATA;
import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_RUN_UPDATE_STATS_ASYNC;
import static org.apache.phoenix.schema.PTable.EncodedCQCounter.NULL_COUNTER;
Expand Down Expand Up @@ -1507,6 +1508,16 @@ public MutationState close(CloseStatement statement) throws SQLException {
return new MutationState(0, 0, connection);
}

/**
* Supprort long viewIndexId only if client has explicitly set
* the QueryServices.LONG_VIEW_INDEX_ENABLED_ATTRIB connection property to 'true'.
* @return
*/
private PDataType getViewIndexDataType() throws SQLException {
boolean supportsLongViewIndexId = "true".equalsIgnoreCase(connection.getClientInfo(LONG_VIEW_INDEX_ENABLED_ATTRIB));
return supportsLongViewIndexId ? MetaDataUtil.getViewIndexIdDataType() : MetaDataUtil.getLegacyViewIndexIdDataType();
}

/**
* Create an index table by morphing the CreateIndexStatement into a CreateTableStatement and calling
* MetaDataClient.createTable. In doing so, we perform the following translations:
Expand Down Expand Up @@ -1604,7 +1615,7 @@ public MutationState createIndex(CreateIndexStatement statement, byte[][] splits
*/
if (isLocalIndex || (dataTable.getType() == PTableType.VIEW && dataTable.getViewType() != ViewType.MAPPED)) {
allocateIndexId = true;
PDataType dataType = MetaDataUtil.getViewIndexIdDataType();
PDataType dataType = getViewIndexDataType();
ColumnName colName = ColumnName.caseSensitiveColumnName(MetaDataUtil.getViewIndexIdColumnName());
allPkColumns.add(new ColumnDefInPkConstraint(colName, SortOrder.getDefault(), false));
columnDefs.add(FACTORY.columnDef(colName, dataType.getSqlTypeName(), false, null, null, false, SortOrder.getDefault(), null, false));
Expand Down

0 comments on commit 89404a4

Please sign in to comment.