Search in sources :

Example 1 with OWNING

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING in project ignite by apache.

the class GridDhtPartitionTopologyImpl method resetOwners.

/**
 * {@inheritDoc}
 */
@Override
public Map<UUID, Set<Integer>> resetOwners(Map<Integer, Set<UUID>> ownersByUpdCounters, Set<Integer> haveHist, GridDhtPartitionsExchangeFuture exchFut) {
    Map<UUID, Set<Integer>> res = new HashMap<>();
    Collection<DiscoveryEvent> evts = exchFut.events().events();
    Set<UUID> joinedNodes = U.newHashSet(evts.size());
    for (DiscoveryEvent evt : evts) {
        if (evt.type() == EVT_NODE_JOINED)
            joinedNodes.add(evt.eventNode().id());
    }
    ctx.database().checkpointReadLock();
    try {
        Map<UUID, Set<Integer>> addToWaitGroups = new HashMap<>();
        lock.writeLock().lock();
        try {
            // First process local partitions.
            UUID locNodeId = ctx.localNodeId();
            for (Map.Entry<Integer, Set<UUID>> entry : ownersByUpdCounters.entrySet()) {
                int part = entry.getKey();
                Set<UUID> maxCounterPartOwners = entry.getValue();
                GridDhtLocalPartition locPart = localPartition(part);
                if (locPart == null || locPart.state() != OWNING)
                    continue;
                // Partition state should be mutated only on joining nodes if they are exists for the exchange.
                if (joinedNodes.isEmpty() && !maxCounterPartOwners.contains(locNodeId)) {
                    rebalancePartition(part, !haveHist.contains(part), exchFut);
                    res.computeIfAbsent(locNodeId, n -> new HashSet<>()).add(part);
                }
            }
            // Then process node maps.
            for (Map.Entry<Integer, Set<UUID>> entry : ownersByUpdCounters.entrySet()) {
                int part = entry.getKey();
                Set<UUID> maxCounterPartOwners = entry.getValue();
                for (Map.Entry<UUID, GridDhtPartitionMap> remotes : node2part.entrySet()) {
                    UUID remoteNodeId = remotes.getKey();
                    if (!joinedNodes.isEmpty() && !joinedNodes.contains(remoteNodeId))
                        continue;
                    GridDhtPartitionMap partMap = remotes.getValue();
                    GridDhtPartitionState state = partMap.get(part);
                    if (state != OWNING)
                        continue;
                    if (!maxCounterPartOwners.contains(remoteNodeId)) {
                        partMap.put(part, MOVING);
                        partMap.updateSequence(partMap.updateSequence() + 1, partMap.topologyVersion());
                        if (partMap.nodeId().equals(locNodeId))
                            updateSeq.setIfGreater(partMap.updateSequence());
                        res.computeIfAbsent(remoteNodeId, n -> new HashSet<>()).add(part);
                    }
                }
            }
            for (Map.Entry<UUID, Set<Integer>> entry : res.entrySet()) {
                UUID nodeId = entry.getKey();
                Set<Integer> rebalancedParts = entry.getValue();
                addToWaitGroups.put(nodeId, new HashSet<>(rebalancedParts));
                if (!rebalancedParts.isEmpty()) {
                    Set<Integer> historical = rebalancedParts.stream().filter(haveHist::contains).collect(Collectors.toSet());
                    // Filter out partitions having WAL history.
                    rebalancedParts.removeAll(historical);
                    U.warn(log, "Partitions have been scheduled for rebalancing due to outdated update counter " + "[grp=" + grp.cacheOrGroupName() + ", readyTopVer=" + readyTopVer + ", topVer=" + exchFut.initialVersion() + ", nodeId=" + nodeId + ", partsFull=" + S.compact(rebalancedParts) + ", partsHistorical=" + S.compact(historical) + "]");
                }
            }
            node2part = new GridDhtPartitionFullMap(node2part, updateSeq.incrementAndGet());
        } finally {
            lock.writeLock().unlock();
        }
        List<List<ClusterNode>> ideal = ctx.affinity().affinity(groupId()).idealAssignmentRaw();
        for (Map.Entry<UUID, Set<Integer>> entry : addToWaitGroups.entrySet()) {
            // Add to wait groups to ensure late assignment switch after all partitions are rebalanced.
            for (Integer part : entry.getValue()) {
                ctx.cache().context().affinity().addToWaitGroup(groupId(), part, topologyVersionFuture().initialVersion(), ideal.get(part));
            }
        }
    } finally {
        ctx.database().checkpointReadUnlock();
    }
    return res;
}
Also used : GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) CachePartitionFullCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionFullCountersMap) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) GridLongList(org.apache.ignite.internal.util.GridLongList) EVT_CACHE_REBALANCE_PART_DATA_LOST(org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST) RollbackRecord(org.apache.ignite.internal.pagemem.wal.record.RollbackRecord) SB(org.apache.ignite.internal.util.typedef.internal.SB) Map(java.util.Map) X(org.apache.ignite.internal.util.typedef.X) GridDhtTopologyFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture) EventType(org.apache.ignite.events.EventType) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) ALL(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.ExchangeType.ALL) OWNING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) CU(org.apache.ignite.internal.util.typedef.internal.CU) LOST(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.LOST) GridClusterStateProcessor(org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor) ExchangeDiscoveryEvents(org.apache.ignite.internal.processors.cache.ExchangeDiscoveryEvents) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) NotNull(org.jetbrains.annotations.NotNull) GridDhtCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry) RENTING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.RENTING) GridAtomicLong(org.apache.ignite.internal.util.GridAtomicLong) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) U(org.apache.ignite.internal.util.typedef.internal.U) EVT_DISCOVERY_CUSTOM_EVT(org.apache.ignite.internal.events.DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) AffinityAssignment(org.apache.ignite.internal.processors.affinity.AffinityAssignment) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) F0(org.apache.ignite.internal.util.F0) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) S(org.apache.ignite.internal.util.typedef.internal.S) MOVING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.MOVING) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) NoSuchElementException(java.util.NoSuchElementException) EVICTED(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.EVICTED) IGNORE(org.apache.ignite.cache.PartitionLossPolicy.IGNORE) F(org.apache.ignite.internal.util.typedef.F) EVT_NODE_JOINED(org.apache.ignite.events.EventType.EVT_NODE_JOINED) Iterator(java.util.Iterator) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) StripedCompositeReadWriteLock(org.apache.ignite.internal.util.StripedCompositeReadWriteLock) NONE(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.ExchangeType.NONE) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) Collections(java.util.Collections) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridLongList(org.apache.ignite.internal.util.GridLongList) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) CachePartitionFullCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionFullCountersMap) Map(java.util.Map) HashMap(java.util.HashMap) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) CachePartitionPartialCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) HashSet(java.util.HashSet)

