Search in sources :

Example 1 with FLAG_IDX

use of org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX 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 2 with FLAG_IDX

use of org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX in project ignite by apache.

the class PageMemoryImplTest method runThrottlingEmptifyCpBufFirst.

/**
 * @throws Exception if failed.
 */
public void runThrottlingEmptifyCpBufFirst(PageMemoryImpl.ThrottlingPolicy plc) throws Exception {
    TestPageStoreManager pageStoreMgr = new TestPageStoreManager();
    final List<FullPageId> allocated = new ArrayList<>();
    int pagesForStartThrottling = 10;
    // Number of pages which were poll from checkpoint buffer for throttling.
    AtomicInteger cpBufferPollPages = new AtomicInteger();
    // Create a 1 mb page memory.
    PageMemoryImpl memory = createPageMemory(1, plc, pageStoreMgr, pageStoreMgr, (IgniteInClosure<FullPageId>) fullPageId -> {
        assertEquals(cpBufferPollPages.incrementAndGet(), pageStoreMgr.storedPages.size());
    });
    assert pagesForStartThrottling < memory.checkpointBufferPagesSize() / 3;
    for (int i = 0; i < pagesForStartThrottling + (memory.checkpointBufferPagesSize() * 2 / 3); i++) {
        long id = memory.allocatePage(1, INDEX_PARTITION, FLAG_IDX);
        FullPageId fullId = new FullPageId(id, 1);
        allocated.add(fullId);
        writePage(memory, fullId, (byte) 1);
    }
    GridMultiCollectionWrapper<FullPageId> markedPages = memory.beginCheckpoint(new GridFinishedFuture());
    for (int i = 0; i < pagesForStartThrottling + (memory.checkpointBufferPagesSize() * 2 / 3); i++) writePage(memory, allocated.get(i), (byte) 1);
    doCheckpoint(markedPages, memory, pageStoreMgr);
    // There is 'pagesForStartThrottling - 1' because we should write pagesForStartThrottling pages
    // from checkpoint buffer before throttling will be disabled but at least one page always would be written
    // outside of throttling and in our case we certainly know that this page is also contained in checkpoint buffer
    // (because all of our pages are in checkpoint buffer).
    assertEquals(pagesForStartThrottling - 1, cpBufferPollPages.get());
}
Also used : PageStore(org.apache.ignite.internal.pagemem.store.PageStore) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) ByteBuffer(java.nio.ByteBuffer) NoopMetricExporterSpi(org.apache.ignite.spi.metric.noop.NoopMetricExporterSpi) GridSystemViewManager(org.apache.ignite.internal.managers.systemview.GridSystemViewManager) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) IgnitePluginProcessor(org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) Map(java.util.Map) PageUtils(org.apache.ignite.internal.pagemem.PageUtils) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) FailureProcessor(org.apache.ignite.internal.processors.failure.FailureProcessor) CheckpointProgressImpl(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgressImpl) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteOutClosure(org.apache.ignite.lang.IgniteOutClosure) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) GridInternalSubscriptionProcessor(org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) ByteOrder(java.nio.ByteOrder) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) PerformanceStatisticsProcessor(org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsProcessor) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteOutOfMemoryException(org.apache.ignite.internal.mem.IgniteOutOfMemoryException) JmxSystemViewExporterSpi(org.apache.ignite.internal.managers.systemview.JmxSystemViewExporterSpi) FLAG_IDX(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX) CHECKPOINT_POOL_OVERFLOW_ERROR_MSG(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl.CHECKPOINT_POOL_OVERFLOW_ERROR_MSG) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) GridMultiCollectionWrapper(org.apache.ignite.internal.util.GridMultiCollectionWrapper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CheckpointProgress(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgress) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) NoopEventStorageSpi(org.apache.ignite.spi.eventstorage.NoopEventStorageSpi) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) GridEncryptionManager(org.apache.ignite.internal.managers.encryption.GridEncryptionManager) NoOpFailureHandler(org.apache.ignite.failure.NoOpFailureHandler) NoopEncryptionSpi(org.apache.ignite.spi.encryption.noop.NoopEncryptionSpi) Test(org.junit.Test) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) Mockito(org.mockito.Mockito) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) PluginProvider(org.apache.ignite.plugin.PluginProvider) DummyPageIO(org.apache.ignite.internal.processors.cache.persistence.DummyPageIO) PageStoreWriter(org.apache.ignite.internal.processors.cache.persistence.PageStoreWriter) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) GridInClosure3X(org.apache.ignite.internal.util.lang.GridInClosure3X) GridEventStorageManager(org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager) Collections(java.util.Collections) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 3 with FLAG_IDX

