Search in sources :

Example 16 with GridDhtPartitionState

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

the class GridCacheDatabaseSharedManager method dumpPartitionsInfo.

/**
 * Retrieves from page memory meta information about given {@code grp} group partitions
 * and dumps this information to log INFO level.
 *
 * @param grp Cache group.
 * @param log Logger.
 * @throws IgniteCheckedException If failed.
 */
private static void dumpPartitionsInfo(CacheGroupContext grp, IgniteLogger log) throws IgniteCheckedException {
    PageMemoryEx pageMem = (PageMemoryEx) grp.dataRegion().pageMemory();
    IgnitePageStoreManager pageStore = grp.shared().pageStore();
    assert pageStore != null : "Persistent cache should have initialize page store manager.";
    for (int p = 0; p < grp.affinity().partitions(); p++) {
        GridDhtLocalPartition part = grp.topology().localPartition(p);
        if (part != null) {
            if (log.isInfoEnabled())
                log.info("Partition [grp=" + grp.cacheOrGroupName() + ", id=" + p + ", state=" + part.state() + ", counter=" + part.dataStore().partUpdateCounter() + ", size=" + part.fullSize() + "]");
            continue;
        }
        if (!pageStore.exists(grp.groupId(), p))
            continue;
        pageStore.ensure(grp.groupId(), p);
        if (pageStore.pages(grp.groupId(), p) <= 1) {
            if (log.isInfoEnabled())
                log.info("Partition [grp=" + grp.cacheOrGroupName() + ", id=" + p + ", state=N/A (only file header) ]");
            continue;
        }
        long partMetaId = pageMem.partitionMetaPageId(grp.groupId(), p);
        long partMetaPage = pageMem.acquirePage(grp.groupId(), partMetaId);
        try {
            long pageAddr = pageMem.readLock(grp.groupId(), partMetaId, partMetaPage);
            try {
                PagePartitionMetaIO io = PagePartitionMetaIO.VERSIONS.forPage(pageAddr);
                GridDhtPartitionState partState = fromOrdinal(io.getPartitionState(pageAddr));
                String state = partState != null ? partState.toString() : "N/A";
                long updateCntr = io.getUpdateCounter(pageAddr);
                long size = io.getSize(pageAddr);
                if (log.isInfoEnabled())
                    log.info("Partition [grp=" + grp.cacheOrGroupName() + ", id=" + p + ", state=" + state + ", counter=" + updateCntr + ", size=" + size + "]");
            } finally {
                pageMem.readUnlock(grp.groupId(), partMetaId, partMetaPage);
            }
        } finally {
            pageMem.releasePage(grp.groupId(), partMetaId, partMetaPage);
        }
    }
}
Also used : IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO)

Example 17 with GridDhtPartitionState

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

the class GridCacheDatabaseSharedManager method performBinaryMemoryRestore.

/**
 * @param status Checkpoint status.
 * @param cacheGroupsPredicate Cache groups to restore.
 * @throws IgniteCheckedException If failed.
 * @throws StorageException In case I/O error occurred during operations with storage.
 */
