Search in sources :

Example 1 with IoStatisticsHolderIndex

use of org.apache.ignite.internal.metric.IoStatisticsHolderIndex in project ignite by apache.

the class DurableBackgroundCleanupIndexTreeTask method execute.

/**
 * Task execution.
 *
 * @param ctx Kernal context.
 */
private void execute(GridKernalContext ctx) {
    List<InlineIndexTree> trees0 = trees;
    if (trees0 == null) {
        trees0 = new ArrayList<>(rootPages.size());
        GridCacheContext cctx = ctx.cache().context().cacheContext(CU.cacheId(cacheName));
        int grpId = CU.cacheGroupId(cacheName, cacheGrpName);
        CacheGroupContext grpCtx = ctx.cache().cacheGroup(grpId);
        // If group context is null, it means that group doesn't exist and we don't need this task anymore.
        if (grpCtx == null)
            return;
        IgniteCacheOffheapManager offheap = grpCtx.offheap();
        if (treeName != null) {
            ctx.cache().context().database().checkpointReadLock();
            try {
                int cacheId = CU.cacheId(cacheName);
                for (int segment = 0; segment < rootPages.size(); segment++) {
                    try {
                        RootPage rootPage = offheap.findRootPageForIndex(cacheId, treeName, segment);
                        if (rootPage != null && rootPages.get(segment) == rootPage.pageId().pageId())
                            offheap.dropRootPageForIndex(cacheId, treeName, segment);
                    } catch (IgniteCheckedException e) {
                        throw new IgniteException(e);
                    }
                }
            } finally {
                ctx.cache().context().database().checkpointReadUnlock();
            }
        }
        IoStatisticsHolderIndex stats = new IoStatisticsHolderIndex(SORTED_INDEX, cctx.name(), idxName, cctx.kernalContext().metric());
        PageMemory pageMem = grpCtx.dataRegion().pageMemory();
        for (int i = 0; i < rootPages.size(); i++) {
            Long rootPage = rootPages.get(i);
            assert rootPage != null;
            if (skipDeletedRoot(grpId, pageMem, rootPage)) {
                ctx.log(getClass()).warning(S.toString("Skipping deletion of the index tree", "cacheGrpName", cacheGrpName, false, "cacheName", cacheName, false, "idxName", idxName, false, "segment", i, false, "rootPageId", PageIdUtils.toDetailString(rootPage), false));
                continue;
            }
            // because we just going to free memory pages that are occupied by tree structure.
            try {
                String treeName = "deletedTree_" + i + "_" + name();
                InlineIndexTree tree = new InlineIndexTree(null, grpCtx, treeName, cctx.offheap(), cctx.offheap().reuseListForIndex(treeName), cctx.dataRegion().pageMemory(), PageIoResolver.DEFAULT_PAGE_IO_RESOLVER, rootPage, false, 0, 0, new IndexKeyTypeSettings(), null, stats, new NoopRowHandlerFactory(), null);
                trees0.add(tree);
            } catch (IgniteCheckedException e) {
                throw new IgniteException(e);
            }
        }
    }
    ctx.cache().context().database().checkpointReadLock();
    try {
        for (int i = 0; i < trees0.size(); i++) {
            BPlusTree tree = trees0.get(i);
            try {
                tree.destroy(null, true);
            } catch (IgniteCheckedException e) {
                throw new IgniteException(e);
            }
        }
    } finally {
        ctx.cache().context().database().checkpointReadUnlock();
    }
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) InlineIndexTree(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexTree) IoStatisticsHolderIndex(org.apache.ignite.internal.metric.IoStatisticsHolderIndex) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) NoopRowHandlerFactory(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.NoopRowHandlerFactory) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) IgniteException(org.apache.ignite.IgniteException) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) BPlusTree(org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree)

Example 2 with IoStatisticsHolderIndex

use of org.apache.ignite.internal.metric.IoStatisticsHolderIndex in project ignite by apache.

the class InlineIndexFactory method createIndex.

/**
 * {@inheritDoc}
 */
@Override
public Index createIndex(GridCacheContext<?, ?> cctx, IndexDefinition def) {
    SortedIndexDefinition sdef = (SortedIndexDefinition) def;
    InlineIndexTree[] trees = new InlineIndexTree[sdef.segments()];
    InlineRecommender recommender = new InlineRecommender(cctx, sdef);
    IoStatisticsHolderIndex stats = new IoStatisticsHolderIndex(SORTED_INDEX, cctx.name(), sdef.idxName().idxName(), cctx.kernalContext().metric());
    try {
        for (int i = 0; i < sdef.segments(); ++i) {
            // Required for persistence.
            IgniteCacheDatabaseSharedManager db = cctx.shared().database();
            db.checkpointReadLock();
            try {
                RootPage page = rootPage(cctx, sdef.treeName(), i);
                trees[i] = createIndexSegment(cctx, sdef, page, stats, recommender, i);
            } finally {
                db.checkpointReadUnlock();
            }
        }
        return new InlineIndexImpl(cctx, sdef, trees, stats);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) IoStatisticsHolderIndex(org.apache.ignite.internal.metric.IoStatisticsHolderIndex) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Aggregations

IoStatisticsHolderIndex (org.apache.ignite.internal.metric.IoStatisticsHolderIndex)2 RootPage (org.apache.ignite.internal.processors.cache.persistence.RootPage)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 NoopRowHandlerFactory (org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.NoopRowHandlerFactory)1 SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)1 InlineIndexTree (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexTree)1 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)1 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 IgniteCacheOffheapManager (org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager)1 IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)1 BPlusTree (org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree)1