use of org.apache.ignite.internal.processors.query.h2.opt.H2CacheRow in project ignite by apache.
the class ValidateIndexesClosure method processIndex.
/**
* @param cacheCtxWithIdx Cache context and appropriate index.
* @param idleChecker Idle check closure.
*/
private Map<String, ValidateIndexesPartitionResult> processIndex(T2<GridCacheContext, Index> cacheCtxWithIdx, IgniteInClosure<Integer> idleChecker) {
if (validateCtx.isCancelled())
return emptyMap();
GridCacheContext ctx = cacheCtxWithIdx.get1();
Index idx = cacheCtxWithIdx.get2();
ValidateIndexesPartitionResult idxValidationRes = new ValidateIndexesPartitionResult();
boolean enoughIssues = false;
Cursor cursor = null;
try (Session session = mvccSession(cacheCtxWithIdx.get1())) {
cursor = idx.find(session, null, null);
if (cursor == null)
throw new IgniteCheckedException("Can't iterate through index: " + idx);
} catch (Throwable t) {
IndexValidationIssue is = new IndexValidationIssue(null, ctx.name(), idx.getName(), t);
log.error("Find in index failed: " + is.toString());
idxValidationRes.reportIssue(is);
enoughIssues = true;
}
final boolean skipConditions = checkFirst > 0 || checkThrough > 0;
final boolean bothSkipConditions = checkFirst > 0 && checkThrough > 0;
long current = 0;
long processedNumber = 0;
KeyCacheObject previousKey = null;
while (!enoughIssues && !validateCtx.isCancelled()) {
KeyCacheObject h2key = null;
try {
try {
if (!cursor.next())
break;
} catch (DbException e) {
if (X.hasCause(e, CorruptedTreeException.class))
throw new IgniteCheckedException("Key is present in SQL index, but is missing in corresponding " + "data page. Previous successfully read key: " + CacheObjectUtils.unwrapBinaryIfNeeded(ctx.cacheObjectContext(), previousKey, true, true), X.cause(e, CorruptedTreeException.class));
throw e;
}
H2CacheRow h2Row = (H2CacheRow) cursor.get();
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;
}
}
}
h2key = h2Row.key();
if (h2Row.link() != 0L) {
CacheDataRow cacheDataStoreRow = ctx.group().offheap().read(ctx, h2key);
if (cacheDataStoreRow == null)
throw new IgniteCheckedException("Key is present in SQL index, but can't be found in CacheDataTree.");
} else
throw new IgniteCheckedException("Invalid index row, possibly deleted " + h2Row);
} catch (Throwable t) {
Object o = CacheObjectUtils.unwrapBinaryIfNeeded(ctx.cacheObjectContext(), h2key, true, true);
IndexValidationIssue is = new IndexValidationIssue(String.valueOf(o), ctx.name(), idx.getName(), t);
log.error("Failed to lookup key: " + is.toString());
enoughIssues |= idxValidationRes.reportIssue(is);
} finally {
previousKey = h2key;
}
}
CacheGroupContext group = ctx.group();
String uniqueIdxName = String.format("[cacheGroup=%s, cacheGroupId=%s, cache=%s, cacheId=%s, idx=%s]", group.name(), group.groupId(), ctx.name(), ctx.cacheId(), idx.getName());
idleChecker.apply(group.groupId());
processedIndexes.incrementAndGet();
printProgressOfIndexValidationIfNeeded();
return Collections.singletonMap(uniqueIdxName, idxValidationRes);
}
use of org.apache.ignite.internal.processors.query.h2.opt.H2CacheRow 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);
}
}
}
}
Aggregations