Example 2 with OWNING

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING in project ignite by apache.

the class SnapshotPartitionsVerifyHandler method invoke.

/**
 * {@inheritDoc}
 */
@Override
public Map<PartitionKeyV2, PartitionHashRecordV2> invoke(SnapshotHandlerContext opCtx) throws IgniteCheckedException {
    SnapshotMetadata meta = opCtx.metadata();
    Set<Integer> grps = F.isEmpty(opCtx.groups()) ? new HashSet<>(meta.partitions().keySet()) : opCtx.groups().stream().map(CU::cacheId).collect(Collectors.toSet());
    Set<File> partFiles = new HashSet<>();
    IgniteSnapshotManager snpMgr = cctx.snapshotMgr();
    for (File dir : snpMgr.snapshotCacheDirectories(meta.snapshotName(), meta.folderName())) {
        int grpId = CU.cacheId(cacheGroupName(dir));
        if (!grps.remove(grpId))
            continue;
        Set<Integer> parts = meta.partitions().get(grpId) == null ? Collections.emptySet() : new HashSet<>(meta.partitions().get(grpId));
        for (File part : cachePartitionFiles(dir)) {
            int partId = partId(part.getName());
            if (!parts.remove(partId))
                continue;
            partFiles.add(part);
        }
        if (!parts.isEmpty()) {
            throw new IgniteException("Snapshot data doesn't contain required cache group partition " + "[grpId=" + grpId + ", snpName=" + meta.snapshotName() + ", consId=" + meta.consistentId() + ", missed=" + parts + ", meta=" + meta + ']');
        }
    }
    if (!grps.isEmpty()) {
        throw new IgniteException("Snapshot data doesn't contain required cache groups " + "[grps=" + grps + ", snpName=" + meta.snapshotName() + ", consId=" + meta.consistentId() + ", meta=" + meta + ']');
    }
    Map<PartitionKeyV2, PartitionHashRecordV2> res = new ConcurrentHashMap<>();
    ThreadLocal<ByteBuffer> buff = ThreadLocal.withInitial(() -> ByteBuffer.allocateDirect(meta.pageSize()).order(ByteOrder.nativeOrder()));
    GridKernalContext snpCtx = snpMgr.createStandaloneKernalContext(meta.snapshotName(), meta.folderName());
    for (GridComponent comp : snpCtx) comp.start();
    try {
        U.doInParallel(snpMgr.snapshotExecutorService(), partFiles, part -> {
            String grpName = cacheGroupName(part.getParentFile());
            int grpId = CU.cacheId(grpName);
            int partId = partId(part.getName());
            FilePageStoreManager storeMgr = (FilePageStoreManager) cctx.pageStore();
            try (FilePageStore pageStore = (FilePageStore) storeMgr.getPageStoreFactory(grpId, false).createPageStore(getTypeByPartId(partId), part::toPath, val -> {
            })) {
                if (partId == INDEX_PARTITION) {
                    checkPartitionsPageCrcSum(() -> pageStore, INDEX_PARTITION, FLAG_IDX);
                    return null;
                }
                if (grpId == MetaStorage.METASTORAGE_CACHE_ID) {
                    checkPartitionsPageCrcSum(() -> pageStore, partId, FLAG_DATA);
                    return null;
                }
                ByteBuffer pageBuff = buff.get();
                pageBuff.clear();
                pageStore.read(0, pageBuff, true);
                long pageAddr = GridUnsafe.bufferAddress(pageBuff);
                PagePartitionMetaIO io = PageIO.getPageIO(pageBuff);
                GridDhtPartitionState partState = fromOrdinal(io.getPartitionState(pageAddr));
                if (partState != OWNING) {
                    throw new IgniteCheckedException("Snapshot partitions must be in the OWNING " + "state only: " + partState);
                }
                long updateCntr = io.getUpdateCounter(pageAddr);
                long size = io.getSize(pageAddr);
                if (log.isDebugEnabled()) {
                    log.debug("Partition [grpId=" + grpId + ", id=" + partId + ", counter=" + updateCntr + ", size=" + size + "]");
                }
                // Snapshot partitions must always be in OWNING state.
                // There is no `primary` partitions for snapshot.
                PartitionKeyV2 key = new PartitionKeyV2(grpId, partId, grpName);
                PartitionHashRecordV2 hash = calculatePartitionHash(key, updateCntr, meta.consistentId(), GridDhtPartitionState.OWNING, false, size, snpMgr.partitionRowIterator(snpCtx, grpName, partId, pageStore));
                assert hash != null : "OWNING must have hash: " + key;
                res.put(key, hash);
            } catch (IOException e) {
                throw new IgniteCheckedException(e);
            }
            return null;
        });
    } catch (Throwable t) {
        log.error("Error executing handler: ", t);
        throw t;
    } finally {
        for (GridComponent comp : snpCtx) comp.stop(true);
    }
    return res;
}
Also used : FLAG_DATA(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_DATA) PartitionHashRecordV2(org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2) IdleVerifyUtility.calculatePartitionHash(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility.calculatePartitionHash) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) ByteBuffer(java.nio.ByteBuffer) IdleVerifyUtility.checkPartitionsPageCrcSum(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility.checkPartitionsPageCrcSum) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) GridDhtPartitionState.fromOrdinal(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.fromOrdinal) Map(java.util.Map) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) FilePageStoreManager.cachePartitionFiles(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.cachePartitionFiles) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) F(org.apache.ignite.internal.util.typedef.F) FilePageStoreManager.cacheGroupName(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.cacheGroupName) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridComponent(org.apache.ignite.internal.GridComponent) Set(java.util.Set) GridUnsafe(org.apache.ignite.internal.util.GridUnsafe) IOException(java.io.IOException) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) OWNING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING) Collectors(java.util.stream.Collectors) File(java.io.File) FilePageStoreManager.partId(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.partId) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) ByteOrder(java.nio.ByteOrder) List(java.util.List) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) PartitionKeyV2(org.apache.ignite.internal.processors.cache.verify.PartitionKeyV2) CU(org.apache.ignite.internal.util.typedef.internal.CU) GroupPartitionId.getTypeByPartId(org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId.getTypeByPartId) Collections(java.util.Collections) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) FLAG_IDX(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridComponent(org.apache.ignite.internal.GridComponent) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) PartitionKeyV2(org.apache.ignite.internal.processors.cache.verify.PartitionKeyV2) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashSet(java.util.HashSet) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) CU(org.apache.ignite.internal.util.typedef.internal.CU) PartitionHashRecordV2(org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) File(java.io.File)

