use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.
the class BlockedEvictionsTest method testCacheGroupDestroy_Volatile.
/**
* @throws Exception If failed.
*/
@Test
public void testCacheGroupDestroy_Volatile() throws Exception {
AtomicReference<IgniteInternalFuture> ref = new AtomicReference<>();
testOperationDuringEviction(false, 1, p -> {
IgniteInternalFuture fut = runAsync(new Runnable() {
@Override
public void run() {
grid(0).destroyCache(DEFAULT_CACHE_NAME);
}
});
doSleep(500);
// Cache stop should be blocked by concurrent unfinished eviction.
assertFalse(fut.isDone());
ref.set(fut);
}, this::preload);
try {
ref.get().get(10_000);
} catch (IgniteFutureTimeoutCheckedException e) {
fail(X.getFullStackTrace(e));
}
PartitionsEvictManager mgr = grid(0).context().cache().context().evict();
// Group eviction context should remain in map.
Map evictionGroupsMap = U.field(mgr, "evictionGroupsMap");
assertFalse("Group context must be cleaned up", evictionGroupsMap.containsKey(CU.cacheId(DEFAULT_CACHE_NAME)));
grid(0).getOrCreateCache(cacheConfiguration());
assertEquals(2, evictionGroupsMap.size());
assertPartitionsSame(idleVerify(grid(0), DEFAULT_CACHE_NAME));
}
use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.
the class GridCacheColocatedDebugTest method testConcurrentCheckThreadChain.
/**
* Covers scenario when thread chain locks acquisition for XID 1 should be continued during unsuccessful attempt
* to acquire lock on certain key for XID 2 (XID 1 with uncompleted chain becomes owner of this key instead).
*
* Scenario:
* 1) Start 1 server node with transactional cache
* 2) With 10 threads, perform 100000 transactions with massive puts
* 2.1) Every put affects the same common key, which is not first and not last in the keys list
* 3) Expected: 100000 transaction should end, load threads shouldn't hang for more than 5 seconds
*
* @throws Exception If failed.
*/
protected void testConcurrentCheckThreadChain(TransactionConcurrency txConcurrency) throws Exception {
storeEnabled = false;
startGrid(0);
try {
final AtomicLong iterCnt = new AtomicLong();
int commonKey = 1000;
int otherKeyPickVariance = 10;
int otherKeysCnt = 5;
int maxIterCnt = MAX_ITER_CNT * 10;
IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {
@Override
public void run() {
long threadId = Thread.currentThread().getId();
long itNum;
while ((itNum = iterCnt.getAndIncrement()) < maxIterCnt) {
Map<Integer, String> vals = U.newLinkedHashMap(otherKeysCnt * 2 + 1);
for (int i = 0; i < otherKeysCnt; i++) {
int key = ThreadLocalRandom.current().nextInt(otherKeyPickVariance * i, otherKeyPickVariance * (i + 1));
vals.put(key, String.valueOf(key) + threadId);
}
vals.put(commonKey, String.valueOf(commonKey) + threadId);
for (int i = 0; i < otherKeysCnt; i++) {
int key = ThreadLocalRandom.current().nextInt(commonKey + otherKeyPickVariance * (i + 1), otherKeyPickVariance * (i + 2) + commonKey);
vals.put(key, String.valueOf(key) + threadId);
}
try (Transaction tx = grid(0).transactions().txStart(txConcurrency, READ_COMMITTED)) {
jcache(0).putAll(vals);
tx.commit();
}
if (itNum > 0 && itNum % 5000 == 0)
info(">>> " + itNum + " iterations completed.");
}
}
}, THREAD_CNT);
while (true) {
long prevIterCnt = iterCnt.get();
try {
fut.get(5_000);
break;
} catch (IgniteFutureTimeoutCheckedException ignored) {
if (iterCnt.get() == prevIterCnt) {
Collection<IgniteInternalTx> hangingTxes = ignite(0).context().cache().context().tm().activeTransactions();
fail(hangingTxes.toString());
}
}
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.
the class IgniteTxOriginatingNodeFailureAbstractSelfTest method testTxOriginatingNodeFails.
/**
* @param keys Keys to update.
* @param partial Flag indicating whether to simulate partial prepared state.
* @throws Exception If failed.
*/
protected void testTxOriginatingNodeFails(Collection<Integer> keys, final boolean partial) throws Exception {
assertFalse(keys.isEmpty());
final Collection<IgniteKernal> grids = new ArrayList<>();
ClusterNode txNode = grid(originatingNode()).localNode();
for (int i = 1; i < gridCount(); i++) grids.add((IgniteKernal) grid(i));
final Map<Integer, String> map = new HashMap<>();
final String initVal = "initialValue";
for (Integer key : keys) {
grid(originatingNode()).cache(DEFAULT_CACHE_NAME).put(key, initVal);
map.put(key, String.valueOf(key));
}
Map<Integer, Collection<ClusterNode>> nodeMap = new HashMap<>();
info("Node being checked: " + grid(1).localNode().id());
for (Integer key : keys) {
Collection<ClusterNode> nodes = new ArrayList<>();
nodes.addAll(grid(1).affinity(DEFAULT_CACHE_NAME).mapKeyToPrimaryAndBackups(key));
nodes.remove(txNode);
nodeMap.put(key, nodes);
}
info("Starting optimistic tx " + "[values=" + map + ", topVer=" + (grid(1)).context().discovery().topologyVersion() + ']');
if (partial)
ignoreMessages(grid(1).localNode().id(), ignoreMessageClass());
final Ignite txIgniteNode = G.ignite(txNode.id());
GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
IgniteCache<Integer, String> cache = txIgniteNode.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
TransactionProxyImpl tx = (TransactionProxyImpl) txIgniteNode.transactions().txStart();
GridNearTxLocal txEx = tx.tx();
assertTrue(txEx.optimistic());
cache.putAll(map);
try {
txEx.prepareNearTxLocal().get(3, TimeUnit.SECONDS);
} catch (IgniteFutureTimeoutCheckedException ignored) {
info("Failed to wait for prepare future completion: " + partial);
}
return null;
}
}).get();
info("Stopping originating node " + txNode);
G.stop(G.ignite(txNode.id()).name(), true);
info("Stopped grid, waiting for transactions to complete.");
boolean txFinished = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (IgniteKernal g : grids) {
GridCacheSharedContext<Object, Object> ctx = g.context().cache().context();
int txNum = ctx.tm().idMapSize();
if (txNum != 0)
return false;
}
return true;
}
}, 10000);
assertTrue(txFinished);
info("Transactions finished.");
for (Map.Entry<Integer, Collection<ClusterNode>> e : nodeMap.entrySet()) {
final Integer key = e.getKey();
final String val = map.get(key);
assertFalse(e.getValue().isEmpty());
for (ClusterNode node : e.getValue()) {
compute(G.ignite(node.id()).cluster().forNode(node)).call(new IgniteCallable<Void>() {
/**
*/
@IgniteInstanceResource
private Ignite ignite;
@Override
public Void call() throws Exception {
IgniteCache<Integer, String> cache = ignite.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
assertEquals(partial ? initVal : val, cache.localPeek(key));
return null;
}
});
}
}
for (Map.Entry<Integer, String> e : map.entrySet()) {
for (Ignite g : G.allGrids()) {
UUID locNodeId = g.cluster().localNode().id();
assertEquals("Check failed for node: " + locNodeId, partial ? initVal : e.getValue(), g.cache(DEFAULT_CACHE_NAME).get(e.getKey()));
}
}
}
use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.
the class GridServiceDeploymentCompoundFutureSelfTest method testWaitForCompletionOnFailingFuture.
/**
* @throws Exception If failed.
*/
@Test
public void testWaitForCompletionOnFailingFuture() throws Exception {
GridServiceDeploymentCompoundFuture<IgniteUuid> compFut = new GridServiceDeploymentCompoundFuture<>();
int failingFutsNum = 2;
int completingFutsNum = 5;
Collection<GridServiceDeploymentFuture> failingFuts = new ArrayList<>(completingFutsNum);
for (int i = 0; i < failingFutsNum; i++) {
ServiceConfiguration failingCfg = config("Failed-" + i);
GridServiceDeploymentFuture<IgniteUuid> failingFut = new GridServiceDeploymentFuture<>(failingCfg, IgniteUuid.randomUuid());
failingFuts.add(failingFut);
compFut.add(failingFut);
}
List<GridFutureAdapter<Object>> futs = new ArrayList<>(completingFutsNum);
for (int i = 0; i < completingFutsNum; i++) {
GridServiceDeploymentFuture<IgniteUuid> fut = new GridServiceDeploymentFuture<>(config(String.valueOf(i)), IgniteUuid.randomUuid());
futs.add(fut);
compFut.add(fut);
}
compFut.markInitialized();
List<Exception> causes = new ArrayList<>();
for (GridServiceDeploymentFuture fut : failingFuts) {
Exception cause = new Exception("Test error");
causes.add(cause);
fut.onDone(cause);
}
try {
compFut.get(100);
fail("Should never reach here.");
} catch (IgniteFutureTimeoutCheckedException e) {
log.info("Expected exception: " + e.getMessage());
}
for (GridFutureAdapter<Object> fut : futs) fut.onDone();
try {
compFut.get();
fail("Should never reach here.");
} catch (IgniteCheckedException ce) {
log.info("Expected exception: " + ce.getMessage());
IgniteException e = U.convertException(ce);
assertTrue(e instanceof ServiceDeploymentException);
Throwable[] supErrs = e.getSuppressed();
assertEquals(failingFutsNum, supErrs.length);
for (int i = 0; i < failingFutsNum; i++) assertEquals(causes.get(i), supErrs[i].getCause());
}
}
use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.
the class PageMemoryImplTest method testCheckpointBufferCantOverflowWithThrottlingMixedLoad.
/**
* @throws Exception If failed.
*/
private void testCheckpointBufferCantOverflowWithThrottlingMixedLoad(PageMemoryImpl.ThrottlingPolicy plc) throws Exception {
PageMemoryImpl memory = createPageMemory(plc, null);
List<FullPageId> pages = new ArrayList<>();
for (int i = 0; i < (MAX_SIZE - 10) * MB / PAGE_SIZE / 2; i++) {
long pageId = memory.allocatePage(1, INDEX_PARTITION, FLAG_IDX);
FullPageId fullPageId = new FullPageId(pageId, 1);
pages.add(fullPageId);
acquireAndReleaseWriteLock(memory, fullPageId);
}
memory.beginCheckpoint(new GridFinishedFuture());
CheckpointMetricsTracker mockTracker = Mockito.mock(CheckpointMetricsTracker.class);
for (FullPageId checkpointPage : pages) memory.checkpointWritePage(checkpointPage, ByteBuffer.allocate(PAGE_SIZE), (fullPageId, buffer, tag) -> {
// No-op.
}, mockTracker);
memory.finishCheckpoint();
for (int i = (int) ((MAX_SIZE - 10) * MB / PAGE_SIZE / 2); i < (MAX_SIZE - 20) * MB / PAGE_SIZE; i++) {
long pageId = memory.allocatePage(1, INDEX_PARTITION, FLAG_IDX);
FullPageId fullPageId = new FullPageId(pageId, 1);
pages.add(fullPageId);
acquireAndReleaseWriteLock(memory, fullPageId);
}
memory.beginCheckpoint(new GridFinishedFuture());
// Mix pages in checkpoint with clean pages
Collections.shuffle(pages);
AtomicBoolean stop = new AtomicBoolean(false);
try {
GridTestUtils.runAsync(() -> {
for (FullPageId page : pages) {
if (// Mark dirty 50% of pages
ThreadLocalRandom.current().nextDouble() < 0.5)
try {
acquireAndReleaseWriteLock(memory, page);
if (stop.get())
break;
} catch (IgniteCheckedException e) {
log.error("runAsync ended with exception", e);
fail();
}
}
}).get(5_000);
} catch (IgniteFutureTimeoutCheckedException ex) {
// Expected.
} finally {
stop.set(true);
}
memory.finishCheckpoint();
LongAdderMetric totalThrottlingTime = U.field(memory.metrics(), "totalThrottlingTime");
assertNotNull(totalThrottlingTime);
assertTrue(totalThrottlingTime.value() > 0);
}
Aggregations