use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class CacheMvccBackupsAbstractTest method assertKeyVersionsEquals.
/**
* @param leftRows Left rows.
* @param rightRows Right rows.
* @throws IgniteCheckedException If failed.
*/
private void assertKeyVersionsEquals(List<CacheDataRow> leftRows, List<CacheDataRow> rightRows) throws IgniteCheckedException {
assertNotNull(leftRows);
assertNotNull(rightRows);
assertEquals("leftRows=" + leftRows + ", rightRows=" + rightRows, leftRows.size(), rightRows.size());
for (int i = 0; i < leftRows.size(); i++) {
CacheDataRow leftRow = leftRows.get(i);
CacheDataRow rightRow = rightRows.get(i);
assertNotNull(leftRow);
assertNotNull(rightRow);
assertTrue(leftRow instanceof MvccDataRow);
assertTrue(rightRow instanceof MvccDataRow);
leftRow.key().valueBytes(null);
assertEquals(leftRow.expireTime(), rightRow.expireTime());
assertEquals(leftRow.partition(), rightRow.partition());
assertArrayEquals(leftRow.value().valueBytes(null), rightRow.value().valueBytes(null));
assertEquals(leftRow.version(), rightRow.version());
assertEquals(leftRow.cacheId(), rightRow.cacheId());
assertEquals(leftRow.hash(), rightRow.hash());
assertEquals(leftRow.key(), rightRow.key());
assertTrue(MvccUtils.compare(leftRow, rightRow.mvccVersion()) == 0);
assertTrue(MvccUtils.compareNewVersion(leftRow, rightRow.newMvccVersion()) == 0);
assertEquals(leftRow.newMvccCoordinatorVersion(), rightRow.newMvccCoordinatorVersion());
assertEquals(leftRow.newMvccCounter(), rightRow.newMvccCounter());
assertEquals(leftRow.newMvccOperationCounter(), rightRow.newMvccOperationCounter());
}
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class CacheMvccBackupsAbstractTest method assertVersionsEquals.
/**
* Checks stored versions equality.
*
* @param left Keys versions to compare.
* @param right Keys versions to compare.
* @throws IgniteCheckedException If failed.
*/
private void assertVersionsEquals(Map<KeyCacheObject, List<CacheDataRow>> left, Map<KeyCacheObject, List<CacheDataRow>> right) throws IgniteCheckedException {
assertNotNull(left);
assertNotNull(right);
assertTrue(!left.isEmpty());
assertTrue(!right.isEmpty());
assertEqualsCollections(left.keySet(), right.keySet());
for (KeyCacheObject key : right.keySet()) {
List<CacheDataRow> leftRows = left.get(key);
List<CacheDataRow> rightRows = right.get(key);
assertKeyVersionsEquals(leftRows, rightRows);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class CacheMvccBackupsAbstractTest method allKeyVersions.
/**
* @param cache Cache.
* @param key Key.
* @return Collection of versioned rows.
* @throws IgniteCheckedException if failed.
*/
private List<CacheDataRow> allKeyVersions(IgniteCache cache, Object key) throws IgniteCheckedException {
IgniteCacheProxy cache0 = (IgniteCacheProxy) cache;
GridCacheContext cctx = cache0.context();
KeyCacheObject key0 = cctx.toCacheKeyObject(key);
GridCursor<CacheDataRow> cur = cctx.offheap().mvccAllVersionsCursor(cctx, key0, null);
List<CacheDataRow> rows = new ArrayList<>();
while (cur.next()) {
CacheDataRow row = cur.get();
rows.add(row);
}
return rows;
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow 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.cache.persistence.CacheDataRow 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