Data removeInternal(Data key) { VersionedValue versionedValue = lockAndGet(key, tx.getTimeoutMillis()); tx.add(new MapTransactionLogRecord(name, key, getPartitionId(key), operationProvider.createTxnDeleteOperation(name, key, versionedValue.version), versionedValue.version, tx.getOwnerUuid())); return versionedValue.value; }
private TransactionContext createTransactionContext(Xid xid) { XAService xaService = getService(); TransactionContext context = xaService.newXATransactionContext(xid, null, timeoutInSeconds.get(), false); getTransaction(context).begin(); return context; }
@Override protected Object call() throws Exception { String transactionId = parameters.transactionId; TransactionContext transactionContext = endpoint.getTransactionContext(transactionId); if (transactionContext == null) { throw new TransactionException("No transaction context with given transactionId: " + transactionId); } Transaction transaction = TransactionAccessor.getTransaction(transactionContext); if (parameters.onePhase) { transaction.prepare(); } transaction.commit(); endpoint.removeTransactionContext(transactionId); return null; }
private void addTransactionRecords(ClusterStateChange stateChange, Transaction tx, Collection<MemberImpl> members, int memberListVersion, int partitionStateVersion, boolean isTransient) { long leaseTime = Math.min(tx.getTimeoutMillis(), LOCK_LEASE_EXTENSION_MILLIS); for (Member member : members) { tx.add(new ClusterStateTransactionLogRecord(stateChange, node.getThisAddress(), member.getAddress(), tx.getTxnId(), leaseTime, memberListVersion, partitionStateVersion, isTransient)); } }
Collection<MultiMapRecord> removeAllInternal(Data key) { checkObjectNotNull(key); long timeout = tx.getTimeoutMillis(); long ttl = extendTimeout(timeout); Collection<MultiMapRecord> coll = txMap.get(key); MultiMapTransactionLogRecord logRecord; if (coll == null) { MultiMapResponse response = lockAndGet(key, timeout, ttl); if (response == null) { throw new ConcurrentModificationException("Transaction couldn't obtain lock " + getThreadId()); } coll = createCollection(response.getRecordCollection(getNodeEngine())); logRecord = new MultiMapTransactionLogRecord(getPartitionId(key), key, name, ttl, getThreadId()); tx.add(logRecord); } else { logRecord = (MultiMapTransactionLogRecord) tx.get(getRecordLogKey(key)); } txMap.put(key, createCollection()); TxnRemoveAllOperation operation = new TxnRemoveAllOperation(name, key, coll); logRecord.addOperation(operation); return coll; }
Transaction tx = txManagerService.newAllowedDuringPassiveStateTransaction(options); notifyBeforeStateChange(oldState, requestedState, isTransient); tx.begin(); try { String txnId = tx.getTxnId(); Collection<MemberImpl> members = memberMap.getMembers(); int memberListVersion = memberMap.getVersion(); tx.prepare(); tx.rollback(); notifyAfterStateChange(oldState, requestedState, isTransient); if (e instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException) { tx.commit(); } catch (Throwable e) { if (e instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException) {
= new TxnReserveOfferOperation(name, timeout, offeredQueue.size(), tx.getTxnId()); operation.setCallerUuid(tx.getOwnerUuid()); try { Future<Long> future = invoke(operation);
void checkTransactionState() { if (!tx.getState().equals(Transaction.State.ACTIVE)) { throw new TransactionNotActiveException("Transaction is not active!"); } }
private void addUnlockTransactionRecord(Data key, long version) { TxnUnlockOperation operation = new TxnUnlockOperation(name, key, version); tx.add(new MapTransactionLogRecord(name, key, getPartitionId(key), operation, version, tx.getOwnerUuid())); }
Data peekInternal(long timeout) { QueueItem offer = offeredQueue.peek(); long itemId = offer == null ? -1 : offer.getItemId(); TxnPeekOperation operation = new TxnPeekOperation(name, timeout, itemId, tx.getTxnId()); try { Future<QueueItem> future = invoke(operation); QueueItem item = future.get(); if (item != null) { if (offer != null && item.getItemId() == offer.getItemId()) { return offer.getData(); } return item.getData(); } } catch (Throwable t) { throw ExceptionUtil.rethrow(t); } return null; }
private VersionedValue lockAndGet(Data key, long timeout, boolean shouldLoad) { VersionedValue versionedValue = valueMap.get(key); if (versionedValue != null) { return versionedValue; } boolean blockReads = tx.getTransactionType() == TransactionType.ONE_PHASE; MapOperation operation = operationProvider.createTxnLockAndGetOperation(name, key, timeout, timeout, tx.getOwnerUuid(), shouldLoad, blockReads); operation.setThreadId(ThreadUtil.getThreadId()); try { int partitionId = partitionService.getPartitionId(key); Future<VersionedValue> future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId); versionedValue = future.get(); if (versionedValue == null) { throw new TransactionTimedOutException("Transaction couldn't obtain lock for the key: " + toObjectIfNeeded(key)); } valueMap.put(key, versionedValue); return versionedValue; } catch (Throwable t) { throw rethrow(t); } }
protected Object toObjectIfNeeded(Object data) { if (tx.isOriginatedFromClient()) { return data; } return getNodeEngine().toObject(data); } }
private MultiMapResponse lockAndGet(Data key, long timeout, long ttl) { boolean blockReads = tx.getTransactionType() == TransactionType.ONE_PHASE; TxnLockAndGetOperation operation = new TxnLockAndGetOperation(name, key, timeout, ttl, getThreadId(), blockReads); try { int partitionId = partitionService.getPartitionId(key); Future<MultiMapResponse> future = operationService .invokeOnPartition(MultiMapService.SERVICE_NAME, operation, partitionId); return future.get(); } catch (Throwable t) { throw rethrow(t); } }
Object getForUpdateInternal(Data key) { VersionedValue versionedValue = lockAndGet(key, tx.getTimeoutMillis(), true); addUnlockTransactionRecord(key, versionedValue.version); return versionedValue.value; }
private void unlock(Data key, VersionedValue versionedValue) { try { TxnUnlockOperation unlockOperation = new TxnUnlockOperation(name, key, versionedValue.version); unlockOperation.setThreadId(ThreadUtil.getThreadId()); unlockOperation.setOwnerUuid(tx.getOwnerUuid()); int partitionId = partitionService.getPartitionId(key); Future<VersionedValue> future = operationService.invokeOnPartition(SERVICE_NAME, unlockOperation, partitionId); future.get(); valueMap.remove(key); } catch (Throwable t) { throw rethrow(t); } }
@Override public int size() { checkTransactionActive(); try { Map<Integer, Object> results = operationService.invokeOnAllPartitions(MultiMapService.SERVICE_NAME, new MultiMapOperationFactory(name, MultiMapOperationFactory.OperationFactoryType.SIZE)); int size = 0; for (Object obj : results.values()) { if (obj == null) { continue; } Integer result = getNodeEngine().toObject(obj); size += result; } for (Data key : txMap.keySet()) { MultiMapTransactionLogRecord log = (MultiMapTransactionLogRecord) tx.get(getRecordLogKey(key)); if (log != null) { size += log.size(); } } return size; } catch (Throwable t) { throw rethrow(t); } }
Collection<MultiMapRecord> removeAllInternal(Data key) { checkObjectNotNull(key); long timeout = tx.getTimeoutMillis(); long ttl = extendTimeout(timeout); Collection<MultiMapRecord> coll = txMap.get(key); MultiMapTransactionLogRecord logRecord; if (coll == null) { MultiMapResponse response = lockAndGet(key, timeout, ttl); if (response == null) { throw new ConcurrentModificationException("Transaction couldn't obtain lock " + getThreadId()); } coll = createCollection(response.getRecordCollection(getNodeEngine())); logRecord = new MultiMapTransactionLogRecord(getPartitionId(key), key, name, ttl, getThreadId()); tx.add(logRecord); } else { logRecord = (MultiMapTransactionLogRecord) tx.get(getRecordLogKey(key)); } txMap.put(key, createCollection()); TxnRemoveAllOperation operation = new TxnRemoveAllOperation(name, key, coll); logRecord.addOperation(operation); return coll; }
Transaction tx = txManagerService.newAllowedDuringPassiveStateTransaction(options); notifyBeforeStateChange(oldState, requestedState, isTransient); tx.begin(); try { String txnId = tx.getTxnId(); Collection<MemberImpl> members = memberMap.getMembers(); int memberListVersion = memberMap.getVersion(); tx.prepare(); tx.rollback(); notifyAfterStateChange(oldState, requestedState, isTransient); if (e instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException) { tx.commit(); } catch (Throwable e) { if (e instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException) {