@GridSpiMultipleInstancesSupport(value=true) public class GridH2IndexingSpi extends org.gridgain.grid.spi.GridSpiAdapter implements org.gridgain.grid.spi.indexing.GridIndexingSpi, GridH2IndexingSpiMBean
PUBLIC will be used. To avoid name conflicts user should not explicitly name
a schema PUBLIC.
For each registered GridIndexingTypeDescriptor this SPI will create respective SQL table with
'_key' and '_val' fields for key and value, and fields from
GridIndexingTypeDescriptor.keyFields() and GridIndexingTypeDescriptor.valueFields().
For each table it will create indexes declared in GridIndexingTypeDescriptor.indexes().
Note that you can monitor longer queries by setting setLongQueryExplain(boolean) to true.
In this case a warning and execution plan are printed out if query exceeds certain time threshold. The
time threshold for long queries is configured via setLongQueryExecutionTimeout(long) parameter.
setDefaultIndexFixedTyping(boolean))setDefaultIndexPrimitiveKey(boolean))setDefaultIndexPrimitiveValue(boolean))setSearchPath(String...))setMaxOffHeapMemory(long))setMaxOffheapRowsCacheSize(int))GridSpiAdapter.setName(String))setLongQueryExecutionTimeout(long))setLongQueryExplain(boolean))setIndexCustomFunctionClasses(Class[]))setSpaceConfigurations(GridH2IndexingSpaceConfiguration...))GridH2IndexingSpi.
GridH2IndexingSpi spi = new GridH2IndexingSpi(); // Set SPI name. spi.setName(name); spi.setDefaultIndexPrimitiveKey(true); spi.setDefaultIndexPrimitiveValue(true); GridConfiguration cfg = new GridConfiguration(); // Overrides default indexing SPI. cfg.setIndexingSpi(spi); // Starts grid. G.start(cfg);Here is an example of how to configure
GridH2IndexingSpi from Spring XML configuration file.
<property name="indexingSpi">
<list>
<bean class="org.gridgain.grid.spi.indexing.h2.GridH2IndexingSpi">
<!-- Index primitives. -->
<property name="defaultIndexPrimitiveKey" value="true"/>
<!-- Allow different key types for one value type. -->
<property name="defaultIndexFixedTyping" value="false"/>
</bean>
</list>
</property>
For information about Spring framework visit www.springframework.org
GridIndexingSpi| Modifier and Type | Field and Description |
|---|---|
static long |
DFLT_LONG_QRY_EXEC_TIMEOUT
Default query execution time interpreted as long query (3 seconds).
|
static String |
EXPIRATION_TIME_FIELD_NAME
Field name for value expiration time.
|
static String |
KEY_FIELD_NAME
Field name for key.
|
static String |
VAL_FIELD_NAME
Field name for value.
|
static String |
VAL_STR_FIELD_NAME
Field name for string representation of value.
|
static String |
VER_FIELD_NAME
Field name for value version.
|
| Constructor and Description |
|---|
GridH2IndexingSpi() |
| Modifier and Type | Method and Description |
|---|---|
long |
getAllocatedOffHeapMemory()
Gets currently allocated offheap memory.
|
long |
getIndexWriteLockWaitTime()
Gets index write lock wait time in milliseconds.
|
String |
getInitialScriptPath()
Gets script path to be ran against H2 database after opening.
|
long |
getLongQueryExecutionTimeout()
Get query execution time interpreted by SPI as long query for additional handling (e.g.
|
long |
getMaxOffHeapMemory()
Gets maximum amount of memory available to off-heap storage.
|
int |
getMaxOffheapRowsCacheSize()
Gets maximum allowed off-heap rows cache size in items.
|
int |
getOffheapRowsCacheSize()
Gets current off-heap rows cache size in items.
|
String[] |
getSearchPath()
Gets the optional search path consisting of space names to search SQL schema objects.
|
String |
getSpaceNames()
Gets all registered in this SPI spaces comma separated.
|
protected org.gridgain.grid.spi.GridSpiContext |
getSpiContext() |
boolean |
isDefaultIndexFixedTyping()
If false, SPI will store all keys in BINARY form to make it possible to store
the same value type with different key types.
|
boolean |
isDefaultIndexPrimitiveKey()
Gets if SPI will index primitive key-value pairs by key.
|
boolean |
isDefaultIndexPrimitiveValue()
Gets if SPI will index primitive key-value pairs by value.
|
boolean |
isIndexFixedTyping(String spaceName)
If
false, SPI will store all keys in BINARY form to make it possible to store
the same value type with different key types. |
boolean |
isIndexPrimitiveKey(String spaceName)
Defines whether indexing SPI will index by key entries where key and value are primitive types in given space.
|
boolean |
isIndexPrimitiveValue(String spaceName)
Defines whether indexing SPI will index by value entries where key and value are primitive types in given space.
|
boolean |
isLongQueryExplain()
If
true, SPI prints SQL execution plan for long queries (explain SQL query). |
protected void |
onContextInitialized0(org.gridgain.grid.spi.GridSpiContext spiCtx) |
<K> void |
onSwap(String spaceName,
String swapSpaceName,
K key) |
<K,V> void |
onUnswap(String spaceName,
K key,
V val,
byte[] valBytes) |
<K,V> org.gridgain.grid.spi.GridSpiCloseableIterator<org.gridgain.grid.spi.indexing.GridIndexingKeyValueRow<K,V>> |
query(String spaceName,
String qry,
Collection<Object> params,
org.gridgain.grid.spi.indexing.GridIndexingTypeDescriptor type,
org.gridgain.grid.spi.indexing.GridIndexingQueryFilter<K,V>... filters)
Executes regular query.
|
<K,V> org.gridgain.grid.spi.indexing.GridIndexingFieldsResult |
queryFields(String spaceName,
String qry,
Collection<Object> params,
org.gridgain.grid.spi.indexing.GridIndexingQueryFilter<K,V>... filters) |
<K,V> org.gridgain.grid.spi.GridSpiCloseableIterator<org.gridgain.grid.spi.indexing.GridIndexingKeyValueRow<K,V>> |
queryText(String spaceName,
String qry,
org.gridgain.grid.spi.indexing.GridIndexingTypeDescriptor type,
org.gridgain.grid.spi.indexing.GridIndexingQueryFilter<K,V>... filters) |
void |
rebuildIndexes(String spaceName,
org.gridgain.grid.spi.indexing.GridIndexingTypeDescriptor type) |
void |
registerMarshaller(org.gridgain.grid.spi.indexing.GridIndexingMarshaller marshaller) |
void |
registerSpace(String spaceName) |
boolean |
registerType(String spaceName,
org.gridgain.grid.spi.indexing.GridIndexingTypeDescriptor type)
Registers new class description.
|
<K> boolean |
remove(String spaceName,
org.gridgain.grid.spi.indexing.GridIndexingEntity<K> k) |
void |
setDefaultIndexFixedTyping(boolean dfltIdxFixedTyping)
This flag essentially controls whether all values of the same type have
identical key type.
|
void |
setDefaultIndexPrimitiveKey(boolean dfltIdxPrimitiveKey)
Sets if SPI will index primitive key-value pairs by key.
|
void |
setDefaultIndexPrimitiveValue(boolean dfltIdxPrimitiveVal)
Sets if SPI will index primitive key-value pairs by value.
|
void |
setIndexCustomFunctionClasses(Class<?>... idxCustomFuncClss)
Sets classes with methods annotated by
GridCacheQuerySqlFunction
to be used as user-defined functions from SQL queries. |
void |
setIndexWriteLockWaitTime(long idxWriteLockWaitTime)
Sets index write lock wait time in milliseconds.
|
void |
setInitialScriptPath(String initScriptPath)
Sets script path to be ran against H2 database after opening.
|
void |
setLongQueryExecutionTimeout(long longQryExecTimeout)
Set query execution time threshold.
|
void |
setLongQueryExplain(boolean longQryExplain)
If
true, SPI will print SQL execution plan for long queries (explain SQL query). |
void |
setMaxOffHeapMemory(long maxOffHeapMemory)
Sets maximum amount of memory available to off-heap storage.
|
void |
setMaxOffheapRowsCacheSize(int size)
Specifies max allowed size of cache for deserialized offheap rows to avoid deserialization costs for most
frequently used ones.
|
void |
setSearchPath(String... searchPath)
Sets the optional search path consisting of space names to search SQL schema objects.
|
void |
setSpaceConfigurations(GridH2IndexingSpaceConfiguration... spaceCfgs)
Sets per-space configurations.
|
long |
size(String spaceName,
org.gridgain.grid.spi.indexing.GridIndexingTypeDescriptor type) |
void |
spiStart(String gridName) |
void |
spiStop() |
<K,V> void |
store(String spaceName,
org.gridgain.grid.spi.indexing.GridIndexingTypeDescriptor type,
org.gridgain.grid.spi.indexing.GridIndexingEntity<K> k,
org.gridgain.grid.spi.indexing.GridIndexingEntity<V> v,
byte[] ver,
long expirationTime) |
void |
unregisterType(String spaceName,
org.gridgain.grid.spi.indexing.GridIndexingTypeDescriptor type) |
assertParameter, checkConfigurationConsistency0, configInfo, createSpiAttributeName, getConsistentAttributeNames, getGridGainHome, getLocalNodeId, getName, getNodeAttributes, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, injectables, onContextDestroyed, onContextDestroyed0, onContextInitialized, registerMBean, setName, startInfo, startStopwatch, stopInfo, unregisterMBeanclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitpublic static final long DFLT_LONG_QRY_EXEC_TIMEOUT
public static final String KEY_FIELD_NAME
public static final String VAL_FIELD_NAME
public static final String VAL_STR_FIELD_NAME
public static final String VER_FIELD_NAME
public static final String EXPIRATION_TIME_FIELD_NAME
public <K,V> void store(@Nullable
String spaceName,
org.gridgain.grid.spi.indexing.GridIndexingTypeDescriptor type,
org.gridgain.grid.spi.indexing.GridIndexingEntity<K> k,
org.gridgain.grid.spi.indexing.GridIndexingEntity<V> v,
byte[] ver,
long expirationTime)
throws org.gridgain.grid.spi.GridSpiException
store in interface org.gridgain.grid.spi.indexing.GridIndexingSpiorg.gridgain.grid.spi.GridSpiExceptionpublic <K> boolean remove(@Nullable
String spaceName,
org.gridgain.grid.spi.indexing.GridIndexingEntity<K> k)
throws org.gridgain.grid.spi.GridSpiException
remove in interface org.gridgain.grid.spi.indexing.GridIndexingSpiorg.gridgain.grid.spi.GridSpiExceptionprotected void onContextInitialized0(org.gridgain.grid.spi.GridSpiContext spiCtx)
throws org.gridgain.grid.spi.GridSpiException
onContextInitialized0 in class org.gridgain.grid.spi.GridSpiAdapterorg.gridgain.grid.spi.GridSpiExceptionprotected org.gridgain.grid.spi.GridSpiContext getSpiContext()
getSpiContext in class org.gridgain.grid.spi.GridSpiAdapterpublic <K> void onSwap(@Nullable
String spaceName,
String swapSpaceName,
K key)
throws org.gridgain.grid.spi.GridSpiException
onSwap in interface org.gridgain.grid.spi.indexing.GridIndexingSpiorg.gridgain.grid.spi.GridSpiExceptionpublic <K,V> void onUnswap(@Nullable
String spaceName,
K key,
V val,
byte[] valBytes)
throws org.gridgain.grid.spi.GridSpiException
onUnswap in interface org.gridgain.grid.spi.indexing.GridIndexingSpiorg.gridgain.grid.spi.GridSpiExceptionpublic <K,V> org.gridgain.grid.spi.GridSpiCloseableIterator<org.gridgain.grid.spi.indexing.GridIndexingKeyValueRow<K,V>> queryText(@Nullable
String spaceName,
String qry,
org.gridgain.grid.spi.indexing.GridIndexingTypeDescriptor type,
org.gridgain.grid.spi.indexing.GridIndexingQueryFilter<K,V>... filters)
throws org.gridgain.grid.spi.GridSpiException
queryText in interface org.gridgain.grid.spi.indexing.GridIndexingSpiorg.gridgain.grid.spi.GridSpiExceptionpublic void unregisterType(@Nullable
String spaceName,
org.gridgain.grid.spi.indexing.GridIndexingTypeDescriptor type)
throws org.gridgain.grid.spi.GridSpiException
unregisterType in interface org.gridgain.grid.spi.indexing.GridIndexingSpiorg.gridgain.grid.spi.GridSpiExceptionpublic <K,V> org.gridgain.grid.spi.indexing.GridIndexingFieldsResult queryFields(@Nullable
String spaceName,
String qry,
@Nullable
Collection<Object> params,
org.gridgain.grid.spi.indexing.GridIndexingQueryFilter<K,V>... filters)
throws org.gridgain.grid.spi.GridSpiException
queryFields in interface org.gridgain.grid.spi.indexing.GridIndexingSpiorg.gridgain.grid.spi.GridSpiExceptionpublic <K,V> org.gridgain.grid.spi.GridSpiCloseableIterator<org.gridgain.grid.spi.indexing.GridIndexingKeyValueRow<K,V>> query(@Nullable
String spaceName,
String qry,
@Nullable
Collection<Object> params,
org.gridgain.grid.spi.indexing.GridIndexingTypeDescriptor type,
org.gridgain.grid.spi.indexing.GridIndexingQueryFilter<K,V>... filters)
throws org.gridgain.grid.spi.GridSpiException
query in interface org.gridgain.grid.spi.indexing.GridIndexingSpispaceName - Space name.qry - Query.params - Query parameters.type - Query return type.filters - Space name and key filters.org.gridgain.grid.spi.GridSpiException - If failed.public boolean registerType(@Nullable
String spaceName,
org.gridgain.grid.spi.indexing.GridIndexingTypeDescriptor type)
throws org.gridgain.grid.spi.GridSpiException
registerType in interface org.gridgain.grid.spi.indexing.GridIndexingSpitype - Type description.org.gridgain.grid.spi.GridSpiException - In case of error.public void rebuildIndexes(@Nullable
String spaceName,
org.gridgain.grid.spi.indexing.GridIndexingTypeDescriptor type)
rebuildIndexes in interface org.gridgain.grid.spi.indexing.GridIndexingSpipublic long size(@Nullable
String spaceName,
org.gridgain.grid.spi.indexing.GridIndexingTypeDescriptor type)
throws org.gridgain.grid.spi.GridSpiException
size in interface org.gridgain.grid.spi.indexing.GridIndexingSpiorg.gridgain.grid.spi.GridSpiExceptionpublic void spiStart(@Nullable
String gridName)
throws org.gridgain.grid.spi.GridSpiException
spiStart in interface org.gridgain.grid.spi.GridSpiorg.gridgain.grid.spi.GridSpiExceptionpublic void spiStop()
throws org.gridgain.grid.spi.GridSpiException
spiStop in interface org.gridgain.grid.spi.GridSpiorg.gridgain.grid.spi.GridSpiExceptionpublic void setIndexCustomFunctionClasses(Class<?>... idxCustomFuncClss)
GridCacheQuerySqlFunction
to be used as user-defined functions from SQL queries.idxCustomFuncClss - List of classes.public String getSpaceNames()
getSpaceNames in interface GridH2IndexingSpiMBeanpublic long getLongQueryExecutionTimeout()
getLongQueryExecutionTimeout in interface GridH2IndexingSpiMBeanGridH2IndexingSpiMBean.isLongQueryExplain()@GridSpiConfiguration(optional=true) public void setLongQueryExecutionTimeout(long longQryExecTimeout)
setLongQueryExplain(boolean) is
set to true, then execution plan will be printed out as well.
If not provided, default value is defined by DFLT_LONG_QRY_EXEC_TIMEOUT.
longQryExecTimeout - Long query execution timeout.setLongQueryExplain(boolean)public boolean isLongQueryExplain()
true, SPI prints SQL execution plan for long queries (explain SQL query).isLongQueryExplain in interface GridH2IndexingSpiMBeanGridH2IndexingSpiMBean.getLongQueryExecutionTimeout()@GridSpiConfiguration(optional=true) public void setLongQueryExplain(boolean longQryExplain)
true, SPI will print SQL execution plan for long queries (explain SQL query).
The time threshold of long queries is controlled via setLongQueryExecutionTimeout(long)
parameter.
If not provided, default value is false.
longQryExplain - Flag marking SPI should print SQL execution plan for long queries (explain SQL query).setLongQueryExecutionTimeout(long)public boolean isIndexPrimitiveKey(@Nullable
String spaceName)
isIndexPrimitiveKey in interface GridH2IndexingSpiMBeanspaceName - Space name.public boolean isIndexPrimitiveValue(String spaceName)
isIndexPrimitiveValue in interface GridH2IndexingSpiMBeanspaceName - Space name.public boolean isIndexFixedTyping(String spaceName)
false, SPI 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.
Setting this value to false also means that '_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 false is undefined.
isIndexFixedTyping in interface GridH2IndexingSpiMBeanspaceName - Space name.@GridSpiConfiguration(optional=true) public void setDefaultIndexPrimitiveValue(boolean dfltIdxPrimitiveVal)
setDefaultIndexPrimitiveKey(boolean) set to true.dfltIdxPrimitiveVal - Flag value.public boolean isDefaultIndexPrimitiveValue()
setDefaultIndexPrimitiveKey(boolean) set to true.isDefaultIndexPrimitiveValue in interface GridH2IndexingSpiMBean@GridSpiConfiguration(optional=true) public void setDefaultIndexPrimitiveKey(boolean dfltIdxPrimitiveKey)
dfltIdxPrimitiveKey - Flag value.public boolean isDefaultIndexPrimitiveKey()
isDefaultIndexPrimitiveKey in interface GridH2IndexingSpiMBeanpublic boolean isDefaultIndexFixedTyping()
isDefaultIndexFixedTyping in interface GridH2IndexingSpiMBean@GridSpiConfiguration(optional=true) public void setDefaultIndexFixedTyping(boolean dfltIdxFixedTyping)
If false, SPI 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, hence, improving performance of queries.
Setting this value to false also means that '_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 false is undefined.
This property can be overridden on per-space level via GridH2IndexingSpaceConfiguration.
dfltIdxFixedTyping - FLag value.@GridSpiConfiguration(optional=true) public void setMaxOffHeapMemory(long maxOffHeapMemory)
-1 - Means that off-heap storage is disabled.0 - GridGain 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.
-1, which means that off-heap storage is disabled by default.
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 GridGain will cache most of the data in off-heap space without affecting JVM performance at all.
maxOffHeapMemory - Maximum memory in bytes available to off-heap memory space.public long getMaxOffHeapMemory()
-1 - Means that off-heap storage is disabled.0 - GridGain 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.
-1, which means that off-heap storage is disabled by default.
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 GridGain will cache most of the data in off-heap space without affecting JVM performance at all.
getMaxOffHeapMemory in interface GridH2IndexingSpiMBeanpublic void setIndexWriteLockWaitTime(long idxWriteLockWaitTime)
100.idxWriteLockWaitTime - Index write lock wait time.public long getIndexWriteLockWaitTime()
100.getIndexWriteLockWaitTime in interface GridH2IndexingSpiMBean@GridSpiConfiguration(optional=true) public void setMaxOffheapRowsCacheSize(int size)
size - Cache size in items.@GridSpiConfiguration(optional=true) public void setSearchPath(String... searchPath)
searchPath - Search path.@Nullable public String[] getSearchPath()
getSearchPath in interface GridH2IndexingSpiMBean@Nullable public String getInitialScriptPath()
getInitialScriptPath in interface GridH2IndexingSpiMBean@GridSpiConfiguration(optional=true) public void setInitialScriptPath(String initScriptPath)
initScriptPath - Script path.public int getMaxOffheapRowsCacheSize()
getMaxOffheapRowsCacheSize in interface GridH2IndexingSpiMBeanpublic int getOffheapRowsCacheSize()
getOffheapRowsCacheSize in interface GridH2IndexingSpiMBeanpublic long getAllocatedOffHeapMemory()
getAllocatedOffHeapMemory in interface GridH2IndexingSpiMBeanpublic void registerMarshaller(org.gridgain.grid.spi.indexing.GridIndexingMarshaller marshaller)
registerMarshaller in interface org.gridgain.grid.spi.indexing.GridIndexingSpipublic void registerSpace(String spaceName) throws org.gridgain.grid.spi.GridSpiException
registerSpace in interface org.gridgain.grid.spi.indexing.GridIndexingSpiorg.gridgain.grid.spi.GridSpiException@GridSpiConfiguration(optional=true) public void setSpaceConfigurations(GridH2IndexingSpaceConfiguration... spaceCfgs)
spaceCfgs - Space configurations list.Copyright © 2014. All rights reserved.