use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class IndexingDefragmentation method defragmentTable.
/**
* Defragment one given table.
*/
private boolean defragmentTable(CacheGroupContext newCtx, IntMap<LinkMap> mappingByPartition, CheckpointTimeoutLock cpLock, Runnable cancellationChecker, int pageSize, PageMemoryEx oldCachePageMem, PageMemory newCachePageMemory, long cpLockThreshold, AtomicLong lastCpLockTs, TableIndexes indexes) throws IgniteCheckedException {
cpLock.checkpointReadLock();
try {
TreeIterator treeIterator = new TreeIterator(pageSize);
GridCacheContext<?, ?> cctx = indexes.cctx;
cancellationChecker.run();
for (InlineIndex oldIdx : indexes.idxs) {
InlineIndexRowHandler oldRowHnd = oldIdx.segment(0).rowHandler();
SortedIndexDefinition idxDef = (SortedIndexDefinition) indexing.indexDefinition(oldIdx.id());
InlineIndexImpl newIdx = new DefragIndexFactory(newCtx.offheap(), newCachePageMemory, oldIdx).createIndex(cctx, idxDef).unwrap(InlineIndexImpl.class);
int segments = oldIdx.segmentsCount();
for (int i = 0; i < segments; ++i) {
treeIterator.iterate(oldIdx.segment(i), oldCachePageMem, (theTree, io, pageAddr, idx) -> {
cancellationChecker.run();
if (System.currentTimeMillis() - lastCpLockTs.get() >= cpLockThreshold) {
cpLock.checkpointReadUnlock();
cpLock.checkpointReadLock();
lastCpLockTs.set(System.currentTimeMillis());
}
assert 1 == io.getVersion() : "IO version " + io.getVersion() + " is not supported by current defragmentation algorithm." + " Please implement copying of tree in a new format.";
BPlusIO<IndexRow> h2IO = DefragIndexFactory.wrap(io, oldRowHnd);
IndexRow row = theTree.getRow(h2IO, pageAddr, idx);
if (row instanceof DefragIndexRowImpl) {
DefragIndexRowImpl r = (DefragIndexRowImpl) row;
CacheDataRow cacheDataRow = r.cacheDataRow();
int partition = cacheDataRow.partition();
long link = r.link();
LinkMap map = mappingByPartition.get(partition);
long newLink = map.get(link);
// Use old row handler, as MetaInfo is copied from old tree.
DefragIndexRowImpl newRow = DefragIndexRowImpl.create(oldRowHnd, newLink, r, ((MvccIO) io).storeMvccInfo());
newIdx.putIndexRow(newRow);
}
return true;
});
}
}
return true;
} catch (Throwable t) {
newCtx.cacheObjectContext().kernalContext().failure().process(new FailureContext(CRITICAL_ERROR, t));
throw t;
} finally {
cpLock.checkpointReadUnlock();
}
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class IgniteCacheGroupsTest method testRebalance2.
/**
* @throws Exception If failed.
*/
@Test
public void testRebalance2() throws Exception {
Ignite srv0 = startGrid(0);
IgniteCache<Object, Object> srv0Cache1 = srv0.createCache(cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 0, false));
IgniteCache<Object, Object> srv0Cache2 = srv0.createCache(cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 0, false));
Affinity aff = srv0.affinity("c1");
final int ITEMS = 2_000;
Map<Integer, Integer> c1Data = new HashMap<>();
Map<Integer, Integer> c2Data = new HashMap<>();
for (int i = 0; i < ITEMS; i++) {
srv0Cache1.put(i, i);
c1Data.put(i, i);
if (i % 2 == 0) {
srv0Cache2.put(i, i);
c2Data.put(i, i);
}
}
assertEquals(ITEMS, srv0Cache1.size());
assertEquals(ITEMS / 2, srv0Cache2.size());
Ignite srv1 = startGrid(1);
awaitPartitionMapExchange();
assertEquals(ITEMS, srv0Cache1.size());
assertEquals(ITEMS / 2, srv0Cache2.size());
checkCacheData(c1Data, "c1");
checkCacheData(c2Data, "c2");
Set<Integer> srv1Parts = new HashSet<>();
for (Integer p : aff.primaryPartitions(srv1.cluster().localNode())) srv1Parts.add(p);
CacheGroupContext grpSrv0 = cacheGroup(srv0, GROUP1);
CacheGroupContext grpSrv1 = cacheGroup(srv1, GROUP1);
for (int p = 0; p < aff.partitions(); p++) {
if (srv1Parts.contains(p)) {
GridIterator<CacheDataRow> it = grpSrv0.offheap().partitionIterator(p);
assertFalse(it.hasNext());
it = grpSrv1.offheap().partitionIterator(p);
assertTrue(it.hasNext());
} else {
GridIterator<CacheDataRow> it = grpSrv0.offheap().partitionIterator(p);
assertTrue(it.hasNext());
it = grpSrv1.offheap().partitionIterator(p);
assertFalse(it.hasNext());
}
}
c1Data = new HashMap<>();
c2Data = new HashMap<>();
for (int i = 0; i < ITEMS; i++) {
srv0Cache1.put(i, i + 1);
c1Data.put(i, i + 1);
if (i % 2 == 0) {
srv0Cache2.put(i, i + 1);
c2Data.put(i, i + 1);
}
}
checkCacheData(c1Data, "c1");
checkCacheData(c2Data, "c2");
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class IgniteCacheGroupsTest method testCacheIdSort.
/**
* @throws Exception If failed.
*/
@Test
public void testCacheIdSort() throws Exception {
Ignite node = startGrid(0);
final List<IgniteCache> caches = new ArrayList<>(3);
caches.add(node.createCache(cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1, false).setAffinity(new RendezvousAffinityFunction(false, 8))));
caches.add(node.createCache(cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 1, false).setAffinity(new RendezvousAffinityFunction(false, 8))));
caches.add(node.createCache(cacheConfiguration(GROUP1, "c3", PARTITIONED, ATOMIC, 1, false).setAffinity(new RendezvousAffinityFunction(false, 8))));
Affinity aff = node.affinity("c1");
final List<Integer> keys = new ArrayList<>();
for (int i = 0; i < 1_000_000; i++) {
if (aff.partition(i) == 0) {
keys.add(i);
if (keys.size() >= 10_000)
break;
}
}
assertEquals(10_000, keys.size());
final long stopTime = System.currentTimeMillis() + 10_000;
GridTestUtils.runMultiThreaded(new Callable<Void>() {
@Override
public Void call() throws Exception {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (System.currentTimeMillis() < stopTime) {
for (int i = 0; i < 100; i++) {
IgniteCache cache = caches.get(rnd.nextInt(3));
Integer key = keys.get(rnd.nextInt(10_000));
if (rnd.nextFloat() > 0.8f)
cache.remove(key);
else
cache.put(key, key);
}
}
return null;
}
}, 5, "update-thread");
CacheGroupContext grp = cacheGroup(node, GROUP1);
Integer cacheId = null;
GridIterator<CacheDataRow> it = grp.offheap().partitionIterator(0);
int c = 0;
while (it.hasNext()) {
CacheDataRow row = it.next();
if (cacheId == null || cacheId != row.cacheId()) {
cacheId = row.cacheId();
c++;
}
}
assertEquals(3, c);
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class CachePartitionDefragmentationManager method copyPartitionData.
/**
* Defragmentate partition.
*
* @param partCtx
* @param treeIter
* @throws IgniteCheckedException If failed.
*/
private void copyPartitionData(PartitionContext partCtx, TreeIterator treeIter) throws IgniteCheckedException {
CacheDataTree tree = partCtx.oldCacheDataStore.tree();
CacheDataTree newTree = partCtx.newCacheDataStore.tree();
newTree.enableSequentialWriteMode();
PendingEntriesTree newPendingTree = partCtx.newCacheDataStore.pendingTree();
AbstractFreeList<CacheDataRow> freeList = partCtx.newCacheDataStore.getCacheStoreFreeList();
long cpLockThreshold = 150L;
defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadLock();
try {
AtomicLong lastCpLockTs = new AtomicLong(System.currentTimeMillis());
AtomicInteger entriesProcessed = new AtomicInteger();
treeIter.iterate(tree, partCtx.cachePageMemory, (tree0, io, pageAddr, idx) -> {
checkCancellation();
if (System.currentTimeMillis() - lastCpLockTs.get() >= cpLockThreshold) {
defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadUnlock();
defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadLock();
lastCpLockTs.set(System.currentTimeMillis());
}
AbstractDataLeafIO leafIo = (AbstractDataLeafIO) io;
CacheDataRow row = tree.getRow(io, pageAddr, idx);
int cacheId = row.cacheId();
// Reuse row that we just read.
row.link(0);
// "insertDataRow" will corrupt page memory if we don't do this.
if (row instanceof DataRow && !partCtx.oldGrpCtx.storeCacheIdInDataPage())
((DataRow) row).cacheId(CU.UNDEFINED_CACHE_ID);
freeList.insertDataRow(row, IoStatisticsHolderNoOp.INSTANCE);
// Put it back.
if (row instanceof DataRow)
((DataRow) row).cacheId(cacheId);
newTree.putx(row);
long newLink = row.link();
partCtx.linkMap.put(leafIo.getLink(pageAddr, idx), newLink);
if (row.expireTime() != 0)
newPendingTree.putx(new PendingRow(cacheId, row.expireTime(), newLink));
entriesProcessed.incrementAndGet();
return true;
});
checkCancellation();
defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadUnlock();
defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadLock();
freeList.saveMetadata(IoStatisticsHolderNoOp.INSTANCE);
copyCacheMetadata(partCtx);
} finally {
defragmentationCheckpoint.checkpointTimeoutLock().checkpointReadUnlock();
}
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class GridCacheMapEntry method mvccPeek.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public CacheObject mvccPeek(boolean onheapOnly) throws GridCacheEntryRemovedException, IgniteCheckedException {
if (onheapOnly)
return null;
lockEntry();
try {
checkObsolete();
CacheDataRow row = cctx.offheap().mvccRead(cctx, key, MVCC_MAX_SNAPSHOT);
return row != null ? row.value() : null;
} finally {
unlockEntry();
}
}
Aggregations