use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest method checkCleanState.
/**
* Validates clean state on all participating nodes after query cancellation.
*/
@SuppressWarnings("unchecked")
private void checkCleanState() throws IgniteCheckedException {
for (int i = 0; i < GRIDS_CNT; i++) {
IgniteEx grid = grid(i);
// Validate everything was cleaned up.
ConcurrentMap<UUID, ?> map = U.field(((IgniteH2Indexing) U.field((GridProcessor) U.field(grid.context(), "qryProc"), "idx")).mapQueryExecutor(), "qryRess");
String msg = "Map executor state is not cleared";
// TODO FIXME Current implementation leaves map entry for each node that's ever executed a query.
for (Object result : map.values()) {
Map<Long, ?> m = U.field(result, "res");
assertEquals(msg, 0, m.size());
}
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteCacheQueryNodeRestartSelfTest2 method testRestarts.
/**
* @throws Exception If failed.
*/
public void testRestarts() throws Exception {
int duration = 90 * 1000;
int qryThreadNum = 4;
// 4 + 2 = 6 nodes
int restartThreadsNum = 2;
final int nodeLifeTime = 2 * 1000;
final int logFreq = 10;
startGridsMultiThreaded(GRID_CNT);
final AtomicIntegerArray locks = new AtomicIntegerArray(GRID_CNT);
fillCaches();
final List<List<?>> pRes = grid(0).cache("pu").query(new SqlFieldsQuery(PARTITIONED_QRY)).getAll();
Thread.sleep(3000);
assertEquals(pRes, grid(0).cache("pu").query(new SqlFieldsQuery(PARTITIONED_QRY)).getAll());
final List<List<?>> rRes = grid(0).cache("co").query(new SqlFieldsQuery(REPLICATED_QRY)).getAll();
assertFalse(pRes.isEmpty());
assertFalse(rRes.isEmpty());
final AtomicInteger qryCnt = new AtomicInteger();
final AtomicBoolean qrysDone = new AtomicBoolean();
IgniteInternalFuture<?> fut1 = multithreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
final GridRandom rnd = new GridRandom();
while (!qrysDone.get()) {
int g;
do {
g = rnd.nextInt(locks.length());
} while (!locks.compareAndSet(g, 0, 1));
try {
final IgniteEx grid = grid(g);
if (rnd.nextBoolean()) {
// Partitioned query.
final IgniteCache<?, ?> cache = grid.cache("pu");
final SqlFieldsQuery qry = new SqlFieldsQuery(PARTITIONED_QRY);
boolean smallPageSize = rnd.nextBoolean();
if (smallPageSize)
qry.setPageSize(3);
final IgniteCache<Integer, Company> co = grid.cache("co");
try {
runQuery(grid, new Runnable() {
@Override
public void run() {
if (rnd.nextBoolean())
// Get lock run test with open transaction.
co.get(rnd.nextInt(COMPANY_CNT));
assertEquals(pRes, cache.query(qry).getAll());
}
});
} catch (CacheException e) {
// Interruptions are expected here.
if (e.getCause() instanceof IgniteInterruptedCheckedException || e.getCause() instanceof InterruptedException || e.getCause() instanceof ClusterTopologyException || e.getCause() instanceof TransactionTimeoutException || e.getCause() instanceof TransactionException)
continue;
if (e.getCause() instanceof QueryCancelledException)
fail("Retry is expected");
if (!smallPageSize)
U.error(grid.log(), "On large page size must retry.", e);
assertTrue("On large page size must retry.", smallPageSize);
boolean failedOnRemoteFetch = false;
boolean failedOnInterruption = false;
for (Throwable th = e; th != null; th = th.getCause()) {
if (th instanceof InterruptedException) {
failedOnInterruption = true;
break;
}
if (!(th instanceof CacheException))
continue;
if (th.getMessage() != null && th.getMessage().startsWith("Failed to fetch data from node:")) {
failedOnRemoteFetch = true;
break;
}
}
// Interruptions are expected here.
if (failedOnInterruption)
continue;
if (!failedOnRemoteFetch) {
U.error(grid.log(), "Must fail inside of GridResultPage.fetchNextPage or subclass.", e);
fail("Must fail inside of GridResultPage.fetchNextPage or subclass.");
}
}
} else {
// Replicated query.
IgniteCache<?, ?> cache = grid.cache("co");
assertEquals(rRes, cache.query(new SqlFieldsQuery(REPLICATED_QRY)).getAll());
}
} finally {
// Clearing lock in final handler to avoid endless loop if exception is thrown.
locks.set(g, 0);
int c = qryCnt.incrementAndGet();
if (c % logFreq == 0)
info("Executed queries: " + c);
}
}
}
}, qryThreadNum, "query-thread");
final AtomicInteger restartCnt = new AtomicInteger();
final AtomicBoolean restartsDone = new AtomicBoolean();
IgniteInternalFuture<?> fut2 = multithreadedAsync(new Callable<Object>() {
@SuppressWarnings({ "BusyWait" })
@Override
public Object call() throws Exception {
GridRandom rnd = new GridRandom();
while (!restartsDone.get()) {
int g;
do {
g = rnd.nextInt(locks.length());
} while (!locks.compareAndSet(g, 0, -1));
try {
log.info("Stop node: " + g);
stopGrid(g);
Thread.sleep(rnd.nextInt(nodeLifeTime));
log.info("Start node: " + g);
startGrid(g);
Thread.sleep(rnd.nextInt(nodeLifeTime));
} finally {
locks.set(g, 0);
int c = restartCnt.incrementAndGet();
if (c % logFreq == 0)
info("Node restarts: " + c);
}
}
return true;
}
}, restartThreadsNum, "restart-thread");
Thread.sleep(duration);
info("Stopping..");
restartsDone.set(true);
try {
fut2.get(20_000);
} catch (IgniteFutureTimeoutCheckedException e) {
U.dumpThreads(log);
fail("Stopping restarts timeout.");
}
info("Restarts stopped.");
qrysDone.set(true);
// Query thread can stuck in next page waiting loop because all nodes are left.
try {
fut1.get(5_000);
} catch (IgniteFutureTimeoutCheckedException ignored) {
fut1.cancel();
}
info("Queries stopped.");
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest method checkCleanState.
/**
* Validates clean state on all participating nodes after query cancellation.
*/
@SuppressWarnings("unchecked")
private void checkCleanState() throws IgniteCheckedException {
for (int i = 0; i < GRID_CNT; i++) {
IgniteEx grid = grid(i);
// Validate everything was cleaned up.
ConcurrentMap<UUID, ?> map = U.field(((IgniteH2Indexing) U.field((GridProcessor) U.field(grid.context(), "qryProc"), "idx")).mapQueryExecutor(), "qryRess");
String msg = "Map executor state is not cleared";
// TODO FIXME Current implementation leaves map entry for each node that's ever executed a query.
for (Object result : map.values()) {
Map<Long, ?> m = U.field(result, "res");
assertEquals(msg, 0, m.size());
}
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class AbstractSchemaSelfTest method assertIndex.
/**
* Assert index state on particular node.
*
* @param node Node.
* @param cacheName Cache name.
* @param tblName Table name.
* @param idxName Index name.
* @param inlineSize Inline size.
* @param fields Fields.
*/
static void assertIndex(Ignite node, String cacheName, String tblName, String idxName, int inlineSize, IgniteBiTuple<String, Boolean>... fields) {
awaitCompletion();
node.cache(cacheName);
IgniteEx node0 = (IgniteEx) node;
ArrayList<IgniteBiTuple<String, Boolean>> res = new ArrayList<>();
try {
try (Connection c = connect(node0)) {
try (ResultSet rs = c.getMetaData().getIndexInfo(null, cacheName, tblName, false, false)) {
while (rs.next()) {
if (F.eq(idxName, rs.getString("INDEX_NAME")))
res.add(new T2<>(rs.getString("COLUMN_NAME"), F.eq("A", rs.getString("ASC_OR_DESC"))));
}
}
}
assertTrue("Index not found: " + idxName, res.size() > 0);
assertEquals(Arrays.asList(fields), res);
} catch (SQLException e) {
throw new AssertionError(e);
}
// Also, let's check internal stuff not visible via JDBC - like inline size.
QueryTypeDescriptorImpl typeDesc = typeExisting(node0, cacheName, tblName);
assertInternalIndexParams(typeDesc, idxName, inlineSize);
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class DynamicColumnsAbstractConcurrentSelfTest method checkNodeJoinOnPendingOperation.
/**
* Check node join on pending operation.
*
* @param addOrRemove Pass {@code true} to check add column. Otherwise, drop column is checked.
* @throws Exception If failed.
*/
private void checkNodeJoinOnPendingOperation(boolean addOrRemove) throws Exception {
CountDownLatch finishLatch = new CountDownLatch(4);
IgniteEx srv1 = ignitionStart(serverConfiguration(1), finishLatch);
createSqlCache(srv1);
run(srv1, addOrRemove ? createSql : createSql4Cols);
CountDownLatch idxLatch = blockIndexing(srv1);
QueryField c = c("AGE", Integer.class.getName());
IgniteInternalFuture<?> idxFut = addOrRemove ? addCols(srv1, QueryUtils.DFLT_SCHEMA, c) : dropCols(srv1, QueryUtils.DFLT_SCHEMA, "CITY");
U.await(idxLatch);
ignitionStart(serverConfiguration(2), finishLatch);
ignitionStart(serverConfiguration(3, true), finishLatch);
ignitionStart(clientConfiguration(4), finishLatch);
assertFalse(idxFut.isDone());
unblockIndexing(srv1);
idxFut.get();
U.await(finishLatch);
checkTableState(srv1, QueryUtils.DFLT_SCHEMA, TBL_NAME, c);
}
Aggregations