Search in sources :

Example 6 with PartitionUpdateCounter

use of org.apache.ignite.internal.processors.cache.PartitionUpdateCounter in project ignite by apache.

the class PartitionUpdateCounterTest method testOverlap.

/**
 */
@Test
public void testOverlap() {
    PartitionUpdateCounter pc = new PartitionUpdateCounterTrackingImpl(null);
    assertTrue(pc.update(13, 3));
    assertTrue(pc.update(6, 7));
    assertFalse(pc.update(13, 3));
    assertFalse(pc.update(6, 7));
    Iterator<long[]> iter = pc.iterator();
    assertTrue(iter.hasNext());
    long[] upd = iter.next();
    assertEquals(6, upd[0]);
    assertEquals(10, upd[1]);
    assertFalse(iter.hasNext());
}
Also used : PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 7 with PartitionUpdateCounter

use of org.apache.ignite.internal.processors.cache.PartitionUpdateCounter in project ignite by apache.

the class PartitionUpdateCounterTest method testGapsSerialization.

/**
 */
@Test
public void testGapsSerialization() {
    PartitionUpdateCounter pc = new PartitionUpdateCounterTrackingImpl(null);
    Random r = new Random();
    for (int c = 1; c < 500; c++) pc.update(c * 4, r.nextInt(3) + 1);
    final byte[] bytes = pc.getBytes();
    PartitionUpdateCounter pc2 = new PartitionUpdateCounterTrackingImpl(null);
    pc2.init(0, bytes);
    NavigableMap q0 = U.field(pc, "queue");
    NavigableMap q1 = U.field(pc2, "queue");
    assertEquals(q0, q1);
}
Also used : PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) NavigableMap(java.util.NavigableMap) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 8 with PartitionUpdateCounter

use of org.apache.ignite.internal.processors.cache.PartitionUpdateCounter in project ignite by apache.

the class GridCommonAbstractTest method assertCountersSame.

/**
 * @param partId Partition.
 * @param withReserveCntr {@code True} to compare reserve counters. Because reserve counters are synced during
 * @param cacheName Cache name.
 * PME invoking with {@code true} makes sense only after PME was finished.
 */
