use of org.apache.ignite.cache.ReadRepairStrategy in project ignite by apache.
the class ConsistencyCommand method parseArguments.
/**
* {@inheritDoc}
*/
@Override
public void parseArguments(CommandArgIterator argIter) {
cmd = of(argIter.nextArg("Expected consistency action."));
if (cmd == REPAIR) {
String cacheName = null;
int part = -1;
ReadRepairStrategy strategy = null;
while (argIter.hasNextArg()) {
String arg = argIter.peekNextArg();
if (CACHE.equals(arg) || PARTITION.equals(arg) || STRATEGY.equals(arg)) {
arg = argIter.nextArg("Expected parameter key.");
switch(arg) {
case CACHE:
cacheName = argIter.nextArg("Expected cache name.");
break;
case PARTITION:
part = argIter.nextNonNegativeIntArg("Expected partition.");
break;
case STRATEGY:
strategy = ReadRepairStrategy.fromString(argIter.nextArg("Expected strategy."));
break;
default:
throw new IllegalArgumentException("Illegal argument: " + arg);
}
} else
break;
}
if (cacheName == null)
throw new IllegalArgumentException("Cache name argument missed.");
if (part == -1)
throw new IllegalArgumentException("Partition argument missed.");
if (strategy == null)
throw new IllegalArgumentException("Strategy argument missed.");
cmdArg = new VisorConsistencyRepairTaskArg(cacheName, part, strategy);
} else if (cmd == STATUS)
cmdArg = null;
else
throw new IllegalArgumentException("Unsupported operation.");
}
use of org.apache.ignite.cache.ReadRepairStrategy in project ignite by apache.
the class GridNearTxLocal method loadMissing.
/**
* @param cacheCtx Cache context.
* @param readThrough Read through flag.
* @param async if {@code True}, then loading will happen in a separate thread.
* @param keys Keys.
* @param skipVals Skip values flag.
* @param needVer If {@code true} version is required for loaded values.
* @param c Closure to be applied for loaded values.
* @param readRepairStrategy Read Repair strategy.
* @param expiryPlc Expiry policy.
* @return Future with {@code True} value if loading took place.
*/
private IgniteInternalFuture<Void> loadMissing(final GridCacheContext cacheCtx, AffinityTopologyVersion topVer, boolean readThrough, boolean async, final Collection<KeyCacheObject> keys, final boolean skipVals, final boolean needVer, boolean keepBinary, boolean recovery, ReadRepairStrategy readRepairStrategy, final ExpiryPolicy expiryPlc, final GridInClosure3<KeyCacheObject, Object, GridCacheVersion> c) {
IgniteCacheExpiryPolicy expiryPlc0 = optimistic() ? accessPolicy(cacheCtx, keys) : cacheCtx.cache().expiryPolicy(expiryPlc);
if (cacheCtx.isNear()) {
return cacheCtx.nearTx().txLoadAsync(this, topVer, keys, readThrough, needVer || !cacheCtx.config().isReadFromBackup() || (optimistic() && serializable() && readThrough), /*deserializeBinary*/
false, recovery, expiryPlc0, skipVals, needVer).chain(new C1<IgniteInternalFuture<Map<Object, Object>>, Void>() {
@Override
public Void apply(IgniteInternalFuture<Map<Object, Object>> f) {
try {
Map<Object, Object> map = f.get();
processLoaded(map, keys, needVer, c);
return null;
} catch (Exception e) {
setRollbackOnly();
throw new GridClosureException(e);
}
}
});
} else if (cacheCtx.isColocated()) {
if (readRepairStrategy != null) {
return new GridNearReadRepairCheckOnlyFuture(cacheCtx, keys, readRepairStrategy, readThrough, taskName, false, recovery, expiryPlc0, skipVals, needVer, true, this).multi().chain((fut) -> {
try {
Map<Object, Object> map = fut.get();
processLoaded(map, keys, needVer, c);
return null;
} catch (IgniteConsistencyViolationException e) {
for (KeyCacheObject key : keys) // Will be recreated after repair.
txState().removeEntry(cacheCtx.txKey(key));
throw new GridClosureException(e);
} catch (Exception e) {
setRollbackOnly();
throw new GridClosureException(e);
}
});
}
if (keys.size() == 1) {
final KeyCacheObject key = F.first(keys);
return cacheCtx.colocated().loadAsync(key, readThrough, needVer || !cacheCtx.config().isReadFromBackup() || (optimistic() && serializable() && readThrough), topVer, resolveTaskName(), /*deserializeBinary*/
false, expiryPlc0, skipVals, needVer, /*keepCacheObject*/
true, recovery, null, label()).chain(new C1<IgniteInternalFuture<Object>, Void>() {
@Override
public Void apply(IgniteInternalFuture<Object> f) {
try {
Object val = f.get();
processLoaded(key, val, needVer, skipVals, c);
return null;
} catch (Exception e) {
setRollbackOnly();
throw new GridClosureException(e);
}
}
});
} else {
return cacheCtx.colocated().loadAsync(keys, readThrough, needVer || !cacheCtx.config().isReadFromBackup() || (optimistic() && serializable() && readThrough), topVer, resolveTaskName(), /*deserializeBinary*/
false, recovery, expiryPlc0, skipVals, needVer, /*keepCacheObject*/
true, label(), null).chain(new C1<IgniteInternalFuture<Map<Object, Object>>, Void>() {
@Override
public Void apply(IgniteInternalFuture<Map<Object, Object>> f) {
try {
Map<Object, Object> map = f.get();
processLoaded(map, keys, needVer, c);
return null;
} catch (Exception e) {
setRollbackOnly();
throw new GridClosureException(e);
}
}
});
}
} else {
assert cacheCtx.isLocal();
return localCacheLoadMissing(cacheCtx, topVer, readThrough, async, keys, skipVals, needVer, keepBinary, recovery, expiryPlc, c);
}
}
use of org.apache.ignite.cache.ReadRepairStrategy in project ignite by apache.
the class GridDhtAtomicCache method getAsync.
/**
* {@inheritDoc}
*/
@Override
protected IgniteInternalFuture<V> getAsync(final K key, final boolean forcePrimary, final boolean skipTx, final String taskName, final boolean deserializeBinary, final boolean skipVals, final boolean needVer) {
ctx.checkSecurity(SecurityPermission.CACHE_READ);
CacheOperationContext opCtx = ctx.operationContextPerCall();
final ExpiryPolicy expiryPlc = skipVals ? null : opCtx != null ? opCtx.expiry() : null;
final boolean skipStore = opCtx != null && opCtx.skipStore();
final boolean recovery = opCtx != null && opCtx.recovery();
final ReadRepairStrategy readRepairStrategy = opCtx != null ? opCtx.readRepairStrategy() : null;
return asyncOp(new CO<IgniteInternalFuture<V>>() {
@Override
public IgniteInternalFuture<V> apply() {
return getAsync0(ctx.toCacheKeyObject(key), forcePrimary, taskName, deserializeBinary, recovery, readRepairStrategy, expiryPlc, skipVals, skipStore, needVer);
}
});
}
use of org.apache.ignite.cache.ReadRepairStrategy in project ignite by apache.
the class GridCacheAdapter method containsKeyAsync.
/**
* {@inheritDoc}
*/
@Override
public final IgniteInternalFuture<Boolean> containsKeyAsync(K key) {
A.notNull(key, "key");
CacheOperationContext opCtx = ctx.operationContextPerCall();
IgniteInternalFuture fut = getAsync(key, /*force primary*/
!ctx.config().isReadFromBackup(), /*skip tx*/
false, /*task name*/
null, /*deserialize binary*/
false, /*skip values*/
true, false);
ReadRepairStrategy readRepairStrategy = opCtx != null ? opCtx.readRepairStrategy() : null;
if (readRepairStrategy != null)
return getWithRepairAsync(fut, (ks) -> repairAsync(ks, opCtx, true), () -> containsKeyAsync(key));
return fut;
}
use of org.apache.ignite.cache.ReadRepairStrategy in project ignite by apache.
the class GridDhtColocatedCache method getAsync.
/**
* {@inheritDoc}
*/
@Override
protected IgniteInternalFuture<V> getAsync(final K key, boolean forcePrimary, boolean skipTx, String taskName, final boolean deserializeBinary, final boolean skipVals, final boolean needVer) {
ctx.checkSecurity(SecurityPermission.CACHE_READ);
GridNearTxLocal tx = checkCurrentTx();
final CacheOperationContext opCtx = ctx.operationContextPerCall();
final boolean recovery = opCtx != null && opCtx.recovery();
final ReadRepairStrategy readRepairStrategy = opCtx != null ? opCtx.readRepairStrategy() : null;
// Get operation bypass Tx in Mvcc mode.
if (!ctx.mvccEnabled() && tx != null && !tx.implicit() && !skipTx) {
return asyncOp(tx, new AsyncOp<V>() {
@Override
public IgniteInternalFuture<V> op(GridNearTxLocal tx, AffinityTopologyVersion readyTopVer) {
IgniteInternalFuture<Map<Object, Object>> fut = tx.getAllAsync(ctx, readyTopVer, Collections.singleton(ctx.toCacheKeyObject(key)), deserializeBinary, skipVals, false, opCtx != null && opCtx.skipStore(), recovery, readRepairStrategy, needVer);
return fut.chain(new CX1<IgniteInternalFuture<Map<Object, Object>>, V>() {
@Override
public V applyx(IgniteInternalFuture<Map<Object, Object>> e) throws IgniteCheckedException {
Map<Object, Object> map = e.get();
assert map.isEmpty() || map.size() == 1 : map.size();
if (skipVals) {
Boolean val = map.isEmpty() ? false : (Boolean) F.firstValue(map);
return (V) (val);
}
return (V) F.firstValue(map);
}
});
}
}, opCtx, /*retry*/
false);
}
MvccSnapshot mvccSnapshot = null;
MvccQueryTracker mvccTracker = null;
if (ctx.mvccEnabled()) {
try {
if (tx != null)
mvccSnapshot = MvccUtils.requestSnapshot(tx);
else {
mvccTracker = MvccUtils.mvccTracker(ctx, null);
mvccSnapshot = mvccTracker.snapshot();
}
assert mvccSnapshot != null;
} catch (IgniteCheckedException ex) {
return new GridFinishedFuture<>(ex);
}
}
AffinityTopologyVersion topVer;
if (tx != null)
topVer = tx.topologyVersion();
else if (mvccTracker != null)
topVer = mvccTracker.topologyVersion();
else
topVer = ctx.affinity().affinityTopologyVersion();
if (readRepairStrategy != null) {
return new GridNearReadRepairCheckOnlyFuture(ctx, Collections.singleton(ctx.toCacheKeyObject(key)), readRepairStrategy, opCtx == null || !opCtx.skipStore(), taskName, deserializeBinary, recovery, skipVals ? null : expiryPolicy(opCtx != null ? opCtx.expiry() : null), skipVals, needVer, false, tx).single();
}
GridPartitionedSingleGetFuture fut = new GridPartitionedSingleGetFuture(ctx, ctx.toCacheKeyObject(key), topVer, opCtx == null || !opCtx.skipStore(), forcePrimary, taskName, deserializeBinary, skipVals ? null : expiryPolicy(opCtx != null ? opCtx.expiry() : null), skipVals, needVer, /*keepCacheObjects*/
false, opCtx != null && opCtx.recovery(), null, mvccSnapshot);
fut.init();
if (mvccTracker != null) {
final MvccQueryTracker mvccTracker0 = mvccTracker;
fut.listen(new CI1<IgniteInternalFuture<Object>>() {
@Override
public void apply(IgniteInternalFuture<Object> future) {
if (future.isDone())
mvccTracker0.onDone();
}
});
}
return (IgniteInternalFuture<V>) fut;
}
Aggregations