use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class IgniteSnapshotManagerSelfTest method testSnapshotIteratorLargeRows.
/**
* @throws Exception If fails.
*/
@Test
public void testSnapshotIteratorLargeRows() throws Exception {
int keys = 2;
CacheConfiguration<Integer, Value> ccfg = txCacheConfig(new CacheConfiguration<Integer, Value>(DEFAULT_CACHE_NAME)).setAffinity(new RendezvousAffinityFunction(false, 1));
IgniteEx ignite = startGridsWithoutCache(2);
assertEquals(DFLT_PAGE_SIZE, ignite.configuration().getDataStorageConfiguration().getPageSize());
for (int i = 0; i < keys; i++) ignite.getOrCreateCache(ccfg).put(i, new Value(new byte[SIZE_FOR_FIT_3_PAGES]));
forceCheckpoint();
ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get();
int rows = 0;
try (GridCloseableIterator<CacheDataRow> iter = snp(ignite).partitionRowIterator(ignite.context(), SNAPSHOT_NAME, ignite.context().pdsFolderResolver().resolveFolders().folderName(), dfltCacheCfg.getName(), 0)) {
CacheObjectContext coctx = ignite.cachex(dfltCacheCfg.getName()).context().cacheObjectContext();
while (iter.hasNext()) {
CacheDataRow row = iter.next();
assertEquals(SIZE_FOR_FIT_3_PAGES, ((Value) row.value().value(coctx, false)).arr().length);
assertTrue((Integer) row.key().value(coctx, false, null) < 2);
rows++;
}
}
assertEquals("Invalid number of rows: " + rows, keys, rows);
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class SchemaIndexCachePartitionWorker method processPartition.
/**
* Process partition.
*
* @throws IgniteCheckedException If failed.
*/
private void processPartition() throws IgniteCheckedException {
if (stop())
return;
checkCancelled();
boolean reserved = false;
GridDhtPartitionState partState = locPart.state();
if (partState != EVICTED)
reserved = (partState == OWNING || partState == MOVING || partState == LOST) && locPart.reserve();
if (!reserved)
return;
try {
GridCursor<? extends CacheDataRow> cursor = locPart.dataStore().cursor(cctx.cacheId(), null, null, KEY_ONLY);
boolean locked = false;
try {
int cntr = 0;
while (!stop() && cursor.next()) {
KeyCacheObject key = cursor.get().key();
if (!locked) {
cctx.shared().database().checkpointReadLock();
locked = true;
}
processKey(key);
if (++cntr % batchSize == 0) {
cctx.shared().database().checkpointReadUnlock();
locked = false;
}
cctx.cache().metrics0().addIndexRebuildKeyProcessed(1);
if (locPart.state() == RENTING)
break;
}
wrappedClo.addNumberProcessedKeys(cntr);
} finally {
if (locked)
cctx.shared().database().checkpointReadUnlock();
}
} finally {
locPart.release();
if (partsCnt.getAndUpdate(v -> v > 0 ? v - 1 : 0) > 0)
cctx.group().metrics().decrementIndexBuildCountPartitionsLeft();
}
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class CacheFreeListSelfTest method checkInsertDeleteSingleThreaded.
/**
* @param pageSize Page size.
* @param batched Batch mode flag.
* @throws Exception if failed.
*/
protected void checkInsertDeleteSingleThreaded(int pageSize, boolean batched) throws Exception {
FreeList<CacheDataRow> list = createFreeList(pageSize);
Random rnd = new Random();
Map<Long, CacheDataRow> stored = new HashMap<>();
for (int i = 0; i < 100; i++) {
int keySize = rnd.nextInt(pageSize * 3 / 2) + 10;
int valSize = rnd.nextInt(pageSize * 5 / 2) + 10;
TestDataRow row = new TestDataRow(keySize, valSize);
list.insertDataRow(row, IoStatisticsHolderNoOp.INSTANCE);
assertTrue(row.link() != 0L);
CacheDataRow old = stored.put(row.link(), row);
assertNull(old);
}
boolean grow = true;
List<CacheDataRow> rows = new ArrayList<>(BATCH_SIZE);
for (int i = 0; i < 1_000_000; i++) {
if (grow) {
if (stored.size() > 20_000) {
grow = false;
info("Shrink... [" + stored.size() + ']');
}
} else {
if (stored.size() < 1_000) {
grow = true;
info("Grow... [" + stored.size() + ']');
}
}
boolean insert = rnd.nextInt(100) < 70 == grow;
if (insert) {
int keySize = rnd.nextInt(pageSize * 3 / 2) + 10;
int valSize = rnd.nextInt(pageSize * 3 / 2) + 10;
TestDataRow row = new TestDataRow(keySize, valSize);
if (batched) {
rows.add(row);
if (rows.size() == BATCH_SIZE) {
list.insertDataRows(rows, IoStatisticsHolderNoOp.INSTANCE);
for (CacheDataRow row0 : rows) {
assertTrue(row0.link() != 0L);
CacheDataRow old = stored.put(row0.link(), row0);
assertNull(old);
}
rows.clear();
}
continue;
}
list.insertDataRow(row, IoStatisticsHolderNoOp.INSTANCE);
assertTrue(row.link() != 0L);
CacheDataRow old = stored.put(row.link(), row);
assertNull(old);
} else {
Iterator<CacheDataRow> it = stored.values().iterator();
if (it.hasNext()) {
CacheDataRow row = it.next();
CacheDataRow rmvd = stored.remove(row.link());
assertTrue(rmvd == row);
list.removeDataRowByLink(row.link(), IoStatisticsHolderNoOp.INSTANCE);
}
}
}
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class VisorFindAndDeleteGarbageInPersistenceClosure method processPartition.
/**
* @param grpCtx Group context.
* @param part Local partition.
*/
private Map<Integer, Map<Integer, Long>> processPartition(CacheGroupContext grpCtx, GridDhtLocalPartition part) {
if (!part.reserve())
return Collections.emptyMap();
Map<Integer, Map<Integer, Long>> stoppedCachesForGrpId = new HashMap<>();
try {
if (part.state() != GridDhtPartitionState.OWNING)
return Collections.emptyMap();
GridIterator<CacheDataRow> it = grpCtx.offheap().partitionIterator(part.id());
while (it.hasNextX()) {
CacheDataRow row = it.nextX();
if (row.cacheId() == 0)
break;
int cacheId = row.cacheId();
GridCacheContext cacheCtx = grpCtx.shared().cacheContext(row.cacheId());
if (cacheCtx == null)
stoppedCachesForGrpId.computeIfAbsent(grpCtx.groupId(), (x) -> new HashMap<>()).compute(cacheId, (x, y) -> y == null ? 1 : y + 1);
}
} catch (IgniteCheckedException e) {
U.error(log, "Failed to process partition [grpId=" + grpCtx.groupId() + ", partId=" + part.id() + "]", e);
return Collections.emptyMap();
} finally {
part.release();
}
processedPartitions.incrementAndGet();
printProgressIfNeeded();
return stoppedCachesForGrpId;
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class WalRecoveryTxLogicalRecordsTest method rows.
/**
* @param ignite Ignite.
* @param part Partition.
* @param from From counter.
* @param to To counter.
*/
private List<CacheDataRow> rows(Ignite ignite, int part, long from, long to) throws IgniteCheckedException {
CacheGroupContext grp = ((IgniteEx) ignite).context().cache().cacheGroup(CU.cacheId(CACHE_NAME));
IgniteCacheOffheapManager offh = grp.offheap();
AffinityTopologyVersion topVer = grp.affinity().lastVersion();
IgniteDhtDemandedPartitionsMap map = new IgniteDhtDemandedPartitionsMap();
map.addHistorical(part, from, to, PARTS);
List<CacheDataRow> rows = new ArrayList<>();
WALPointer ptr = reserveWalPointerForIterator(grp.shared());
try (IgniteRebalanceIterator it = offh.rebalanceIterator(map, topVer)) {
assertNotNull(it);
while (it.hasNextX()) rows.add(it.next());
} finally {
releaseWalPointerForIterator(grp.shared(), ptr);
}
return rows;
}
Aggregations