use of org.apache.ignite.internal.processors.query.h2.H2TableDescriptor in project ignite by apache.
the class IgniteH2Indexing method addInitialUserIndex.
/**
* Add initial user index.
*
* @param schemaName Schema name.
* @param desc Table descriptor.
* @param h2Idx User index.
* @throws IgniteCheckedException If failed.
*/
private void addInitialUserIndex(String schemaName, H2TableDescriptor desc, GridH2IndexBase h2Idx) throws IgniteCheckedException {
GridH2Table h2Tbl = desc.table();
h2Tbl.proposeUserIndex(h2Idx);
try {
String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, false);
executeSql(schemaName, sql);
} catch (Exception e) {
// Rollback and re-throw.
h2Tbl.rollbackUserIndex(h2Idx.getName());
throw e;
}
}
use of org.apache.ignite.internal.processors.query.h2.H2TableDescriptor in project ignite by apache.
the class IgniteH2Indexing method dynamicIndexCreate.
/**
* {@inheritDoc}
*/
@Override
public void dynamicIndexCreate(final String schemaName, final String tblName, final QueryIndexDescriptorImpl idxDesc, boolean ifNotExists, SchemaIndexCacheVisitor cacheVisitor) throws IgniteCheckedException {
// Locate table.
H2Schema schema = schemas.get(schemaName);
H2TableDescriptor desc = (schema != null ? schema.tableByName(tblName) : null);
if (desc == null)
throw new IgniteCheckedException("Table not found in internal H2 database [schemaName=" + schemaName + ", tblName=" + tblName + ']');
GridH2Table h2Tbl = desc.table();
// Create index.
final GridH2IndexBase h2Idx = desc.createUserIndex(idxDesc);
h2Tbl.proposeUserIndex(h2Idx);
try {
// Populate index with existing cache data.
final GridH2RowDescriptor rowDesc = h2Tbl.rowDescriptor();
SchemaIndexCacheVisitorClosure clo = new SchemaIndexCacheVisitorClosure() {
@Override
public void apply(CacheDataRow row) throws IgniteCheckedException {
GridH2Row h2Row = rowDesc.createRow(row);
h2Idx.putx(h2Row);
}
};
cacheVisitor.visit(clo);
// At this point index is in consistent state, promote it through H2 SQL statement, so that cached
// prepared statements are re-built.
String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, ifNotExists);
executeSql(schemaName, sql);
} catch (Exception e) {
// Rollback and re-throw.
h2Tbl.rollbackUserIndex(h2Idx.getName());
throw e;
}
}
use of org.apache.ignite.internal.processors.query.h2.H2TableDescriptor in project ignite by apache.
the class IgniteH2Indexing method generateFieldsQuery.
/**
* {@inheritDoc}
*/
@SuppressWarnings("deprecation")
@Override
public SqlFieldsQuery generateFieldsQuery(String cacheName, SqlQuery qry) {
String schemaName = schema(cacheName);
String type = qry.getType();
H2TableDescriptor tblDesc = schemaMgr.tableForType(schemaName, cacheName, type);
if (tblDesc == null)
throw new IgniteSQLException("Failed to find SQL table for type: " + type, IgniteQueryErrorCode.TABLE_NOT_FOUND);
String sql;
try {
sql = generateFieldsQueryString(qry.getSql(), qry.getAlias(), tblDesc);
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
SqlFieldsQuery res = QueryUtils.withQueryTimeout(new SqlFieldsQuery(sql), qry.getTimeout(), TimeUnit.MILLISECONDS);
res.setArgs(qry.getArgs());
res.setDistributedJoins(qry.isDistributedJoins());
res.setLocal(qry.isLocal());
res.setPageSize(qry.getPageSize());
res.setPartitions(qry.getPartitions());
res.setReplicatedOnly(qry.isReplicatedOnly());
res.setSchema(schemaName);
res.setSql(sql);
return res;
}
use of org.apache.ignite.internal.processors.query.h2.H2TableDescriptor in project ignite by apache.
the class IgniteH2Indexing method store.
/**
* {@inheritDoc}
*/
@Override
public void store(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow row, @Nullable CacheDataRow prevRow, boolean prevRowAvailable) throws IgniteCheckedException {
String cacheName = cctx.name();
H2TableDescriptor tbl = schemaMgr.tableForType(schema(cacheName), cacheName, type.name());
if (tbl == null)
// Type was rejected.
return;
if (tbl.luceneIndex() != null) {
long expireTime = row.expireTime();
if (expireTime == 0L)
expireTime = Long.MAX_VALUE;
tbl.luceneIndex().store(row.key(), row.value(), row.version(), expireTime);
}
tbl.table().update(row, prevRow);
}
use of org.apache.ignite.internal.processors.query.h2.H2TableDescriptor in project ignite by apache.
the class SchemaManager method onCacheDestroyed.
/**
* Handle cache destroy.
*
* @param cacheName Cache name.
* @param rmvIdx Whether to remove indexes.
*/
public void onCacheDestroyed(String cacheName, boolean rmvIdx) {
String schemaName = schemaName(cacheName);
H2Schema schema = schemas.get(schemaName);
// Remove this mapping only after callback to DML proc - it needs that mapping internally
cacheName2schema.remove(cacheName);
// Drop tables.
Collection<H2TableDescriptor> rmvTbls = new HashSet<>();
for (H2TableDescriptor tbl : schema.tables()) {
if (F.eq(tbl.cacheName(), cacheName)) {
try {
tbl.table().setRemoveIndexOnDestroy(rmvIdx);
dropTable(tbl, rmvIdx);
} catch (Exception e) {
U.error(log, "Failed to drop table on cache stop (will ignore): " + tbl.fullTableName(), e);
}
schema.drop(tbl);
rmvTbls.add(tbl);
GridH2Table h2Tbl = tbl.table();
dataTables.remove(h2Tbl.identifier(), h2Tbl);
}
}
synchronized (schemaMux) {
if (schema.decrementUsageCount()) {
schemas.remove(schemaName);
try {
dropSchema(schemaName);
} catch (Exception e) {
U.error(log, "Failed to drop schema on cache stop (will ignore): " + cacheName, e);
}
}
}
for (H2TableDescriptor tbl : rmvTbls) {
for (Index idx : tbl.table().getIndexes()) idx.close(null);
}
}
Aggregations