protected void assertCountersSame(int partId, boolean withReserveCntr, String cacheName) throws AssertionFailedError {
    PartitionUpdateCounter cntr0 = null;
    List<T3<String, @Nullable PartitionUpdateCounter, Boolean>> cntrMap = G.allGrids().stream().filter(ignite -> !ignite.configuration().isClientMode()).map(ignite -> new T3<>(ignite.name(), counter(partId, cacheName, ignite.name()), ignite.affinity(cacheName).isPrimary(ignite.cluster().localNode(), partId))).collect(toList());
    for (T3<String, PartitionUpdateCounter, Boolean> cntr : cntrMap) {
        if (cntr.get2() == null)
            continue;
        if (cntr0 != null) {
            assertEquals("Expecting same counters [partId=" + partId + ", cntrs=" + cntrMap + ']', cntr0, cntr.get2());
            if (withReserveCntr)
                assertEquals("Expecting same reservation counters [partId=" + partId + ", cntrs=" + cntrMap + ']', cntr0.reserved(), cntr.get2().reserved());
        }
        cntr0 = cntr.get2();
    }
}
Also used : Arrays(java.util.Arrays) ObjectInstance(javax.management.ObjectInstance) GridCacheUtils.isNearEnabled(org.apache.ignite.internal.processors.cache.GridCacheUtils.isNearEnabled) Map(java.util.Map) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Cache(javax.cache.Cache) AffinityFunctionContext(org.apache.ignite.cache.affinity.AffinityFunctionContext) GridDhtColocatedCache(org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache) ComputeTask(org.apache.ignite.compute.ComputeTask) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) GridAffinityFunctionContextImpl(org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteServiceProcessor(org.apache.ignite.internal.processors.service.IgniteServiceProcessor) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) LOCAL(org.apache.ignite.cache.CacheMode.LOCAL) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Event(org.apache.ignite.events.Event) CacheGroupDescriptor(org.apache.ignite.internal.processors.cache.CacheGroupDescriptor) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Set(java.util.Set) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteCache(org.apache.ignite.IgniteCache) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) DFLT_STORE_DIR(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.DFLT_STORE_DIR) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteCompute(org.apache.ignite.IgniteCompute) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Affinity(org.apache.ignite.cache.affinity.Affinity) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) U(org.apache.ignite.internal.util.typedef.internal.U) Callable(java.util.concurrent.Callable) IgniteLogger(org.apache.ignite.IgniteLogger) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) SSLSession(javax.net.ssl.SSLSession) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) IgniteEvents(org.apache.ignite.IgniteEvents) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) CompletionListener(javax.cache.integration.CompletionListener) DFLT_SNAPSHOT_DIRECTORY(org.apache.ignite.configuration.IgniteConfiguration.DFLT_SNAPSHOT_DIRECTORY) AssertionFailedError(junit.framework.AssertionFailedError) Ignite(org.apache.ignite.Ignite) VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) T3(org.apache.ignite.internal.util.typedef.T3) GridTestNode(org.apache.ignite.testframework.GridTestNode) GridDhtCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) TreeMap(java.util.TreeMap) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) IgniteCacheProxyImpl(org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl) GridLocalCache(org.apache.ignite.internal.processors.cache.local.GridLocalCache) IgniteMessaging(org.apache.ignite.IgniteMessaging) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) GridCacheExplicitLockSpan(org.apache.ignite.internal.processors.cache.GridCacheExplicitLockSpan) VisorIdleVerifyTaskV2(org.apache.ignite.internal.visor.verify.VisorIdleVerifyTaskV2) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HostnameVerifier(javax.net.ssl.HostnameVerifier) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) Method(java.lang.reflect.Method) LoggerResource(org.apache.ignite.resources.LoggerResource) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) Collectors.toSet(java.util.stream.Collectors.toSet) GridDhtTopologyFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture) IgniteFuture(org.apache.ignite.lang.IgniteFuture) CachePeekMode(org.apache.ignite.cache.CachePeekMode) EventType(org.apache.ignite.events.EventType) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) OWNING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING) UUID(java.util.UUID) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) Collectors(java.util.stream.Collectors) NONE(org.apache.ignite.cache.CacheRebalanceMode.NONE) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) GridCachePartitionExchangeManager(org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) WALDisableContext(org.apache.ignite.internal.processors.cache.WalStateManager.WALDisableContext) IgniteDhtDemandedPartitionsMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtDemandedPartitionsMap) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) LT(org.apache.ignite.internal.util.typedef.internal.LT) HashSet(java.util.HashSet) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) MBeanServer(javax.management.MBeanServer) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) CacheException(javax.cache.CacheException) IgniteThrowableFunction(org.apache.ignite.internal.util.lang.IgniteThrowableFunction) MXBeanDescription(org.apache.ignite.mxbean.MXBeanDescription) G(org.apache.ignite.internal.util.typedef.G) F(org.apache.ignite.internal.util.typedef.F) VisorIdleVerifyTaskArg(org.apache.ignite.internal.visor.verify.VisorIdleVerifyTaskArg) Iterator(java.util.Iterator) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) GridCacheFuture(org.apache.ignite.internal.processors.cache.GridCacheFuture) TimeUnit(java.util.concurrent.TimeUnit) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) Collectors.toList(java.util.stream.Collectors.toList) Ignition(org.apache.ignite.Ignition) GridTestUtils.setFieldValue(org.apache.ignite.testframework.GridTestUtils.setFieldValue) PA(org.apache.ignite.internal.util.typedef.PA) BitSet(java.util.BitSet) CacheMetricsImpl(org.apache.ignite.internal.processors.cache.CacheMetricsImpl) Collections(java.util.Collections) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) Nullable(org.jetbrains.annotations.Nullable) T3(org.apache.ignite.internal.util.typedef.T3)

Example 9 with PartitionUpdateCounter

use of org.apache.ignite.internal.processors.cache.PartitionUpdateCounter in project ignite by apache.

the class IgnitePdsSpuriousRebalancingOnNodeJoinTest method testNoSpuriousRebalancing.

/**
 */
