Search in sources :

Example 11 with FilePageStore

use of org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore in project ignite by apache.

the class IgniteIndexReader method checkParts.

/**
 * Checks partitions, comparing partition indexes (cache data tree) to indexes given in {@code aTreesInfo}.
 *
 * @param aTreesInfo Index trees info to compare cache data tree with.
 * @return Map of errors, bound to partition id.
 */
private Map<Integer, List<Throwable>> checkParts(Map<String, TreeTraversalInfo> aTreesInfo) {
    System.out.println();
    // Map partId -> errors.
    Map<Integer, List<Throwable>> res = new HashMap<>();
    Map<String, TreeTraversalInfo> treesInfo = new HashMap<>(aTreesInfo);
    treesInfo.remove(META_TREE_NAME);
    ProgressPrinter progressPrinter = new ProgressPrinter(System.out, "Checking partitions", partCnt);
    for (int i = 0; i < partCnt; i++) {
        progressPrinter.printProgress();
        FilePageStore partStore = partStores[i];
        if (partStore == null)
            continue;
        List<Throwable> errors = new LinkedList<>();
        final int partId = i;
        try {
            long partMetaId = partMetaPageId(i, FLAG_DATA);
            doWithBuffer((buf, addr) -> {
                readPage(partStore, partMetaId, buf);
                PagePartitionMetaIO partMetaIO = PageIO.getPageIO(addr);
                long cacheDataTreeRoot = partMetaIO.getTreeRoot(addr);
                TreeTraversalInfo cacheDataTreeInfo = horizontalTreeScan(cacheDataTreeRoot, "dataTree-" + partId, new ItemsListStorage());
                for (Object dataTreeItem : cacheDataTreeInfo.itemStorage) {
                    CacheAwareLink cacheAwareLink = (CacheAwareLink) dataTreeItem;
                    for (Map.Entry<String, TreeTraversalInfo> e : treesInfo.entrySet()) {
                        String name = e.getKey();
                        TreeTraversalInfo tree = e.getValue();
                        int cacheId = getCacheId(name);
                        if (cacheId != cacheAwareLink.cacheId)
                            // It's index for other cache, don't check.
                            continue;
                        // Tombstones are not indexed and shouldn't be tested.
                        if (!tree.itemStorage.contains(cacheAwareLink) && !cacheAwareLink.tombstone)
                            errors.add(new IgniteException(cacheDataTreeEntryMissingError(name, cacheAwareLink)));
                    }
                    if (errors.size() >= CHECK_PARTS_MAX_ERRORS_PER_PARTITION) {
                        errors.add(new IgniteException("Too many errors (" + CHECK_PARTS_MAX_ERRORS_PER_PARTITION + ") found for partId=" + partId + ", stopping analysis for this partition."));
                        break;
                    }
                }
                return null;
            });
        } catch (IgniteCheckedException e) {
            errors.add(new IgniteException("Partition check failed, partId=" + i, e));
        }
        if (!errors.isEmpty())
            res.put(partId, errors);
    }
    return res;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ProgressPrinter(org.apache.ignite.internal.commandline.ProgressPrinter) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) LinkedList(java.util.LinkedList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 12 with FilePageStore

use of org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore in project ignite by apache.

the class IgniteIndexReader method horizontalTreeScan.

/**
 * Traverse single index tree by each level horizontally.
 *
 * @param rootPageId Root page id.
 * @param treeName Tree name.
 * @param itemStorage Items storage.
 * @return Tree traversal info.
 */
private TreeTraversalInfo horizontalTreeScan(long rootPageId, String treeName, ItemStorage itemStorage) {
    FilePageStore store = filePageStore(partId(rootPageId));
    Map<Long, List<Throwable>> errors = new HashMap<>();
    Map<Class, Long> ioStat = new HashMap<>();
    TreeTraverseContext treeCtx = new TreeTraverseContext(treeName, store, ioStat, errors, null, null, null);
    ByteBuffer buf = allocateBuffer(pageSize);
    try {
        long addr = bufferAddress(buf);
        readPage(store, rootPageId, buf);
        PageIO pageIO = PageIO.getPageIO(addr);
        if (!(pageIO instanceof BPlusMetaIO))
            throw new IgniteException("Root page is not meta, pageId=" + rootPageId);
        BPlusMetaIO metaIO = (BPlusMetaIO) pageIO;
        ioStat.compute(metaIO.getClass(), (k, v) -> v == null ? 1 : v + 1);
        int lvlsCnt = metaIO.getLevelsCount(addr);
        long[] firstPageIds = IntStream.range(0, lvlsCnt).mapToLong(i -> metaIO.getFirstPageId(addr, i)).toArray();
        for (int i = 0; i < lvlsCnt; i++) {
            long pageId = firstPageIds[i];
            while (pageId > 0) {
                try {
                    buf.rewind();
                    readPage(store, pageId, buf);
                    pageIO = PageIO.getPageIO(addr);
                    if (i == 0 && !(pageIO instanceof BPlusLeafIO))
                        throw new IgniteException("Not-leaf page found on leaf level, pageId=" + pageId + ", level=" + i);
                    if (!(pageIO instanceof BPlusIO))
                        throw new IgniteException("Not-BPlus page found, pageId=" + pageId + ", level=" + i);
                    ioStat.compute(pageIO.getClass(), (k, v) -> v == null ? 1 : v + 1);
                    if (pageIO instanceof BPlusLeafIO) {
                        PageIOProcessor ioProcessor = getIOProcessor(pageIO);
                        PageContent pageContent = ioProcessor.getContent(pageIO, addr, pageId, treeCtx);
                        pageContent.items.forEach(itemStorage::add);
                    }
                    pageId = ((BPlusIO) pageIO).getForward(addr);
                } catch (Throwable e) {
                    errors.computeIfAbsent(pageId, k -> new LinkedList<>()).add(e);
                    pageId = 0;
                }
            }
        }
    } catch (Throwable e) {
        errors.computeIfAbsent(rootPageId, k -> new LinkedList<>()).add(e);
    } finally {
        freeBuffer(buf);
    }
    return new TreeTraversalInfo(ioStat, errors, null, rootPageId, itemStorage);
}
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) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) BPlusIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) BPlusLeafIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO) ByteBuffer(java.nio.ByteBuffer) BPlusMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO) IgniteException(org.apache.ignite.IgniteException) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) AbstractDataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.AbstractDataPageIO)