use of org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX in project ignite by apache.

the class PageMemoryImplTest method testCheckpointBufferCantOverflowWithThrottlingMixedLoad.

/**
 * @throws Exception If failed.
 */
private void testCheckpointBufferCantOverflowWithThrottlingMixedLoad(PageMemoryImpl.ThrottlingPolicy plc) throws Exception {
    PageMemoryImpl memory = createPageMemory(plc, null);
    List<FullPageId> pages = new ArrayList<>();
    for (int i = 0; i < (MAX_SIZE - 10) * MB / PAGE_SIZE / 2; i++) {
        long pageId = memory.allocatePage(1, INDEX_PARTITION, FLAG_IDX);
        FullPageId fullPageId = new FullPageId(pageId, 1);
        pages.add(fullPageId);
        acquireAndReleaseWriteLock(memory, fullPageId);
    }
    memory.beginCheckpoint(new GridFinishedFuture());
    CheckpointMetricsTracker mockTracker = Mockito.mock(CheckpointMetricsTracker.class);
    for (FullPageId checkpointPage : pages) memory.checkpointWritePage(checkpointPage, ByteBuffer.allocate(PAGE_SIZE), (fullPageId, buffer, tag) -> {
    // No-op.
    }, mockTracker);
    memory.finishCheckpoint();
    for (int i = (int) ((MAX_SIZE - 10) * MB / PAGE_SIZE / 2); i < (MAX_SIZE - 20) * MB / PAGE_SIZE; i++) {
        long pageId = memory.allocatePage(1, INDEX_PARTITION, FLAG_IDX);
        FullPageId fullPageId = new FullPageId(pageId, 1);
        pages.add(fullPageId);
        acquireAndReleaseWriteLock(memory, fullPageId);
    }
    memory.beginCheckpoint(new GridFinishedFuture());
    // Mix pages in checkpoint with clean pages
    Collections.shuffle(pages);
    AtomicBoolean stop = new AtomicBoolean(false);
    try {
        GridTestUtils.runAsync(() -> {
            for (FullPageId page : pages) {
                if (// Mark dirty 50% of pages
                ThreadLocalRandom.current().nextDouble() < 0.5)
                    try {
                        acquireAndReleaseWriteLock(memory, page);
                        if (stop.get())
                            break;
                    } catch (IgniteCheckedException e) {
                        log.error("runAsync ended with exception", e);
                        fail();
                    }
            }
        }).get(5_000);
    } catch (IgniteFutureTimeoutCheckedException ignore) {
    // Expected.
    } finally {
        stop.set(true);
    }
    memory.finishCheckpoint();
    LongAdderMetric totalThrottlingTime = U.field(memory.metrics(), "totalThrottlingTime");
    assertNotNull(totalThrottlingTime);
    assertTrue(totalThrottlingTime.value() > 0);
}
Also used : PageStore(org.apache.ignite.internal.pagemem.store.PageStore) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) ByteBuffer(java.nio.ByteBuffer) NoopMetricExporterSpi(org.apache.ignite.spi.metric.noop.NoopMetricExporterSpi) GridSystemViewManager(org.apache.ignite.internal.managers.systemview.GridSystemViewManager) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) IgnitePluginProcessor(org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) Map(java.util.Map) PageUtils(org.apache.ignite.internal.pagemem.PageUtils) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) FailureProcessor(org.apache.ignite.internal.processors.failure.FailureProcessor) CheckpointProgressImpl(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgressImpl) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteOutClosure(org.apache.ignite.lang.IgniteOutClosure) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) GridInternalSubscriptionProcessor(org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) ByteOrder(java.nio.ByteOrder) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) PerformanceStatisticsProcessor(org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsProcessor) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteOutOfMemoryException(org.apache.ignite.internal.mem.IgniteOutOfMemoryException) JmxSystemViewExporterSpi(org.apache.ignite.internal.managers.systemview.JmxSystemViewExporterSpi) FLAG_IDX(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX) CHECKPOINT_POOL_OVERFLOW_ERROR_MSG(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl.CHECKPOINT_POOL_OVERFLOW_ERROR_MSG) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) GridMultiCollectionWrapper(org.apache.ignite.internal.util.GridMultiCollectionWrapper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CheckpointProgress(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgress) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) NoopEventStorageSpi(org.apache.ignite.spi.eventstorage.NoopEventStorageSpi) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) GridEncryptionManager(org.apache.ignite.internal.managers.encryption.GridEncryptionManager) NoOpFailureHandler(org.apache.ignite.failure.NoOpFailureHandler) NoopEncryptionSpi(org.apache.ignite.spi.encryption.noop.NoopEncryptionSpi) Test(org.junit.Test) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) Mockito(org.mockito.Mockito) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) PluginProvider(org.apache.ignite.plugin.PluginProvider) DummyPageIO(org.apache.ignite.internal.processors.cache.persistence.DummyPageIO) PageStoreWriter(org.apache.ignite.internal.processors.cache.persistence.PageStoreWriter) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) GridInClosure3X(org.apache.ignite.internal.util.lang.GridInClosure3X) GridEventStorageManager(org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager) Collections(java.util.Collections) ArrayList(java.util.ArrayList) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 4 with FLAG_IDX

