use of org.apache.ignite.cache.CachePartialUpdateException in project ignite by apache.
the class PlatformCache method convertException.
/** {@inheritDoc} */
@Override
public Exception convertException(Exception e) {
if (e instanceof CachePartialUpdateException)
return new PlatformCachePartialUpdateException((CachePartialUpdateCheckedException) e.getCause(), platformCtx, keepBinary);
if (e instanceof CachePartialUpdateCheckedException)
return new PlatformCachePartialUpdateException((CachePartialUpdateCheckedException) e, platformCtx, keepBinary);
if (e.getCause() instanceof EntryProcessorException)
return (Exception) e.getCause();
TransactionDeadlockException deadlockException = X.cause(e, TransactionDeadlockException.class);
if (deadlockException != null)
return deadlockException;
TransactionTimeoutException timeoutException = X.cause(e, TransactionTimeoutException.class);
if (timeoutException != null)
return timeoutException;
return super.convertException(e);
}
use of org.apache.ignite.cache.CachePartialUpdateException in project ignite by apache.
the class GridCacheAtomicInvalidPartitionHandlingSelfTest method checkRestarts.
/**
* @param writeSync Write synchronization mode to check.
* @throws Exception If failed.
*/
private void checkRestarts(CacheWriteSynchronizationMode writeSync) throws Exception {
this.writeSync = writeSync;
final int gridCnt = 6;
startGrids(gridCnt);
awaitPartitionMapExchange();
try {
assertEquals(testClientNode(), (boolean) grid(0).configuration().isClientMode());
final IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME);
final int range = 100_000;
final Set<Integer> keys = new LinkedHashSet<>();
try (IgniteDataStreamer<Integer, Integer> streamer = grid(0).dataStreamer(DEFAULT_CACHE_NAME)) {
streamer.allowOverwrite(true);
for (int i = 0; i < range; i++) {
streamer.addData(i, 0);
keys.add(i);
if (i > 0 && i % 10_000 == 0)
System.err.println("Put: " + i);
}
}
final Affinity<Integer> aff = grid(0).affinity(DEFAULT_CACHE_NAME);
boolean putDone = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
Iterator<Integer> it = keys.iterator();
while (it.hasNext()) {
Integer key = it.next();
Collection<ClusterNode> affNodes = aff.mapKeyToPrimaryAndBackups(key);
for (int i = 0; i < gridCnt; i++) {
ClusterNode locNode = grid(i).localNode();
IgniteCache<Object, Object> cache = grid(i).cache(DEFAULT_CACHE_NAME);
Object val = cache.localPeek(key);
if (affNodes.contains(locNode)) {
if (val == null)
return false;
} else
assertNull(val);
}
it.remove();
}
return true;
}
}, 30_000);
assertTrue(putDone);
assertTrue(keys.isEmpty());
final AtomicBoolean done = new AtomicBoolean();
delay = true;
System.err.println("FINISHED PUTS");
// Start put threads.
IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
Random rnd = new Random();
while (!done.get()) {
try {
int cnt = rnd.nextInt(5);
if (cnt < 2) {
int key = rnd.nextInt(range);
int val = rnd.nextInt();
cache.put(key, val);
} else {
Map<Integer, Integer> upd = new TreeMap<>();
for (int i = 0; i < cnt; i++) upd.put(rnd.nextInt(range), rnd.nextInt());
cache.putAll(upd);
}
} catch (CachePartialUpdateException ignored) {
// No-op.
}
}
return null;
}
}, 4, "putAll-thread");
Random rnd = new Random();
// Restart random nodes.
for (int r = 0; r < 20; r++) {
int idx0 = rnd.nextInt(gridCnt - 1) + 1;
stopGrid(idx0);
U.sleep(200);
startGrid(idx0);
}
done.set(true);
awaitPartitionMapExchange();
fut.get();
for (int k = 0; k < range; k++) {
Collection<ClusterNode> affNodes = affinity(cache).mapKeyToPrimaryAndBackups(k);
// Test is valid with at least one backup.
assert affNodes.size() >= 2;
Object val = null;
GridCacheVersion ver = null;
UUID nodeId = null;
for (int i = 0; i < gridCnt; i++) {
ClusterNode locNode = grid(i).localNode();
GridCacheAdapter<Object, Object> c = ((IgniteKernal) grid(i)).internalCache(DEFAULT_CACHE_NAME);
GridCacheEntryEx entry = null;
try {
entry = c.entryEx(k);
entry.unswap();
} catch (GridDhtInvalidPartitionException ignored) {
// Skip key.
}
for (int r = 0; r < 10; r++) {
try {
if (affNodes.contains(locNode)) {
assert c.affinity().isPrimaryOrBackup(locNode, k);
boolean primary = c.affinity().isPrimary(locNode, k);
assertNotNull("Failed to find entry on node for key [locNode=" + locNode.id() + ", key=" + k + ']', entry);
if (val == null) {
assertNull(ver);
val = CU.value(entry.rawGet(), entry.context(), false);
ver = entry.version();
nodeId = locNode.id();
} else {
assertNotNull(ver);
assertEquals("Failed to check value for key [key=" + k + ", node=" + locNode.id() + ", primary=" + primary + ", recNodeId=" + nodeId + ']', val, CU.value(entry.rawGet(), entry.context(), false));
assertEquals("Failed to check version for key [key=" + k + ", node=" + locNode.id() + ", primary=" + primary + ", recNodeId=" + nodeId + ']', ver, entry.version());
}
} else
assertTrue("Invalid entry: " + entry, entry == null || !entry.partitionValid());
} catch (AssertionError e) {
if (r == 9) {
info("Failed to verify cache contents: " + e.getMessage());
throw e;
}
info("Failed to verify cache contents, will retry: " + e.getMessage());
// Give some time to finish async updates.
U.sleep(1000);
}
}
}
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.cache.CachePartialUpdateException in project ignite by apache.
the class GridCacheUtils method convertToCacheException.
/**
* @param e Ignite checked exception.
* @return CacheException runtime exception, never null.
*/
@NotNull
public static RuntimeException convertToCacheException(IgniteCheckedException e) {
IgniteClientDisconnectedCheckedException disconnectedErr = e.getCause(IgniteClientDisconnectedCheckedException.class);
if (disconnectedErr != null) {
assert disconnectedErr.reconnectFuture() != null : disconnectedErr;
e = disconnectedErr;
}
if (e.hasCause(CacheWriterException.class))
return new CacheWriterException(U.convertExceptionNoWrap(e));
if (e instanceof CachePartialUpdateCheckedException)
return new CachePartialUpdateException((CachePartialUpdateCheckedException) e);
else if (e instanceof CacheAtomicUpdateTimeoutCheckedException)
return new CacheAtomicUpdateTimeoutException(e.getMessage(), e);
else if (e instanceof ClusterTopologyServerNotFoundException)
return new CacheServerNotFoundException(e.getMessage(), e);
if (e.getCause() instanceof CacheException)
return (CacheException) e.getCause();
if (e.getCause() instanceof NullPointerException)
return (NullPointerException) e.getCause();
C1<IgniteCheckedException, IgniteException> converter = U.getExceptionConverter(e.getClass());
return converter != null ? new CacheException(converter.apply(e)) : new CacheException(e);
}
use of org.apache.ignite.cache.CachePartialUpdateException in project ignite by apache.
the class GridCacheIncrementTransformTest method testIncrement.
/**
* @param restarts Whether test is running with node restarts.
* @throws Exception If failed.
*/
private void testIncrement(boolean restarts) throws Exception {
Random rnd = new Random();
for (int i = 0; i < NUM_ITERS; i++) {
int idx = -1;
Ignite ignite = null;
while (ignite == null) {
idx = rnd.nextInt(GRID_CNT);
ignite = restarts ? grids.getAndSet(idx, null) : grid(idx);
}
IgniteCache<String, TestObject> cache = ignite.<String, TestObject>cache(DEFAULT_CACHE_NAME).withNoRetries();
assertNotNull(cache);
TestObject obj = cache.get("key");
assertNotNull(obj);
assertEquals(i, obj.val);
while (true) {
try {
cache.invoke("key", new Processor());
break;
} catch (CachePartialUpdateException ignored) {
// Need to re-check if update actually succeeded.
TestObject updated = cache.get("key");
if (updated != null && updated.val == i + 1)
break;
}
}
if (restarts)
assert grids.compareAndSet(idx, null, ignite);
}
}
Aggregations