ignite-sql-tests
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/8bc23403 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/8bc23403 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/8bc23403 Branch: refs/heads/ignite-sql-tests Commit: 8bc2340352392139e59ea27de496b2a3b40fb789 Parents: 969731f Author: S.Vladykin <svlady...@gridgain.com> Authored: Mon Feb 23 05:54:29 2015 +0300 Committer: S.Vladykin <svlady...@gridgain.com> Committed: Mon Feb 23 05:54:29 2015 +0300 ---------------------------------------------------------------------- .../MemcacheRestExampleNodeStartup.java | 7 - .../ignite/jdbc/JdbcLocalCachesSelfTest.java | 12 +- .../ignite/cache/query/QueryTypeResolver.java | 32 -- .../query/annotations/QuerySqlFunction.java | 4 +- .../configuration/CacheConfiguration.java | 150 ++++++- .../configuration/CacheQueryConfiguration.java | 226 ---------- .../configuration/IgniteConfiguration.java | 17 - .../configuration/QueryConfiguration.java | 202 --------- .../org/apache/ignite/internal/IgnitionEx.java | 1 - .../processors/cache/query/CacheQuery.java | 3 +- .../processors/query/GridQueryIndexing.java | 9 + .../processors/query/GridQueryProcessor.java | 101 +++-- .../visor/cache/VisorCacheConfiguration.java | 2 - .../node/VisorCacheQueryConfiguration.java | 28 -- .../visor/node/VisorGridConfiguration.java | 1 - .../visor/node/VisorQueryConfiguration.java | 33 -- ...idCachePartitionedHitsAndMissesSelfTest.java | 6 - .../processors/query/h2/IgniteH2Indexing.java | 434 ++++++------------- .../query/h2/sql/GridSqlFunction.java | 21 +- .../query/h2/sql/GridSqlFunctionType.java | 3 + .../query/h2/sql/GridSqlQueryParser.java | 11 +- .../query/h2/twostep/GridMapQueryExecutor.java | 4 +- .../h2/twostep/GridReduceQueryExecutor.java | 4 +- .../h2/twostep/messages/GridQueryRequest.java | 14 +- .../GridCacheAbstractFieldsQuerySelfTest.java | 8 - .../cache/GridCacheOffHeapAndSwapSelfTest.java | 7 - .../cache/GridCacheQueryMetricsSelfTest.java | 6 - ...idCacheReduceQueryMultithreadedSelfTest.java | 6 - .../cache/GridIndexingWithNoopSwapSelfTest.java | 6 - .../IgniteCacheAbstractFieldsQuerySelfTest.java | 8 - .../cache/IgniteCacheAbstractQuerySelfTest.java | 14 +- .../IgniteCacheQueryMultiThreadedSelfTest.java | 17 +- .../IgniteCacheQueryNodeRestartSelfTest.java | 9 +- .../query/h2/GridH2IndexingOffheapSelfTest.java | 20 +- .../h2/GridIndexingSpiAbstractSelfTest.java | 62 +-- .../query/h2/sql/GridQueryParsingTest.java | 16 +- .../commands/cache/VisorCacheCommandSpec.scala | 7 - 37 files changed, 383 insertions(+), 1128 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExampleNodeStartup.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExampleNodeStartup.java b/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExampleNodeStartup.java index d8b3ed2..aca572f 100644 --- a/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExampleNodeStartup.java +++ b/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExampleNodeStartup.java @@ -75,13 +75,6 @@ public class MemcacheRestExampleNodeStartup { cacheCfg.setPreloadMode(SYNC); cacheCfg.setAtomicityMode(TRANSACTIONAL); - CacheQueryConfiguration qryCfg = new CacheQueryConfiguration(); - - qryCfg.setIndexPrimitiveKey(true); - qryCfg.setIndexFixedTyping(false); - - cacheCfg.setQueryConfiguration(qryCfg); - cfg.setCacheConfiguration(cacheCfg); TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcLocalCachesSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcLocalCachesSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcLocalCachesSelfTest.java index c7d6dff..e521928 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcLocalCachesSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcLocalCachesSelfTest.java @@ -17,9 +17,7 @@ package org.apache.ignite.jdbc; -import org.apache.ignite.Ignite; -import org.apache.ignite.IgniteCache; -import org.apache.ignite.cache.*; +import org.apache.ignite.*; import org.apache.ignite.configuration.*; import org.apache.ignite.spi.discovery.tcp.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.*; @@ -29,9 +27,9 @@ import org.apache.ignite.testframework.junits.common.*; import java.sql.*; import java.util.*; +import static org.apache.ignite.IgniteJdbcDriver.*; import static org.apache.ignite.cache.CacheMode.*; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; -import static org.apache.ignite.IgniteJdbcDriver.*; /** * Test JDBC with several local caches. @@ -56,12 +54,6 @@ public class JdbcLocalCachesSelfTest extends GridCommonAbstractTest { cache.setCacheMode(LOCAL); cache.setWriteSynchronizationMode(FULL_SYNC); - CacheQueryConfiguration qryCfg = new CacheQueryConfiguration(); - - qryCfg.setIndexPrimitiveKey(true); - - cache.setQueryConfiguration(qryCfg); - cfg.setCacheConfiguration(cache); TcpDiscoverySpi disco = new TcpDiscoverySpi(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/main/java/org/apache/ignite/cache/query/QueryTypeResolver.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/QueryTypeResolver.java b/modules/core/src/main/java/org/apache/ignite/cache/query/QueryTypeResolver.java deleted file mode 100644 index f8bb017..0000000 --- a/modules/core/src/main/java/org/apache/ignite/cache/query/QueryTypeResolver.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.ignite.cache.query; - -/** - * Interface allowing to override table name for portable objects stored in cache. - */ -public interface QueryTypeResolver { - /** - * Allows to override type name for portable objects being stored in cache. - * - * @param key Key. - * @param val Value. - * @return Type name. - */ - public String resolveTypeName(Object key, Object val); -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/main/java/org/apache/ignite/cache/query/annotations/QuerySqlFunction.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/annotations/QuerySqlFunction.java b/modules/core/src/main/java/org/apache/ignite/cache/query/annotations/QuerySqlFunction.java index f938bac..352aa85 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/query/annotations/QuerySqlFunction.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/query/annotations/QuerySqlFunction.java @@ -22,7 +22,7 @@ import java.lang.annotation.*; /** * Annotates public static methods in classes to be used in SQL queries as custom functions. * Annotated class must be registered in H2 indexing SPI using following method - * {@link org.apache.ignite.configuration.QueryConfiguration#setIndexCustomFunctionClasses(Class[])}. + * {@link org.apache.ignite.configuration.QueryConfiguration#setSqlFunctionClasses(Class[])}. * <p> * Example usage: * <pre name="code" class="java"> @@ -34,7 +34,7 @@ import java.lang.annotation.*; * } * * // Register. - * indexing.setIndexCustomFunctionClasses(MyFunctions.class); + * indexing.setSqlFunctionClasses(MyFunctions.class); * * // And use in queries. * cache.queries().createSqlFieldsQuery("select sqr(2) where sqr(1) = 1"); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java index e43bbc6..ae1dba4 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java @@ -21,10 +21,11 @@ import org.apache.ignite.*; import org.apache.ignite.cache.*; import org.apache.ignite.cache.affinity.*; import org.apache.ignite.cache.eviction.*; +import org.apache.ignite.cache.query.annotations.*; import org.apache.ignite.cache.store.*; import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.spi.indexing.*; +import org.apache.ignite.lang.*; import org.jetbrains.annotations.*; import javax.cache.configuration.*; @@ -160,6 +161,12 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> { /** Default value for 'readFromBackup' flag. */ public static final boolean DFLT_READ_FROM_BACKUP = true; + /** Default timeout after which long query warning will be printed. */ + public static final long DFLT_LONG_QRY_WARN_TIMEOUT = 3000; + + /** Default size for onheap SQL row cache size. */ + public static final int DFLT_SQL_ONHEAP_ROW_CACHE_SIZE = 10 * 1024; + /** Cache name. */ private String name; @@ -304,8 +311,11 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> { /** */ private CacheInterceptor<?, ?> interceptor; - /** Query configuration. */ - private CacheQueryConfiguration qryCfg; + /** */ + private Class<?>[] sqlFuncCls; + + /** */ + private long longQryWarnTimeout = DFLT_LONG_QRY_WARN_TIMEOUT; /** * Flag indicating whether data can be read from backup. @@ -316,6 +326,15 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> { /** Collection of type metadata. */ private Collection<CacheTypeMetadata> typeMeta; + /** */ + private boolean sqlEscapeAll; + + /** */ + private IgniteBiTuple<Class<?>,Class<?>>[] indexedTypes; + + /** */ + private int sqlOnheapRowCacheSize = DFLT_SQL_ONHEAP_ROW_CACHE_SIZE; + /** Empty constructor (all values are initialized to their defaults). */ public CacheConfiguration() { /* No-op. */ @@ -359,12 +378,14 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> { evictSyncConcurrencyLvl = cc.getEvictSynchronizedConcurrencyLevel(); evictSyncTimeout = cc.getEvictSynchronizedTimeout(); expiryPolicyFactory = cc.getExpiryPolicyFactory(); + indexedTypes = cc.getIndexedTypes(); interceptor = cc.getInterceptor(); invalidate = cc.isInvalidate(); isReadThrough = cc.isReadThrough(); isWriteThrough = cc.isWriteThrough(); listenerConfigurations = cc.listenerConfigurations; loadPrevVal = cc.isLoadPreviousValue(); + longQryWarnTimeout = cc.getLongQueryWarningTimeout(); offHeapMaxMem = cc.getOffHeapMaxMemory(); maxConcurrentAsyncOps = cc.getMaxConcurrentAsyncOperations(); maxQryIterCnt = cc.getMaximumQueryIteratorCount(); @@ -379,9 +400,10 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> { preloadPoolSize = cc.getPreloadThreadPoolSize(); preloadTimeout = cc.getPreloadTimeout(); preloadThrottle = cc.getPreloadThrottle(); - qryCfg = cc.getQueryConfiguration(); qryIdxEnabled = cc.isQueryIndexEnabled(); readFromBackup = cc.isReadFromBackup(); + sqlEscapeAll = cc.isSqlEscapeAll(); + sqlFuncCls = cc.getSqlFunctionClasses(); startSize = cc.getStartSize(); storeFactory = cc.getCacheStoreFactory(); storeValBytes = cc.isStoreValueBytes(); @@ -1546,26 +1568,6 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> { this.typeMeta = typeMeta; } - - /** - * Gets query configuration. Query configuration defines which fields should be indexed for objects - * without annotations or portable objects. - * - * @return Cache query configuration. - */ - public CacheQueryConfiguration getQueryConfiguration() { - return qryCfg; - } - - /** - * Sets query configuration. - * - * @param qryCfg Query configuration. - */ - public void setQueryConfiguration(CacheQueryConfiguration qryCfg) { - this.qryCfg = qryCfg; - } - /** * Gets flag indicating whether data can be read from backup. * If {@code false} always get data from primary node (never from backup). @@ -1588,6 +1590,106 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> { this.readFromBackup = readFromBackup; } + /** + * Sets classes with methods annotated by {@link QuerySqlFunction} + * to be used as user-defined functions from SQL queries. + * + * @param cls One or more classes with SQL functions. + */ + public void setSqlFunctionClasses(Class<?>... cls) { + this.sqlFuncCls = cls; + } + + /** + * Gets classes with methods annotated by {@link QuerySqlFunction} + * to be used as user-defined functions from SQL queries. + * + * @return Classes with SQL functions. + */ + @Nullable public Class<?>[] getSqlFunctionClasses() { + return sqlFuncCls; + } + + /** + * Gets timeout in milliseconds after which long query warning will be printed. + * + * @return Timeout in milliseconds. + */ + public long getLongQueryWarningTimeout() { + return longQryWarnTimeout; + } + + /** + * Gets timeout in milliseconds after which long query warning will be printed. + * + * @param longQryWarnTimeout Timeout in milliseconds. + */ + public void setLongQueryWarningTimeout(long longQryWarnTimeout) { + this.longQryWarnTimeout = longQryWarnTimeout; + } + + /** + * If {@code true} all the SQL table and field names will be escaped with double quotes like + * ({@code "tableName"."fieldsName"}). This enforces case sensitivity for field names and + * also allows having special characters in table and field names. + * + * @return Flag value. + */ + public boolean isSqlEscapeAll() { + return sqlEscapeAll; + } + + /** + * If {@code true} all the SQL table and field names will be escaped with double quotes like + * ({@code "tableName"."fieldsName"}). This enforces case sensitivity for field names and + * also allows having special characters in table and field names. + * + * @param sqlEscapeAll Flag value. + */ + public void setSqlEscapeAll(boolean sqlEscapeAll) { + this.sqlEscapeAll = sqlEscapeAll; + } + + /** + * Array of key and value type pairs to be indexed. + * + * @return Key and value type pairs. + */ + public IgniteBiTuple<Class<?>,Class<?>>[] getIndexedTypes() { + return indexedTypes; + } + + /** + * Array of key and value type pairs to be indexed. + * + * @param indexedTypes Key and value type pairs. + */ + public void setIndexedTypes(IgniteBiTuple<Class<?>,Class<?>>... indexedTypes) { + this.indexedTypes = indexedTypes; + } + + /** + * Number of SQL rows which will be cached onheap to avoid deserialization on each SQL index access. + * This setting only makes sense when offheap is enabled for this cache. + * + * @return size Cache size. + * @see #setOffHeapMaxMemory(long) + */ + public int getSqlOnheapRowCacheSize() { + return sqlOnheapRowCacheSize; + } + + /** + * Number of SQL rows which will be cached onheap to avoid deserialization on each SQL index access. + * This setting only makes sense when offheap is enabled for this cache. + * + * @param size Cache size. + * @see #setOffHeapMaxMemory(long) + */ + public void setSqlOnheapRowCacheSize(int size) { + this.sqlOnheapRowCacheSize = size; + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(CacheConfiguration.class, this); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/main/java/org/apache/ignite/configuration/CacheQueryConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheQueryConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheQueryConfiguration.java deleted file mode 100644 index 4508e45..0000000 --- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheQueryConfiguration.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * 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.ignite.configuration; - -import org.apache.ignite.cache.query.*; -import org.apache.ignite.lang.*; - -import java.io.*; -import java.util.*; - -/** - * Configuration for embedded indexing facilities. - */ -public class CacheQueryConfiguration implements Serializable { - /** */ - private static final long serialVersionUID = 0L; - - /** Query type resolver. */ - private QueryTypeResolver typeRslvr; - - /** */ - private boolean idxPrimitiveKey; - - /** */ - private boolean idxPrimitiveVal; - - /** */ - private boolean idxFixedTyping; - - /** */ - private boolean escapeAll; - - /** */ - private int pageSize = 1000; - - /** */ - private Collection<IgniteBiTuple<Class<?>, Class<?>>> annotatedEntryTypes; - - /** - * Default constructor. - */ - public CacheQueryConfiguration() { - // No-op. - } - - /** - * @param cfg Configuration to copy. - */ - public CacheQueryConfiguration(CacheQueryConfiguration cfg) { - typeRslvr = cfg.getTypeResolver(); - idxPrimitiveKey = cfg.isIndexPrimitiveKey(); - idxPrimitiveVal = cfg.isIndexPrimitiveValue(); - idxFixedTyping = cfg.isIndexFixedTyping(); - escapeAll = cfg.isEscapeAll(); - } - - /** - * Gets query type resolver. - * - * @return Query type resolver. - */ - public QueryTypeResolver getTypeResolver() { - return typeRslvr; - } - - /** - * Sets query type resolver. - * - * @param typeRslvr Query type resolver. - */ - public void setTypeResolver(QueryTypeResolver typeRslvr) { - this.typeRslvr = typeRslvr; - } - - /** - * Gets flag indicating whether SQL engine should index by key in cases - * where key is primitive type - * - * @return {@code True} if primitive keys should be indexed. - */ - public boolean isIndexPrimitiveKey() { - return idxPrimitiveKey; - } - - /** - * Sets flag indicating whether SQL engine should index by key in cases - * where key is primitive type. - * - * @param idxPrimitiveKey {@code True} if primitive keys should be indexed. - */ - public void setIndexPrimitiveKey(boolean idxPrimitiveKey) { - this.idxPrimitiveKey = idxPrimitiveKey; - } - - /** - * Gets flag indicating whether SQL engine should index by value in cases - * where value is primitive type - * - * @return {@code True} if primitive values should be indexed. - */ - public boolean isIndexPrimitiveValue() { - return idxPrimitiveVal; - } - - /** - * Sets flag indexing whether SQL engine should index by value in cases - * where value is primitive type. - * - * @param idxPrimitiveVal {@code True} if primitive values should be indexed. - */ - public void setIndexPrimitiveValue(boolean idxPrimitiveVal) { - this.idxPrimitiveVal = idxPrimitiveVal; - } - - /** - * This flag essentially controls whether all values of the same type have - * identical key type. - * <p> - * If {@code false}, SQL engine will store all keys in BINARY form to make it possible to store - * the same value type with different key types. If {@code true}, key type will be converted - * to respective SQL type if it is possible, hence, improving performance of queries. - * <p> - * Setting this value to {@code false} also means that {@code '_key'} column cannot be indexed and - * cannot participate in query where clauses. The behavior of using '_key' column in where - * clauses with this flag set to {@code false} is undefined. - * - * @return {@code True} if SQL engine should try to convert values to their respective SQL - * types for better performance. - */ - public boolean isIndexFixedTyping() { - return idxFixedTyping; - } - - /** - * This flag essentially controls whether key type is going to be identical - * for all values of the same type. - * <p> - * If false, SQL engine will store all keys in BINARY form to make it possible to store - * the same value type with different key types. If true, key type will be converted - * to respective SQL type if it is possible, which may provide significant performance - * boost. - * - * @param idxFixedTyping {@code True} if SQL engine should try to convert values to their respective SQL - * types for better performance. - */ - public void setIndexFixedTyping(boolean idxFixedTyping) { - this.idxFixedTyping = idxFixedTyping; - } - - /** - * If {@code true}, then table name and all column names in 'create table' SQL - * generated for SQL engine are escaped with double quotes. This flag should be set if table name of - * column name is H2 reserved word or is not valid H2 identifier (e.g. contains space or hyphen). - * <p> - * Note if this flag is set then table and column name in SQL queries also must be escaped with double quotes. - - * @return Flag value. - */ - public boolean isEscapeAll() { - return escapeAll; - } - - /** - * If {@code true}, then table name and all column names in 'create table' SQL - * generated for SQL engine are escaped with double quotes. This flag should be set if table name of - * column name is H2 reserved word or is not valid H2 identifier (e.g. contains space or hyphen). - * <p> - * Note if this flag is set then table and column name in SQL queries also must be escaped with double quotes. - - * @param escapeAll Flag value. - */ - public void setEscapeAll(boolean escapeAll) { - this.escapeAll = escapeAll; - } - - /** - * Gets default query result page size. - * - * @return Page size. - */ - public int getPageSize() { - return pageSize; - } - - /** - * Sets default query result page size. - * - * @param pageSize Page size. - */ - public void setPageSize(int pageSize) { - this.pageSize = pageSize; - } - - /** - * Gets annotates types for cache entries to be indexed as SQL table for this cache. - * - * @return Annotates types. - */ - public Collection<IgniteBiTuple<Class<?>,Class<?>>> getAnnotatedEntryTypes() { - return annotatedEntryTypes; - } - - /** - * Gets annotates types for cache entries to be indexed as SQL table for this cache. - * - * @param annotatedEntryTypes Annotates types. - */ - public void setAnnotatedEntryTypes(Collection<IgniteBiTuple<Class<?>,Class<?>>> annotatedEntryTypes) { - this.annotatedEntryTypes = annotatedEntryTypes; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java index 767da36..58d8be9 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java @@ -363,9 +363,6 @@ public class IgniteConfiguration { private IgniteInClosure<IgniteConfiguration> warmupClos; /** */ - private QueryConfiguration qryCfg; - - /** */ private AtomicConfiguration atomicCfg = new AtomicConfiguration(); /** User's class loader. */ @@ -1886,20 +1883,6 @@ public class IgniteConfiguration { } /** - * @return Query configuration. - */ - public QueryConfiguration getQueryConfiguration() { - return qryCfg; - } - - /** - * @param qryCfg Query configuration. - */ - public void setQueryConfiguration(QueryConfiguration qryCfg) { - this.qryCfg = qryCfg; - } - - /** * @return Atomic data structures configuration. */ public AtomicConfiguration getAtomicConfiguration() { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/main/java/org/apache/ignite/configuration/QueryConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/QueryConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/QueryConfiguration.java deleted file mode 100644 index 98b0f6f..0000000 --- a/modules/core/src/main/java/org/apache/ignite/configuration/QueryConfiguration.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * 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.ignite.configuration; - -import org.apache.ignite.cache.query.annotations.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -/** - * Configuration for embedded indexing facilities. - */ -public class QueryConfiguration { - /** Default query execution time interpreted as long query (3 seconds). */ - public static final long DFLT_LONG_QRY_EXEC_TIMEOUT = 3000; - - /** Default value for {@link #setUseOptimizedSerializer(boolean)} flag. */ - public static final boolean DFLT_USE_OPTIMIZED_SERIALIZER = true; - - /** */ - private Class<?>[] idxCustomFuncClss; - - /** */ - private String[] searchPath; - - /** */ - private String initScriptPath; - - /** */ - private long maxOffHeapMemory = -1; - - /** */ - private long longQryExecTimeout = DFLT_LONG_QRY_EXEC_TIMEOUT; - - /** */ - private boolean longQryExplain; - - /** */ - private boolean useOptimizedSerializer = DFLT_USE_OPTIMIZED_SERIALIZER; - - /** - * Sets maximum amount of memory available to off-heap storage. Possible values are - * <ul> - * <li>{@code -1} - Means that off-heap storage is disabled.</li> - * <li> - * {@code 0} - Ignite will not limit off-heap storage (it's up to user to properly - * add and remove entries from cache to ensure that off-heap storage does not grow - * indefinitely. - * </li> - * <li>Any positive value specifies the limit of off-heap storage in bytes.</li> - * </ul> - * Default value is {@code -1}, which means that off-heap storage is disabled by default. - * <p> - * Use off-heap storage to load gigabytes of data in memory without slowing down - * Garbage Collection. Essentially in this case you should allocate very small amount - * of memory to JVM and Ignite will cache most of the data in off-heap space - * without affecting JVM performance at all. - * - * @param maxOffHeapMemory Maximum memory in bytes available to off-heap memory space. - */ - public void setMaxOffHeapMemory(long maxOffHeapMemory) { - this.maxOffHeapMemory = maxOffHeapMemory; - } - - /** {@inheritDoc} */ - public long getMaxOffHeapMemory() { - return maxOffHeapMemory; - } - - /** - * Specifies max allowed size of cache for deserialized offheap rows to avoid deserialization costs for most - * frequently used ones. In general performance is better with greater cache size. Must be more than 128 items. - * - * @param size Cache size in items. - */ - public void setMaxOffheapRowsCacheSize(int size) { - A.ensure(size >= 128, "Offheap rows cache size must be not less than 128."); - -// rowCache = new CacheLongKeyLIRS<>(size, 1, 128, 256); TODO - } - - /** - * Sets the optional search path consisting of space names to search SQL schema objects. Useful for cross cache - * queries to avoid writing fully qualified table names. - * - * @param searchPath Search path. - */ - public void setSearchPath(String... searchPath) { - this.searchPath = searchPath; - } - - /** {@inheritDoc} */ - @Nullable public String[] getSearchPath() { - return searchPath; - } - - /** {@inheritDoc} */ - @Nullable public String getInitialScriptPath() { - return initScriptPath; - } - - /** - * Sets script path to be ran against H2 database after opening. - * The script must be UTF-8 encoded file. - * - * @param initScriptPath Script path. - */ - public void setInitialScriptPath(String initScriptPath) { - this.initScriptPath = initScriptPath; - } - - /** - * Sets classes with methods annotated by {@link QuerySqlFunction} - * to be used as user-defined functions from SQL queries. - * - * @param idxCustomFuncClss List of classes. - */ - public void setIndexCustomFunctionClasses(Class<?>... idxCustomFuncClss) { - this.idxCustomFuncClss = idxCustomFuncClss; - } - - /** {@inheritDoc} */ - @Nullable public Class<?>[] getIndexCustomFunctionClasses() { - return idxCustomFuncClss; - } - - /** {@inheritDoc} */ - public long getLongQueryExecutionTimeout() { - return longQryExecTimeout; - } - - /** - * Set query execution time threshold. If queries exceed this threshold, - * then a warning will be printed out. If {@link #setLongQueryExplain(boolean)} is - * set to {@code true}, then execution plan will be printed out as well. - * <p> - * If not provided, default value is defined by {@link #DFLT_LONG_QRY_EXEC_TIMEOUT}. - * - * @param longQryExecTimeout Long query execution timeout. - * @see #setLongQueryExplain(boolean) - */ - public void setLongQueryExecutionTimeout(long longQryExecTimeout) { - this.longQryExecTimeout = longQryExecTimeout; - } - - /** {@inheritDoc} */ - public boolean isLongQueryExplain() { - return longQryExplain; - } - - /** - * If {@code true}, SPI will print SQL execution plan for long queries (explain SQL query). - * The time threshold of long queries is controlled via {@link #setLongQueryExecutionTimeout(long)} - * parameter. - * <p> - * If not provided, default value is {@code false}. - * - * @param longQryExplain Flag marking SPI should print SQL execution plan for long queries (explain SQL query). - * @see #setLongQueryExecutionTimeout(long) - */ - public void setLongQueryExplain(boolean longQryExplain) { - this.longQryExplain = longQryExplain; - } - - /** - * The flag indicating that serializer for H2 database will be set to Ignite's marshaller. - * This setting usually makes sense for offheap indexing only. - * <p> - * Default is {@link #DFLT_USE_OPTIMIZED_SERIALIZER}. - * - * @param useOptimizedSerializer Flag value. - */ - public void setUseOptimizedSerializer(boolean useOptimizedSerializer) { - this.useOptimizedSerializer = useOptimizedSerializer; - } - - /** - * The flag indicating that serializer for H2 database will be set to Ignite's marshaller. - * This setting usually makes sense for offheap indexing only. - * <p> - * Default is {@link #DFLT_USE_OPTIMIZED_SERIALIZER}. - * - * @return Flag value. - */ - public boolean isUseOptimizedSerializer() { - return useOptimizedSerializer; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java index 684e2cf..23dbd27 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java @@ -1389,7 +1389,6 @@ public class IgnitionEx { myCfg.setWarmupClosure(cfg.getWarmupClosure()); myCfg.setPluginConfigurations(cfg.getPluginConfigurations()); myCfg.setTransactionConfiguration(new TransactionConfiguration(cfg.getTransactionConfiguration())); - myCfg.setQueryConfiguration(cfg.getQueryConfiguration()); myCfg.setClassLoader(cfg.getClassLoader()); myCfg.setAtomicConfiguration(cfg.getAtomicConfiguration()); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/CacheQuery.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/CacheQuery.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/CacheQuery.java index c584b82..129d146 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/CacheQuery.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/CacheQuery.java @@ -18,7 +18,6 @@ package org.apache.ignite.internal.processors.cache.query; import org.apache.ignite.cache.query.*; -import org.apache.ignite.cache.query.*; import org.apache.ignite.cache.query.annotations.*; import org.apache.ignite.cluster.*; import org.apache.ignite.lang.*; @@ -54,7 +53,7 @@ import org.jetbrains.annotations.*; * <h2 class="header">Custom functions in SQL queries.</h2> * It is possible to write custom Java methods and call then form SQL queries. These methods must be public static * and annotated with {@link QuerySqlFunction}. Classes containing these methods must be registered in - * {@link org.apache.ignite.configuration.QueryConfiguration#setIndexCustomFunctionClasses(Class[])}. + * {@link org.apache.ignite.configuration.QueryConfiguration#setSqlFunctionClasses(Class[])}. * <h1 class="header">Full Text Queries</h1> * Ignite supports full text queries based on Apache Lucene engine. This queries are created by * {@link CacheQueries#createFullTextQuery(Class, String)} method. Note that all fields that http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java index 5a7e1d3..fb8f4b8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java @@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.query; import org.apache.ignite.*; import org.apache.ignite.cache.query.*; +import org.apache.ignite.configuration.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.query.*; import org.apache.ignite.internal.util.lang.*; @@ -132,6 +133,14 @@ public interface GridQueryIndexing { throws IgniteCheckedException; /** + * Registers cache. + * + * @param ccfg Cache configuration. + * @throws IgniteCheckedException If failed. + */ + public void registerCache(CacheConfiguration<?,?> ccfg) throws IgniteCheckedException; + + /** * Registers type if it was not known before or updates it otherwise. * * @param spaceName Space name. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index 1e91397..b57ff27 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -37,6 +37,7 @@ import org.apache.ignite.internal.util.worker.*; import org.apache.ignite.lang.*; import org.apache.ignite.spi.*; import org.apache.ignite.spi.indexing.*; +import org.jdk8.backport.*; import org.jetbrains.annotations.*; import javax.cache.*; @@ -59,10 +60,10 @@ public class GridQueryProcessor extends GridProcessorAdapter { private final GridSpinBusyLock busyLock = new GridSpinBusyLock(); /** Type descriptors. */ - private final Map<TypeId, TypeDescriptor> types = new HashMap<>(); + private final Map<TypeId, TypeDescriptor> types = new ConcurrentHashMap8<>(); /** Type descriptors. */ - private final Map<TypeName, TypeDescriptor> typesByName = new HashMap<>(); + private final Map<TypeName, TypeDescriptor> typesByName = new ConcurrentHashMap8<>(); /** */ private ExecutorService execSvc; @@ -71,10 +72,7 @@ public class GridQueryProcessor extends GridProcessorAdapter { private final GridQueryIndexing idx; /** Portable ID to name mapping. */ - private final Map<Integer, String> portableIds = new HashMap<>(); - - /** Type resolvers per space name. */ - private final Map<String,QueryTypeResolver> typeResolvers = new HashMap<>(); + private final Map<Integer, String> portableIds = new ConcurrentHashMap8<>(); /** * @param ctx Kernal context. @@ -98,46 +96,56 @@ public class GridQueryProcessor extends GridProcessorAdapter { if (idx != null) { ctx.resource().injectGeneric(idx); - idx.start(ctx); + execSvc = ctx.getExecutorService(); - for (CacheConfiguration<?, ?> ccfg : ctx.config().getCacheConfiguration()){ - CacheQueryConfiguration qryCfg = ccfg.getQueryConfiguration(); + idx.start(ctx); - if (qryCfg != null && qryCfg.getTypeResolver() != null) - typeResolvers.put(ccfg.getName(), qryCfg.getTypeResolver()); + for (CacheConfiguration<?, ?> ccfg : ctx.config().getCacheConfiguration()) + initializeCache(ccfg); + } + } - Map<TypeName,CacheTypeMetadata> declaredTypes = new HashMap<>(); + /** + * @param ccfg Cache configuration. + */ + public void initializeCache(CacheConfiguration<?, ?> ccfg) throws IgniteCheckedException { + Map<TypeName,CacheTypeMetadata> declaredTypes = new HashMap<>(); - if (!F.isEmpty(ccfg.getTypeMetadata())) { - for (CacheTypeMetadata meta : ccfg.getTypeMetadata()) { - declaredTypes.put(new TypeName(ccfg.getName(), meta.getValueType()), meta); + boolean cacheRegistered = false; - int valTypeId = ctx.portable().typeId(meta.getValueType()); + if (!F.isEmpty(ccfg.getTypeMetadata())) { + idx.registerCache(ccfg); - portableIds.put(valTypeId, meta.getValueType()); + cacheRegistered = true; - TypeDescriptor desc = processPortableMeta(meta); + for (CacheTypeMetadata meta : ccfg.getTypeMetadata()) { + declaredTypes.put(new TypeName(ccfg.getName(), meta.getValueType()), meta); - desc.registered(idx.registerType(ccfg.getName(), desc)); + int valTypeId = ctx.portable().typeId(meta.getValueType()); - typesByName.put(new TypeName(ccfg.getName(), desc.name()), desc); - types.put(new TypeId(ccfg.getName(), valTypeId), desc); - } - } + portableIds.put(valTypeId, meta.getValueType()); - if (qryCfg != null && !F.isEmpty(qryCfg.getAnnotatedEntryTypes())) { - for (IgniteBiTuple<Class<?>,Class<?>> types : qryCfg.getAnnotatedEntryTypes()) { - TypeDescriptor desc = processKeyAndValue(ccfg.getName(), types.getKey(), types.getValue(), - declaredTypes); + TypeDescriptor desc = processPortableMeta(meta); - desc.registered(idx.registerType(ccfg.getName(), desc)); + desc.registered(idx.registerType(ccfg.getName(), desc)); - typesByName.put(new TypeName(ccfg.getName(), desc.name()), desc); - } - } + typesByName.put(new TypeName(ccfg.getName(), desc.name()), desc); + types.put(new TypeId(ccfg.getName(), valTypeId), desc); } + } - execSvc = ctx.getExecutorService(); + if (!F.isEmpty(ccfg.getIndexedTypes())) { + if (!cacheRegistered) + idx.registerCache(ccfg); + + for (IgniteBiTuple<Class<?>,Class<?>> types : ccfg.getIndexedTypes()) { + TypeDescriptor desc = processKeyAndValue(ccfg.getName(), types.getKey(), types.getValue(), + declaredTypes); + + desc.registered(idx.registerType(ccfg.getName(), desc)); + + typesByName.put(new TypeName(ccfg.getName(), desc.name()), desc); + } } } @@ -335,31 +343,20 @@ public class GridQueryProcessor extends GridProcessorAdapter { final Class<?> valCls = val.getClass(); - TypeId id = null; + TypeId id; - QueryTypeResolver rslvr = typeResolvers.get(space); + if (ctx.portable().isPortableObject(val)) { + int typeId = ctx.portable().typeId(val); - if (rslvr != null) { - String typeName = rslvr.resolveTypeName(key, val); + String typeName = portableName(typeId); - if (typeName != null) - id = new TypeId(space, ctx.portable().typeId(typeName)); - } - - if (id == null) { - if (ctx.portable().isPortableObject(val)) { - int typeId = ctx.portable().typeId(val); - - String typeName = portableName(typeId); + if (typeName == null) + return; - if (typeName == null) - return; - - id = new TypeId(space, typeId); - } - else - id = new TypeId(space, valCls); + id = new TypeId(space, typeId); } + else + id = new TypeId(space, valCls); TypeDescriptor desc = types.get(id); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java index 02d9da9..20d9a8b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfiguration.java @@ -195,8 +195,6 @@ public class VisorCacheConfiguration implements Serializable { cfg.writerFactory(compactClass(ccfg.getCacheWriterFactory())); cfg.expiryPolicyFactory(compactClass(ccfg.getExpiryPolicyFactory())); - cfg.queryConfiguration(VisorCacheQueryConfiguration.from(ccfg.getQueryConfiguration())); - return cfg; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorCacheQueryConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorCacheQueryConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorCacheQueryConfiguration.java index 882fa34..291ea42 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorCacheQueryConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorCacheQueryConfiguration.java @@ -17,10 +17,6 @@ package org.apache.ignite.internal.visor.node; -import org.apache.ignite.cache.query.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.util.typedef.internal.*; - import java.io.*; /** @@ -46,30 +42,6 @@ public class VisorCacheQueryConfiguration implements Serializable { private boolean escapeAll; /** - * @param qccfg Cache query configuration. - * @return Fill data transfer object with cache query configuration data. - */ - public static VisorCacheQueryConfiguration from(CacheQueryConfiguration qccfg) { - VisorCacheQueryConfiguration cfg = null; - - if (qccfg != null) { - cfg = new VisorCacheQueryConfiguration(); - - QueryTypeResolver rslvr = qccfg.getTypeResolver(); - - if (rslvr != null) - cfg.typeResolver(U.compact(rslvr.getClass().getName())); - - cfg.indexPrimitiveKey(qccfg.isIndexPrimitiveKey()); - cfg.indexPrimitiveValue(qccfg.isIndexPrimitiveValue()); - cfg.indexFixedTyping(qccfg.isIndexFixedTyping()); - cfg.escapeAll(qccfg.isEscapeAll()); - } - - return cfg; - } - - /** * @return Query type resolver class name. */ public String typeResolver() { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorGridConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorGridConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorGridConfiguration.java index 446db32..1576fc7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorGridConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorGridConfiguration.java @@ -120,7 +120,6 @@ public class VisorGridConfiguration implements Serializable { systemProperties(getProperties()); atomic(VisorAtomicConfiguration.from(c.getAtomicConfiguration())); transaction(VisorTransactionConfiguration.from(c.getTransactionConfiguration())); - queryConfiguration(VisorQueryConfiguration.from(c.getQueryConfiguration())); return this; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorQueryConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorQueryConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorQueryConfiguration.java index a2599ab..7c50b52 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorQueryConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorQueryConfiguration.java @@ -18,8 +18,6 @@ package org.apache.ignite.internal.visor.node; import org.apache.ignite.cache.query.annotations.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.util.typedef.internal.*; import java.io.*; @@ -52,37 +50,6 @@ public class VisorQueryConfiguration implements Serializable { private boolean useOptimizedSerializer; /** - * @param qcfg Query configuration. - * @return Fill data transfer object with query configuration data. - */ - public static VisorQueryConfiguration from(QueryConfiguration qcfg) { - VisorQueryConfiguration c = null; - - if (qcfg != null) { - c = new VisorQueryConfiguration(); - - Class<?>[] clss = qcfg.getIndexCustomFunctionClasses(); - - int sz = clss != null ? clss.length : 0; - - String[] strClss = new String[sz]; - - for (int i = 0; i < sz; i++) - strClss[i] = U.compact(clss[i].getName()); - - c.indexCustomFunctionClasses(strClss); - c.searchPath(qcfg.getSearchPath()); - c.initialScriptPath(qcfg.getInitialScriptPath()); - c.maxOffHeapMemory(qcfg.getMaxOffHeapMemory()); - c.longQueryExecutionTimeout(qcfg.getLongQueryExecutionTimeout()); - c.longQueryExplain(qcfg.isLongQueryExplain()); - c.useOptimizedSerializer(qcfg.isUseOptimizedSerializer()); - } - - return c; - } - - /** * @return Classes with methods annotated by {@link QuerySqlFunction}. */ public String[] indexCustomFunctionClasses() { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java index d3464ea..fd6e88a 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java @@ -90,12 +90,6 @@ public class GridCachePartitionedHitsAndMissesSelfTest extends GridCommonAbstrac cfg.setBackups(1); cfg.setStatisticsEnabled(true); - CacheQueryConfiguration qcfg = new CacheQueryConfiguration(); - - qcfg.setIndexPrimitiveKey(true); - - cfg.setQueryConfiguration(qcfg); - return cfg; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8bc23403/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index db37b1d..0c4bfde 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -96,7 +96,7 @@ import static org.h2.result.SortOrder.*; public class IgniteH2Indexing implements GridQueryIndexing { /** Default DB options. */ private static final String DB_OPTIONS = ";LOCK_MODE=3;MULTI_THREADED=1;DB_CLOSE_ON_EXIT=FALSE" + - ";DEFAULT_LOCK_TIMEOUT=10000;FUNCTIONS_IN_SCHEMA=false;OPTIMIZE_REUSE_RESULTS=0;QUERY_CACHE_SIZE=0;" + + ";DEFAULT_LOCK_TIMEOUT=10000;FUNCTIONS_IN_SCHEMA=true;OPTIMIZE_REUSE_RESULTS=0;QUERY_CACHE_SIZE=0;" + "RECOMPILE_ALWAYS=1;MAX_OPERATION_MEMORY=0"; /** Field name for key. */ @@ -122,12 +122,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { } } - /** */ - private volatile String cachedSearchPathCmd; - - /** Cache for deserialized offheap rows. */ - private CacheLongKeyLIRS<GridH2KeyValueRowOffheap> rowCache = new CacheLongKeyLIRS<>(32 * 1024, 1, 128, 256); - /** Logger. */ @LoggerResource private IgniteLogger log; @@ -138,12 +132,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { /** */ private Marshaller marshaller; - /** */ - private GridUnsafeMemory offheap; - - /** */ - private final Collection<String> schemaNames = new GridConcurrentHashSet<>(); - /** Collection of schemaNames and registered tables. */ private final ConcurrentMap<String, Schema> schemas = new ConcurrentHashMap8<>(); @@ -188,29 +176,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { try { c = DriverManager.getConnection(dbUrl); - String[] searchPath = cfg.getSearchPath(); - - if (!F.isEmpty(searchPath)) { - try (Statement s = c.createStatement()) { - String cmd = cachedSearchPathCmd; - - if (cmd == null) { - SB b = new SB("SET SCHEMA_SEARCH_PATH "); - - for (int i = 0; i < searchPath.length; i++) { - if (i != 0) - b.a(','); - - b.a('"').a(schema(searchPath[i])).a('"'); - } - - cachedSearchPathCmd = cmd = b.toString(); - } - - s.executeUpdate(cmd); - } - } - conns.add(c); return new ConnectionWrapper(c); @@ -224,9 +189,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { }; /** */ - private volatile QueryConfiguration cfg = new QueryConfiguration(); - - /** */ private volatile GridKernalContext ctx; /** @@ -286,22 +248,23 @@ public class IgniteH2Indexing implements GridQueryIndexing { * @param schema Schema name. * @throws IgniteCheckedException If failed to create db schema. */ - private void createSchemaIfAbsent(String schema) throws IgniteCheckedException { - executeStatement("CREATE SCHEMA IF NOT EXISTS \"" + schema + '"'); + private void createSchema(String schema) throws IgniteCheckedException { + executeStatement(schema(null), "CREATE SCHEMA \"" + schema + '"'); if (log.isDebugEnabled()) log.debug("Created H2 schema for index database: " + schema); } /** + * @param schema Schema * @param sql SQL statement. * @throws IgniteCheckedException If failed. */ - private void executeStatement(String sql) throws IgniteCheckedException { + private void executeStatement(String schema, String sql) throws IgniteCheckedException { Statement stmt = null; try { - Connection c = connectionForThread(null); + Connection c = connectionForThread(schema); stmt = c.createStatement(); @@ -331,11 +294,8 @@ public class IgniteH2Indexing implements GridQueryIndexing { Collection<TableDescriptor> tbls = tables(schema(spaceName)); if (tbls.size() > 1) { - boolean fixedTyping = isIndexFixedTyping(spaceName); - for (TableDescriptor tbl : tbls) { - if (tbl != tblToUpdate && (tbl.type().keyClass().equals(key.getClass()) || - !fixedTyping)) { + if (tbl != tblToUpdate && tbl.type().keyClass().equals(key.getClass())) { if (tbl.tbl.update(key, null, 0)) { if (tbl.luceneIdx != null) tbl.luceneIdx.remove(key); @@ -413,7 +373,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { log.debug("Removing key from cache query index [locId=" + nodeId + ", key=" + key + ']'); for (TableDescriptor tbl : tables(schema(spaceName))) { - if (tbl.type().keyClass().equals(key.getClass()) || !isIndexFixedTyping(spaceName)) { + if (tbl.type().keyClass().equals(key.getClass())) { if (tbl.tbl.update(key, null, 0)) { if (tbl.luceneIdx != null) tbl.luceneIdx.remove(key); @@ -431,8 +391,8 @@ public class IgniteH2Indexing implements GridQueryIndexing { if (schema == null) return; - for (TableDescriptor tbl : schema.values()) { - if (tbl.type().keyClass().equals(key.getClass()) || !isIndexFixedTyping(spaceName)) { + for (TableDescriptor tbl : schema.tbls.values()) { + if (tbl.type().keyClass().equals(key.getClass())) { try { if (tbl.tbl.onSwap(key)) return; @@ -448,7 +408,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { @Override public void onUnswap(@Nullable String spaceName, Object key, Object val, byte[] valBytes) throws IgniteCheckedException { for (TableDescriptor tbl : tables(schema(spaceName))) { - if (tbl.type().keyClass().equals(key.getClass()) || !isIndexFixedTyping(spaceName)) { + if (tbl.type().keyClass().equals(key.getClass())) { try { if (tbl.tbl.onUnswap(key, val)) return; @@ -505,10 +465,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { if (tbl.luceneIdx != null) U.closeQuiet(tbl.luceneIdx); - ConcurrentMap<String, TableDescriptor> tbls = schemas.get(tbl.schema()); - - if (!F.isEmpty(tbls)) - tbls.remove(tbl.name()); + tbl.schema.tbls.remove(tbl.name()); } /** {@inheritDoc} */ @@ -543,7 +500,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { try { Connection conn = connectionForThread(schema(spaceName)); - ResultSet rs = executeSqlQueryWithTimer(conn, qry, params); + ResultSet rs = executeSqlQueryWithTimer(spaceName, conn, qry, params); List<GridQueryFieldMetadata> meta = null; @@ -588,13 +545,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { } /** - * @return Configuration. - */ - public QueryConfiguration configuration() { - return cfg; - } - - /** * Executes sql query. * * @param conn Connection,. @@ -603,8 +553,8 @@ public class IgniteH2Indexing implements GridQueryIndexing { * @return Result. * @throws IgniteCheckedException If failed. */ - @Nullable private ResultSet executeSqlQuery(Connection conn, String sql, - @Nullable Collection<Object> params) throws IgniteCheckedException { + private ResultSet executeSqlQuery(Connection conn, String sql, Collection<Object> params) + throws IgniteCheckedException { PreparedStatement stmt; try { @@ -643,7 +593,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { * @return Result. * @throws IgniteCheckedException If failed. */ - public ResultSet executeSqlQueryWithTimer(Connection conn, String sql, + public ResultSet executeSqlQueryWithTimer(String space, Connection conn, String sql, @Nullable Collection<Object> params) throws IgniteCheckedException { long start = U.currentTimeMillis(); @@ -652,26 +602,18 @@ public class IgniteH2Indexing implements GridQueryIndexing { long time = U.currentTimeMillis() - start; - long longQryExecTimeout = cfg.getLongQueryExecutionTimeout(); + long longQryExecTimeout = ctx.cache().cache(space).configuration().getLongQueryWarningTimeout(); if (time > longQryExecTimeout) { String msg = "Query execution is too long (" + time + " ms): " + sql; - String longMsg = msg; - - if (cfg.isLongQueryExplain()) { - ResultSet plan = executeSqlQuery(conn, "EXPLAIN " + sql, params); + ResultSet plan = executeSqlQuery(conn, "EXPLAIN " + sql, params); - if (plan == null) - longMsg = "Failed to explain plan because required table does not exist: " + sql; - else { - plan.next(); + plan.next(); - // Add SQL explain result message into log. - longMsg = "Query execution is too long [time=" + time + " ms, sql='" + sql + '\'' + - ", plan=" + U.nl() + plan.getString(1) + U.nl() + ", parameters=" + params + "]"; - } - } + // Add SQL explain result message into log. + String longMsg = "Query execution is too long [time=" + time + " ms, sql='" + sql + '\'' + + ", plan=" + U.nl() + plan.getString(1) + U.nl() + ", parameters=" + params + "]"; LT.warn(log, null, longMsg, msg); } @@ -688,19 +630,20 @@ public class IgniteH2Indexing implements GridQueryIndexing { /** * Executes query. * + * @param space Space. * @param qry Query. * @param params Query parameters. * @param tbl Target table of query to generate select. * @return Result set. * @throws IgniteCheckedException If failed. */ - private ResultSet executeQuery(String qry, @Nullable Collection<Object> params, - @Nullable TableDescriptor tbl) throws IgniteCheckedException { + private ResultSet executeQuery(String space, String qry, @Nullable Collection<Object> params, + TableDescriptor tbl) throws IgniteCheckedException { Connection conn = connectionForThread(tbl != null ? tbl.schema() : "PUBLIC"); String sql = generateQuery(qry, tbl); - return executeSqlQueryWithTimer(conn, sql, params); + return executeSqlQueryWithTimer(space, conn, sql, params); } /** @@ -743,7 +686,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { setFilters(filters); try { - ResultSet rs = executeQuery(qry, params, tbl); + ResultSet rs = executeQuery(spaceName, qry, params, tbl); return new KeyValIterator(rs); } @@ -833,46 +776,23 @@ public class IgniteH2Indexing implements GridQueryIndexing { * @return Prepared statement. * @throws IgniteCheckedException In case of error. */ - private String generateQuery(String qry, @Nullable TableDescriptor tbl) throws IgniteCheckedException { - boolean needSelect = tbl != null; - - String str = qry.trim().toUpperCase(); - - if (!str.startsWith("FROM")) { - if (str.startsWith("SELECT")) { - if (needSelect) { - StringTokenizer st = new StringTokenizer(str, " "); - - String errMsg = "Wrong query format, query must start with 'select * from' " + - "or 'from' or without such keywords."; + private String generateQuery(String qry, TableDescriptor tbl) throws IgniteCheckedException { + assert tbl != null; - if (st.countTokens() > 3) { - st.nextToken(); - String wildcard = st.nextToken(); - String from = st.nextToken(); + String t = tbl.fullTableName(); - if (!"*".equals(wildcard) || !"FROM".equals(from)) - throw new IgniteCheckedException(errMsg); + String from = " "; - needSelect = false; - } - else - throw new IgniteCheckedException(errMsg); - } - } - else { - boolean needWhere = !str.startsWith("ORDER") && !str.startsWith("LIMIT"); + String upper = qry.trim().toUpperCase(); - qry = needWhere ? "FROM " + tbl.fullTableName() + " WHERE " + qry : - "FROM " + tbl.fullTableName() + ' ' + qry; - } - } + if (!upper.startsWith("FROM")) + from = " FROM " + t + + (upper.startsWith("WHERE") || upper.startsWith("ORDER") || upper.startsWith("LIMIT") ? + " " : " WHERE "); - GridStringBuilder ptrn = new SB("SELECT {0}.").a(KEY_FIELD_NAME); + qry = "SELECT " + t + "." + KEY_FIELD_NAME + ", " + t + "." + VAL_FIELD_NAME + from + qry; - ptrn.a(", {0}.").a(VAL_FIELD_NAME); - - return needSelect ? MessageFormat.format(ptrn.toString(), tbl.fullTableName()) + ' ' + qry : qry; + return qry; } /** @@ -888,33 +808,16 @@ public class IgniteH2Indexing implements GridQueryIndexing { if (!validateTypeDescriptor(spaceName, type)) return false; - for (TableDescriptor table : tables(schema(spaceName))) - // Need to compare class names rather than classes to define - // whether a class was previously undeployed. - if (table.type().valueClass().getClass().getName().equals(type.valueClass().getName())) - throw new IgniteCheckedException("Failed to register type in query index because" + - " class is already registered (most likely that class with the same name" + - " was not properly undeployed): " + type); + Schema schema = schemas.get(schema(spaceName)); - TableDescriptor tbl = new TableDescriptor(spaceName, type); + TableDescriptor tbl = new TableDescriptor(schema, type); try { Connection conn = connectionForThread(null); - Schema schema = schemas.get(tbl.schema()); - - if (schema == null) { - schema = new Schema(spaceName); - - Schema existing = schemas.putIfAbsent(tbl.schema(), schema); - - if (existing != null) - schema = existing; - } - createTable(schema, tbl, conn); - schema.put(tbl.name(), tbl); + schema.add(tbl); } catch (SQLException e) { onSqlException(); @@ -926,17 +829,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { } /** - * @param cls Class. - * @return True if given class has primitive respective sql type. - */ - private boolean isPrimitive(Class<?> cls) { - DBTypeEnum valType = DBTypeEnum.fromClass(cls); - - return valType != DBTypeEnum.BINARY && valType != DBTypeEnum.OTHER && - valType != DBTypeEnum.ARRAY; - } - - /** * Validates properties described by query types. * * @param spaceName Space name. @@ -948,14 +840,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { throws IgniteCheckedException { assert type != null; - boolean keyPrimitive = isPrimitive(type.keyClass()); - boolean valPrimitive = isPrimitive(type.valueClass()); - - // Do not register if value is not primitive and - // there are no indexes or fields defined. - if (!type.valueTextIndex() && type.indexes().isEmpty() && type.fields().isEmpty()) - return keyPrimitive && isIndexPrimitiveKey(spaceName) || valPrimitive && isIndexPrimitiveValue(spaceName); - Collection<String> names = new HashSet<>(); names.addAll(type.fields().keySet()); @@ -971,6 +855,10 @@ public class IgniteH2Indexing implements GridQueryIndexing { throw new IgniteCheckedException(MessageFormat.format(ptrn, name)); } + Schema s = schemas.get(spaceName); + + + return true; } @@ -1022,13 +910,12 @@ public class IgniteH2Indexing implements GridQueryIndexing { * @throws SQLException If failed to create db table. */ private void createTable(Schema schema, TableDescriptor tbl, Connection conn) throws SQLException { + assert schema != null; assert tbl != null; - boolean keyAsObj = !isIndexFixedTyping(schema.spaceName); - boolean escapeAll = isEscapeAll(schema.spaceName); - String keyType = keyAsObj ? "OTHER" : dbTypeFromClass(tbl.type().keyClass()); + String keyType = dbTypeFromClass(tbl.type().keyClass()); String valTypeStr = dbTypeFromClass(tbl.type().valueClass()); SB sql = new SB(); @@ -1046,9 +933,9 @@ public class IgniteH2Indexing implements GridQueryIndexing { if (log.isDebugEnabled()) log.debug("Creating DB table with SQL: " + sql); - GridH2RowDescriptor desc = new RowDescriptor(tbl.type(), schema, keyAsObj); + GridH2RowDescriptor desc = new RowDescriptor(tbl.type(), schema); - GridH2Table.Engine.createTable(conn, sql.toString(), desc, tbl, tbl.spaceName); + GridH2Table.Engine.createTable(conn, sql.toString(), desc, tbl, tbl.schema.spaceName); } /** @@ -1080,12 +967,12 @@ public class IgniteH2Indexing implements GridQueryIndexing { * @return Table descriptor. */ @Nullable private TableDescriptor tableDescriptor(String type, @Nullable String space) { - ConcurrentMap<String, TableDescriptor> tbls = schemas.get(schema(space)); + Schema s = schemas.get(schema(space)); - if (tbls == null) + if (s == null) return null; - return tbls.get(type); + return s.tbls.get(type); } /** @@ -1095,12 +982,12 @@ public class IgniteH2Indexing implements GridQueryIndexing { * @return Collection of table descriptors. */ private Collection<TableDescriptor> tables(String schema) { - ConcurrentMap<String, TableDescriptor> tbls = schemas.get(schema); + Schema s = schemas.get(schema); - if (tbls == null) + if (s == null) return Collections.emptySet(); - return tbls.values(); + return s.tbls.values(); } /** @@ -1118,11 +1005,11 @@ public class IgniteH2Indexing implements GridQueryIndexing { /** {@inheritDoc} */ @Override public void rebuildIndexes(@Nullable String spaceName, GridQueryTypeDescriptor type) { - if (offheap != null) - throw new UnsupportedOperationException("Index rebuilding is not supported when off-heap memory is used"); - TableDescriptor tbl = tableDescriptor(spaceName, type); + if (tbl.schema.offheap != null) + throw new UnsupportedOperationException("Index rebuilding is not supported when off-heap memory is used"); + if (tbl == null) return; @@ -1157,14 +1044,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { nodeId = ctx.localNodeId(); marshaller = ctx.config().getMarshaller(); - QueryConfiguration cfg0 = ctx.config().getQueryConfiguration(); - - if (cfg0 != null) - cfg = cfg0; - - for (CacheConfiguration cacheCfg : ctx.config().getCacheConfiguration()) - registerSpace(cacheCfg.getName()); - mapQryExec = new GridMapQueryExecutor(); rdcQryExec = new GridReduceQueryExecutor(); @@ -1180,16 +1059,10 @@ public class IgniteH2Indexing implements GridQueryIndexing { SysProperties.serializeJavaObject = false; } - if (cfg.isUseOptimizedSerializer()) - Utils.serializer = h2Serializer(ctx != null && ctx.deploy().enabled()); - - long maxOffHeapMemory = cfg.getMaxOffHeapMemory(); + if (Utils.serializer != null) + U.warn(log, "Custom H2 serialization is already configured, will override."); - if (maxOffHeapMemory != -1) { - assert maxOffHeapMemory >= 0 : maxOffHeapMemory; - - offheap = new GridUnsafeMemory(maxOffHeapMemory); - } + Utils.serializer = h2Serializer(ctx != null && ctx.deploy().enabled()); String dbName = UUID.randomUUID().toString(); @@ -1202,13 +1075,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { throw new IgniteCheckedException("Failed to find org.h2.Driver class", e); } - for (String schema : schemaNames) - createSchemaIfAbsent(schema); - try { - createSqlFunctions(); - runInitScript(); - if (getString(IGNITE_H2_DEBUG_CONSOLE) != null) { Connection c = DriverManager.getConnection(dbUrl); @@ -1321,37 +1188,17 @@ public class IgniteH2Indexing implements GridQueryIndexing { } /** - * Runs initial script. - * - * @throws IgniteCheckedException If failed. - * @throws SQLException If failed. - */ - private void runInitScript() throws IgniteCheckedException, SQLException { - String initScriptPath = cfg.getInitialScriptPath(); - - if (initScriptPath == null) - return; - - try (PreparedStatement p = connectionForThread(null).prepareStatement("RUNSCRIPT FROM ? CHARSET 'UTF-8'")) { - p.setString(1, initScriptPath); - - p.execute(); - } - } - - /** * Registers SQL functions. * - * @throws SQLException If failed. + * @param schema Schema. + * @param clss Classes. * @throws IgniteCheckedException If failed. */ - private void createSqlFunctions() throws SQLException, IgniteCheckedException { - Class<?>[] idxCustomFuncClss = cfg.getIndexCustomFunctionClasses(); - - if (F.isEmpty(idxCustomFuncClss)) + private void createSqlFunctions(String schema, Class<?>[] clss) throws IgniteCheckedException { + if (F.isEmpty(clss)) return; - for (Class<?> cls : idxCustomFuncClss) { + for (Class<?> cls : clss) { for (Method m : cls.getDeclaredMethods()) { QuerySqlFunction ann = m.getAnnotation(QuerySqlFunction.class); @@ -1363,14 +1210,12 @@ public class IgniteH2Indexing implements GridQueryIndexing { String alias = ann.alias().isEmpty() ? m.getName() : ann.alias(); - String clause = "CREATE ALIAS " + alias + (ann.deterministic() ? " DETERMINISTIC FOR \"" : - " FOR \"") + cls.getName() + '.' + m.getName() + '"'; - - Connection c = connectionForThread(schema(null)); + String clause = "CREATE ALIAS IF NOT EXISTS " + alias + (ann.deterministic() ? + " DETERMINISTIC FOR \"" : + " FOR \"") + + cls.getName() + '.' + m.getName() + '"'; - try (Statement s = c.createStatement()) { - s.execute(clause); - } + executeStatement(schema, clause); } } } @@ -1385,8 +1230,8 @@ public class IgniteH2Indexing implements GridQueryIndexing { Connection conn = connectionForThread(null); - for (ConcurrentMap<String, TableDescriptor> m : schemas.values()) { - for (TableDescriptor desc : m.values()) { + for (Schema schema : schemas.values()) { + for (TableDescriptor desc : schema.tbls.values()) { desc.tbl.close(); if (desc.luceneIdx != null) @@ -1416,74 +1261,26 @@ public class IgniteH2Indexing implements GridQueryIndexing { conns.clear(); schemas.clear(); - rowCache.clear(); if (log.isDebugEnabled()) log.debug("Cache query index stopped."); } - /** - * @param spaceName Space name. - * @return {@code true} If primitive keys must be indexed. - */ - public boolean isIndexPrimitiveKey(@Nullable String spaceName) { - CacheQueryConfiguration cfg = cacheQueryConfiguration(spaceName); - - return cfg != null && cfg.isIndexPrimitiveKey(); - } - - /** - * @param spaceName Space name. - * @return {@code true} If primitive values must be indexed. - */ - public boolean isIndexPrimitiveValue(String spaceName) { - CacheQueryConfiguration cfg = cacheQueryConfiguration(spaceName); - - return cfg != null && cfg.isIndexPrimitiveValue(); - } - - /** {@inheritDoc} */ - public boolean isIndexFixedTyping(String spaceName) { - CacheQueryConfiguration cfg = cacheQueryConfiguration(spaceName); - - return cfg != null && cfg.isIndexFixedTyping(); - } - /** {@inheritDoc} */ public boolean isEscapeAll(String spaceName) { - CacheQueryConfiguration cfg = cacheQueryConfiguration(spaceName); - - return cfg != null && cfg.isEscapeAll(); - } - - /** - * @param spaceName Space name. - * @return Cache query configuration. - */ - @Nullable private CacheQueryConfiguration cacheQueryConfiguration(String spaceName) { - return ctx == null ? null : ctx.cache().internalCache(spaceName).configuration().getQueryConfiguration(); + return ctx.cache().cache(spaceName).configuration().isSqlEscapeAll(); } /** {@inheritDoc} */ - public int getMaxOffheapRowsCacheSize() { - return (int)rowCache.getMaxMemory(); - } + public void registerCache(CacheConfiguration<?,?> ccfg) throws IgniteCheckedException { + String schema = schema(ccfg.getName()); - /** {@inheritDoc} */ - public int getOffheapRowsCacheSize() { - return (int)rowCache.getUsedMemory(); - } + createSchema(schema); - /** {@inheritDoc} */ - public long getAllocatedOffHeapMemory() { - return offheap == null ? -1 : offheap.allocatedSize(); - } + schemas.put(schema, new Schema(schema, ccfg.getOffHeapMaxMemory() >= 0 ? new GridUnsafeMemory(0) : null, + ccfg.getSqlOnheapRowCacheSize())); - /** - * @param spaceName Space name. - */ - public void registerSpace(String spaceName) { - schemaNames.add(schema(spaceName)); + createSqlFunctions(schema, ccfg.getSqlFunctionClasses()); } /** {@inheritDoc} */ @@ -1695,10 +1492,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { private final GridQueryTypeDescriptor type; /** */ - private final String spaceName; - - /** */ - private final String schema; + private final Schema schema; /** */ private GridH2Table tbl; @@ -1707,23 +1501,22 @@ public class IgniteH2Indexing implements GridQueryIndexing { private GridLuceneIndex luceneIdx; /** - * @param spaceName Space name. + * @param schema Schema. * @param type Type descriptor. */ - TableDescriptor(@Nullable String spaceName, GridQueryTypeDescriptor type) { - this.spaceName = spaceName; + TableDescriptor(Schema schema, GridQueryTypeDescriptor type) { this.type = type; + this.schema = schema; - schema = IgniteH2Indexing.schema(spaceName); - - fullTblName = '\"' + schema + "\"." + escapeName(type.name(), isEscapeAll(spaceName)); + fullTblName = '\"' + IgniteH2Indexing.schema(schema.spaceName) + "\"." + + escapeName(type.name(), isEscapeAll(schema.spaceName)); } /** * @return Schema name. */ public String schema() { - return schema; + return IgniteH2Indexing.schema(schema.spaceName); } /** @@ -1762,7 +1555,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { if (type().valueClass() == String.class) { try { - luceneIdx = new GridLuceneIndex(ctx, marshaller, offheap, spaceName, type, true); + luceneIdx = new GridLuceneIndex(ctx, marshaller, schema.offheap, schema.spaceName, type, true); } catch (IgniteCheckedException e1) { throw new IgniteException(e1); @@ -1775,7 +1568,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { if (idx.type() == FULLTEXT) { try { - luceneIdx = new GridLuceneIndex(ctx, marshaller, offheap, spaceName, type, true); + luceneIdx = new GridLuceneIndex(ctx, marshaller, schema.offheap, schema.spaceName, type, true); } catch (IgniteCheckedException e1) { throw new IgniteException(e1); @@ -1786,7 +1579,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { int i = 0; - boolean escapeAll = isEscapeAll(spaceName); + boolean escapeAll = isEscapeAll(schema.spaceName); for (String field : idx.fields()) { // H2 reserved keywords used as column name is case sensitive. @@ -1982,18 +1775,42 @@ public class IgniteH2Indexing implements GridQueryIndexing { /** * Database schema object. */ - private static class Schema extends ConcurrentHashMap8<String, TableDescriptor> { + private static class Schema { /** */ private static final long serialVersionUID = 0L; /** */ private final String spaceName; + /** */ + private final GridUnsafeMemory offheap; + + /** */ + private final ConcurrentMap<String, TableDescriptor> tbls = new ConcurrentHashMap8<>(); + + /** Cache for deserialized offheap rows. */ + private final CacheLongKeyLIRS<GridH2KeyValueRowOffheap> rowCache; + /** * @param spaceName Space name. + * @param offheap Offheap memory. */ - private Schema(@Nullable String spaceName) { + private Schema(@Nullable String spaceName, GridUnsafeMemory offheap, int onheapCacheSize) { this.spaceName = spaceName; + this.offheap = offheap; + + if (offheap != null) + rowCache = new CacheLongKeyLIRS<>(onheapCacheSize, 1, 128, 256); + else + rowCache = null; + } + + /** + * @param tbl Table descriptor. + */ + public void add(TableDescriptor tbl) { + if (tbls.putIfAbsent(tbl.name(), tbl) != null) + throw new IllegalStateException("Table already registered: " + tbl.name()); } } @@ -2020,20 +1837,21 @@ public class IgniteH2Indexing implements GridQueryIndexing { private final Schema schema; /** */ - private final GridUnsafeGuard guard = offheap == null ? null : new GridUnsafeGuard(); + private final GridUnsafeGuard guard; /** * @param type Type descriptor. * @param schema Schema. - * @param keyAsObj Store key as java object. */ - RowDescriptor(GridQueryTypeDescriptor type, Schema schema, boolean keyAsObj) { + RowDescriptor(GridQueryTypeDescriptor type, Schema schema) { assert type != null; assert schema != null; this.type = type; this.schema = schema; + guard = schema.offheap == null ? null : new GridUnsafeGuard(); + Map<String, Class<?>> allFields = new LinkedHashMap<>(); allFields.putAll(type.fields()); @@ -2047,7 +1865,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { for (int i = 0; i < fieldTypes.length; i++) fieldTypes[i] = DataType.getTypeFromClass(classes[i]); - keyType = keyAsObj ? Value.JAVA_OBJECT : DataType.getTypeFromClass(type.keyClass()); + keyType = DataType.getTypeFromClass(type.keyClass()); valType = DataType.getTypeFromClass(type.valueClass()); } @@ -2062,17 +1880,17 @@ public class IgniteH2Indexing implements GridQueryIndexing { assert ptr > 0 : ptr; - rowCache.put(ptr, row); + schema.rowCache.put(ptr, row); } /** {@inheritDoc} */ @Override public void uncache(long ptr) { - rowCache.remove(ptr); + schema.rowCache.remove(ptr); } /** {@inheritDoc} */ @Override public GridUnsafeMemory memory() { - return offheap; + return schema.offheap; } /** {@inheritDoc} */ @@ -2084,7 +1902,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { @Override public GridH2AbstractKeyValueRow createRow(Object key, @Nullable Object val, long expirationTime) throws IgniteCheckedException { try { - return offheap == null ? + return schema.offheap == null ? new GridH2KeyValueRowOnheap(this, key, keyType, val, valType, expirationTime) : new GridH2KeyValueRowOffheap(this, key, keyType, val, valType, expirationTime); } @@ -2137,7 +1955,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { /** {@inheritDoc} */ @Override public GridH2KeyValueRowOffheap createPointer(long ptr) { - GridH2KeyValueRowOffheap row = rowCache.get(ptr); + GridH2KeyValueRowOffheap row = schema.rowCache.get(ptr); if (row != null) { assert row.pointer() == ptr : ptr + " " + row.pointer();