use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.
the class GridCacheInterceptorAbstractSelfTest method assertBeforePutValue.
/**
* @param key Key.
* @param oldVal Expected old value.
* @param newVal Expected new value.
*/
private void assertBeforePutValue(String key, @Nullable Object oldVal, @Nullable Object newVal) {
IgniteBiTuple t = interceptor.beforePutMap.get(key);
assertNotNull(t);
assertEquals(t.get1(), oldVal);
assertEquals(t.get2(), newVal);
}
use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.
the class GridCacheInterceptorAbstractSelfTest method testModifyUpdate.
/**
* @param key Key.
* @param op Operation type.
* @throws Exception If failed.
*/
private void testModifyUpdate(String key, Operation op) throws Exception {
// Interceptor returns incremented new value.
CacheInterceptor retInterceptor = new PutIncrementInterceptor();
// Execute update when value is null.
interceptor.retInterceptor = retInterceptor;
log.info("Update 1 " + op);
update(0, op, key, 1, null);
checkCacheValue(key, 2);
// Check values passed to interceptor.
assertEquals(1, interceptor.beforePutMap.size());
IgniteBiTuple t = interceptor.beforePutMap.get(key);
assertEquals(null, t.get1());
assertEquals(1, t.get2());
assertEquals(1, interceptor.afterPutMap.size());
assertEquals(2, interceptor.afterPutMap.get(key));
// Execute update when value is not null.
interceptor.reset();
interceptor.retInterceptor = retInterceptor;
log.info("Update 2 " + op);
update(0, op, key, 3, 2);
checkCacheValue(key, 4);
// Check values passed to interceptor.
assertEquals(1, interceptor.beforePutMap.size());
t = interceptor.beforePutMap.get(key);
assertEquals(2, t.get1());
assertEquals(3, t.get2());
assertEquals(1, interceptor.afterPutMap.size());
assertEquals(4, interceptor.afterPutMap.get(key));
}
use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.
the class GridCacheAbstractDataStructuresFailoverSelfTest method doTestAtomicStamped.
/**
* Tests atomic stamped value.
*
* @param topWorker Topology change worker.
* @throws Exception If failed.
*/
private void doTestAtomicStamped(ConstantTopologyChangeWorker topWorker) throws Exception {
try (IgniteAtomicStamped<Integer, Integer> s = grid(0).atomicStamped(STRUCTURE_NAME, 1, 1, true)) {
IgniteInternalFuture<?> fut = topWorker.startChangingTopology(new IgniteClosure<Ignite, Object>() {
@Override
public Object apply(Ignite ignite) {
IgniteBiTuple<Integer, Integer> t = ignite.atomicStamped(STRUCTURE_NAME, 1, 1, false).get();
assert t.get1() > 0;
assert t.get2() > 0;
return null;
}
});
int val = s.value();
while (!fut.isDone()) {
IgniteBiTuple<Integer, Integer> t = s.get();
assertEquals(val, (int) t.get1());
assertEquals(val, (int) t.get2());
++val;
s.set(val, val);
}
fut.get();
for (Ignite g : G.allGrids()) {
IgniteBiTuple<Integer, Integer> t = g.atomicStamped(STRUCTURE_NAME, 1, 1, false).get();
assertEquals(val, (int) t.get1());
assertEquals(val, (int) t.get2());
}
}
}
use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.
the class GridCacheProcessor method onExchangeDone.
/**
* Callback invoked when first exchange future for dynamic cache is completed.
*
* @param cacheStartVer Started caches version to create proxy for.
* @param exchActions Change requests.
* @param err Error.
*/
@SuppressWarnings("unchecked")
public void onExchangeDone(AffinityTopologyVersion cacheStartVer, @Nullable ExchangeActions exchActions, @Nullable Throwable err) {
initCacheProxies(cacheStartVer, err);
if (exchActions == null)
return;
if (exchActions.systemCachesStarting() && exchActions.stateChangeRequest() == null) {
ctx.dataStructures().restoreStructuresState(ctx);
ctx.service().updateUtilityCache();
}
if (err == null) {
// Force checkpoint if there is any cache stop request
if (exchActions.cacheStopRequests().size() > 0) {
try {
sharedCtx.database().waitForCheckpoint("caches stop");
} catch (IgniteCheckedException e) {
U.error(log, "Failed to wait for checkpoint finish during cache stop.", e);
}
}
for (ExchangeActions.CacheActionData action : exchActions.cacheStopRequests()) {
CacheGroupContext gctx = cacheGrps.get(action.descriptor().groupId());
// Cancel all operations blocking gateway
if (gctx != null) {
final String msg = "Failed to wait for topology update, cache group is stopping.";
// If snapshot operation in progress we must throw CacheStoppedException
// for correct cache proxy restart. For more details see
// IgniteCacheProxy.cacheException()
gctx.affinity().cancelFutures(new CacheStoppedException(msg));
}
stopGateway(action.request());
sharedCtx.database().checkpointReadLock();
try {
prepareCacheStop(action.request().cacheName(), action.request().destroy());
} finally {
sharedCtx.database().checkpointReadUnlock();
}
}
sharedCtx.database().checkpointReadLock();
try {
// Do not invoke checkpoint listeners for groups are going to be destroyed to prevent metadata corruption.
for (ExchangeActions.CacheGroupActionData action : exchActions.cacheGroupsToStop()) {
Integer groupId = action.descriptor().groupId();
CacheGroupContext grp = cacheGrps.get(groupId);
if (grp != null && grp.persistenceEnabled() && sharedCtx.database() instanceof GridCacheDatabaseSharedManager) {
GridCacheDatabaseSharedManager mngr = (GridCacheDatabaseSharedManager) sharedCtx.database();
mngr.removeCheckpointListener((DbCheckpointListener) grp.offheap());
}
}
} finally {
sharedCtx.database().checkpointReadUnlock();
}
List<IgniteBiTuple<CacheGroupContext, Boolean>> stoppedGroups = new ArrayList<>();
for (ExchangeActions.CacheGroupActionData action : exchActions.cacheGroupsToStop()) {
Integer groupId = action.descriptor().groupId();
if (cacheGrps.containsKey(groupId)) {
stoppedGroups.add(F.t(cacheGrps.get(groupId), action.destroy()));
stopCacheGroup(groupId);
}
}
if (!sharedCtx.kernalContext().clientNode())
sharedCtx.database().onCacheGroupsStopped(stoppedGroups);
if (exchActions.deactivate())
sharedCtx.deactivate();
}
}
use of org.apache.ignite.lang.IgniteBiTuple in project ignite by apache.
the class GridLocalAtomicCache method updatePartialBatch.
/**
* @param entries Entries to update.
* @param ver Cache version.
* @param writeVals Cache values.
* @param putMap Values to put.
* @param rmvKeys Keys to remove.
* @param expiryPlc Expiry policy.
* @param err Optional partial update exception.
* @param subjId Subject ID.
* @param taskName Task name.
* @return Partial update exception.
*/
@SuppressWarnings({ "unchecked", "ConstantConditions", "ForLoopReplaceableByForEach" })
@Nullable
private CachePartialUpdateCheckedException updatePartialBatch(List<GridCacheEntryEx> entries, final GridCacheVersion ver, @Nullable List<CacheObject> writeVals, @Nullable Map<KeyCacheObject, CacheObject> putMap, @Nullable Collection<KeyCacheObject> rmvKeys, @Nullable ExpiryPolicy expiryPlc, boolean keepBinary, @Nullable CachePartialUpdateCheckedException err, UUID subjId, String taskName) {
assert putMap == null ^ rmvKeys == null;
GridCacheOperation op;
CacheStorePartialUpdateException storeErr = null;
try {
if (putMap != null) {
try {
Map<? extends KeyCacheObject, IgniteBiTuple<? extends CacheObject, GridCacheVersion>> view = F.viewReadOnly(putMap, new C1<CacheObject, IgniteBiTuple<? extends CacheObject, GridCacheVersion>>() {
@Override
public IgniteBiTuple<? extends CacheObject, GridCacheVersion> apply(CacheObject val) {
return F.t(val, ver);
}
});
ctx.store().putAll(null, view);
} catch (CacheStorePartialUpdateException e) {
storeErr = e;
}
op = UPDATE;
} else {
try {
ctx.store().removeAll(null, rmvKeys);
} catch (CacheStorePartialUpdateException e) {
storeErr = e;
}
op = DELETE;
}
} catch (IgniteCheckedException e) {
if (err == null)
err = partialUpdateException();
err.add(putMap != null ? putMap.keySet() : rmvKeys, e);
return err;
}
boolean intercept = ctx.config().getInterceptor() != null;
for (int i = 0; i < entries.size(); i++) {
GridCacheEntryEx entry = entries.get(i);
assert entry.lockedByCurrentThread();
if (entry.obsolete() || (storeErr != null && storeErr.failedKeys().contains(entry.key().value(ctx.cacheObjectContext(), false))))
continue;
try {
// We are holding java-level locks on entries at this point.
CacheObject writeVal = op == UPDATE ? writeVals.get(i) : null;
assert writeVal != null || op == DELETE : "null write value found.";
GridTuple3<Boolean, Object, EntryProcessorResult<Object>> t = entry.innerUpdateLocal(ver, op, writeVal, null, false, false, false, keepBinary, expiryPlc, true, true, null, false, subjId, taskName);
if (intercept) {
if (op == UPDATE)
ctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(ctx, entry.key(), writeVal, keepBinary));
else
ctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(ctx, entry.key(), t.get2(), keepBinary));
}
} catch (GridCacheEntryRemovedException ignore) {
assert false : "Entry cannot become obsolete while holding lock.";
} catch (IgniteCheckedException e) {
if (err == null)
err = partialUpdateException();
err.add(Collections.singleton(entry.key()), e);
}
}
return err;
}
Aggregations