Example 13 with FilePageStore

use of org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore in project ignite by apache.

the class IgniteClusterSnapshotCheckTest method testClusterSnapshotCheckPartitionCounters.

/**
 * @throws Exception If fails.
 */
@Test
public void testClusterSnapshotCheckPartitionCounters() throws Exception {
    IgniteEx ignite = startGridsWithCache(3, dfltCacheCfg.setAffinity(new RendezvousAffinityFunction(false, 1)), CACHE_KEYS_RANGE);
    ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get();
    Path part0 = U.searchFileRecursively(snp(ignite).snapshotLocalDir(SNAPSHOT_NAME).toPath(), getPartitionFileName(PART_ID));
    assertNotNull(part0);
    assertTrue(part0.toString(), part0.toFile().exists());
    try (FilePageStore pageStore = (FilePageStore) ((FilePageStoreManager) ignite.context().cache().context().pageStore()).getPageStoreFactory(CU.cacheId(dfltCacheCfg.getName()), false).createPageStore(getTypeByPartId(PART_ID), () -> part0, val -> {
    })) {
        ByteBuffer buff = ByteBuffer.allocateDirect(ignite.configuration().getDataStorageConfiguration().getPageSize()).order(ByteOrder.nativeOrder());
        buff.clear();
        pageStore.read(0, buff, false);
        PagePartitionMetaIO io = PageIO.getPageIO(buff);
        long pageAddr = GridUnsafe.bufferAddress(buff);
        io.setUpdateCounter(pageAddr, CACHE_KEYS_RANGE * 2);
        pageStore.beginRecover();
        buff.flip();
        pageStore.write(PageIO.getPageId(buff), buff, 0, true);
        pageStore.finishRecover();
    }
    IdleVerifyResultV2 res = snp(ignite).checkSnapshot(SNAPSHOT_NAME).get();
    StringBuilder b = new StringBuilder();
    res.print(b::append, true);
    assertTrue(F.isEmpty(res.exceptions()));
    assertContains(log, b.toString(), "The check procedure has failed, conflict partitions has been found: [counterConflicts=1, hashConflicts=0]");
}
Also used : Path(java.nio.file.Path) IgniteSnapshotManager.databaseRelativePath(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.databaseRelativePath) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Arrays(java.util.Arrays) PartitionHashRecordV2(org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheObjectBinaryProcessorImpl.binaryWorkDir(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.binaryWorkDir) ByteBuffer(java.nio.ByteBuffer) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Collections.singletonList(java.util.Collections.singletonList) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) Map(java.util.Map) X(org.apache.ignite.internal.util.typedef.X) Path(java.nio.file.Path) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) Parameterized(org.junit.runners.Parameterized) SNAPSHOT_METAFILE_EXT(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.SNAPSHOT_METAFILE_EXT) IgniteDataIntegrityViolationException(org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) MarshallerContextImpl.mappingFileStoreWorkDir(org.apache.ignite.internal.MarshallerContextImpl.mappingFileStoreWorkDir) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) UUID(java.util.UUID) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) ByteOrder(java.nio.ByteOrder) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) PartitionKeyV2(org.apache.ignite.internal.processors.cache.verify.PartitionKeyV2) GridJobExecuteRequest(org.apache.ignite.internal.GridJobExecuteRequest) CU(org.apache.ignite.internal.util.typedef.internal.CU) BinaryObjectImpl(org.apache.ignite.internal.binary.BinaryObjectImpl) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) FilePageStoreManager.getPartitionFileName(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.getPartitionFileName) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) FilePageStoreManager.cacheDirName(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.cacheDirName) DR_NONE(org.apache.ignite.internal.processors.dr.GridDrType.DR_NONE) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PdsFolderSettings(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteSnapshotManager.databaseRelativePath(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.databaseRelativePath) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) GridTestUtils.assertNotContains(org.apache.ignite.testframework.GridTestUtils.assertNotContains) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) VerifyBackupPartitionsTaskV2(org.apache.ignite.internal.processors.cache.verify.VerifyBackupPartitionsTaskV2) Before(org.junit.Before) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) F(org.apache.ignite.internal.util.typedef.F) VisorIdleVerifyTaskArg(org.apache.ignite.internal.visor.verify.VisorIdleVerifyTaskArg) Files(java.nio.file.Files) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridUnsafe(org.apache.ignite.internal.util.GridUnsafe) DFLT_SNAPSHOT_DIRECTORY(org.apache.ignite.configuration.IgniteConfiguration.DFLT_SNAPSHOT_DIRECTORY) TTL_ETERNAL(org.apache.ignite.internal.processors.cache.GridCacheUtils.TTL_ETERNAL) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) CacheObjectBinaryProcessorImpl(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl) GridIterator(org.apache.ignite.internal.util.lang.GridIterator) GridTestUtils.assertContains(org.apache.ignite.testframework.GridTestUtils.assertContains) NONE(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion.NONE) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) GridTopic(org.apache.ignite.internal.GridTopic) Paths(java.nio.file.Paths) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CacheFilterEnum(org.apache.ignite.internal.visor.verify.CacheFilterEnum) GroupPartitionId.getTypeByPartId(org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId.getTypeByPartId) Collections(java.util.Collections) TxState(org.apache.ignite.internal.processors.cache.mvcc.txlog.TxState) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 14 with FilePageStore