private RestoreBinaryState performBinaryMemoryRestore(CheckpointStatus status, IgnitePredicate<Integer> cacheGroupsPredicate, IgniteBiPredicate<WALRecord.RecordType, WALPointer> recordTypePredicate, boolean finalizeState) throws IgniteCheckedException {
    if (log.isInfoEnabled())
        log.info("Checking memory state [lastValidPos=" + status.endPtr + ", lastMarked=" + status.startPtr + ", lastCheckpointId=" + status.cpStartId + ']');
    WALPointer recPtr = status.endPtr;
    boolean apply = status.needRestoreMemory();
    try {
        WALRecord startRec = !CheckpointStatus.NULL_PTR.equals(status.startPtr) || apply ? cctx.wal().read(status.startPtr) : null;
        if (apply) {
            if (finalizeState)
                U.quietAndWarn(log, "Ignite node stopped in the middle of checkpoint. Will restore memory state and " + "finish checkpoint on node start.");
            cctx.cache().cacheGroupDescriptors().forEach((grpId, desc) -> {
                if (!cacheGroupsPredicate.apply(grpId))
                    return;
                try {
                    DataRegion region = cctx.database().dataRegion(desc.config().getDataRegionName());
                    if (region == null || !cctx.isLazyMemoryAllocation(region))
                        return;
                    region.pageMemory().start();
                } catch (IgniteCheckedException e) {
                    throw new IgniteException(e);
                }
            });
            cctx.pageStore().beginRecover();
            if (!(startRec instanceof CheckpointRecord))
                throw new StorageException("Checkpoint marker doesn't point to checkpoint record " + "[ptr=" + status.startPtr + ", rec=" + startRec + "]");
            WALPointer cpMark = ((CheckpointRecord) startRec).checkpointMark();
            if (cpMark != null) {
                if (log.isInfoEnabled())
                    log.info("Restoring checkpoint after logical recovery, will start physical recovery from " + "back pointer: " + cpMark);
                recPtr = cpMark;
            }
        } else
            cctx.wal().notchLastCheckpointPtr(status.startPtr);
    } catch (NoSuchElementException e) {
        throw new StorageException("Failed to read checkpoint record from WAL, persistence consistency " + "cannot be guaranteed. Make sure configuration points to correct WAL folders and WAL folder is " + "properly mounted [ptr=" + status.startPtr + ", walPath=" + persistenceCfg.getWalPath() + ", walArchive=" + persistenceCfg.getWalArchivePath() + "]");
    }
    AtomicReference<Throwable> applyError = new AtomicReference<>();
    StripedExecutor exec = cctx.kernalContext().pools().getStripedExecutorService();
    Semaphore semaphore = new Semaphore(semaphorePertmits(exec));
    long start = U.currentTimeMillis();
    long lastArchivedSegment = cctx.wal().lastArchivedSegment();
    WALIterator it = cctx.wal().replay(recPtr, recordTypePredicate);
    RestoreBinaryState restoreBinaryState = new RestoreBinaryState(status, it, lastArchivedSegment, cacheGroupsPredicate);
    AtomicLong applied = new AtomicLong();
    try {
        while (restoreBinaryState.hasNext()) {
            if (applyError.get() != null)
                break;
            WALRecord rec = restoreBinaryState.next();
            if (rec == null)
                break;
            switch(rec.type()) {
                case PAGE_RECORD:
                    if (restoreBinaryState.needApplyBinaryUpdate()) {
                        PageSnapshot pageSnapshot = (PageSnapshot) rec;
                        // Here we do not require tag check because we may be applying memory changes after
                        // several repetitive restarts and the same pages may have changed several times.
                        int groupId = pageSnapshot.fullPageId().groupId();
                        int partId = partId(pageSnapshot.fullPageId().pageId());
                        if (skipRemovedIndexUpdates(groupId, partId))
                            break;
                        stripedApplyPage((pageMem) -> {
                            try {
                                applyPageSnapshot(pageMem, pageSnapshot);
                                applied.incrementAndGet();
                            } catch (Throwable t) {
                                U.error(log, "Failed to apply page snapshot. rec=[" + pageSnapshot + ']');
                                applyError.compareAndSet(null, (t instanceof IgniteCheckedException) ? (IgniteCheckedException) t : new IgniteCheckedException("Failed to apply page snapshot", t));
                            }
                        }, groupId, partId, exec, semaphore);
                    }
                    break;
                case PART_META_UPDATE_STATE:
                    PartitionMetaStateRecord metaStateRecord = (PartitionMetaStateRecord) rec;
                    {
                        int groupId = metaStateRecord.groupId();
                        int partId = metaStateRecord.partitionId();
                        stripedApplyPage((pageMem) -> {
                            GridDhtPartitionState state = fromOrdinal(metaStateRecord.state());
                            if (state == null || state == GridDhtPartitionState.EVICTED)
                                schedulePartitionDestroy(groupId, partId);
                            else {
                                try {
                                    cancelOrWaitPartitionDestroy(groupId, partId);
                                } catch (Throwable t) {
                                    U.error(log, "Failed to cancel or wait partition destroy. rec=[" + metaStateRecord + ']');
                                    applyError.compareAndSet(null, (t instanceof IgniteCheckedException) ? (IgniteCheckedException) t : new IgniteCheckedException("Failed to cancel or wait partition destroy", t));
                                }
                            }
                        }, groupId, partId, exec, semaphore);
                    }
                    break;
                case PARTITION_DESTROY:
                    PartitionDestroyRecord destroyRecord = (PartitionDestroyRecord) rec;
                    {
                        int groupId = destroyRecord.groupId();
                        int partId = destroyRecord.partitionId();
                        stripedApplyPage((pageMem) -> {
                            pageMem.invalidate(groupId, partId);
                            schedulePartitionDestroy(groupId, partId);
                        }, groupId, partId, exec, semaphore);
                    }
                    break;
                default:
                    if (restoreBinaryState.needApplyBinaryUpdate() && rec instanceof PageDeltaRecord) {
                        PageDeltaRecord pageDelta = (PageDeltaRecord) rec;
                        int groupId = pageDelta.groupId();
                        int partId = partId(pageDelta.pageId());
                        if (skipRemovedIndexUpdates(groupId, partId))
                            break;
                        stripedApplyPage((pageMem) -> {
                            try {
                                applyPageDelta(pageMem, pageDelta, true);
                                applied.incrementAndGet();
                            } catch (Throwable t) {
                                U.error(log, "Failed to apply page delta. rec=[" + pageDelta + ']');
                                applyError.compareAndSet(null, (t instanceof IgniteCheckedException) ? (IgniteCheckedException) t : new IgniteCheckedException("Failed to apply page delta", t));
                            }
                        }, groupId, partId, exec, semaphore);
                    }
            }
        }
    } finally {
        it.close();
        awaitApplyComplete(exec, applyError);
    }
    if (!finalizeState)
        return null;
    WALPointer lastReadPtr = restoreBinaryState.lastReadRecordPointer();
    if (status.needRestoreMemory()) {
        if (restoreBinaryState.needApplyBinaryUpdate())
            throw new StorageException("Failed to restore memory state (checkpoint marker is present " + "on disk, but checkpoint record is missed in WAL) " + "[cpStatus=" + status + ", lastRead=" + lastReadPtr + "]");
        if (log.isInfoEnabled())
            log.info("Finished applying memory changes [changesApplied=" + applied + ", time=" + (U.currentTimeMillis() - start) + " ms]");
        finalizeCheckpointOnRecovery(status.cpStartTs, status.cpStartId, status.startPtr, exec);
    }
    return restoreBinaryState;
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) Arrays(java.util.Arrays) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) TxLog(org.apache.ignite.internal.processors.cache.mvcc.txlog.TxLog) PartitionClearingStartRecord(org.apache.ignite.internal.pagemem.wal.record.PartitionClearingStartRecord) DistributedConfigurationLifecycleListener(org.apache.ignite.internal.processors.configuration.distributed.DistributedConfigurationLifecycleListener) MetastorageLifecycleListener(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetastorageLifecycleListener) CheckpointStatus(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointStatus) MASTER_KEY_CHANGE_RECORD(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.MASTER_KEY_CHANGE_RECORD) METASTORE_DATA_RECORD(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.METASTORE_DATA_RECORD) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) GridPortRecord(org.apache.ignite.internal.processors.port.GridPortRecord) LightweightCheckpointManager(org.apache.ignite.internal.processors.cache.persistence.checkpoint.LightweightCheckpointManager) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) GridDhtPartitionState.fromOrdinal(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.fromOrdinal) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) Map(java.util.Map) PageUtils(org.apache.ignite.internal.pagemem.PageUtils) IGNITE_PREFER_WAL_REBALANCE(org.apache.ignite.IgniteSystemProperties.IGNITE_PREFER_WAL_REBALANCE) Path(java.nio.file.Path) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) PageIdAllocator(org.apache.ignite.internal.pagemem.PageIdAllocator) IgniteDataIntegrityViolationException(org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheGroupDescriptor(org.apache.ignite.internal.processors.cache.CacheGroupDescriptor) Set(java.util.Set) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) Serializable(java.io.Serializable) ByteOrder(java.nio.ByteOrder) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) CheckpointHistoryResult(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistoryResult) GB(org.apache.ignite.internal.util.IgniteUtils.GB) GridCountDownCallback(org.apache.ignite.internal.util.GridCountDownCallback) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteLogger(org.apache.ignite.IgniteLogger) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) IGNITE_RECOVERY_SEMAPHORE_PERMITS(org.apache.ignite.IgniteSystemProperties.IGNITE_RECOVERY_SEMAPHORE_PERMITS) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) CheckpointManager(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointManager) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) PageReadWriteManager(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageReadWriteManager) MvccDataEntry(org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) FINISHED(org.apache.ignite.internal.processors.cache.persistence.CheckpointState.FINISHED) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) CachePartitionDefragmentationManager(org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager) PageIdUtils.partId(org.apache.ignite.internal.pagemem.PageIdUtils.partId) DataStorageMetrics(org.apache.ignite.DataStorageMetrics) IoStatisticsHolderNoOp(org.apache.ignite.internal.metric.IoStatisticsHolderNoOp) TX_RECORD(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.TX_RECORD) SystemProperty(org.apache.ignite.SystemProperty) A(org.apache.ignite.internal.util.typedef.internal.A) IOException(java.io.IOException) MaintenanceTask(org.apache.ignite.maintenance.MaintenanceTask) IGNITE_PDS_WAL_REBALANCE_THRESHOLD(org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD) File(java.io.File) T2(org.apache.ignite.internal.util.typedef.T2) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) SimpleDistributedProperty(org.apache.ignite.internal.processors.configuration.distributed.SimpleDistributedProperty) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) DefragmentationPageReadWriteManager(org.apache.ignite.internal.processors.cache.persistence.defragmentation.DefragmentationPageReadWriteManager) IgniteCacheSnapshotManager(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteCacheSnapshotManager) GridInClosure3X(org.apache.ignite.internal.util.lang.GridInClosure3X) WalRecordCacheGroupAware(org.apache.ignite.internal.pagemem.wal.record.WalRecordCacheGroupAware) CompressionProcessor(org.apache.ignite.internal.processors.compress.CompressionProcessor) DefragmentationParameters.fromStore(org.apache.ignite.internal.processors.cache.persistence.defragmentation.maintenance.DefragmentationParameters.fromStore) PartitionDestroyRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecord) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) StripedExecutor(org.apache.ignite.internal.util.StripedExecutor) IgniteSystemProperties.getBoolean(org.apache.ignite.IgniteSystemProperties.getBoolean) TimeBag(org.apache.ignite.internal.util.TimeBag) TRANSACTIONAL_SNAPSHOT(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) ByteBuffer(java.nio.ByteBuffer) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) RollbackRecord(org.apache.ignite.internal.pagemem.wal.record.RollbackRecord) IgniteUtils.checkpointBufferSize(org.apache.ignite.internal.util.IgniteUtils.checkpointBufferSize) SB(org.apache.ignite.internal.util.typedef.internal.SB) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataRegionMetricsProvider(org.apache.ignite.DataRegionMetricsProvider) TxRecord(org.apache.ignite.internal.pagemem.wal.record.TxRecord) X(org.apache.ignite.internal.util.typedef.X) DataStorageMetricsMXBean(org.apache.ignite.mxbean.DataStorageMetricsMXBean) Checkpointer(org.apache.ignite.internal.processors.cache.persistence.checkpoint.Checkpointer) DefragmentationWorkflowCallback(org.apache.ignite.internal.processors.cache.persistence.defragmentation.maintenance.DefragmentationWorkflowCallback) IGNITE_DEFRAGMENTATION_REGION_SIZE_PERCENTAGE(org.apache.ignite.IgniteSystemProperties.IGNITE_DEFRAGMENTATION_REGION_SIZE_PERCENTAGE) ToLongFunction(java.util.function.ToLongFunction) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) MetastorageViewWalker(org.apache.ignite.internal.managers.systemview.walker.MetastorageViewWalker) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) Collectors.toSet(java.util.stream.Collectors.toSet) DEFRAGMENTATION_MNTC_TASK_NAME(org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager.DEFRAGMENTATION_MNTC_TASK_NAME) FailureType(org.apache.ignite.failure.FailureType) CacheState(org.apache.ignite.internal.pagemem.wal.record.CacheState) IgniteOutClosure(org.apache.ignite.lang.IgniteOutClosure) Predicate(java.util.function.Predicate) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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) UUID(java.util.UUID) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) Collectors(java.util.stream.Collectors) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) PageDeltaRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord) DataRegionMetrics(org.apache.ignite.DataRegionMetrics) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) DistributedPropertyDispatcher(org.apache.ignite.internal.processors.configuration.distributed.DistributedPropertyDispatcher) CU(org.apache.ignite.internal.util.typedef.internal.CU) Function.identity(java.util.function.Function.identity) CheckpointEntry(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointEntry) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) Objects.nonNull(java.util.Objects.nonNull) IgniteSystemProperties.getInteger(org.apache.ignite.IgniteSystemProperties.getInteger) CHECKPOINT_LOCK_HOLD_COUNT(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointReadWriteLock.CHECKPOINT_LOCK_HOLD_COUNT) CheckpointProgress(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgress) HashMap(java.util.HashMap) MvccTxRecord(org.apache.ignite.internal.pagemem.wal.record.MvccTxRecord) AtomicReference(java.util.concurrent.atomic.AtomicReference) DirectMemoryRegion(org.apache.ignite.internal.mem.DirectMemoryRegion) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) HashSet(java.util.HashSet) IndexRenameRootPageRecord(org.apache.ignite.internal.pagemem.wal.record.IndexRenameRootPageRecord) FailureContext(org.apache.ignite.failure.FailureContext) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) MasterKeyChangeRecordV2(org.apache.ignite.internal.pagemem.wal.record.MasterKeyChangeRecordV2) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) NoSuchElementException(java.util.NoSuchElementException) MemoryRecoveryRecord(org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord) MetastorageView(org.apache.ignite.spi.systemview.view.MetastorageView) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) F(org.apache.ignite.internal.util.typedef.F) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) ReencryptionStartRecord(org.apache.ignite.internal.pagemem.wal.record.ReencryptionStartRecord) GroupPartitionId(org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId) Iterator(java.util.Iterator) Semaphore(java.util.concurrent.Semaphore) CheckpointHistory(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) DataPageEvictionMode(org.apache.ignite.configuration.DataPageEvictionMode) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) CHECKPOINT_RECORD(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.CHECKPOINT_RECORD) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) Consumer(java.util.function.Consumer) DistributedConfigurationUtils.makeUpdateListener(org.apache.ignite.internal.cluster.DistributedConfigurationUtils.makeUpdateListener) PartitionMetaStateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord) DistributedConfigurationUtils.setDefaultValue(org.apache.ignite.internal.cluster.DistributedConfigurationUtils.setDefaultValue) Collectors.toList(java.util.stream.Collectors.toList) TransactionState(org.apache.ignite.transactions.TransactionState) LOCK_RELEASED(org.apache.ignite.internal.processors.cache.persistence.CheckpointState.LOCK_RELEASED) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) MASTER_KEY_CHANGE_RECORD_V2(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.MASTER_KEY_CHANGE_RECORD_V2) Comparator(java.util.Comparator) Collections(java.util.Collections) TxState(org.apache.ignite.internal.processors.cache.mvcc.txlog.TxState) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) ReservationReason(org.apache.ignite.internal.processors.cache.persistence.checkpoint.ReservationReason) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) CORRUPTED_DATA_FILES_MNTC_TASK_NAME(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CORRUPTED_DATA_FILES_MNTC_TASK_NAME) PageDeltaRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord) Semaphore(java.util.concurrent.Semaphore) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) IgniteException(org.apache.ignite.IgniteException) PartitionDestroyRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecord) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) PartitionMetaStateRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicLong(java.util.concurrent.atomic.AtomicLong) StripedExecutor(org.apache.ignite.internal.util.StripedExecutor) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) NoSuchElementException(java.util.NoSuchElementException)

