use of org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType 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.inline.InlineIndexKeyType in project ignite by apache.
the class InlineIndexColumnTest method putAndCompare.
/**
* @param v1 Value 1.
* @param v2 Value 2.
* @param maxSize Max inline size.
* @return Compare result.
* @throws Exception If failed.
*/
private <T> int putAndCompare(T v1, T v2, Class<T> cls, int maxSize) throws Exception {
DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
DataRegionMetricsImpl dataRegionMetrics = new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log()));
PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, dataRegionMetrics, false);
pageMem.start();
long pageId = 0L;
long page = 0L;
try {
pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
page = pageMem.acquirePage(CACHE_ID, pageId);
long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
int off = 0;
IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjHash(inlineObjHash).stringOptimizedCompare(true);
InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(wrap(v1, cls).getType(), keyTypeSettings);
keyType.put(pageAddr, off, idxKey(wrap(v1, cls)), maxSize);
return keyType.compare(pageAddr, off, maxSize, idxKey(wrap(v2, cls)));
} finally {
if (page != 0L)
pageMem.releasePage(CACHE_ID, pageId, page);
pageMem.stop(true);
}
}
use of org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType in project ignite by apache.
the class GeoSpatialUtils method createIndex.
/**
*/
public static GridH2SpatialIndex createIndex(GridH2Table tbl, String idxName, List<IndexColumn> cols) {
try {
IndexName name = new IndexName(tbl.cacheName(), tbl.getSchema().getName(), tbl.getName(), idxName);
LinkedHashMap<String, IndexKeyDefinition> keyDefs = new QueryIndexKeyDefinitionProvider(tbl, cols).keyDefinitions();
List<InlineIndexKeyType> idxKeyTypes = InlineIndexKeyTypeRegistry.types(keyDefs.values(), DUMMY_SETTINGS);
QueryIndexRowHandler rowHnd = new QueryIndexRowHandler(tbl, cols, keyDefs, idxKeyTypes, DUMMY_SETTINGS);
final int segments = tbl.rowDescriptor().cacheInfo().config().getQueryParallelism();
IndexDefinition def = new GeoSpatialIndexDefinition(name, keyDefs, rowHnd, segments);
Index idx = tbl.cacheContext().kernalContext().indexProcessor().createIndex(tbl.cacheContext(), GeoSpatialIndexFactory.INSTANCE, def);
return new GridH2SpatialIndex(idx.unwrap(GeoSpatialIndexImpl.class));
} catch (Exception e) {
throw new IgniteException("Failed to instantiate", e);
}
}
use of org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType in project ignite by apache.
the class InlineIndexColumnTest method testPutGet.
/**
*/
private void testPutGet(Value v1, Value v2, Value v3) throws Exception {
DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log())), false);
pageMem.start();
long pageId = 0L;
long page = 0L;
try {
pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
page = pageMem.acquirePage(CACHE_ID, pageId);
long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
int off = 0;
int max = 255;
IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjHash(false).stringOptimizedCompare(false);
InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(v1.getType(), keyTypeSettings);
off += keyType.put(pageAddr, off, idxKey(v1), max - off);
off += keyType.put(pageAddr, off, idxKey(v2), max - off);
off += keyType.put(pageAddr, off, idxKey(v3), max - off);
IndexKey v11 = keyType.get(pageAddr, 0, max);
IndexKey v22 = keyType.get(pageAddr, keyType.inlineSize(pageAddr, 0), max);
assertEquals(v1.getObject(), v11.key());
assertEquals(v2.getObject(), v22.key());
assertEquals(0, keyType.compare(pageAddr, 0, max, idxKey(v1)));
} finally {
if (page != 0L)
pageMem.releasePage(CACHE_ID, pageId, page);
pageMem.stop(true);
}
}
use of org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType in project ignite by apache.
the class InlineIndexColumnTest method testBytes.
/**
*/
@Test
public void testBytes() throws Exception {
DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log())), false);
pageMem.start();
long pageId = 0L;
long page = 0L;
try {
pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
page = pageMem.acquirePage(CACHE_ID, pageId);
long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
int off = 0;
IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjHash(false).stringOptimizedCompare(false);
InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(Value.BYTES, keyTypeSettings);
int maxSize = 3 + 3;
int savedBytesCnt = keyType.put(pageAddr, off, idxKey(ValueBytes.get(new byte[] { 1, 2, 3, 4, 5 }), keyTypeSettings), maxSize);
assertTrue(savedBytesCnt > 0);
assertTrue(savedBytesCnt <= maxSize);
maxSize = 3 + 5;
assertTrue(Arrays.equals(new byte[] { 1, 2, 3 }, (byte[]) keyType.get(pageAddr, off, maxSize).key()));
savedBytesCnt = keyType.put(pageAddr, off, idxKey(ValueBytes.get(new byte[] { 1, 2, 3, 4, 5 }), keyTypeSettings), maxSize);
assertTrue(savedBytesCnt > 0);
assertTrue(savedBytesCnt <= maxSize);
assertTrue(Arrays.equals(new byte[] { 1, 2, 3, 4, 5 }, (byte[]) keyType.get(pageAddr, off, maxSize).key()));
} finally {
if (page != 0L)
pageMem.releasePage(CACHE_ID, pageId, page);
pageMem.stop(true);
}
}
Aggregations