PHOENIX-1644 Check for min HBase version before creating local index and provide means of disabling usage
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/2b8e6634 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/2b8e6634 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/2b8e6634 Branch: refs/heads/master Commit: 2b8e66346d2c890ff664c9f2f826acb77a7ac950 Parents: 47ca595 Author: James Taylor <[email protected]> Authored: Fri Feb 6 18:26:57 2015 -0800 Committer: James Taylor <[email protected]> Committed: Fri Feb 6 18:26:57 2015 -0800 ---------------------------------------------------------------------- .../phoenix/exception/SQLExceptionCode.java | 3 ++- .../phoenix/jdbc/PhoenixDatabaseMetaData.java | 3 ++- .../phoenix/query/ConnectionQueryServices.java | 2 +- .../query/ConnectionQueryServicesImpl.java | 24 ++++++++++++++++---- .../query/ConnectionlessQueryServicesImpl.java | 2 +- .../apache/phoenix/schema/MetaDataClient.java | 3 ++- 6 files changed, 28 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/2b8e6634/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 19e7cdf..b2ca979 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 @@ -236,7 +236,8 @@ public enum SQLExceptionCode { CANNOT_SET_PROPERTY_FOR_COLUMN_NOT_ADDED(1052, "43A09", "Property cannot be specified for a column family that is not being added or modified"), CANNOT_SET_TABLE_PROPERTY_ADD_COLUMN(1053, "43A10", "Table level property cannot be set when adding a column"), - NO_LOCAL_INDEXES(1054, "43A11", "Local secondary indexes are only supported for HBase version " + MetaDataUtil.decodeHBaseVersionAsString(PhoenixDatabaseMetaData.LOCAL_SI_VERSION_THRESHOLD) + " and above."), + NO_LOCAL_INDEXES(1054, "43A11", "Local secondary indexes are not supported for HBase versions " + + MetaDataUtil.decodeHBaseVersionAsString(PhoenixDatabaseMetaData.MIN_LOCAL_SI_VERSION_DISALLOW) + " through " + MetaDataUtil.decodeHBaseVersionAsString(PhoenixDatabaseMetaData.MAX_LOCAL_SI_VERSION_DISALLOW) + " inclusive."), UNALLOWED_LOCAL_INDEXES(1055, "43A12", "Local secondary indexes are configured to not be allowed."), /** Sequence related */ http://git-wip-us.apache.org/repos/asf/phoenix/blob/2b8e6634/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java index 7ac2bb6..034c40a 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java @@ -269,12 +269,13 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData, org.apache.pho private final PhoenixConnection connection; private final ResultSet emptyResultSet; + public static final int MAX_LOCAL_SI_VERSION_DISALLOW = VersionUtil.encodeVersion("0", "98", "8"); + public static final int MIN_LOCAL_SI_VERSION_DISALLOW = VersionUtil.encodeVersion("0", "98", "6"); // Version below which we should turn off essential column family. public static final int ESSENTIAL_FAMILY_VERSION_THRESHOLD = VersionUtil.encodeVersion("0", "94", "7"); // Version below which we should disallow usage of mutable secondary indexing. public static final int MUTABLE_SI_VERSION_THRESHOLD = VersionUtil.encodeVersion("0", "94", "10"); - public static final int LOCAL_SI_VERSION_THRESHOLD = VersionUtil.encodeVersion("0", "98", "9"); /** Version below which we fall back on the generic KeyValueBuilder */ public static final int CLIENT_KEY_VALUE_BUILDER_THRESHOLD = VersionUtil.encodeVersion("0", "94", "14"); http://git-wip-us.apache.org/repos/asf/phoenix/blob/2b8e6634/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 fa44835..09705c6 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 @@ -101,7 +101,7 @@ public interface ConnectionQueryServices extends QueryServices, MetaDataMutated */ public KeyValueBuilder getKeyValueBuilder(); - public enum Feature {}; + public enum Feature {LOCAL_INDEX}; public boolean supportsFeature(Feature feature); public String getUserName(); http://git-wip-us.apache.org/repos/asf/phoenix/blob/2b8e6634/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 7763a0a..4a9eac0 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 @@ -156,6 +156,7 @@ import com.google.common.base.Stopwatch; import com.google.common.base.Throwables; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; @@ -200,6 +201,19 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement // setting this member variable guarded by "connectionCountLock" private volatile ConcurrentMap<SequenceKey,Sequence> sequenceMap = Maps.newConcurrentMap(); private KeyValueBuilder kvBuilder; + + private static interface FeatureSupported { + boolean isSupported(ConnectionQueryServices services); + } + + private final Map<Feature, FeatureSupported> featureMap = ImmutableMap.<Feature, FeatureSupported>of( + Feature.LOCAL_INDEX, new FeatureSupported(){ + @Override + public boolean isSupported(ConnectionQueryServices services) { + int hbaseVersion = services.getLowestClusterHBaseVersion(); + return hbaseVersion < PhoenixDatabaseMetaData.MIN_LOCAL_SI_VERSION_DISALLOW || hbaseVersion > PhoenixDatabaseMetaData.MAX_LOCAL_SI_VERSION_DISALLOW; + } + }); private PMetaData newEmptyMetaData() { long maxSizeBytes = props.getLong(QueryServices.MAX_CLIENT_METADATA_CACHE_SIZE_ATTRIB, @@ -1074,7 +1088,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement // If we're not allowing local indexes or the hbase version is too low, // don't create the local index table if ( !this.getProps().getBoolean(QueryServices.ALLOW_LOCAL_INDEX_ATTRIB, QueryServicesOptions.DEFAULT_ALLOW_LOCAL_INDEX) - || getLowestClusterHBaseVersion() < PhoenixDatabaseMetaData.LOCAL_SI_VERSION_THRESHOLD) { + || !this.supportsFeature(Feature.LOCAL_INDEX)) { return; } @@ -2428,9 +2442,11 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement @Override public boolean supportsFeature(Feature feature) { - // TODO: Keep map of Feature -> min HBase version - // For now, only Feature is REVERSE_SCAN and it's not supported in any version yet - return false; + FeatureSupported supported = featureMap.get(feature); + if (supported == null) { + return false; + } + return supported.isSupported(this); } @Override http://git-wip-us.apache.org/repos/asf/phoenix/blob/2b8e6634/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java index 9efbf93..742c38e 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java @@ -457,7 +457,7 @@ public class ConnectionlessQueryServicesImpl extends DelegateQueryServices imple @Override public boolean supportsFeature(Feature feature) { - return false; + return true; } @Override http://git-wip-us.apache.org/repos/asf/phoenix/blob/2b8e6634/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 effdb54..fceb724 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 @@ -144,6 +144,7 @@ import org.apache.phoenix.parse.ParseNodeFactory; import org.apache.phoenix.parse.PrimaryKeyConstraint; import org.apache.phoenix.parse.TableName; import org.apache.phoenix.parse.UpdateStatisticsStatement; +import org.apache.phoenix.query.ConnectionQueryServices.Feature; import org.apache.phoenix.query.QueryConstants; import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.query.QueryServicesOptions; @@ -915,7 +916,7 @@ public class MetaDataClient { if (!connection.getQueryServices().getProps().getBoolean(QueryServices.ALLOW_LOCAL_INDEX_ATTRIB, QueryServicesOptions.DEFAULT_ALLOW_LOCAL_INDEX)) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.UNALLOWED_LOCAL_INDEXES).setTableName(indexTableName.getTableName()).build().buildException(); } - if (hbaseVersion < PhoenixDatabaseMetaData.LOCAL_SI_VERSION_THRESHOLD) { + if (!connection.getQueryServices().supportsFeature(Feature.LOCAL_INDEX)) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.NO_LOCAL_INDEXES).setTableName(indexTableName.getTableName()).build().buildException(); } }