Example 18 with GridDhtPartitionState

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

the class GridDhtPartitionsExchangeFuture method assignPartitionSizes.

/**
 * @param top Topology.
 */
private void assignPartitionSizes(GridDhtPartitionTopology top) {
    Map<Integer, Long> partSizes = new HashMap<>();
    for (Map.Entry<UUID, GridDhtPartitionsSingleMessage> e : msgs.entrySet()) {
        GridDhtPartitionsSingleMessage singleMsg = e.getValue();
        GridDhtPartitionMap partMap = singleMsg.partitions().get(top.groupId());
        if (partMap == null)
            continue;
        for (Map.Entry<Integer, GridDhtPartitionState> e0 : partMap.entrySet()) {
            int p = e0.getKey();
            GridDhtPartitionState state = e0.getValue();
            if (state == GridDhtPartitionState.OWNING)
                partSizes.put(p, singleMsg.partitionSizes(top.groupId()).get(p));
        }
    }
    for (GridDhtLocalPartition locPart : top.currentLocalPartitions()) {
        if (locPart.state() == GridDhtPartitionState.OWNING)
            partSizes.put(locPart.id(), locPart.fullSize());
    }
    top.globalPartSizes(partSizes);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IgniteSystemProperties.getLong(org.apache.ignite.IgniteSystemProperties.getLong) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) UUID(java.util.UUID) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 19 with GridDhtPartitionState

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState 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 20 with GridDhtPartitionState

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