Example 3 with OWNING

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING in project ignite by apache.

the class WalScannerTest method shouldFindCorrectRecordsForMoreThanOnePages.

/**
 * @throws Exception If failed.
 */
@Test
public void shouldFindCorrectRecordsForMoreThanOnePages() throws Exception {
    // given: Iterator with random value and value which should be find by scanner with several ids.
    long expPageId1 = 984;
    long expPageId2 = 9584;
    long expPageId3 = 98344;
    int grpId = 123;
    PageSnapshot expPageSnapshot = new PageSnapshot(new FullPageId(expPageId1, grpId), dummyPage(1024, expPageId1), 1024);
    CheckpointRecord expCheckpoint = new CheckpointRecord(new WALPointer(5738, 0, 0));
    FixCountRecord expDeltaPage1 = new FixCountRecord(grpId, expPageId2, 4);
    FixCountRecord expDeltaPage2 = new FixCountRecord(grpId, expPageId3, 4);
    WALIterator mockedIter = mockWalIterator(new IgniteBiTuple<>(NULL_PTR, expPageSnapshot), new IgniteBiTuple<>(NULL_PTR, new PageSnapshot(new FullPageId(455, grpId), dummyPage(1024, 455), 1024)), new IgniteBiTuple<>(NULL_PTR, expCheckpoint), new IgniteBiTuple<>(NULL_PTR, new MetastoreDataRecord("key", new byte[0])), new IgniteBiTuple<>(NULL_PTR, new PartitionMetaStateRecord(grpId, 1, OWNING, 1)), new IgniteBiTuple<>(NULL_PTR, expDeltaPage1), new IgniteBiTuple<>(NULL_PTR, new FixCountRecord(grpId, 98348, 4)), new IgniteBiTuple<>(NULL_PTR, new PartitionMetaStateRecord(grpId, 1, OWNING, 1)), new IgniteBiTuple<>(NULL_PTR, expDeltaPage2));
    IgniteWalIteratorFactory mockedFactory = mock(IgniteWalIteratorFactory.class);
    when(mockedFactory.iterator(any(IteratorParametersBuilder.class))).thenReturn(mockedIter);
    List<WALRecord> holder = new ArrayList<>();
    ScannerHandler recordCaptor = (rec) -> holder.add(rec.get2());
    Set<T2<Integer, Long>> groupAndPageIds = new HashSet<>();
    groupAndPageIds.add(new T2<>(grpId, expPageId1));
    groupAndPageIds.add(new T2<>(grpId, expPageId2));
    groupAndPageIds.add(new T2<>(grpId, expPageId3));
    // when: Scanning WAL for searching expected page.
    buildWalScanner(withIteratorParameters(), mockedFactory).findAllRecordsFor(groupAndPageIds).forEach(recordCaptor);
    // then: Should be find only expected value.
    assertEquals(4, holder.size());
    assertEquals(expPageSnapshot, holder.get(0));
    assertEquals(expCheckpoint, holder.get(1));
    assertEquals(expDeltaPage1, holder.get(2));
    assertEquals(expDeltaPage2, holder.get(3));
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) Arrays(java.util.Arrays) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteLogger(org.apache.ignite.IgniteLogger) FixCountRecord(org.apache.ignite.internal.pagemem.wal.record.delta.FixCountRecord) IteratorParametersBuilder.withIteratorParameters(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder.withIteratorParameters) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) ScannerHandlers.printToFile(org.apache.ignite.internal.processors.cache.persistence.wal.scanner.ScannerHandlers.printToFile) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) Files(java.nio.file.Files) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) Set(java.util.Set) GridUnsafe(org.apache.ignite.internal.util.GridUnsafe) Test(org.junit.Test) OWNING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) NULL_PTR(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointStatus.NULL_PTR) Collectors(java.util.stream.Collectors) File(java.io.File) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) T2(org.apache.ignite.internal.util.typedef.T2) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) PartitionMetaStateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord) List(java.util.List) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) Paths(java.nio.file.Paths) DummyPageIO(org.apache.ignite.internal.processors.cache.persistence.DummyPageIO) TestCase.assertTrue(junit.framework.TestCase.assertTrue) WalScanner.buildWalScanner(org.apache.ignite.internal.processors.cache.persistence.wal.scanner.WalScanner.buildWalScanner) ScannerHandlers.printToLog(org.apache.ignite.internal.processors.cache.persistence.wal.scanner.ScannerHandlers.printToLog) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) PartitionMetaStateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) ArrayList(java.util.ArrayList) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) FixCountRecord(org.apache.ignite.internal.pagemem.wal.record.delta.FixCountRecord) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) T2(org.apache.ignite.internal.util.typedef.T2) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with OWNING

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING 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();
    }
}
Also used : IgniteSystemProperties.getBoolean(org.apache.ignite.IgniteSystemProperties.getBoolean) IgniteSystemProperties.getInteger(org.apache.ignite.IgniteSystemProperties.getInteger) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) GridWorker(org.apache.ignite.internal.util.worker.GridWorker) GridCursor(org.apache.ignite.internal.util.lang.GridCursor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) S(org.apache.ignite.internal.util.typedef.internal.S) MOVING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.MOVING) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) EVICTED(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.EVICTED) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IGNITE_ENABLE_EXTRA_INDEX_REBUILD_LOGGING(org.apache.ignite.IgniteSystemProperties.IGNITE_ENABLE_EXTRA_INDEX_REBUILD_LOGGING) QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) OWNING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) Nullable(org.jetbrains.annotations.Nullable) KEY_ONLY(org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter.RowData.KEY_ONLY) LOST(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.LOST) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Objects.nonNull(java.util.Objects.nonNull) IGNITE_INDEX_REBUILD_BATCH_SIZE(org.apache.ignite.IgniteSystemProperties.IGNITE_INDEX_REBUILD_BATCH_SIZE) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) RENTING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.RENTING) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 5 with OWNING

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING in project ignite by apache.