@SuppressWarnings("ConstantConditions")
@Test
public void testNoSpuriousRebalancing() throws Exception {
    try {
        IgniteEx crd = startGrids(2);
        crd.cluster().active(true);
        crd.cluster().baselineAutoAdjustEnabled(false);
        List<Integer> moving = movingKeysAfterJoin(crd, DEFAULT_CACHE_NAME, 10);
        int[] primParts = crd.affinity(DEFAULT_CACHE_NAME).primaryPartitions(crd.localNode());
        Arrays.sort(primParts);
        // This partition will be new primary on joining node.
        int primChangePartId = -1;
        for (int id : moving) {
            if (Arrays.binarySearch(primParts, id) >= 0) {
                primChangePartId = id;
                break;
            }
        }
        assertTrue(primChangePartId != -1);
        startGrid(2);
        // Trigger partition movement.
        resetBaselineTopology();
        awaitPartitionMapExchange();
        GridCacheContext<Object, Object> ctx = crd.cachex(DEFAULT_CACHE_NAME).context();
        AffinityAssignment a0 = ctx.affinity().assignment(new AffinityTopologyVersion(3, 1));
        List<ClusterNode> nodes = a0.get(primChangePartId);
        assertEquals(3, nodes.size());
        assertEquals(crd.configuration().getConsistentId(), nodes.get(0).consistentId());
        awaitPartitionMapExchange();
        for (int k = 0; k < PARTS * 2; k++) crd.cache(DEFAULT_CACHE_NAME).put(k, k);
        forceCheckpoint();
        stopGrid(2);
        // Forge the counter on coordinator for switching partition.
        GridDhtLocalPartition part = ctx.topology().localPartition(primChangePartId);
        assertNotNull(part);
        PartitionUpdateCounter cntr0 = part.dataStore().partUpdateCounter();
        assertTrue(cntr0 instanceof PartitionUpdateCounterErrorWrapper);
        PartitionUpdateCounterTrackingImpl delegate = U.field(cntr0, "delegate");
        AtomicLong cntr = U.field(delegate, "cntr");
        cntr.set(cntr.get() - 1);
        TestRecordingCommunicationSpi.spi(crd).record((node, msg) -> msg instanceof GridDhtPartitionDemandMessage);
        startGrid(2);
        awaitPartitionMapExchange();
        // Expecting no rebalancing.
        List<Object> msgs = TestRecordingCommunicationSpi.spi(crd).recordedMessages(true);
        assertTrue("Rebalancing is not expected " + msgs, msgs.isEmpty());
    } finally {
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityAssignment(org.apache.ignite.internal.processors.affinity.AffinityAssignment) PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) PartitionUpdateCounterErrorWrapper(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterErrorWrapper) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteEx(org.apache.ignite.internal.IgniteEx) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 10 with PartitionUpdateCounter

use of org.apache.ignite.internal.processors.cache.PartitionUpdateCounter in project ignite by apache.

the class PagesPossibleCorruptionDiagnosticTest method testCorruptedNodeFailsOnStart.

/**
 * Tests that node with corrupted partition fails on start.
 */
@Test
public void testCorruptedNodeFailsOnStart() throws Exception {
    IgniteEx ignite = startGrid(0);
    ignite.cluster().state(ClusterState.ACTIVE);
    IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(new CacheConfiguration<Integer, Integer>(DEFAULT_CACHE_NAME).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setAffinity(new RendezvousAffinityFunction(false, 1)));
    cache.put(1, 1);
    PartitionUpdateCounter counter = counter(0, DEFAULT_CACHE_NAME, ignite.name());
    counter.update(10, 5);
    forceCheckpoint();
    FilePageStore store = filePageStore(ignite, 0);
    stopAllGrids();
    store.ensure();
    // Index of meta page is always 0.
    int metaPageIdx = 0;
    long offset = store.headerSize() + metaPageIdx * PAGE_SIZE + PART_META_REUSE_LIST_ROOT_OFF;
    writeLongToFileByOffset(store.getFileAbsolutePath(), offset, 0L);
    try {
        startGrid(0);
    } catch (Exception ignored) {
    /* No-op. */
    }
    assertTrue(correctFailure);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CorruptedFreeListException(org.apache.ignite.internal.processors.cache.persistence.freelist.CorruptedFreeListException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

PartitionUpdateCounter (org.apache.ignite.internal.processors.cache.PartitionUpdateCounter)29 Test (org.junit.Test)17 IgniteEx (org.apache.ignite.internal.IgniteEx)15 Ignite (org.apache.ignite.Ignite)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)12 PartitionUpdateCounterTrackingImpl (org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl)10 List (java.util.List)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 T2 (org.apache.ignite.internal.util.typedef.T2)7 Map (java.util.Map)6 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)6 Nullable (org.jetbrains.annotations.Nullable)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)5 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)5 Collections (java.util.Collections)4 IgniteException (org.apache.ignite.IgniteException)4 Collection (java.util.Collection)3