the class GridCacheDhtPreloadDelayedSelfTest method testAutomaticPreloadWithEmptyCache.

/**
 * @throws Exception If failed.
 */
@Test
public void testAutomaticPreloadWithEmptyCache() throws Exception {
    preloadMode = SYNC;
    delay = 0;
    Collection<Ignite> ignites = new ArrayList<>();
    try {
        for (int i = 0; i < 5; i++) {
            ignites.add(startGrid(i));
            if (persistenceEnabled()) {
                if (i == 0)
                    grid(0).cluster().active(true);
                else
                    resetBaselineTopology();
            }
            awaitPartitionMapExchange(true, true, null, false);
            for (Ignite g : ignites) {
                info(">>> Checking affinity for grid: " + g.name());
                GridDhtPartitionTopology top = topology(g);
                GridDhtPartitionFullMap fullMap = top.partitionMap(true);
                for (Map.Entry<UUID, GridDhtPartitionMap> fe : fullMap.entrySet()) {
                    UUID nodeId = fe.getKey();
                    GridDhtPartitionMap m = fe.getValue();
                    for (Map.Entry<Integer, GridDhtPartitionState> e : m.entrySet()) {
                        int p = e.getKey();
                        GridDhtPartitionState state = e.getValue();
                        Collection<ClusterNode> nodes = affinityNodes(g, p);
                        Collection<UUID> nodeIds = U.nodeIds(nodes);
                        assert nodeIds.contains(nodeId) : "Invalid affinity mapping [nodeId=" + nodeId + ", part=" + p + ", state=" + state + ", igniteInstanceName=" + G.ignite(nodeId).name() + ", affNames=" + U.nodes2names(nodes) + ", affIds=" + nodeIds + ']';
                    }
                }
            }
        }
    } finally {
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) ArrayList(java.util.ArrayList) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) Map(java.util.Map) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

GridDhtPartitionState (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState)25 Map (java.util.Map)13 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)11 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)8 GridDhtPartitionMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)8 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 Ignite (org.apache.ignite.Ignite)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 IgniteException (org.apache.ignite.IgniteException)5 IgniteKernal (org.apache.ignite.internal.IgniteKernal)5 GridDhtPartitionFullMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap)5 HashSet (java.util.HashSet)4 GridPartitionStateMap (org.apache.ignite.internal.util.GridPartitionStateMap)4 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)4 U (org.apache.ignite.internal.util.typedef.internal.U)4