the class WalScannerTest method shouldFindCorrectRecords.

/**
 * @throws Exception If failed.
 */
@Test
public void shouldFindCorrectRecords() throws Exception {
    // given: Iterator with random value and value which should be find by scanner.
    long expPageId = 984;
    int grpId = 123;
    PageSnapshot expPageSnapshot = new PageSnapshot(new FullPageId(expPageId, grpId), dummyPage(1024, expPageId), 1024);
    CheckpointRecord expCheckpoint = new CheckpointRecord(new WALPointer(5738, 0, 0));
    FixCountRecord expDeltaPage = new FixCountRecord(grpId, expPageId, 4);
    WALIterator mockedIter = mockWalIterator(new IgniteBiTuple<>(NULL_PTR, expPageSnapshot), new IgniteBiTuple<>(NULL_PTR, new PageSnapshot(new FullPageId(455, grpId), dummyPage(4096, 455), 1024)), new IgniteBiTuple<>(NULL_PTR, expCheckpoint), new IgniteBiTuple<>(NULL_PTR, new MetastoreDataRecord("key", new byte[0])), new IgniteBiTuple<>(NULL_PTR, new PartitionMetaStateRecord(grpId, 1, OWNING, 1)), new IgniteBiTuple<>(NULL_PTR, expDeltaPage), new IgniteBiTuple<>(NULL_PTR, new FixCountRecord(grpId, 98348, 4)));
    IgniteWalIteratorFactory mockedFactory = mock(IgniteWalIteratorFactory.class);
    when(mockedFactory.iterator(any(IteratorParametersBuilder.class))).thenReturn(mockedIter);
    // Test scanner handler for holding found value instead of printing its.
    List<WALRecord> holder = new ArrayList<>();
    ScannerHandler recordCaptor = (rec) -> holder.add(rec.get2());
    Set<T2<Integer, Long>> groupAndPageIds = new HashSet<>();
    groupAndPageIds.add(new T2<>(grpId, expPageId));
    // when: Scanning WAL for searching expected page.
    buildWalScanner(withIteratorParameters(), mockedFactory).findAllRecordsFor(groupAndPageIds).forEach(recordCaptor);
    // then: Should be find only expected value.
    assertEquals(holder.size(), 3);
    assertEquals(expPageSnapshot, holder.get(0));
    assertEquals(expCheckpoint, holder.get(1));
    assertEquals(expDeltaPage, holder.get(2));
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) Arrays(java.util.Arrays) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteLogger(org.apache.ignite.IgniteLogger) FixCountRecord(org.apache.ignite.internal.pagemem.wal.record.delta.FixCountRecord) IteratorParametersBuilder.withIteratorParameters(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder.withIteratorParameters) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) ScannerHandlers.printToFile(org.apache.ignite.internal.processors.cache.persistence.wal.scanner.ScannerHandlers.printToFile) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) Files(java.nio.file.Files) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) Set(java.util.Set) GridUnsafe(org.apache.ignite.internal.util.GridUnsafe) Test(org.junit.Test) OWNING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) NULL_PTR(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointStatus.NULL_PTR) Collectors(java.util.stream.Collectors) File(java.io.File) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) T2(org.apache.ignite.internal.util.typedef.T2) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) PartitionMetaStateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord) List(java.util.List) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) Paths(java.nio.file.Paths) DummyPageIO(org.apache.ignite.internal.processors.cache.persistence.DummyPageIO) TestCase.assertTrue(junit.framework.TestCase.assertTrue) WalScanner.buildWalScanner(org.apache.ignite.internal.processors.cache.persistence.wal.scanner.WalScanner.buildWalScanner) ScannerHandlers.printToLog(org.apache.ignite.internal.processors.cache.persistence.wal.scanner.ScannerHandlers.printToLog) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) PartitionMetaStateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) ArrayList(java.util.ArrayList) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) FixCountRecord(org.apache.ignite.internal.pagemem.wal.record.delta.FixCountRecord) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) T2(org.apache.ignite.internal.util.typedef.T2) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

OWNING (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING)7 U (org.apache.ignite.internal.util.typedef.internal.U)7 HashSet (java.util.HashSet)6 Set (java.util.Set)6 IgniteLogger (org.apache.ignite.IgniteLogger)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 IgniteException (org.apache.ignite.IgniteException)5 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 F (org.apache.ignite.internal.util.typedef.F)4 File (java.io.File)3 ByteBuffer (java.nio.ByteBuffer)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)3 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)3