use of org.apache.ignite.internal.cache.query.index.Index 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.Index in project ignite by apache.
the class ComputeInlineSizeTest method checkIdxsInlineSizes.
/**
*/
private void checkIdxsInlineSizes() {
Collection<Index> idx = ignite.context().indexProcessor().indexes(context());
Map<String, Integer> expInlineSize = new HashMap<String, Integer>() {
{
// 9 is inline for _KEY (LongIndexKeyType).
put("PERSON_STR_IDX", 9 + InlineIndexTree.IGNITE_VARIABLE_TYPE_DEFAULT_INLINE_SIZE);
put("PERSON_STRPRECBIG_IDX", InlineIndexTree.IGNITE_MAX_INDEX_PAYLOAD_SIZE_DEFAULT);
// 3 is for storing info (type, length) of inlined key.
put("PERSON_STRPREC_IDX", 9 + InlineIndexTree.IGNITE_VARIABLE_TYPE_DEFAULT_INLINE_SIZE + 10 + 3);
put("PERSON_BYTES_IDX", 9 + InlineIndexTree.IGNITE_VARIABLE_TYPE_DEFAULT_INLINE_SIZE);
put("PERSON_BYTESPREC_IDX", 9 + InlineIndexTree.IGNITE_VARIABLE_TYPE_DEFAULT_INLINE_SIZE + 20 + 3);
}
};
for (Index i : idx) {
InlineIndexImpl impl = (InlineIndexImpl) i;
if (expInlineSize.containsKey(impl.name())) {
int inlineSize = expInlineSize.remove(impl.name());
assertEquals(inlineSize, impl.inlineSize());
}
}
assertTrue(expInlineSize.isEmpty());
}
use of org.apache.ignite.internal.cache.query.index.Index in project ignite by apache.
the class DropIndexTest method checkDestroyIndexTrees.
/**
* Checking {@link DurableBackgroundCleanupIndexTreeTaskV2#destroyIndexTrees}.
*
* @param persistent Persistent default data region.
* @param expRes Expected result should not be less than which.
* @throws Exception If failed.
*/
private void checkDestroyIndexTrees(boolean persistent, long expRes) throws Exception {
IgniteEx n = startGrid(0, cfg -> {
cfg.getDataStorageConfiguration().getDefaultDataRegionConfiguration().setPersistenceEnabled(persistent);
});
n.cluster().state(ACTIVE);
IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
populate(cache, 100);
String idxName = "IDX0";
createIdx(cache, idxName);
GridCacheContext<Integer, Person> cctx = cacheContext(cache);
Index idx = index(n, cache, idxName);
SortedIndexDefinition idxDef = indexDefinition(idx);
String treeName = idxDef.treeName();
int segments = idxDef.segments();
Map<Integer, RootPage> rootPages = new HashMap<>();
if (persistent)
rootPages.putAll(findIndexRootPages(cctx.group(), cctx.name(), treeName, segments));
else
rootPages.putAll(toRootPages(segments(idx)));
assertFalse(rootPages.isEmpty());
// Emulating worker cancellation, let's make sure it doesn't cause problems.
Thread.currentThread().interrupt();
long pageCnt = 0;
for (Map.Entry<Integer, RootPage> e : rootPages.entrySet()) pageCnt += destroyIndexTrees(cctx.group(), e.getValue(), cctx.name(), treeName, e.getKey());
assertTrue(pageCnt >= expRes);
assertTrue(findIndexRootPages(cctx.group(), cctx.name(), treeName, segments).isEmpty());
}
use of org.apache.ignite.internal.cache.query.index.Index in project ignite by apache.
the class DropIndexTest method testCorrectTaskExecute.
/**
* Checking that the {@link DurableBackgroundCleanupIndexTreeTaskV2} will work correctly.
*
* @throws Exception If failed.
*/
@Test
public void testCorrectTaskExecute() throws Exception {
IgniteEx n = startGrid(0);
IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
populate(cache, 100);
String idxName = "IDX0";
createIdx(cache, idxName);
GridCacheContext<Integer, Person> cctx = cacheContext(cache);
Index idx = index(n, cache, idxName);
SortedIndexDefinition idxDef = indexDefinition(idx);
InlineIndexTree[] trees = segments(idx);
Map<Integer, RootPage> rootPages = toRootPages(trees);
for (int i = 0; i < trees.length; i++) {
InlineIndexTree tree = trees[i];
assertEquals(new FullPageId(tree.getMetaPageId(), tree.groupId()), rootPages.get(i).pageId());
}
String oldTreeName = idxDef.treeName();
String newTreeName = UUID.randomUUID().toString();
int segments = idxDef.segments();
assertFalse(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
assertTrue(findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments).isEmpty());
DurableBackgroundCleanupIndexTreeTaskV2 task = new DurableBackgroundCleanupIndexTreeTaskV2(cctx.group().name(), cctx.name(), idxName, oldTreeName, newTreeName, segments, trees);
assertTrue(task.name().startsWith(taskNamePrefix(cctx.name(), idxName)));
assertTrue(getFieldValue(task, "needToRen"));
GridFutureAdapter<Void> startFut = new GridFutureAdapter<>();
GridFutureAdapter<Void> endFut = new GridFutureAdapter<>();
idxTreeFactory = taskIndexTreeFactoryEx(startFut, endFut);
IgniteInternalFuture<DurableBackgroundTaskResult<Long>> taskFut = task.executeAsync(n.context());
startFut.get(getTestTimeout());
assertTrue(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
assertFalse(findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments).isEmpty());
endFut.onDone();
DurableBackgroundTaskResult<Long> res = taskFut.get(getTestTimeout());
assertTrue(res.completed());
assertNull(res.error());
assertTrue(res.result() >= 3);
assertTrue(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
assertTrue(findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments).isEmpty());
assertFalse(getFieldValue(task, "needToRen"));
}
Aggregations