use of org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore in project ignite by apache.

the class PagesPossibleCorruptionDiagnosticTest method filePageStore.

/**
 * @param ignite Ignite instance.
 * @param partId Partition id.
 * @return File page store for given partition id.
 * @throws IgniteCheckedException If failed.
 */
private FilePageStore filePageStore(IgniteEx ignite, int partId) throws IgniteCheckedException {
    final PdsFolderSettings folderSettings = ignite.context().pdsFolderResolver().resolveFolders();
    File storeWorkDir = new File(folderSettings.persistentStoreRootPath(), folderSettings.folderName());
    File cacheWorkDir = new File(storeWorkDir, CACHE_DIR_PREFIX + DEFAULT_CACHE_NAME);
    File partFile = new File(cacheWorkDir, format(PART_FILE_TEMPLATE, partId));
    return (FilePageStore) storeFactory.createPageStore(FLAG_DATA, partFile, a -> {
    });
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) RandomAccessFile(java.io.RandomAccessFile) PageIdUtils.pageId(org.apache.ignite.internal.pagemem.PageIdUtils.pageId) CACHE_DIR_PREFIX(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CACHE_DIR_PREFIX) FLAG_DATA(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_DATA) GridCacheUtils.cacheGroupId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheGroupId) ClusterState(org.apache.ignite.cluster.ClusterState) PdsFolderSettings(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings) LongListReuseBag(org.apache.ignite.internal.processors.cache.persistence.tree.reuse.LongListReuseBag) IgniteEx(org.apache.ignite.internal.IgniteEx) IGNITE_PDS_SKIP_CRC(org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_SKIP_CRC) ByteBuffer(java.nio.ByteBuffer) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) PART_META_REUSE_LIST_ROOT_OFF(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIOV2.PART_META_REUSE_LIST_ROOT_OFF) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) AbstractFreeList(org.apache.ignite.internal.processors.cache.persistence.freelist.AbstractFreeList) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) ReuseBag(org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseBag) PART_FILE_TEMPLATE(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.PART_FILE_TEMPLATE) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CorruptedFreeListException(org.apache.ignite.internal.processors.cache.persistence.freelist.CorruptedFreeListException) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) AsyncFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.AsyncFileIOFactory) Test(org.junit.Test) FileVersionCheckingFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileVersionCheckingFactory) File(java.io.File) IgniteCache(org.apache.ignite.IgniteCache) String.format(java.lang.String.format) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) FailureHandlerWithCallback(org.apache.ignite.failure.FailureHandlerWithCallback) FileChannel(java.nio.channels.FileChannel) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) PdsFolderSettings(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 15 with FilePageStore

use of org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore in project ignite by apache.

the class AbstractEncryptionTest method checkGroupKey.

/**
 * Ensures that all pages of page store have expected encryption key identifier.
 *
 * @param grpId Cache group ID.
 * @param expKeyId Encryption key ID.
 * @param timeout Timeout to wait for encryption to complete.
 * @throws Exception If failed.
 */
protected void checkGroupKey(int grpId, int expKeyId, long timeout) throws Exception {
    awaitEncryption(G.allGrids(), grpId, timeout);
    for (Ignite g : G.allGrids()) {
        IgniteEx grid = (IgniteEx) g;
        if (grid.context().clientNode())
            continue;
        info("Validating encryption key [node=" + g.cluster().localNode().id() + ", grp=" + grpId + "]");
        CacheGroupContext grp = grid.context().cache().cacheGroup(grpId);
        if (grp == null || !grp.affinityNode()) {
            info("Context doesn't exits on " + grid.localNode().id());
            continue;
        }
        GridEncryptionManager encryption = grid.context().encryption();
        assertEquals(grid.localNode().id().toString(), (byte) expKeyId, encryption.getActiveKey(grpId).id());
        IgniteInternalFuture<Void> fut = encryption.reencryptionFuture(grpId);
        // The future will be completed after the checkpoint, forcecheckpoint does nothing
        // if the checkpoint has already been scheduled.
        GridTestUtils.waitForCondition(() -> {
            if (fut.isDone())
                return true;
            try {
                forceCheckpoint(g);
            } catch (IgniteCheckedException e) {
                throw new RuntimeException(e);
            }
            return fut.isDone();
        }, timeout);
        assertTrue(fut.isDone());
        assertEquals(0, encryption.getBytesLeftForReencryption(grpId));
        List<Integer> parts = IntStream.range(0, grp.shared().affinity().affinity(grpId).partitions()).boxed().collect(Collectors.toList());
        parts.add(INDEX_PARTITION);
        int realPageSize = grp.dataRegion().pageMemory().realPageSize(grpId);
        int encryptionBlockSize = grp.shared().kernalContext().config().getEncryptionSpi().blockSize();
        for (int p : parts) {
            FilePageStore pageStore = (FilePageStore) ((FilePageStoreManager) grp.shared().pageStore()).getStore(grpId, p);
            if (!pageStore.exists())
                continue;
            long state = grid.context().encryption().getEncryptionState(grpId, p);
            String msg = String.format("p=%d, off=%d, total=%d", p, ReencryptStateUtils.pageIndex(state), ReencryptStateUtils.pageCount(state));
            assertEquals(msg, 0, ReencryptStateUtils.pageCount(state));
            assertEquals(msg, 0, ReencryptStateUtils.pageIndex(state));
            long startPageId = PageIdUtils.pageId(p, PageIdAllocator.FLAG_DATA, 0);
            int pagesCnt = pageStore.pages();
            int pageSize = pageStore.getPageSize();
            ByteBuffer pageBuf = ByteBuffer.allocate(pageSize);
            Path path = new File(pageStore.getFileAbsolutePath()).toPath();
            try (FileChannel ch = FileChannel.open(path, StandardOpenOption.READ)) {
                for (int n = 0; n < pagesCnt; n++) {
                    long pageId = startPageId + n;
                    long pageOff = pageStore.pageOffset(pageId);
                    pageBuf.position(0);
                    ch.position(pageOff);
                    ch.read(pageBuf);
                    pageBuf.position(realPageSize + encryptionBlockSize);
                    int pageCrc = pageBuf.getInt();
                    int pageKeyId = pageBuf.get() & 0xff;
                    // If this page is empty we can skip it.
                    if (pageCrc == 0 && pageKeyId == 0) {
                        pageBuf.position(0);
                        boolean emptyPage = false;
                        while (pageBuf.hasRemaining() && !emptyPage) emptyPage = pageBuf.getLong() == 0;
                        if (emptyPage)
                            continue;
                    }
                    msg = String.format("File=%s, page=%d", pageStore.getFileAbsolutePath(), n);
                    assertEquals(msg, expKeyId, pageKeyId);
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) GridEncryptionManager(org.apache.ignite.internal.managers.encryption.GridEncryptionManager) FileChannel(java.nio.channels.FileChannel) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) ByteBuffer(java.nio.ByteBuffer) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) File(java.io.File)

Aggregations

FilePageStore (org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore)16 File (java.io.File)11 ByteBuffer (java.nio.ByteBuffer)11 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 ArrayList (java.util.ArrayList)9 IgniteException (org.apache.ignite.IgniteException)8 FilePageStoreManager (org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 List (java.util.List)7 Map (java.util.Map)7 PageIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO)7 Collections (java.util.Collections)6 HashSet (java.util.HashSet)6 Set (java.util.Set)6 IgniteEx (org.apache.ignite.internal.IgniteEx)6 PagePartitionMetaIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO)6 F (org.apache.ignite.internal.util.typedef.F)6 Path (java.nio.file.Path)5 Arrays (java.util.Arrays)5