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 cacheName Cache name.
* @param tblName Table name.
* @param idxName Index name.
* @param inlineSize Inline size.
* @param fields Fields.
*/
static void assertIndex(Ignite node, String cacheName, String tblName, String idxName, int inlineSize, IgniteBiTuple<String, Boolean>... fields) {
awaitCompletion();
node.cache(cacheName);
IgniteEx node0 = (IgniteEx) node;
ArrayList<IgniteBiTuple<String, Boolean>> res = new ArrayList<>();
try {
try (Connection c = connect(node0)) {
try (ResultSet rs = c.getMetaData().getIndexInfo(null, cacheName, tblName, false, false)) {
while (rs.next()) {
if (F.eq(idxName, rs.getString("INDEX_NAME")))
res.add(new T2<>(rs.getString("COLUMN_NAME"), F.eq("A", rs.getString("ASC_OR_DESC"))));
}
}
}
assertTrue("Index not found: " + idxName, res.size() > 0);
assertEquals(Arrays.asList(fields), res);
} catch (SQLException e) {
throw new AssertionError(e);
}
// Also, let's check internal stuff not visible via JDBC - like inline size.
QueryTypeDescriptorImpl typeDesc = typeExisting(node0, cacheName, tblName);
assertInternalIndexParams(typeDesc, idxName, inlineSize);
}
use of org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl in project ignite by apache.
the class AbstractSchemaSelfTest method types.
/**
* Get available types on the given node for the given cache.
*
* @param node Node.
* @param cacheName Cache name.
* @return Map from table name to type.
*/
protected static Map<String, QueryTypeDescriptorImpl> types(IgniteEx node, String cacheName) {
Map<String, QueryTypeDescriptorImpl> res = new HashMap<>();
Collection<GridQueryTypeDescriptor> descs = node.context().query().types(cacheName);
for (GridQueryTypeDescriptor desc : descs) {
QueryTypeDescriptorImpl desc0 = (QueryTypeDescriptorImpl) desc;
res.put(desc0.tableName(), desc0);
}
return res;
}
use of org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl in project ignite by apache.
the class H2DynamicTableSelfTest method doTestCreateTable.
/**
* Test that {@code CREATE TABLE} with given template cache name actually creates new cache,
* H2 table and type descriptor on all nodes, optionally with cache type check.
* @param tplCacheName Template cache name.
* @param mode Expected cache mode, or {@code null} if no check is needed.
*/
private void doTestCreateTable(String tplCacheName, CacheMode mode) {
executeDdl("CREATE TABLE \"Person\" (\"id\" int, \"city\" varchar," + " \"name\" varchar, \"surname\" varchar, \"age\" int, PRIMARY KEY (\"id\", \"city\")) WITH " + (F.isEmpty(tplCacheName) ? "" : "\"template=" + tplCacheName + "\",") + "\"backups=10,atomicity=atomic\"");
for (int i = 0; i < 4; i++) {
IgniteEx node = grid(i);
assertNotNull(node.cache("Person"));
DynamicCacheDescriptor cacheDesc = node.context().cache().cacheDescriptor("Person");
assertNotNull(cacheDesc);
if (mode == CacheMode.REPLICATED)
assertEquals(Integer.MAX_VALUE, cacheDesc.cacheConfiguration().getBackups());
else
assertEquals(10, cacheDesc.cacheConfiguration().getBackups());
assertEquals(CacheAtomicityMode.ATOMIC, cacheDesc.cacheConfiguration().getAtomicityMode());
assertTrue(cacheDesc.sql());
if (mode != null)
assertEquals(mode, cacheDesc.cacheConfiguration().getCacheMode());
QueryTypeDescriptorImpl desc = typeExisting(node, "Person", "Person");
assertEquals(Object.class, desc.keyClass());
assertEquals("PersonKey", desc.keyTypeName());
assertEquals(Object.class, desc.valueClass());
assertEquals("Person", desc.valueTypeName());
assertEquals(F.asList("id", "city", "name", "surname", "age"), new ArrayList<>(desc.fields().keySet()));
assertProperty(desc, "id", Integer.class, true);
assertProperty(desc, "city", String.class, true);
assertProperty(desc, "name", String.class, false);
assertProperty(desc, "surname", String.class, false);
assertProperty(desc, "age", Integer.class, false);
GridH2Table tbl = ((IgniteH2Indexing) node.context().query().getIndexing()).dataTable("PUBLIC", "Person");
assertNotNull(tbl);
}
}
use of org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl in project ignite by apache.
the class SchemaIndexCacheVisitorImpl method indexStatStr.
/**
* Prints index cache stats to log.
*
* @param stat Index cache stats.
* @throws IgniteCheckedException if failed to get index size.
*/
private String indexStatStr(SchemaIndexCacheStat stat) throws IgniteCheckedException {
SB res = new SB();
res.a("Details for cache rebuilding [name=" + cctx.cache().name() + ", grpName=" + cctx.group().name() + ']');
res.a(U.nl());
res.a(" Scanned rows " + stat.scannedKeys() + ", visited types " + stat.typeNames());
res.a(U.nl());
final GridQueryIndexing idx = cctx.kernalContext().query().getIndexing();
for (QueryTypeDescriptorImpl type : stat.types()) {
res.a(" Type name=" + type.name());
res.a(U.nl());
String pk = QueryUtils.PRIMARY_KEY_INDEX;
String tblName = type.tableName();
res.a(" Index: name=" + pk + ", size=" + idx.indexSize(type.schemaName(), tblName, pk));
res.a(U.nl());
for (GridQueryIndexDescriptor descriptor : type.indexes().values()) {
long size = idx.indexSize(type.schemaName(), tblName, descriptor.name());
res.a(" Index: name=" + descriptor.name() + ", size=" + size);
res.a(U.nl());
}
}
return res.toString();
}
use of org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl in project ignite by apache.
the class ValidateIndexesClosure method calcCacheSize.
/**
* Calculation of caches size with divided by tables.
*
* @param grpCtx Cache group context.
* @param locPart Local partition.
* @return Cache size representation object.
*/
private CacheSize calcCacheSize(CacheGroupContext grpCtx, GridDhtLocalPartition locPart) {
try {
if (validateCtx.isCancelled())
return new CacheSize(null, emptyMap());
@Nullable PartitionUpdateCounter updCntr = locPart.dataStore().partUpdateCounter();
PartitionUpdateCounter updateCntrBefore = updCntr == null ? updCntr : updCntr.copy();
int grpId = grpCtx.groupId();
if (failCalcCacheSizeGrpIds.contains(grpId))
return new CacheSize(null, null);
boolean reserve = false;
int partId = locPart.id();
try {
if (!(reserve = locPart.reserve()))
throw new IgniteException("Can't reserve partition");
if (locPart.state() != OWNING)
throw new IgniteException("Partition not in state " + OWNING);
Map<Integer, Map<String, AtomicLong>> cacheSizeByTbl = new HashMap<>();
GridIterator<CacheDataRow> partIter = grpCtx.offheap().partitionIterator(partId);
GridQueryProcessor qryProcessor = ignite.context().query();
IgniteH2Indexing h2Indexing = (IgniteH2Indexing) qryProcessor.getIndexing();
while (partIter.hasNextX() && !failCalcCacheSizeGrpIds.contains(grpId)) {
CacheDataRow cacheDataRow = partIter.nextX();
int cacheId = cacheDataRow.cacheId();
GridCacheContext cacheCtx = cacheId == 0 ? grpCtx.singleCacheContext() : grpCtx.shared().cacheContext(cacheId);
if (cacheCtx == null)
throw new IgniteException("Unknown cacheId of CacheDataRow: " + cacheId);
if (cacheDataRow.link() == 0L)
throw new IgniteException("Contains invalid partition row, possibly deleted");
String cacheName = cacheCtx.name();
QueryTypeDescriptorImpl qryTypeDesc = qryProcessor.typeByValue(cacheName, cacheCtx.cacheObjectContext(), cacheDataRow.key(), cacheDataRow.value(), true);
if (isNull(qryTypeDesc))
// Tolerate - (k, v) is just not indexed.
continue;
String tableName = qryTypeDesc.tableName();
GridH2Table gridH2Tbl = h2Indexing.schemaManager().dataTable(cacheName, tableName);
if (isNull(gridH2Tbl))
// Tolerate - (k, v) is just not indexed.
continue;
cacheSizeByTbl.computeIfAbsent(cacheCtx.cacheId(), i -> new HashMap<>()).computeIfAbsent(tableName, s -> new AtomicLong()).incrementAndGet();
}
PartitionUpdateCounter updateCntrAfter = locPart.dataStore().partUpdateCounter();
if (updateCntrAfter != null && !updateCntrAfter.equals(updateCntrBefore)) {
throw new GridNotIdleException(GRID_NOT_IDLE_MSG + "[grpName=" + grpCtx.cacheOrGroupName() + ", grpId=" + grpCtx.groupId() + ", partId=" + locPart.id() + "] changed during size " + "calculation [updCntrBefore=" + updateCntrBefore + ", updCntrAfter=" + updateCntrAfter + "]");
}
return new CacheSize(null, cacheSizeByTbl);
} catch (Throwable t) {
IgniteException cacheSizeErr = new IgniteException("Cache size calculation error [" + cacheGrpInfo(grpCtx) + ", locParId=" + partId + ", err=" + t.getMessage() + "]", t);
error(log, cacheSizeErr);
failCalcCacheSizeGrpIds.add(grpId);
return new CacheSize(cacheSizeErr, null);
} finally {
if (reserve)
locPart.release();
}
} finally {
processedCacheSizePartitions.incrementAndGet();
printProgressOfIndexValidationIfNeeded();
}
}
Aggregations