use of org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler in project ignite by apache.
the class AbstractInlineLeafIO method storeByOffset.
/**
* {@inheritDoc}
*/
@SuppressWarnings("ForLoopReplaceableByForEach")
@Override
public final void storeByOffset(long pageAddr, int off, IndexRow row) {
assert row.link() != 0 : row;
assertPageType(pageAddr);
int fieldOff = 0;
InlineIndexRowHandler rowHnd = ThreadLocalRowHandlerHolder.rowHandler();
for (int i = 0; i < rowHnd.inlineIndexKeyTypes().size(); i++) {
try {
InlineIndexKeyType keyType = rowHnd.inlineIndexKeyTypes().get(i);
int size = keyType.put(pageAddr, off + fieldOff, row.key(i), inlineSize - fieldOff);
// Inline size has exceeded.
if (size == 0)
break;
fieldOff += size;
} catch (Exception e) {
throw new IgniteException("Failed to store new index row.", e);
}
}
IORowHandler.store(pageAddr, off + inlineSize, row, storeMvccInfo());
}
use of org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler 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();
}
}
use of org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler in project ignite by apache.
the class IndexQueryProcessor method alignCriteriaWithIndex.
/**
* Checks that specified index matches index query criteria.
*/
private IndexRangeQuery alignCriteriaWithIndex(InlineIndexImpl idx, Map<String, RangeIndexQueryCriterion> criteria, IndexDefinition idxDef) {
// Size of bounds array has to be equal to count of indexed fields.
IndexKey[] lowerBounds = new IndexKey[idxDef.indexKeyDefinitions().size()];
IndexKey[] upperBounds = new IndexKey[idxDef.indexKeyDefinitions().size()];
boolean lowerAllNulls = true;
boolean upperAllNulls = true;
IndexRangeQuery qry = new IndexRangeQuery(criteria.size());
// Checks that users criteria matches a prefix subset of index fields.
int i = 0;
for (Map.Entry<String, IndexKeyDefinition> keyDef : idxDef.indexKeyDefinitions().entrySet()) {
RangeIndexQueryCriterion criterion = criteria.remove(keyDef.getKey());
if (keyDef.getValue().order().sortOrder() == DESC)
criterion = criterion.swap();
qry.criteria[i] = criterion;
IndexKey l = (IndexKey) criterion.lower();
IndexKey u = (IndexKey) criterion.upper();
if (l != null)
lowerAllNulls = false;
if (u != null)
upperAllNulls = false;
lowerBounds[i] = l;
upperBounds[i++] = u;
if (criteria.isEmpty())
break;
}
InlineIndexRowHandler hnd = idx.segment(0).rowHandler();
qry.lower = lowerAllNulls ? null : new IndexSearchRowImpl(lowerBounds, hnd);
qry.upper = upperAllNulls ? null : new IndexSearchRowImpl(upperBounds, hnd);
return qry;
}
use of org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler in project ignite by apache.
the class AbstractInlineInnerIO method storeByOffset.
/**
* {@inheritDoc}
*/
@SuppressWarnings("ForLoopReplaceableByForEach")
@Override
public final void storeByOffset(long pageAddr, int off, IndexRow row) {
assert row.link() != 0 : row;
assertPageType(pageAddr);
int fieldOff = 0;
InlineIndexRowHandler rowHnd = ThreadLocalRowHandlerHolder.rowHandler();
for (int i = 0; i < rowHnd.inlineIndexKeyTypes().size(); i++) {
try {
InlineIndexKeyType keyType = rowHnd.inlineIndexKeyTypes().get(i);
int size = keyType.put(pageAddr, off + fieldOff, row.key(i), inlineSize - fieldOff);
// Inline size has exceeded.
if (size == 0)
break;
fieldOff += size;
} catch (Exception e) {
throw new IgniteException("Failed to store new index row.", e);
}
}
IORowHandler.store(pageAddr, off + inlineSize, row, storeMvccInfo());
}
use of org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler in project ignite by apache.
the class InlineIndexTree method inlineObjectSupported.
/**
* Find whether tree supports inlining objects or not.
*
* @param def Index definition.
* @param metaInfo Metapage info.
* @return {@code true} if inline object is supported by exists tree.
*/
private boolean inlineObjectSupported(SortedIndexDefinition def, MetaPageInfo metaInfo, InlineIndexRowHandlerFactory rowHndFactory) {
if (metaInfo.flagsSupported())
return metaInfo.inlineObjectSupported();
else {
try {
if (InlineObjectBytesDetector.objectMayBeInlined(metaInfo.inlineSize(), def.indexKeyDefinitions().values())) {
try {
InlineObjectBytesDetector inlineObjDetector = new InlineObjectBytesDetector(metaInfo.inlineSize(), def.indexKeyDefinitions().values(), def.idxName(), log);
// Create a settings for case where java objects inilned as byte array.
IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjSupported(true).inlineObjHash(false);
InlineIndexRowHandler rowHnd = rowHndFactory.create(def, keyTypeSettings);
ThreadLocalRowHandlerHolder.rowHandler(rowHnd);
findFirst(inlineObjDetector);
return inlineObjDetector.inlineObjectSupported();
} finally {
ThreadLocalRowHandlerHolder.clearRowHandler();
}
} else
return false;
} catch (IgniteCheckedException e) {
throw new IgniteException("Unexpected exception on detect inline object", e);
}
}
}
Aggregations