use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.
the class DataStreamerImpl method doFlush.
/**
* Performs flush.
*
* @throws IgniteCheckedException If failed.
*/
private void doFlush() throws IgniteCheckedException {
lastFlushTime = U.currentTimeMillis();
List<IgniteInternalFuture> activeFuts0 = null;
int doneCnt = 0;
for (IgniteInternalFuture<?> f : activeFuts) {
if (!f.isDone()) {
if (activeFuts0 == null)
activeFuts0 = new ArrayList<>((int) (activeFuts.size() * 1.2));
activeFuts0.add(f);
} else {
f.get();
doneCnt++;
}
}
if (activeFuts0 == null || activeFuts0.isEmpty())
return;
while (true) {
Queue<IgniteInternalFuture<?>> q = null;
for (Buffer buf : bufMappings.values()) {
IgniteInternalFuture<?> flushFut = buf.flush();
if (flushFut != null) {
if (q == null)
q = new ArrayDeque<>(bufMappings.size() * 2);
q.add(flushFut);
}
}
if (q != null) {
assert !q.isEmpty();
boolean err = false;
long startTimeMillis = U.currentTimeMillis();
for (IgniteInternalFuture fut = q.poll(); fut != null; fut = q.poll()) {
try {
if (timeout == DFLT_UNLIMIT_TIMEOUT)
fut.get();
else {
long timeRemain = timeout - U.currentTimeMillis() + startTimeMillis;
if (timeRemain <= 0)
throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout on flush.");
fut.get(timeRemain);
}
} catch (IgniteClientDisconnectedCheckedException e) {
if (log.isDebugEnabled())
log.debug("Failed to flush buffer: " + e);
throw CU.convertToCacheException(e);
} catch (IgniteFutureTimeoutCheckedException e) {
if (log.isDebugEnabled())
log.debug("Failed to flush buffer: " + e);
throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout on flush.", e);
} catch (IgniteCheckedException e) {
if (log.isDebugEnabled())
log.debug("Failed to flush buffer: " + e);
err = true;
}
}
if (err)
// Remaps needed - flush buffers.
continue;
}
doneCnt = 0;
for (int i = 0; i < activeFuts0.size(); i++) {
IgniteInternalFuture f = activeFuts0.get(i);
if (f == null)
doneCnt++;
else if (f.isDone()) {
f.get();
doneCnt++;
activeFuts0.set(i, null);
} else
break;
}
if (doneCnt == activeFuts0.size())
return;
}
}
use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.
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()));
}
}
}
Aggregations