Search in sources :

Example 41 with GridDhtLocalPartition

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);
            }
        }
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 42 with GridDhtLocalPartition

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractFreeList(org.apache.ignite.internal.processors.cache.persistence.freelist.AbstractFreeList) ArrayList(java.util.ArrayList) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor)

Example 43 with GridDhtLocalPartition

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));
    }
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) IgniteEx(org.apache.ignite.internal.IgniteEx) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) GridDhtPartitionTopologyImpl(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopologyImpl) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException)

Example 44 with GridDhtLocalPartition

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());
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)

Example 45 with GridDhtLocalPartition

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();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CacheException(javax.cache.CacheException) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridH2QueryRequest(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2QueryRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) Person(org.apache.ignite.internal.processors.query.h2.twostep.JoinSqlTestHelper.Person) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Aggregations

GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)95 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)19 IgniteEx (org.apache.ignite.internal.IgniteEx)19 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)19 ArrayList (java.util.ArrayList)18 Map (java.util.Map)18 Test (org.junit.Test)18 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)16 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 ClusterNode (org.apache.ignite.cluster.ClusterNode)15 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)15 HashMap (java.util.HashMap)14 HashSet (java.util.HashSet)13 AtomicLong (java.util.concurrent.atomic.AtomicLong)13 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)13 Ignite (org.apache.ignite.Ignite)12 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)12 IgniteException (org.apache.ignite.IgniteException)11