use of org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX in project ignite by apache.

the class IgniteIndexReader method readIdx.

/**
 * Read index file.
 */
public void readIdx() {
    long partPageStoresNum = Arrays.stream(partStores).filter(Objects::nonNull).count();
    print("Partitions files num: " + partPageStoresNum);
    Map<Class, Long> pageClasses = new HashMap<>();
    long pagesNum = isNull(idxStore) ? 0 : (idxStore.size() - idxStore.headerSize()) / pageSize;
    print("Going to check " + pagesNum + " pages.");
    Set<Long> pageIds = new HashSet<>();
    AtomicReference<Map<String, TreeTraversalInfo>> treeInfo = new AtomicReference<>();
    AtomicReference<Map<String, TreeTraversalInfo>> horizontalScans = new AtomicReference<>();
    AtomicReference<PageListsInfo> pageListsInfo = new AtomicReference<>();
    List<Throwable> errors;
    try {
        IgniteBiTuple<Long, Long> indexPartitionRoots = partitionRoots(partMetaPageId(INDEX_PARTITION, FLAG_IDX));
        long metaTreeRootId = indexPartitionRoots.get1();
        long pageListMetaPageId = indexPartitionRoots.get2();
        // Traversing trees.
        treeInfo.set(traverseAllTrees("Index trees traversal", metaTreeRootId, CountOnlyStorage::new, this::traverseTree));
        treeInfo.get().forEach((name, info) -> {
            pageIds.addAll(info.innerPageIds);
            pageIds.add(info.rootPageId);
        });
        Supplier<ItemStorage> itemStorageFactory = checkParts ? LinkStorage::new : CountOnlyStorage::new;
        horizontalScans.set(traverseAllTrees("Scan index trees horizontally", metaTreeRootId, itemStorageFactory, this::horizontalTreeScan));
        // Scanning page reuse lists.
        if (pageListMetaPageId != 0)
            pageListsInfo.set(getPageListsInfo(pageListMetaPageId));
        ProgressPrinter progressPrinter = new ProgressPrinter(System.out, "Reading pages sequentially", pagesNum);
        // Scan all pages in file.
        errors = scanFileStore(INDEX_PARTITION, FLAG_IDX, idxStore, (pageId, addr, io) -> {
            progressPrinter.printProgress();
            pageClasses.compute(io.getClass(), (k, v) -> v == null ? 1 : v + 1);
            if (!(io instanceof PageMetaIO || io instanceof PagesListMetaIO)) {
                if (idxFilter == null) {
                    if ((io instanceof BPlusMetaIO || io instanceof BPlusInnerIO) && !pageIds.contains(pageId) && pageListsInfo.get() != null && !pageListsInfo.get().allPages.contains(pageId)) {
                        throw new IgniteException("Possibly orphan " + io.getClass().getSimpleName() + " page, pageId=" + pageId);
                    }
                }
            }
            return true;
        });
    } catch (IgniteCheckedException e) {
        throw new IgniteException(INDEX_FILE_NAME + " scan problem", e);
    }
    if (treeInfo.get() == null)
        printErr("No tree meta info found.");
    else {
        printTraversalResults(RECURSIVE_TRAVERSE_NAME, treeInfo.get());
        printTraversalResults(HORIZONTAL_SCAN_NAME, horizontalScans.get());
    }
    compareTraversals(treeInfo.get(), horizontalScans.get());
    if (pageListsInfo.get() == null)
        printErr("No page lists meta info found.");
    else
        printPagesListsInfo(pageListsInfo.get());
    printPageStat("", "\n---These pages types were encountered during sequential scan:", pageClasses);
    if (!errors.isEmpty()) {
        printErr("---");
        printErr("Errors:");
        errors.forEach(this::printStackTrace);
    }
    print("---");
    print("Total pages encountered during sequential scan: " + pageClasses.values().stream().mapToLong(a -> a).sum());
    print("Total errors occurred during sequential scan: " + errors.size());
    if (idxFilter != null)
        print("Orphan pages were not reported due to --indexes filter.");
    print("Note that some pages can be occupied by meta info, tracking info, etc., so total page count can differ " + "from count of pages found in index trees and page lists.");
    if (checkParts) {
        Map<Integer, List<Throwable>> checkPartsErrors = checkParts(horizontalScans.get());
        print("");
        printErrors("", "Partitions check:", "Partitions check detected no errors.", "Errors detected in partition, partId=%s", false, checkPartsErrors);
        print("\nPartition check finished, total errors: " + checkPartsErrors.values().stream().mapToInt(List::size).sum() + ", total problem partitions: " + checkPartsErrors.size());
    }
}
Also used : Arrays(java.util.Arrays) PAGE_SIZE(org.apache.ignite.internal.commandline.indexreader.IgniteIndexReader.Args.PAGE_SIZE) PART_CNT(org.apache.ignite.internal.commandline.indexreader.IgniteIndexReader.Args.PART_CNT) IgnitePair(org.apache.ignite.internal.util.lang.IgnitePair) MvccInnerIO(org.apache.ignite.internal.cache.query.index.sorted.inline.io.MvccInnerIO) Collections.singletonList(java.util.Collections.singletonList) Matcher(java.util.regex.Matcher) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) Arrays.asList(java.util.Arrays.asList) PageIdUtils.itemId(org.apache.ignite.internal.pagemem.PageIdUtils.itemId) Map(java.util.Map) PageUtils(org.apache.ignite.internal.pagemem.PageUtils) Objects.isNull(java.util.Objects.isNull) GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) IgniteDataIntegrityViolationException(org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Set(java.util.Set) CLIArgument.optionalArg(org.apache.ignite.internal.commandline.argument.parser.CLIArgument.optionalArg) StringBuilderOutputStream(org.apache.ignite.internal.commandline.StringBuilderOutputStream) Collectors.joining(java.util.stream.Collectors.joining) PageIO.getType(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO.getType) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) GridUnsafe.allocateBuffer(org.apache.ignite.internal.util.GridUnsafe.allocateBuffer) CLIArgument.mandatoryArg(org.apache.ignite.internal.commandline.argument.parser.CLIArgument.mandatoryArg) PageIdUtils(org.apache.ignite.internal.pagemem.PageIdUtils) PageIdUtils.pageIndex(org.apache.ignite.internal.pagemem.PageIdUtils.pageIndex) Supplier(java.util.function.Supplier) PagesListNodeIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) PageIO.getVersion(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO.getVersion) PagesListMetaIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO) AbstractInlineInnerIO(org.apache.ignite.internal.cache.query.index.sorted.inline.io.AbstractInlineInnerIO) PageIdUtils.partId(org.apache.ignite.internal.pagemem.PageIdUtils.partId) LongStream(java.util.stream.LongStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) InnerIO(org.apache.ignite.internal.cache.query.index.sorted.inline.io.InnerIO) File(java.io.File) BPlusMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO) AtomicLong(java.util.concurrent.atomic.AtomicLong) PageIdUtils.flag(org.apache.ignite.internal.pagemem.PageIdUtils.flag) PageIdUtils.pageId(org.apache.ignite.internal.pagemem.PageIdUtils.pageId) StorageException(org.apache.ignite.internal.processors.cache.persistence.StorageException) FLAG_DATA(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_DATA) MvccLeafIO(org.apache.ignite.internal.cache.query.index.sorted.inline.io.MvccLeafIO) ByteBuffer(java.nio.ByteBuffer) GridLongList(org.apache.ignite.internal.util.GridLongList) PAGE_STORE_VER(org.apache.ignite.internal.commandline.indexreader.IgniteIndexReader.Args.PAGE_STORE_VER) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MvccDataLeafIO(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataLeafIO) INDEXES(org.apache.ignite.internal.commandline.indexreader.IgniteIndexReader.Args.INDEXES) PendingRowIO(org.apache.ignite.internal.processors.cache.tree.PendingRowIO) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) BPlusLeafIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO) Predicate(java.util.function.Predicate) IgniteException(org.apache.ignite.IgniteException) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) DEST_FILE(org.apache.ignite.internal.commandline.indexreader.IgniteIndexReader.Args.DEST_FILE) String.format(java.lang.String.format) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Objects(java.util.Objects) GridUnsafe.freeBuffer(org.apache.ignite.internal.util.GridUnsafe.freeBuffer) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Pattern(java.util.regex.Pattern) AbstractInlineLeafIO(org.apache.ignite.internal.cache.query.index.sorted.inline.io.AbstractInlineLeafIO) CLIArgumentParser(org.apache.ignite.internal.commandline.argument.parser.CLIArgumentParser) Objects.nonNull(java.util.Objects.nonNull) InlineIO(org.apache.ignite.internal.cache.query.index.sorted.inline.io.InlineIO) FLAG_IDX(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX) IntStream(java.util.stream.IntStream) ProgressPrinter(org.apache.ignite.internal.commandline.ProgressPrinter) DataPagePayload(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPagePayload) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) PageMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO) IndexStorageImpl(org.apache.ignite.internal.processors.cache.persistence.IndexStorageImpl) GridUnsafe.bufferAddress(org.apache.ignite.internal.util.GridUnsafe.bufferAddress) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) DIR(org.apache.ignite.internal.commandline.indexreader.IgniteIndexReader.Args.DIR) LinkedList(java.util.LinkedList) AbstractDataLeafIO(org.apache.ignite.internal.processors.cache.tree.AbstractDataLeafIO) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) RowLinkIO(org.apache.ignite.internal.processors.cache.tree.RowLinkIO) F(org.apache.ignite.internal.util.typedef.F) BPlusIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO) GridClosure3(org.apache.ignite.internal.util.lang.GridClosure3) Integer.parseInt(java.lang.Integer.parseInt) AbstractDataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.AbstractDataPageIO) BPlusInnerIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO) LeafIO(org.apache.ignite.internal.cache.query.index.sorted.inline.io.LeafIO) CLIArgument(org.apache.ignite.internal.commandline.argument.parser.CLIArgument) Collectors.toList(java.util.stream.Collectors.toList) INDEX_FILE_NAME(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.INDEX_FILE_NAME) FileChannel(java.nio.channels.FileChannel) Collections(java.util.Collections) CHECK_PARTS(org.apache.ignite.internal.commandline.indexreader.IgniteIndexReader.Args.CHECK_PARTS) PageMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) PagesListMetaIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO) ProgressPrinter(org.apache.ignite.internal.commandline.ProgressPrinter) BPlusMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) GridLongList(org.apache.ignite.internal.util.GridLongList) List(java.util.List) LinkedList(java.util.LinkedList) Collectors.toList(java.util.stream.Collectors.toList) HashSet(java.util.HashSet) BPlusInnerIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Aggregations

ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 ByteOrder (java.nio.ByteOrder)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 FLAG_IDX (org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX)3 INDEX_PARTITION (org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION)3 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)3 PageIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO)3 U (org.apache.ignite.internal.util.typedef.internal.U)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 NoOpFailureHandler (org.apache.ignite.failure.NoOpFailureHandler)2