use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class CachePageWriteLockUnlockTest method preloadPartition.
/**
* Preload partition fast by iterating on all pages in disk order.
*
* @param grid Grid.
* @param cacheName Cache name.
* @param p P.
*/
private void preloadPartition(Ignite grid, String cacheName, int p) throws IgniteCheckedException {
GridDhtCacheAdapter<Object, Object> dht = ((IgniteKernal) grid).internalCache(cacheName).context().dht();
GridDhtLocalPartition part = dht.topology().localPartition(p);
assertNotNull(part);
assertTrue(part.state() == OWNING);
CacheGroupContext grpCtx = dht.context().group();
if (part.state() != OWNING)
return;
IgnitePageStoreManager pageStoreMgr = grpCtx.shared().pageStore();
if (pageStoreMgr instanceof FilePageStoreManager) {
FilePageStoreManager filePageStoreMgr = (FilePageStoreManager) pageStoreMgr;
PageStore pageStore = filePageStoreMgr.getStore(grpCtx.groupId(), part.id());
PageMemoryEx pageMemory = (PageMemoryEx) grpCtx.dataRegion().pageMemory();
long pageId = pageMemory.partitionMetaPageId(grpCtx.groupId(), part.id());
for (int pageNo = 0; pageNo < pageStore.pages(); pageId++, pageNo++) {
long pagePointer = -1;
try {
pagePointer = pageMemory.acquirePage(grpCtx.groupId(), pageId);
} finally {
if (pagePointer != -1)
pageMemory.releasePage(grpCtx.groupId(), pageId, pagePointer);
}
}
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class WalRecoveryTxLogicalRecordsTest method allocatedPages.
/**
* @param ignite Node.
* @param cacheName Cache name.
* @return Allocated pages per-store.
* @throws Exception If failed.
*/
private List<Integer> allocatedPages(Ignite ignite, String cacheName) throws Exception {
GridCacheProcessor cacheProc = ((IgniteEx) ignite).context().cache();
FilePageStoreManager storeMgr = (FilePageStoreManager) cacheProc.context().pageStore();
int parts = ignite.affinity(cacheName).partitions();
List<Integer> res = new ArrayList<>(parts);
for (int p = 0; p < parts; p++) {
PageStore store = storeMgr.getStore(CU.cacheId(cacheName), p);
cacheProc.context().database().checkpointReadLock();
try {
GridDhtLocalPartition part = cacheProc.cache(cacheName).context().topology().localPartition(p);
if (part.dataStore().rowStore() != null) {
AbstractFreeList freeList = (AbstractFreeList) part.dataStore().rowStore().freeList();
// Flush free-list onheap cache to page memory.
freeList.saveMetadata(IoStatisticsHolderNoOp.INSTANCE);
}
} finally {
cacheProc.context().database().checkpointReadUnlock();
}
store.sync();
res.add(store.pages());
}
PageStore store = storeMgr.getStore(CU.cacheId(cacheName), PageIdAllocator.INDEX_PARTITION);
store.sync();
res.add(store.pages());
return res;
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class TxRollbackOnMapOnInvalidTopologyTest method doTestRollback.
/**
* Test scenario: mock partition to fail check, start new node.
* Expected result: Transaction is rolled back.
*
* @param near Near mode.
* @param node Owner.
*/
private void doTestRollback(Ignite near, IgniteEx node) throws Exception {
List<Integer> primKeys = primaryKeys(node.cache(DEFAULT_CACHE_NAME), 100);
List<Integer> movingKeys = movingKeysAfterJoin(node, DEFAULT_CACHE_NAME, 100);
primKeys.removeAll(movingKeys);
/**
* {@code primKeys} contains stable partitions.
*/
int part = primKeys.get(0);
IgniteEx grid = (IgniteEx) grid(node.affinity(DEFAULT_CACHE_NAME).mapPartitionToNode(part));
GridDhtPartitionTopologyImpl top = (GridDhtPartitionTopologyImpl) grid.cachex(DEFAULT_CACHE_NAME).context().topology();
AffinityTopologyVersion failCheckVer = new AffinityTopologyVersion(GRIDS + 2, 1);
top.partitionFactory((ctx, grp, id, recovery) -> new GridDhtLocalPartition(ctx, grp, id, recovery) {
@Override
public boolean primary(AffinityTopologyVersion topVer) {
return !(id == part && topVer.equals(failCheckVer)) && super.primary(topVer);
}
});
// Re-create mocked part.
GridDhtLocalPartition p0 = top.localPartition(part);
p0.rent().get();
assertTrue(p0.state() == EVICTED);
ReadWriteLock lock = U.field(top, "lock");
lock.writeLock().lock();
p0 = top.getOrCreatePartition(part);
p0.own();
lock.writeLock().unlock();
startGrid(GRIDS);
awaitPartitionMapExchange();
try (Transaction tx = near.transactions().txStart()) {
near.cache(DEFAULT_CACHE_NAME).put(part, part);
tx.commit();
fail();
} catch (TransactionRollbackException ignore) {
// Expected.
} catch (Exception e) {
fail(X.getFullStackTrace(e));
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class IgniteCacheLockPartitionOnAffinityRunAbstractTest method checkPartitionsReservations.
/**
* @param ignite Ignite.
* @param orgId Org id.
* @param expReservations Expected reservations.
* @throws Exception If failed.
*/
protected static void checkPartitionsReservations(final IgniteEx ignite, int orgId, final int expReservations) throws Exception {
int part = ignite.affinity(Organization.class.getSimpleName()).partition(orgId);
final GridDhtLocalPartition pPers = ignite.context().cache().internalCache(Person.class.getSimpleName()).context().topology().localPartition(part, AffinityTopologyVersion.NONE, false);
assertNotNull(pPers);
final GridDhtLocalPartition pOrgs = ignite.context().cache().internalCache(Organization.class.getSimpleName()).context().topology().localPartition(part, AffinityTopologyVersion.NONE, false);
assertNotNull(pOrgs);
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return expReservations == pOrgs.reservations() && expReservations == pPers.reservations();
}
}, 1000L);
assertEquals("Unexpected reservations count", expReservations, pOrgs.reservations());
assertEquals("Unexpected reservations count", expReservations, pPers.reservations());
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class RetryCauseMessageSelfTest method testPartitionedCacheReserveFailureMessage.
/**
* Failed to reserve partitions for query (partition of PARTITIONED cache cannot be reserved)
*/
@Test
public void testPartitionedCacheReserveFailureMessage() {
GridMapQueryExecutor mapQryExec = GridTestUtils.getFieldValue(h2Idx, IgniteH2Indexing.class, "mapQryExec");
final GridKernalContext ctx = GridTestUtils.getFieldValue(mapQryExec, GridMapQueryExecutor.class, "ctx");
GridTestUtils.setFieldValue(h2Idx, "mapQryExec", new MockGridMapQueryExecutor() {
@Override
public void onQueryRequest(ClusterNode node, GridH2QueryRequest qryReq) throws IgniteCheckedException {
GridCacheContext<?, ?> cctx = ctx.cache().context().cacheContext(qryReq.caches().get(0));
GridDhtLocalPartition part = cctx.topology().localPartition(0, NONE, false);
AtomicLong aState = GridTestUtils.getFieldValue(part, GridDhtLocalPartition.class, "state");
long stateVal = aState.getAndSet(2);
startedExecutor.onQueryRequest(node, qryReq);
aState.getAndSet(stateVal);
}
}.insertRealExecutor(mapQryExec));
SqlQuery<String, Person> qry = new SqlQuery<String, Person>(Person.class, JOIN_SQL).setArgs("Organization #0");
qry.setDistributedJoins(true);
try {
personCache.query(qry).getAll();
} catch (CacheException e) {
assertTrue(e.getMessage().contains("Failed to reserve partitions for query (partition of PARTITIONED " + "cache is not found or not in OWNING state) "));
return;
} finally {
GridTestUtils.setFieldValue(h2Idx, "mapQryExec", mapQryExec);
}
fail();
}
Aggregations