@Override public StoredXidRecord recordXid(final long format, final byte[] globalId, final byte[] branchId, EnqueueRecord[] enqueues, DequeueRecord[] dequeues) { _localDistributedTransactionsRecords.put(new Xid(format, globalId, branchId), new DistributedTransactionRecords(enqueues, dequeues)); return new MemoryStoredXidRecord(format, globalId, branchId); }
private StringBuilder xidAsString(Xid id) { return new StringBuilder("(") .append(id.getFormat()) .append(',') .append(Functions.str(id.getGlobalId())) .append(',') .append(Functions.str(id.getBranchId())) .append(')'); }
@Override public int hashCode() { int result = 0; for(int i = 0; i < _xid.getGlobalId().length; i++) { result = 31 * result + (int) _xid.getGlobalId()[i]; } for(int i = 0; i < _xid.getBranchId().length; i++) { result = 31 * result + (int) _xid.getBranchId()[i]; } return result; } }
byte[] globalId = rs.getBytes(2); byte[] branchId = rs.getBytes(3); xids.add(new Xid(format, globalId, branchId)); pstmt.setLong(1, xid.getFormat()); pstmt.setBytes(2, xid.getGlobalId()); pstmt.setBytes(3, xid.getBranchId()); if (!handler.handle(new JDBCStoredXidRecord(xid.getFormat(), xid.getGlobalId(), xid.getBranchId()), enqueues.toArray(new RecordImpl[enqueues.size()]), dequeues.toArray(new RecordImpl[dequeues.size()])))
@Override public boolean equals(Object o) { if(this == o) { return true; } if(o == null || getClass() != o.getClass()) { return false; } ComparableXid that = (ComparableXid) o; return compareBytes(_xid.getBranchId(), that._xid.getBranchId()) && compareBytes(_xid.getGlobalId(), that._xid.getGlobalId()); }
private StringBuilder xidAsString(Xid id) { return new StringBuilder("(") .append(id.getFormat()) .append(',') .append(Functions.str(id.getGlobalId())) .append(',') .append(Functions.str(id.getBranchId())) .append(')'); }
@Override public void removeXid(final StoredXidRecord record) { _localDistributedTransactionsRemoves.add(new Xid(record.getFormat(), record.getGlobalId(), record.getBranchId())); }
@Override public void objectToEntry(Xid xid, TupleOutput output) { output.writeLong(xid.getFormat()); output.writeInt(xid.getGlobalId() == null ? 0 : xid.getGlobalId().length); if(xid.getGlobalId() != null) { output.write(xid.getGlobalId()); } output.writeInt(xid.getBranchId() == null ? 0 : xid.getBranchId().length); if(xid.getBranchId() != null) { output.write(xid.getBranchId()); } } }
public DtxBranch(Transaction.StoredXidRecord storedXidRecord, DtxRegistry dtxRegistry) { this(new Xid(storedXidRecord.getFormat(), storedXidRecord.getGlobalId(), storedXidRecord.getBranchId()), dtxRegistry); _storedXidRecord = storedXidRecord; }
public List<Xid> recoverDtx() { List<Xid> xids = new ArrayList<>(); Iterator<org.apache.qpid.server.txn.Xid> dtxXids = getAddressSpace().getDtxRegistry().recover().iterator(); while(dtxXids.hasNext()) { org.apache.qpid.server.txn.Xid dtxXid = dtxXids.next(); xids.add(new Xid(dtxXid.getFormat(), dtxXid.getGlobalId(), dtxXid.getBranchId())); } return xids; }
public static org.apache.qpid.server.txn.Xid toDtxXid(final Xid xid) { return new org.apache.qpid.server.txn.Xid(xid.getFormat(), xid.getGlobalId(), xid.getBranchId()); }
public void prepare() throws StoreException { LOGGER.debug("Performing prepare for DtxBranch {}", _xid); Transaction txn = _dtxRegistry.getMessageStore().newTransaction(); _storedXidRecord = txn.recordXid(_xid.getFormat(), _xid.getGlobalId(), _xid.getBranchId(), _enqueueRecords.toArray(new EnqueueRecord[_enqueueRecords.size()]), _dequeueRecords.toArray(new DequeueRecord[_dequeueRecords.size()])); txn.commitTran(); prePrepareTransaction(); }
@Override public Xid entryToObject(TupleInput input) { long format = input.readLong(); byte[] globalId = new byte[input.readInt()]; input.readFast(globalId); byte[] branchId = new byte[input.readInt()]; input.readFast(branchId); return new Xid(format,globalId,branchId); }
@Override public void visitDistributedTransactions(final DistributedTransactionHandler handler) throws StoreException { synchronized (_transactionLock) { for (Map.Entry<Xid, DistributedTransactionRecords> entry : _distributedTransactions.entrySet()) { Xid xid = entry.getKey(); DistributedTransactionRecords records = entry.getValue(); if (!handler.handle(new MemoryStoredXidRecord(xid.getFormat(), xid.getGlobalId(), xid.getBranchId()), records.getEnqueues(), records.getDequeues())) { break; } } } }
private void removeXid(Transaction txn, long format, byte[] globalId, byte[] branchId) throws StoreException { DatabaseEntry key = new DatabaseEntry(); Xid xid = new Xid(format, globalId, branchId); XidBinding keyBinding = XidBinding.getInstance(); keyBinding.objectToEntry(xid, key); try { OperationStatus status = getXidDb().delete(txn, key); if (status == OperationStatus.NOTFOUND) { throw new StoreException("Unable to find xid"); } else if (status != OperationStatus.SUCCESS) { throw new StoreException("Unable to remove xid"); } } catch (RuntimeException e) { getLogger().error("Failed to remove xid in transaction " + txn, e); throw getEnvironmentFacade().handleDatabaseException("Error accessing database while removing xid: " + e.getMessage(), e); } }
@Override public void visitDistributedTransactions(final DistributedTransactionHandler handler) throws StoreException { checkMessageStoreOpen(); try(Cursor cursor = getXidDb().openCursor(null, null)) { CachingUUIDFactory uuidFactory = new CachingUUIDFactory(); DatabaseEntry key = new DatabaseEntry(); XidBinding keyBinding = XidBinding.getInstance(); DatabaseEntry value = new DatabaseEntry(); while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) { Xid xid = keyBinding.entryToObject(key); PreparedTransaction preparedTransaction = PreparedTransactionBinding.entryToObject(uuidFactory, value); if (!handler.handle(new BDBStoredXidRecord(xid.getFormat(), xid.getGlobalId(), xid.getBranchId()), preparedTransaction.getEnqueues(), preparedTransaction.getDequeues())) { break; } } } catch (RuntimeException e) { throw getEnvironmentFacade().handleDatabaseException("Cannot recover distributed transactions", e); } }
Xid xid = new Xid(format, globalId, branchId); XidBinding keyBinding = XidBinding.getInstance(); keyBinding.objectToEntry(xid,key);
final Transaction.DequeueRecord[] dequeues) Xid id = new Xid(storedXid.getFormat(), storedXid.getGlobalId(), storedXid.getBranchId()); DtxRegistry dtxRegistry = _virtualHost.getDtxRegistry(); DtxBranch branch = dtxRegistry.getBranch(id);
final Transaction.DequeueRecord[] dequeues) Xid id = new Xid(storedXid.getFormat(), storedXid.getGlobalId(), storedXid.getBranchId()); DtxRegistry dtxRegistry = getVirtualHost().getDtxRegistry(); DtxBranch branch = dtxRegistry.getBranch(id);