use of org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition in project ignite by apache.
the class IndexQueryProcessor method prepareQuery.
/**
* Prepare index query.
*
* @return Prepared query for index range.
*/
private IndexRangeQuery prepareQuery(SortedSegmentedIndex idx, IndexQueryDesc idxQryDesc) throws IgniteCheckedException {
SortedIndexDefinition idxDef = (SortedIndexDefinition) idxProc.indexDefinition(idx.id());
// For PK indexes will serialize _KEY column.
if (F.isEmpty(idxQryDesc.criteria()))
return new IndexRangeQuery(1);
InlineIndexImpl sortedIdx = (InlineIndexImpl) idx;
Map<String, RangeIndexQueryCriterion> merged = mergeIndexQueryCriteria(sortedIdx, idxDef, idxQryDesc);
return alignCriteriaWithIndex(sortedIdx, merged, idxDef);
}
use of org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition in project ignite by apache.
the class InlineIndexFactory method createIndex.
/**
* {@inheritDoc}
*/
@Override
public Index createIndex(GridCacheContext<?, ?> cctx, IndexDefinition def) {
SortedIndexDefinition sdef = (SortedIndexDefinition) def;
InlineIndexTree[] trees = new InlineIndexTree[sdef.segments()];
InlineRecommender recommender = new InlineRecommender(cctx, sdef);
IoStatisticsHolderIndex stats = new IoStatisticsHolderIndex(SORTED_INDEX, cctx.name(), sdef.idxName().idxName(), cctx.kernalContext().metric());
try {
for (int i = 0; i < sdef.segments(); ++i) {
// Required for persistence.
IgniteCacheDatabaseSharedManager db = cctx.shared().database();
db.checkpointReadLock();
try {
RootPage page = rootPage(cctx, sdef.treeName(), i);
trees[i] = createIndexSegment(cctx, sdef, page, stats, recommender, i);
} finally {
db.checkpointReadUnlock();
}
}
return new InlineIndexImpl(cctx, sdef, trees, stats);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition in project ignite by apache.
the class RenameIndexTreeTest method testNotPersistRenamingIndexRootPage.
/**
* Checking that if we rename the index root pages without a checkpoint,
* then after restarting the node we will not find them.
*
* @throws Exception If failed.
*/
@Test
public void testNotPersistRenamingIndexRootPage() throws Exception {
IgniteEx n = startGrid(0);
IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
populate(cache, 100);
String idxName = "IDX0";
createIdx(cache, idxName);
enableCheckpoints(n, getTestIgniteInstanceName(), false);
SortedIndexDefinition idxDef = indexDefinition(index(n, cache, idxName));
String oldTreeName = idxDef.treeName();
String newTreeName = UUID.randomUUID().toString();
int segments = idxDef.segments();
assertEquals(segments, renameIndexRoot(cache, oldTreeName, newTreeName, segments).size());
stopGrid(0);
n = startGrid(0);
cache = n.cache(DEFAULT_CACHE_NAME);
assertExistIndexRoot(cache, oldTreeName, segments, true);
assertExistIndexRoot(cache, newTreeName, segments, false);
}
use of org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition in project ignite by apache.
the class RenameIndexTreeTest method testRenamingIndexRootPage.
/**
* Checking the correct renaming of the index root pages.
*
* @throws Exception If failed.
*/
@Test
public void testRenamingIndexRootPage() throws Exception {
IgniteEx n = startGrid(0);
IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
populate(cache, 100);
String idxName = "IDX0";
createIdx(cache, idxName);
SortedIndexDefinition idxDef = indexDefinition(index(n, cache, idxName));
int segments = idxDef.segments();
String oldTreeName = idxDef.treeName();
assertExistIndexRoot(cache, oldTreeName, segments, true);
String newTreeName = UUID.randomUUID().toString();
// There will be no renaming.
assertExistIndexRoot(cache, newTreeName, segments, false);
assertTrue(renameIndexRoot(cache, newTreeName, newTreeName, segments).isEmpty());
// Checking the validation of the new index name.
String moreMaxLenName = Arrays.toString(new byte[MAX_IDX_NAME_LEN + 1]);
assertThrows(log, () -> renameIndexRoot(cache, oldTreeName, moreMaxLenName, segments), Exception.class, null);
assertEquals(segments, renameIndexRoot(cache, oldTreeName, newTreeName, segments).size());
assertExistIndexRoot(cache, oldTreeName, segments, false);
assertExistIndexRoot(cache, newTreeName, segments, true);
}
use of org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition in project ignite by apache.
the class RenameIndexTreeTest method testRenameFromTask.
/**
* Checking the correctness of {@link DurableBackgroundCleanupIndexTreeTaskV2#findIndexRootPages}
* and {@link DurableBackgroundCleanupIndexTreeTaskV2#renameIndexRootPages}.
*
* @throws Exception If failed.
*/
@Test
public void testRenameFromTask() throws Exception {
IgniteEx n = startGrid(0);
IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
populate(cache, 100);
String idxName = "IDX0";
createIdx(cache, idxName);
SortedIndexDefinition idxDef = indexDefinition(index(n, cache, idxName));
GridCacheContext<Integer, Person> cctx = cacheContext(cache);
String oldTreeName = idxDef.treeName();
int segments = idxDef.segments();
assertExistIndexRoot(cache, oldTreeName, segments, true);
Map<Integer, RootPage> rootPages0 = findIndexRoots(cache, oldTreeName, segments);
Map<Integer, RootPage> rootPages1 = findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments);
assertEqualsCollections(toPageIds(rootPages0), toPageIds(rootPages1));
long currSegIdx = walMgr(n).currentSegment();
String newTreeName = UUID.randomUUID().toString();
renameIndexRootPages(cctx.group(), cctx.name(), oldTreeName, newTreeName, segments);
assertExistIndexRoot(cache, oldTreeName, segments, false);
assertExistIndexRoot(cache, newTreeName, segments, true);
assertTrue(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
rootPages0 = findIndexRoots(cache, newTreeName, segments);
rootPages1 = findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments);
assertEqualsCollections(toPageIds(rootPages0), toPageIds(rootPages1));
WALPointer start = new WALPointer(currSegIdx, 0, 0);
IgniteBiPredicate<WALRecord.RecordType, WALPointer> pred = (t, p) -> t == INDEX_ROOT_PAGE_RENAME_RECORD;
try (WALIterator it = walMgr(n).replay(start, pred)) {
List<WALRecord> records = stream(it.spliterator(), false).map(IgniteBiTuple::get2).collect(toList());
assertEquals(1, records.size());
IndexRenameRootPageRecord record = (IndexRenameRootPageRecord) records.get(0);
assertEquals(cctx.cacheId(), record.cacheId());
assertEquals(oldTreeName, record.oldTreeName());
assertEquals(newTreeName, record.newTreeName());
assertEquals(segments, record.segments());
}
}
Aggregations