@GridSpiInfo(author="GridGain Systems", url="www.gridgain.com", email="support@gridgain.com", version="6.0.2.${gg.ver.build}") @GridSpiMultipleInstancesSupport(value=true) public class GridH2IndexingSpi extends GridSpiAdapter implements 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))setIndexH2Options(String))setIndexMaxOperationMemory(int))setIndexUsername(String))setIndexPassword(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.
|
String |
getIndexH2Options()
Gets H2 specific options as string.
|
int |
getIndexMaxOperationMemory()
Gets maximum index operation memory.
|
String |
getIndexPassword()
Gets index database password.
|
String |
getIndexUsername()
Gets user name for index database.
|
long |
getIndexWriteLockWaitTime()
Gets index write lock wait time in milliseconds.
|
long |
getLongQueryExecutionTimeout()
Get query execution time interpreted by SPI as long query for additional handling (e.g. print warning).
|
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 |
getSpaceNames()
Gets all registered in this SPI spaces comma separated.
|
protected GridSpiContext |
getSpiContext()
Gets SPI context.
|
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(GridSpiContext spiCtx)
Method to be called in the end of onContextInitialized method.
|
<K> void |
onSwap(String spaceName,
String swapSpaceName,
K key)
Will be called when entry with given key is swapped.
|
<K,V> void |
onUnswap(String spaceName,
K key,
V val,
byte[] valBytes)
Will be called when entry with given key is unswapped.
|
<K,V> GridSpiCloseableIterator<GridIndexingKeyValueRow<K,V>> |
query(String spaceName,
String qry,
Collection<Object> params,
GridIndexingTypeDescriptor type,
GridIndexingQueryFilter<K,V>... filters)
Executes regular query.
|
<K,V> GridIndexingFieldsResult |
queryFields(String spaceName,
String qry,
Collection<Object> params,
GridIndexingQueryFilter<K,V>... filters)
Queries individual fields (generally used by JDBC drivers).
|
<K,V> GridSpiCloseableIterator<GridIndexingKeyValueRow<K,V>> |
queryText(String spaceName,
String qry,
GridIndexingTypeDescriptor type,
GridIndexingQueryFilter<K,V>... filters)
Executes text query.
|
void |
rebuildIndexes(String spaceName,
GridIndexingTypeDescriptor type)
Rebuilds all indexes of given type.
|
void |
registerMarshaller(GridIndexingMarshaller marshaller)
Marshaller to be used by SPI.
|
void |
registerSpace(String spaceName)
Registers space in this SPI.
|
boolean |
registerType(String spaceName,
GridIndexingTypeDescriptor type)
Registers new class description.
|
<K> boolean |
remove(String spaceName,
GridIndexingEntity<K> k)
Removes index entry by key.
|
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 |
setIndexH2Options(String idxH2Options)
Gets H2 specific options as string.
|
void |
setIndexMaxOperationMemory(int idxMaxOperationMemory)
Sets maximum index operation memory in bytes or 0 for no limit.
|
void |
setIndexPassword(String idxPwd)
Gets index database password.
|
void |
setIndexUsername(String idxUsername)
Sets user name for index database.
|
void |
setIndexWriteLockWaitTime(long idxWriteLockWaitTime)
Sets index write lock wait time in milliseconds.
|
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 |
setSpaceConfigurations(GridH2IndexingSpaceConfiguration... spaceCfgs)
Sets per-space configurations.
|
long |
size(String spaceName,
GridIndexingTypeDescriptor type)
Gets size of index for given type or -1 if it is a unknown type.
|
void |
spiStart(String gridName)
This method is called to start SPI.
|
void |
spiStop()
This method is called to stop SPI.
|
<K,V> void |
store(String spaceName,
GridIndexingTypeDescriptor type,
GridIndexingEntity<K> k,
GridIndexingEntity<V> v,
byte[] ver,
long expirationTime)
Updates index.
|
void |
unregisterType(String spaceName,
GridIndexingTypeDescriptor type)
Unregisters type and removes all corresponding data.
|
assertParameter, checkConfigurationConsistency0, configInfo, createSpiAttributeName, getAuthor, getConsistentAttributeNames, getGridGainHome, getLocalNodeId, getName, getNodeAttributes, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion, injectables, onContextDestroyed, onContextDestroyed0, onContextInitialized, registerMBean, setJson, setName, startInfo, startStopwatch, stopInfo, unregisterMBeanclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetName, getNodeAttributes, onContextDestroyed, onContextInitializedgetAuthor, getGridGainHome, getLocalNodeId, getName, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersionpublic 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, GridIndexingTypeDescriptor type, GridIndexingEntity<K> k, GridIndexingEntity<V> v, byte[] ver, long expirationTime) throws GridSpiException
store in interface GridIndexingSpispaceName - Space name.type - Value type.k - Key.v - Value.ver - Version.expirationTime - Expiration time or 0 if never expires.GridSpiException - If failed.public <K> boolean remove(@Nullable String spaceName, GridIndexingEntity<K> k) throws GridSpiException
remove in interface GridIndexingSpispaceName - Space name.k - Key.True if removed by this operation, false otherwise.GridSpiException - If failed.protected void onContextInitialized0(GridSpiContext spiCtx) throws GridSpiException
onContextInitialized0 in class GridSpiAdapterspiCtx - SPI context.GridSpiException - In case of errors.protected GridSpiContext getSpiContext()
getSpiContext in class GridSpiAdapterpublic <K> void onSwap(@Nullable String spaceName, String swapSpaceName, K key) throws GridSpiException
onSwap in interface GridIndexingSpispaceName - Space name.swapSpaceName - Swap space name.key - Key.GridSpiException - If failed.public <K,V> void onUnswap(@Nullable String spaceName, K key, V val, byte[] valBytes) throws GridSpiException
onUnswap in interface GridIndexingSpispaceName - Space name.key - Key.val - Value.valBytes - Value bytes.GridSpiException - If failed.public <K,V> GridSpiCloseableIterator<GridIndexingKeyValueRow<K,V>> queryText(@Nullable String spaceName, String qry, GridIndexingTypeDescriptor type, GridIndexingQueryFilter<K,V>... filters) throws GridSpiException
queryText in interface GridIndexingSpispaceName - Space name.qry - Text query.type - Query return type.filters - Space name and key filter.GridSpiException - If failed.public void unregisterType(@Nullable
String spaceName,
GridIndexingTypeDescriptor type)
throws GridSpiException
unregisterType in interface GridIndexingSpispaceName - Space name.type - Type descriptor.GridSpiException - If failed.public <K,V> GridIndexingFieldsResult queryFields(@Nullable String spaceName, String qry, @Nullable Collection<Object> params, GridIndexingQueryFilter<K,V>... filters) throws GridSpiException
queryFields in interface GridIndexingSpispaceName - Space name.qry - Query.params - Query parameters.filters - Space name and key filters.GridSpiException - If failed.public <K,V> GridSpiCloseableIterator<GridIndexingKeyValueRow<K,V>> query(@Nullable String spaceName, String qry, @Nullable Collection<Object> params, GridIndexingTypeDescriptor type, GridIndexingQueryFilter<K,V>... filters) throws GridSpiException
query in interface GridIndexingSpispaceName - Space name.qry - Query.params - Query parameters.type - Query return type.filters - Space name and key filters.GridSpiException - If failed.public boolean registerType(@Nullable
String spaceName,
GridIndexingTypeDescriptor type)
throws GridSpiException
registerType in interface GridIndexingSpitype - Type description.spaceName - Space name.True if type was registered, false if for some reason it was rejected.GridSpiException - In case of error.public void rebuildIndexes(@Nullable
String spaceName,
GridIndexingTypeDescriptor type)
rebuildIndexes in interface GridIndexingSpispaceName - Space name.type - Type descriptor.public long size(@Nullable
String spaceName,
GridIndexingTypeDescriptor type)
throws GridSpiException
size in interface GridIndexingSpispaceName - Space name.type - Type descriptor.GridSpiException - If failed.public void spiStart(@Nullable
String gridName)
throws GridSpiException
spiStart in interface GridSpigridName - Name of grid instance this SPI is being started for
(null for default grid).GridSpiException - Throws in case of any error during SPI start.public void spiStop()
throws GridSpiException
Note that this method can be called at any point including during recovery of failed start. It should make no assumptions on what state SPI will be in when this method is called.
spiStop in interface GridSpiGridSpiException - Thrown in case of any error during SPI stop.public String getIndexUsername()
getIndexUsername in interface GridH2IndexingSpiMBean@GridSpiConfiguration(optional=true) public void setIndexUsername(String idxUsername)
idxUsername - User name.public String getIndexPassword()
getIndexPassword in interface GridH2IndexingSpiMBean@GridSpiConfiguration(optional=true) public void setIndexPassword(String idxPwd)
idxPwd - Password.public 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.public int getIndexMaxOperationMemory()
getIndexMaxOperationMemory in interface GridH2IndexingSpiMBean@GridSpiConfiguration(optional=true) public void setIndexMaxOperationMemory(int idxMaxOperationMemory)
idxMaxOperationMemory - Max operation memory.public String getIndexH2Options()
getIndexH2Options in interface GridH2IndexingSpiMBean@GridSpiConfiguration(optional=true) public void setIndexH2Options(String idxH2Options)
idxH2Options - H2 Options.@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.public int getMaxOffheapRowsCacheSize()
getMaxOffheapRowsCacheSize in interface GridH2IndexingSpiMBeanpublic int getOffheapRowsCacheSize()
getOffheapRowsCacheSize in interface GridH2IndexingSpiMBeanpublic long getAllocatedOffHeapMemory()
getAllocatedOffHeapMemory in interface GridH2IndexingSpiMBeanpublic void registerMarshaller(GridIndexingMarshaller marshaller)
registerMarshaller in interface GridIndexingSpimarshaller - Marshaller.public void registerSpace(String spaceName) throws GridSpiException
registerSpace in interface GridIndexingSpispaceName - Space name.GridSpiException - If failed.@GridSpiConfiguration(optional=true) public void setSpaceConfigurations(GridH2IndexingSpaceConfiguration... spaceCfgs)
spaceCfgs - Space configurations list.
Core Products
:
Data Grid ver. 6.0.2,
Streaming ver. 6.0.2
Accelerators
:
Hadoop Accelerator ver. 6.0.2
Release Date
:
March 24 2014