use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class TxPessimisticDeadlockDetectionTest method doTestDeadlock.
/**
* @throws Exception If failed.
*/
private void doTestDeadlock(final int txCnt, final boolean loc, boolean lockPrimaryFirst, final boolean clientTx, final IgniteClosure<Integer, Object> transformer) throws Exception {
log.info(">>> Test deadlock [txCnt=" + txCnt + ", loc=" + loc + ", lockPrimaryFirst=" + lockPrimaryFirst + ", clientTx=" + clientTx + ", transformer=" + transformer.getClass().getName() + ']');
final AtomicInteger threadCnt = new AtomicInteger();
final CyclicBarrier barrier = new CyclicBarrier(txCnt);
final AtomicReference<TransactionDeadlockException> deadlockErr = new AtomicReference<>();
final List<List<Integer>> keySets = generateKeys(txCnt, loc, !lockPrimaryFirst);
final Set<Integer> involvedKeys = new GridConcurrentHashSet<>();
final Set<Integer> involvedLockedKeys = new GridConcurrentHashSet<>();
final Set<IgniteInternalTx> involvedTxs = new GridConcurrentHashSet<>();
IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Runnable() {
@Override
public void run() {
int threadNum = threadCnt.incrementAndGet();
Ignite ignite = loc ? ignite(0) : ignite(clientTx ? threadNum - 1 + txCnt : threadNum - 1);
IgniteCache<Object, Integer> cache = ignite.cache(CACHE_NAME);
List<Integer> keys = keySets.get(threadNum - 1);
int txTimeout = 500 + txCnt * 100;
try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, txTimeout, 0)) {
involvedTxs.add(((TransactionProxyImpl) tx).tx());
Integer key = keys.get(0);
involvedKeys.add(key);
Object k;
log.info(">>> Performs put [node=" + ((IgniteKernal) ignite).localNode() + ", tx=" + tx + ", key=" + transformer.apply(key) + ']');
cache.put(transformer.apply(key), 0);
involvedLockedKeys.add(key);
barrier.await();
key = keys.get(1);
ClusterNode primaryNode = ((IgniteCacheProxy) cache).context().affinity().primaryByKey(key, NONE);
List<Integer> primaryKeys = primaryKeys(grid(primaryNode).cache(CACHE_NAME), 5, key + (100 * threadNum));
Map<Object, Integer> entries = new HashMap<>();
involvedKeys.add(key);
entries.put(transformer.apply(key), 0);
for (Integer i : primaryKeys) {
involvedKeys.add(i);
entries.put(transformer.apply(i), 1);
k = transformer.apply(i + 13);
involvedKeys.add(i + 13);
entries.put(k, 2);
}
log.info(">>> Performs put [node=" + ((IgniteKernal) ignite).localNode() + ", tx=" + tx + ", entries=" + entries + ']');
cache.putAll(entries);
tx.commit();
} catch (Throwable e) {
// At least one stack trace should contain TransactionDeadlockException.
if (hasCause(e, TransactionTimeoutException.class) && hasCause(e, TransactionDeadlockException.class)) {
if (deadlockErr.compareAndSet(null, cause(e, TransactionDeadlockException.class)))
U.error(log, "At least one stack trace should contain " + TransactionDeadlockException.class.getSimpleName(), e);
}
}
}
}, loc ? 2 : txCnt, "tx-thread");
try {
fut.get();
} catch (IgniteCheckedException e) {
U.error(null, "Unexpected exception", e);
fail();
}
U.sleep(1000);
TransactionDeadlockException deadlockE = deadlockErr.get();
assertNotNull(deadlockE);
boolean fail = false;
// Check transactions, futures and entry locks state.
for (int i = 0; i < NODES_CNT * 2; i++) {
Ignite ignite = ignite(i);
int cacheId = ((IgniteCacheProxy) ignite.cache(CACHE_NAME)).context().cacheId();
GridCacheSharedContext<Object, Object> cctx = ((IgniteKernal) ignite).context().cache().context();
IgniteTxManager txMgr = cctx.tm();
Collection<IgniteInternalTx> activeTxs = txMgr.activeTransactions();
for (IgniteInternalTx tx : activeTxs) {
Collection<IgniteTxEntry> entries = tx.allEntries();
for (IgniteTxEntry entry : entries) {
if (entry.cacheId() == cacheId) {
fail = true;
U.error(log, "Transaction still exists: " + "\n" + tx.xidVersion() + "\n" + tx.nearXidVersion() + "\n nodeId=" + cctx.localNodeId() + "\n tx=" + tx);
}
}
}
Collection<IgniteInternalFuture<?>> futs = txMgr.deadlockDetectionFutures();
assertTrue(futs.isEmpty());
GridCacheAdapter<Object, Integer> intCache = internalCache(i, CACHE_NAME);
GridCacheConcurrentMap map = intCache.map();
for (Integer key : involvedKeys) {
Object key0 = transformer.apply(key);
KeyCacheObject keyCacheObj = intCache.context().toCacheKeyObject(key0);
GridCacheMapEntry entry = map.getEntry(keyCacheObj);
if (entry != null)
assertNull("Entry still has locks " + entry, entry.mvccAllLocal());
}
}
if (fail)
fail("Some transactions still exist");
// Check deadlock report
String msg = deadlockE.getMessage();
for (IgniteInternalTx tx : involvedTxs) assertTrue(msg.contains("[txId=" + tx.xidVersion() + ", nodeId=" + tx.nodeId() + ", threadId=" + tx.threadId() + ']'));
for (Integer key : involvedKeys) {
if (involvedLockedKeys.contains(key))
assertTrue(msg.contains("[key=" + transformer.apply(key) + ", cache=" + CACHE_NAME + ']'));
else
assertFalse(msg.contains("[key=" + transformer.apply(key)));
}
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class GridMapQueryExecutor method sendNextPage.
/**
* @param nodeRess Results.
* @param node Node.
* @param qr Query results.
* @param qry Query.
* @param segmentId Index segment ID.
* @param pageSize Page size.
*/
private void sendNextPage(NodeResults nodeRess, ClusterNode node, QueryResults qr, int qry, int segmentId, int pageSize) {
QueryResult res = qr.result(qry);
assert res != null;
if (res.closed)
return;
int page = res.page;
List<Value[]> rows = new ArrayList<>(Math.min(64, pageSize));
boolean last = res.fetchNextPage(rows, pageSize);
if (last) {
res.close();
if (qr.isAllClosed())
nodeRess.remove(qr.qryReqId, segmentId, qr);
}
try {
boolean loc = node.isLocal();
GridQueryNextPageResponse msg = new GridQueryNextPageResponse(qr.qryReqId, segmentId, qry, page, page == 0 ? res.rowCnt : -1, res.cols, loc ? null : toMessages(rows, new ArrayList<Message>(res.cols)), loc ? rows : null);
if (loc)
h2.reduceQueryExecutor().onMessage(ctx.localNodeId(), msg);
else
ctx.io().sendToGridTopic(node, GridTopic.TOPIC_QUERY, msg, QUERY_POOL);
} catch (IgniteCheckedException e) {
log.error("Failed to send message.", e);
throw new IgniteException(e);
}
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class OptimizedObjectStreamSelfTest method testRequireSerializable.
/**
* @throws Exception If failed.
*/
public void testRequireSerializable() throws Exception {
try {
OptimizedMarshaller marsh = new OptimizedMarshaller(true);
marsh.setContext(CTX);
marsh.marshal(new Object());
assert false : "Exception not thrown.";
} catch (IgniteCheckedException e) {
NotSerializableException serEx = e.getCause(NotSerializableException.class);
if (serEx == null)
throw e;
}
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class GridLog4j2InitializedTest method testLogInitialize.
/** */
public void testLogInitialize() {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setIgniteInstanceName("grid" + 1);
cfg.setNodeId(new UUID(1, 1));
// cfg.setIgniteHome("/home/glutters/Documenti/apache-ignite/ignite-master/ignite/");
URL xml = U.resolveIgniteUrl("config/ignite-log4j2.xml");
IgniteLogger log;
try {
log = new Log4J2Logger(xml);
// log.isQuiet();
cfg.setGridLogger(log);
} catch (IgniteCheckedException e) {
e.printStackTrace();
return;
}
assert log.isInfoEnabled() == true;
if (log.isDebugEnabled())
log.debug("This is 'debug' message.");
log.info("This is 'info' message.");
log.warning("This is 'warning' message.");
log.warning("This is 'warning' message.", new Exception("It's a test warning exception"));
log.error("This is 'error' message.");
assert log.getLogger(GridLog4j2InitializedTest.class.getName()) instanceof Log4J2Logger;
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class IgfsSharedMemoryTestServer method main.
@SuppressWarnings({ "BusyWait", "InfiniteLoopStatement" })
public static void main(String[] args) throws IgniteCheckedException {
System.out.println("Starting server ...");
// Tell our process PID to the wrapper.
X.println(GridJavaProcess.PID_MSG_PREFIX + U.jvmPid());
InputStream is = null;
try {
IpcServerEndpoint srv = new IpcSharedMemoryServerEndpoint(U.defaultWorkDirectory());
new IgniteTestResources().inject(srv);
srv.start();
System.out.println("IPC shared memory server endpoint started");
IpcEndpoint clientEndpoint = srv.accept();
is = clientEndpoint.inputStream();
for (; ; ) {
X.println("Before read.");
is.read();
Thread.sleep(IpcSharedMemoryCrashDetectionSelfTest.RW_SLEEP_TIMEOUT);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
U.closeQuiet(is);
}
}
Aggregations