Search in sources :

Example 1 with DefragIndexRowImpl

use of org.apache.ignite.internal.cache.query.index.sorted.defragmentation.DefragIndexFactory.DefragIndexRowImpl in project ignite by apache.

the class IndexingDefragmentation method defragmentTable.

/**
 * Defragment one given table.
 */
private boolean defragmentTable(CacheGroupContext newCtx, IntMap<LinkMap> mappingByPartition, CheckpointTimeoutLock cpLock, Runnable cancellationChecker, int pageSize, PageMemoryEx oldCachePageMem, PageMemory newCachePageMemory, long cpLockThreshold, AtomicLong lastCpLockTs, TableIndexes indexes) throws IgniteCheckedException {
    cpLock.checkpointReadLock();
    try {
        TreeIterator treeIterator = new TreeIterator(pageSize);
        GridCacheContext<?, ?> cctx = indexes.cctx;
        cancellationChecker.run();
        for (InlineIndex oldIdx : indexes.idxs) {
            InlineIndexRowHandler oldRowHnd = oldIdx.segment(0).rowHandler();
            SortedIndexDefinition idxDef = (SortedIndexDefinition) indexing.indexDefinition(oldIdx.id());
            InlineIndexImpl newIdx = new DefragIndexFactory(newCtx.offheap(), newCachePageMemory, oldIdx).createIndex(cctx, idxDef).unwrap(InlineIndexImpl.class);
            int segments = oldIdx.segmentsCount();
            for (int i = 0; i < segments; ++i) {
                treeIterator.iterate(oldIdx.segment(i), oldCachePageMem, (theTree, io, pageAddr, idx) -> {
                    cancellationChecker.run();
                    if (System.currentTimeMillis() - lastCpLockTs.get() >= cpLockThreshold) {
                        cpLock.checkpointReadUnlock();
                        cpLock.checkpointReadLock();
                        lastCpLockTs.set(System.currentTimeMillis());
                    }
                    assert 1 == io.getVersion() : "IO version " + io.getVersion() + " is not supported by current defragmentation algorithm." + " Please implement copying of tree in a new format.";
                    BPlusIO<IndexRow> h2IO = DefragIndexFactory.wrap(io, oldRowHnd);
                    IndexRow row = theTree.getRow(h2IO, pageAddr, idx);
                    if (row instanceof DefragIndexRowImpl) {
                        DefragIndexRowImpl r = (DefragIndexRowImpl) row;
                        CacheDataRow cacheDataRow = r.cacheDataRow();
                        int partition = cacheDataRow.partition();
                        long link = r.link();
                        LinkMap map = mappingByPartition.get(partition);
                        long newLink = map.get(link);
                        // Use old row handler, as MetaInfo is copied from old tree.
                        DefragIndexRowImpl newRow = DefragIndexRowImpl.create(oldRowHnd, newLink, r, ((MvccIO) io).storeMvccInfo());
                        newIdx.putIndexRow(newRow);
                    }
                    return true;
                });
            }
        }
        return true;
    } catch (Throwable t) {
        newCtx.cacheObjectContext().kernalContext().failure().process(new FailureContext(CRITICAL_ERROR, t));
        throw t;
    } finally {
        cpLock.checkpointReadUnlock();
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) LinkMap(org.apache.ignite.internal.processors.cache.persistence.defragmentation.LinkMap) SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) InlineIndex(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndex) DefragIndexRowImpl(org.apache.ignite.internal.cache.query.index.sorted.defragmentation.DefragIndexFactory.DefragIndexRowImpl) InlineIndexRowHandler(org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler) InlineIndexImpl(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl) FailureContext(org.apache.ignite.failure.FailureContext) TreeIterator(org.apache.ignite.internal.processors.cache.persistence.defragmentation.TreeIterator)

Aggregations

FailureContext (org.apache.ignite.failure.FailureContext)1 IndexRow (org.apache.ignite.internal.cache.query.index.sorted.IndexRow)1 InlineIndexRowHandler (org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler)1 SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)1 DefragIndexRowImpl (org.apache.ignite.internal.cache.query.index.sorted.defragmentation.DefragIndexFactory.DefragIndexRowImpl)1 InlineIndex (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndex)1 InlineIndexImpl (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl)1 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)1 LinkMap (org.apache.ignite.internal.processors.cache.persistence.defragmentation.LinkMap)1 TreeIterator (org.apache.ignite.internal.processors.cache.persistence.defragmentation.TreeIterator)1