use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal in project ignite by apache.
the class IgfsMetaManager method format.
/**
* Deletes (moves to TRASH) all elements under the root folder.
*
* @return The new Id if the artificially created folder containing all former root
* elements moved to TRASH folder.
* @throws IgniteCheckedException On error.
*/
@SuppressWarnings("RedundantCast")
IgniteUuid format() throws IgniteCheckedException {
if (busyLock.enterBusy()) {
try {
validTxState(false);
IgniteUuid trashId = IgfsUtils.randomTrashId();
try (GridNearTxLocal tx = startTx()) {
// NB: We may lock root because its id is less than any other id:
final IgfsEntryInfo rootInfo = lockIds(IgfsUtils.ROOT_ID, trashId).get(IgfsUtils.ROOT_ID);
assert rootInfo != null;
Map<String, IgfsListingEntry> rootListingMap = rootInfo.listing();
assert rootListingMap != null;
if (rootListingMap.isEmpty())
// Root is empty, nothing to do.
return null;
// Construct new info and move locked entries from root to it.
Map<String, IgfsListingEntry> transferListing = new HashMap<>(rootListingMap);
IgfsEntryInfo newInfo = IgfsUtils.createDirectory(IgniteUuid.randomUuid(), transferListing, (Map<String, String>) null);
createNewEntry(newInfo, trashId, newInfo.id().toString());
// Remove listing entries from root.
// Note that root directory properties and other attributes are preserved:
id2InfoPrj.put(IgfsUtils.ROOT_ID, rootInfo.listing(null));
tx.commit();
signalDeleteWorker();
return newInfo.id();
}
} finally {
busyLock.leaveBusy();
}
} else
throw new IllegalStateException("Failed to perform format because Grid is stopping.");
}
use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal in project ignite by apache.
the class IgniteCacheSystemTransactionsSelfTest method testSystemTxInsideUserTx.
/**
* @throws Exception If failed.
*/
public void testSystemTxInsideUserTx() throws Exception {
IgniteKernal ignite = (IgniteKernal) grid(0);
IgniteCache<Object, Object> jcache = ignite.cache(DEFAULT_CACHE_NAME);
try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
jcache.get("1");
jcache.put("1", "11");
IgniteInternalCache<Object, Object> utilityCache = ignite.context().cache().utilityCache();
utilityCache.getAndPutIfAbsent("2", "2");
try (GridNearTxLocal itx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) {
assertEquals(null, utilityCache.get("1"));
assertEquals("2", utilityCache.get("2"));
assertEquals(null, utilityCache.get("3"));
utilityCache.getAndPut("3", "3");
itx.commit();
}
jcache.put("2", "22");
tx.commit();
}
checkTransactionsCommitted();
checkEntries(DEFAULT_CACHE_NAME, "1", "11", "2", "22", "3", null);
checkEntries(CU.UTILITY_CACHE_NAME, "1", null, "2", "2", "3", "3");
}
use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal in project ignite by apache.
the class HibernateReadWriteAccessStrategy method unlock.
/**
*
* @param ctx Transaction context.
* @param key Key.
*/
private void unlock(TxContext ctx, Object key) {
if (ctx.unlocked(key)) {
// Finish transaction if last key is unlocked.
txCtx.remove();
GridNearTxLocal tx = cache.tx();
assert tx != null;
try {
tx.proxy().commit();
} finally {
tx.proxy().close();
}
assert cache.tx() == null;
}
}
use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal in project ignite by apache.
the class GridCacheAdapter method asyncOp.
/**
* @param op Cache operation.
* @param <T> Return type.
* @return Future.
*/
@SuppressWarnings("unchecked")
private <T> IgniteInternalFuture<T> asyncOp(final AsyncOp<T> op) {
try {
checkJta();
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(e);
}
if (log.isDebugEnabled())
log.debug("Performing async op: " + op);
GridNearTxLocal tx = ctx.tm().threadLocalTx(ctx);
CacheOperationContext opCtx = ctx.operationContextPerCall();
final TransactionConfiguration txCfg = CU.transactionConfiguration(ctx, ctx.kernalContext().config());
if (tx == null || tx.implicit()) {
// Save value of thread-local flag.
boolean skipStore = ctx.skipStore();
int retries = opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES;
if (retries == 1) {
tx = ctx.tm().newTx(true, op.single(), ctx.systemTx() ? ctx : null, OPTIMISTIC, READ_COMMITTED, txCfg.getDefaultTxTimeout(), !skipStore, 0);
return asyncOp(tx, op, opCtx, /*retry*/
false);
} else {
AsyncOpRetryFuture<T> fut = new AsyncOpRetryFuture<>(op, retries, opCtx);
fut.execute(/*retry*/
false);
return fut;
}
} else
return asyncOp(tx, op, opCtx, /*retry*/
false);
}
use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal in project ignite by apache.
the class GridCacheAdapter method asyncOp.
/**
* @param tx Transaction.
* @param op Cache operation.
* @param opCtx Cache operation context.
* @param <T> Return type.
* @return Future.
*/
@SuppressWarnings("unchecked")
protected <T> IgniteInternalFuture<T> asyncOp(GridNearTxLocal tx, final AsyncOp<T> op, final CacheOperationContext opCtx, final boolean retry) {
IgniteInternalFuture<T> fail = asyncOpAcquire(retry);
if (fail != null)
return fail;
FutureHolder holder = lastFut.get();
holder.lock();
try {
IgniteInternalFuture fut = holder.future();
final GridNearTxLocal tx0 = tx;
if (fut != null && !fut.isDone()) {
IgniteInternalFuture<T> f = new GridEmbeddedFuture(fut, new IgniteOutClosure<IgniteInternalFuture>() {
@Override
public IgniteInternalFuture<T> apply() {
if (ctx.kernalContext().isStopping())
return new GridFinishedFuture<>(new IgniteCheckedException("Operation has been cancelled (node is stopping)."));
return op.op(tx0, opCtx).chain(new CX1<IgniteInternalFuture<T>, T>() {
@Override
public T applyx(IgniteInternalFuture<T> tFut) throws IgniteCheckedException {
try {
return tFut.get();
} catch (IgniteTxRollbackCheckedException e) {
throw e;
} catch (IgniteCheckedException e1) {
tx0.rollbackNearTxLocalAsync();
throw e1;
} finally {
ctx.shared().txContextReset();
}
}
});
}
});
saveFuture(holder, f, retry);
return f;
}
final IgniteInternalFuture<T> f = op.op(tx, opCtx).chain(new CX1<IgniteInternalFuture<T>, T>() {
@Override
public T applyx(IgniteInternalFuture<T> tFut) throws IgniteCheckedException {
try {
return tFut.get();
} catch (IgniteTxRollbackCheckedException e) {
throw e;
} catch (IgniteCheckedException e1) {
tx0.rollbackNearTxLocalAsync();
throw e1;
} finally {
ctx.shared().txContextReset();
}
}
});
saveFuture(holder, f, retry);
if (tx.implicit())
ctx.tm().resetContext();
return f;
} finally {
holder.unlock();
}
}
Aggregations