use of org.apache.ignite.internal.cache.query.index.sorted.IndexRow in project ignite by apache.
the class InlineIndexImpl method putx.
/**
*/
private boolean putx(IndexRowImpl idxRow, int segment, boolean flag) throws IgniteCheckedException {
try {
boolean replaced;
if (flag)
replaced = segments[segment].putx(idxRow);
else {
IndexRow prevRow0 = segments[segment].put(idxRow);
replaced = prevRow0 != null;
}
return replaced;
} catch (Throwable t) {
cctx.kernalContext().failure().process(new FailureContext(CRITICAL_ERROR, t));
throw t;
}
}
use of org.apache.ignite.internal.cache.query.index.sorted.IndexRow in project ignite by apache.
the class InlineObjectBytesDetector method apply.
/**
* {@inheritDoc}
*/
@Override
public boolean apply(BPlusTree<IndexRow, IndexRow> tree, BPlusIO<IndexRow> io, long pageAddr, int idx) throws IgniteCheckedException {
IndexRow r = tree.getRow(io, pageAddr, idx);
int off = io.offset(idx);
int fieldOff = 0;
boolean varLenPresents = false;
IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings();
Iterator<IndexKeyDefinition> it = keyDefs.iterator();
for (int i = 0; i < keyDefs.size(); ++i) {
IndexKeyDefinition keyDef = it.next();
if (fieldOff >= inlineSize)
return false;
if (keyDef.idxType() != IndexKeyTypes.JAVA_OBJECT) {
InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(keyDef.idxType(), keyTypeSettings);
if (keyType.inlineSize() < 0)
varLenPresents = true;
fieldOff += keyType.inlineSize(pageAddr, off + fieldOff);
continue;
}
IndexKey key = r.key(i);
if (key == NullIndexKey.INSTANCE)
return false;
int type = PageUtils.getByte(pageAddr, off + fieldOff);
// We can have garbage in memory and need to compare data.
if (type == IndexKeyTypes.JAVA_OBJECT) {
int len = PageUtils.getShort(pageAddr, off + fieldOff + 1);
len &= 0x7FFF;
byte[] originalObjBytes = ((JavaObjectIndexKey) key).bytesNoCopy();
// Read size more then available space or more then origin length.
if (len > inlineSize - fieldOff - 3 || len > originalObjBytes.length) {
inlineObjectSupportedDecision(false, "length is big " + len);
return true;
}
// Try compare byte by byte for fully or partial inlined object.
byte[] inlineBytes = PageUtils.getBytes(pageAddr, off + fieldOff + 3, len);
if (!Arrays.equals(inlineBytes, originalObjBytes)) {
inlineObjectSupportedDecision(false, "byte compare");
return true;
}
inlineObjectSupportedDecision(true, len + " bytes compared");
return true;
}
if (type == IndexKeyTypes.UNKNOWN && varLenPresents) {
// 2: short string, inlined java object
return false;
}
inlineObjectSupportedDecision(false, "inline type " + type);
return true;
}
inlineObjectSupportedDecision(true, "no java objects for inlining");
return true;
}
use of org.apache.ignite.internal.cache.query.index.sorted.IndexRow in project ignite by apache.
the class H2TreeIndex method findFirstOrLast.
/**
* {@inheritDoc}
*/
@Override
public Cursor findFirstOrLast(Session ses, boolean b) {
try {
QueryContext qctx = H2Utils.context(ses);
IndexQueryContext qryCtx = idxQryContext(qctx);
GridCursor<IndexRow> cursor = b ? queryIndex.findFirst(segment(qctx), qryCtx) : queryIndex.findLast(segment(qctx), qryCtx);
return new H2Cursor(new IndexValueCursor<>(cursor, this::mapIndexRow));
} catch (IgniteCheckedException e) {
throw DbException.convert(e);
}
}
use of org.apache.ignite.internal.cache.query.index.sorted.IndexRow in project ignite by apache.
the class GeoSpatialIndexImpl method put.
/**
*/
private boolean put(CacheDataRow row) {
checkClosed();
Object key = def.rowHandler().key(row);
assert key != null;
final int seg = segmentForRow(row);
Long rowId = keyToId.get(key);
if (rowId != null) {
Long oldRowId = segments[seg].remove(getEnvelope(idToRow.get(rowId).cacheDataRow(), rowId));
assert rowId.equals(oldRowId);
} else {
rowId = ++rowIds;
keyToId.put(key, rowId);
}
IndexRow old = idToRow.put(rowId, new IndexRowImpl(def.rowHandler(), row));
segments[seg].put(getEnvelope(row, rowId), rowId);
if (old == null)
// No replace.
rowCnt++;
return old != null;
}
use of org.apache.ignite.internal.cache.query.index.sorted.IndexRow in project ignite by apache.
the class IndexQueryProcessor method querySortedIndex.
/**
* Runs an index query.
*
* @return Result cursor.
*/
private GridCursor<IndexRow> querySortedIndex(GridCacheContext<?, ?> cctx, SortedSegmentedIndex idx, IndexingQueryFilter cacheFilter, IndexRangeQuery qry) throws IgniteCheckedException {
int segmentsCnt = cctx.isPartitioned() ? cctx.config().getQueryParallelism() : 1;
BPlusTree.TreeRowClosure<IndexRow, IndexRow> treeFilter = null;
// Also skips filtering if the current search is unbounded (both boundaries equal to null).
if (qry.criteria.length > 1 && !(qry.lower == null && qry.upper == null)) {
LinkedHashMap<String, IndexKeyDefinition> idxDef = idxProc.indexDefinition(idx.id()).indexKeyDefinitions();
treeFilter = new IndexQueryCriteriaClosure(qry, idxDef, ((SortedIndexDefinition) idxProc.indexDefinition(idx.id())).rowComparator());
}
IndexQueryContext qryCtx = new IndexQueryContext(cacheFilter, treeFilter, null);
if (segmentsCnt == 1)
return treeIndexRange(idx, 0, qry, qryCtx);
final GridCursor<IndexRow>[] segmentCursors = new GridCursor[segmentsCnt];
// Actually it just traverses BPlusTree to find boundaries. It's too fast to parallelize this.
for (int i = 0; i < segmentsCnt; i++) segmentCursors[i] = treeIndexRange(idx, i, qry, qryCtx);
return new SegmentedIndexCursor(segmentCursors, (SortedIndexDefinition) idxProc.indexDefinition(idx.id()));
}
Aggregations