use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.
the class GridIndexRebuildSelfTest method testDataRaceWhenMarkIdxRebuild.
/**
* Test checks that there will be no data race between notifications about index rebuilding
* and an indication that index has been rebuilt.
*
* Steps:
* 1)Create a node with data filling;
* 2)Stopping a node with deletion index.bin;
* 3)Set a delay between notification and a note about index rebuilding;
* 4)Restarting node with waiting index rebuild;
* 5)Checking that index is not being rebuilt.
*
* @throws Exception if failed.
*/
@Test
public void testDataRaceWhenMarkIdxRebuild() throws Exception {
IgniteEx srv = startServer();
IgniteInternalCache internalCache = createAndFillTableWithIndex(srv);
File idxFile = indexFile(internalCache);
stopAllGrids();
assertTrue(delete(idxFile));
BlockingIndexesRebuildTask.slowRebuildIdxFut = true;
srv = startServer();
srv.cache(CACHE_NAME).indexReadyFuture().get();
IgniteH2Indexing idx = (IgniteH2Indexing) srv.context().query().getIndexing();
GridH2Table tbl = idx.schemaManager().dataTable(DFLT_SCHEMA, CACHE_NAME);
assertNotNull(tbl);
assertFalse(tbl.rebuildFromHashInProgress());
}
use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.
the class GridIndexRebuildSelfTest method checkDataState.
/**
* Check versions presence in index tree.
*
* @param srv Node.
* @param afterRebuild Whether index rebuild has occurred.
* @throws IgniteCheckedException if failed.
*/
@SuppressWarnings({ "ConstantConditions", "unchecked" })
protected void checkDataState(IgniteEx srv, boolean afterRebuild) throws IgniteCheckedException {
IgniteInternalCache icache = srv.cachex(CACHE_NAME);
IgniteCache cache = srv.cache(CACHE_NAME);
assertNotNull(icache);
for (IgniteCacheOffheapManager.CacheDataStore store : icache.context().offheap().cacheDataStores()) {
GridCursor<? extends CacheDataRow> cur = store.cursor();
while (cur.next()) {
CacheDataRow row = cur.get();
int key = row.key().value(icache.context().cacheObjectContext(), false);
if (!afterRebuild || key <= AMOUNT / 2)
assertEquals(key, cache.get(key));
else
assertEquals(-1, cache.get(key));
}
}
}
use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.
the class GridIndexRebuildSelfTest method createAndFillTableWithIndex.
/**
* Creating a cache, table, index and populating data.
*
* @param node Node.
* @return Cache.
* @throws Exception if failed.
*/
private IgniteInternalCache createAndFillTableWithIndex(IgniteEx node) throws Exception {
requireNonNull(node);
String cacheName = CACHE_NAME;
execute(node, "CREATE TABLE T(k int primary key, v int) WITH \"cache_name=" + cacheName + ",wrap_value=false,atomicity=transactional\"");
execute(node, "CREATE INDEX IDX ON T(v)");
IgniteInternalCache cc = node.cachex(cacheName);
assertNotNull(cc);
putData(node, false);
return cc;
}
use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.
the class GridIndexRebuildWithMvccEnabledSelfTest method testIndexRebuild.
/**
* {@inheritDoc}
*/
@Test
@Override
public void testIndexRebuild() throws Exception {
IgniteEx srv = startServer();
execute(srv, "CREATE TABLE T(k int primary key, v int) WITH \"cache_name=T,wrap_value=false," + "atomicity=transactional_snapshot\"");
execute(srv, "CREATE INDEX IDX ON T(v)");
IgniteInternalCache cc = srv.cachex(CACHE_NAME);
assertNotNull(cc);
lockVersion(srv);
putData(srv, false);
checkDataState(srv, false);
File idxPath = indexFile(cc);
stopAllGrids();
assertTrue(U.delete(idxPath));
srv = startServer();
putData(srv, true);
checkDataState(srv, true);
}
use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.
the class GridIndexRebuildWithMvccEnabledSelfTest method checkDataState.
/**
* {@inheritDoc}
*/
@Override
protected void checkDataState(IgniteEx srv, boolean afterRebuild) throws IgniteCheckedException {
IgniteInternalCache icache = srv.cachex(CACHE_NAME);
assertNotNull(icache);
CacheObjectContext coCtx = icache.context().cacheObjectContext();
for (IgniteCacheOffheapManager.CacheDataStore store : icache.context().offheap().cacheDataStores()) {
GridCursor<? extends CacheDataRow> cur = store.cursor();
while (cur.next()) {
CacheDataRow row = cur.get();
int key = row.key().value(coCtx, false);
List<IgniteBiTuple<Object, MvccVersion>> vers = store.mvccFindAllVersions(icache.context(), row.key());
if (!afterRebuild || key <= AMOUNT / 2)
assertEquals(key, vers.size());
else {
// For keys affected by concurrent put there are two versions -
// -1 (concurrent put mark) and newest restored value as long as put cleans obsolete versions.
assertEquals(2, vers.size());
Object val0 = ((CacheObject) vers.get(0).getKey()).value(coCtx, false);
Object val1 = ((CacheObject) vers.get(1).getKey()).value(coCtx, false);
assertEquals(-1, val0);
assertEquals(key, val1);
}
}
}
}
Aggregations