use of org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl in project ignite by apache.
the class AbstractSchemaSelfTest method assertIndex.
/**
* Assert index state on particular node.
*
* @param node Node.
* @param checkNonAffinityNode Whether existence of {@link GridQueryIndexDescriptor} must be checked regardless of
* whether this node is affinity node or not.
* @param cacheName Cache name.
* @param tblName Table name.
* @param idxName Index name.
* @param fields Fields.
*/
protected static void assertIndex(Ignite node, boolean checkNonAffinityNode, String cacheName, String tblName, String idxName, IgniteBiTuple<String, Boolean>... fields) {
IgniteEx node0 = (IgniteEx) node;
assertIndexDescriptor(node0, cacheName, tblName, idxName, fields);
if (checkNonAffinityNode || affinityNode(node0, cacheName)) {
QueryTypeDescriptorImpl typeDesc = typeExisting(node0, cacheName, tblName);
assertIndex(typeDesc, idxName, fields);
}
}
use of org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl in project ignite by apache.
the class ValidateIndexesClosure method processPartIterator.
/**
* Process partition iterator.
*
* @param grpCtx Cache group context.
* @param partRes Result object.
* @param session H2 session.
* @param it Partition iterator.
* @throws IgniteCheckedException
*/
private void processPartIterator(CacheGroupContext grpCtx, ValidateIndexesPartitionResult partRes, Session session, GridIterator<CacheDataRow> it) throws IgniteCheckedException {
boolean enoughIssues = false;
GridQueryProcessor qryProcessor = ignite.context().query();
final boolean skipConditions = checkFirst > 0 || checkThrough > 0;
final boolean bothSkipConditions = checkFirst > 0 && checkThrough > 0;
long current = 0;
long processedNumber = 0;
while (it.hasNextX() && !validateCtx.isCancelled()) {
if (enoughIssues)
break;
CacheDataRow row = it.nextX();
if (skipConditions) {
if (bothSkipConditions) {
if (processedNumber > checkFirst)
break;
else if (current++ % checkThrough > 0)
continue;
else
processedNumber++;
} else {
if (checkFirst > 0) {
if (current++ > checkFirst)
break;
} else {
if (current++ % checkThrough > 0)
continue;
}
}
}
int cacheId = row.cacheId() == 0 ? grpCtx.groupId() : row.cacheId();
GridCacheContext<?, ?> cacheCtx = row.cacheId() == 0 ? grpCtx.singleCacheContext() : grpCtx.shared().cacheContext(row.cacheId());
if (cacheCtx == null)
throw new IgniteException("Unknown cacheId of CacheDataRow: " + cacheId);
if (row.link() == 0L) {
String errMsg = "Invalid partition row, possibly deleted";
log.error(errMsg);
IndexValidationIssue is = new IndexValidationIssue(null, cacheCtx.name(), null, new IgniteCheckedException(errMsg));
enoughIssues |= partRes.reportIssue(is);
continue;
}
QueryTypeDescriptorImpl res = qryProcessor.typeByValue(cacheCtx.name(), cacheCtx.cacheObjectContext(), row.key(), row.value(), true);
if (res == null)
// Tolerate - (k, v) is just not indexed.
continue;
IgniteH2Indexing indexing = (IgniteH2Indexing) qryProcessor.getIndexing();
GridH2Table gridH2Tbl = indexing.schemaManager().dataTable(cacheCtx.name(), res.tableName());
if (gridH2Tbl == null)
// Tolerate - (k, v) is just not indexed.
continue;
GridH2RowDescriptor gridH2RowDesc = gridH2Tbl.rowDescriptor();
H2CacheRow h2Row = gridH2RowDesc.createRow(row);
ArrayList<Index> indexes = gridH2Tbl.getIndexes();
for (Index idx : indexes) {
if (validateCtx.isCancelled())
break;
if (!(idx instanceof H2TreeIndexBase))
continue;
try {
Cursor cursor = idx.find(session, h2Row, h2Row);
if (cursor == null || !cursor.next())
throw new IgniteCheckedException("Key is present in CacheDataTree, but can't be found in SQL index.");
} catch (Throwable t) {
Object o = CacheObjectUtils.unwrapBinaryIfNeeded(grpCtx.cacheObjectContext(), row.key(), true, true);
IndexValidationIssue is = new IndexValidationIssue(o.toString(), cacheCtx.name(), idx.getName(), t);
log.error("Failed to lookup key: " + is.toString(), t);
enoughIssues |= partRes.reportIssue(is);
}
}
}
}
use of org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl in project ignite by apache.
the class H2DynamicTableSelfTest method testDropTableFromClient.
/**
* Test that {@code DROP TABLE} executed at client node actually removes specified cache and type descriptor on all nodes.
* @throws Exception if failed.
*/
@Test
public void testDropTableFromClient() throws Exception {
execute(grid(0), "CREATE TABLE IF NOT EXISTS \"Person\" (\"id\" int, \"city\" varchar," + " \"name\" varchar, \"surname\" varchar, \"age\" int, PRIMARY KEY (\"id\", \"city\")) WITH " + "\"template=cache\"");
execute(client(), "DROP TABLE \"Person\"");
for (int i = 0; i < 4; i++) {
IgniteEx node = grid(i);
assertNull(node.cache("Person"));
QueryTypeDescriptorImpl desc = type(node, "Person", "Person");
assertNull(desc);
}
}
use of org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl in project ignite by apache.
the class H2DynamicTableSelfTest method testDropTable.
/**
* Test that {@code DROP TABLE} actually removes specified cache and type descriptor on all nodes.
* @throws Exception if failed.
*/
@Test
public void testDropTable() throws Exception {
execute("CREATE TABLE IF NOT EXISTS \"Person\" (\"id\" int, \"city\" varchar," + " \"name\" varchar, \"surname\" varchar, \"age\" int, PRIMARY KEY (\"id\", \"city\")) WITH " + "\"template=cache\"");
execute("DROP TABLE \"Person\"");
for (int i = 0; i < 4; i++) {
IgniteEx node = grid(i);
assertNull(node.cache("Person"));
QueryTypeDescriptorImpl desc = type(node, "Person", "Person");
assertNull(desc);
}
}
use of org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl in project ignite by apache.
the class H2DynamicTableSelfTest method testTableEnabledDynamicallyNotExistsIfCacheDestroyed.
/**
* Tests that after destroying cache with table enabled dynamically that table also is removed.
*
* @throws Exception If failed.
*/
@Test
public void testTableEnabledDynamicallyNotExistsIfCacheDestroyed() throws Exception {
String cacheName = "new";
String tableName = "NewTable";
String createSql = "CREATE TABLE \"" + tableName + "\" (id int primary key, x varchar) WITH " + "\"wrap_key,wrap_value,cache_name=" + cacheName + "\"";
client().getOrCreateCache(cacheName);
execute(client(), createSql);
client().destroyCache(cacheName);
for (Ignite g : G.allGrids()) {
IgniteEx node = (IgniteEx) g;
QueryTypeDescriptorImpl desc = type(node, cacheName, tableName);
assertNull(desc);
assertTrue(execute(g, "SELECT * FROM SYS.TABLES WHERE table_name = '" + tableName + "'").isEmpty());
}
}
Aggregations