/** * Return the timestamp of the oldest in-flight transaction. * @return the timestamp or Long.MIN_VALUE if there is no in-flight transaction. */ public long getOldestInFlightTransactionTimestamp() { if (inFlightTransactions.isEmpty()) { if (log.isDebugEnabled()) log.debug("oldest in-flight transaction's timestamp: " + Long.MIN_VALUE); return Long.MIN_VALUE; } long oldestTimestamp = Long.MAX_VALUE; for (Map.Entry<Uid, BitronixTransaction> entry : inFlightTransactions.entrySet()) { Uid gtrid = entry.getKey(); long currentTimestamp = gtrid.extractTimestamp(); if (currentTimestamp < oldestTimestamp) oldestTimestamp = currentTimestamp; } if (log.isDebugEnabled()) log.debug("oldest in-flight transaction's timestamp: " + oldestTimestamp); return oldestTimestamp; }
/** * Get the BQUAL of the XID. * @return the XID branch qualifier. */ @Override public byte[] getBranchQualifier() { return branchQualifier.getArray(); }
public Uid(byte[] array) { this.array = new byte[array.length]; System.arraycopy(array, 0, this.array, 0, array.length); this.hashCodeValue = arrayHashCode(array); this.toStringValue = arrayToString(array); }
public void testExtracts() throws Exception { byte[] timestamp = Encoder.longToBytes(System.currentTimeMillis()); byte[] sequence = Encoder.intToBytes(1); byte[] serverId = "my-server-id".getBytes(); int uidLength = serverId.length + timestamp.length + sequence.length; byte[] uidArray = new byte[uidLength]; System.arraycopy(serverId, 0, uidArray, 0, serverId.length); System.arraycopy(timestamp, 0, uidArray, serverId.length, timestamp.length); System.arraycopy(sequence, 0, uidArray, serverId.length + timestamp.length, sequence.length); Uid uid = new Uid(uidArray); assertTrue(Arrays.equals(serverId, uid.extractServerId())); assertEquals(Encoder.bytesToLong(timestamp, 0), uid.extractTimestamp()); assertEquals(Encoder.bytesToInt(sequence, 0), uid.extractSequence()); }
if (xid.getFormatId() != BitronixXid.FORMAT_ID) { if (log.isDebugEnabled()) log.debug("skipping non-bitronix XID " + xid + "(format ID: " + xid.getFormatId() + " GTRID: " + new Uid(xid.getGlobalTransactionId()) + "BQUAL: " + new Uid(xid.getBranchQualifier()) + ")"); continue; byte[] extractedServerId = bitronixXid.getGlobalTransactionIdUid().extractServerId(); byte[] jvmUniqueId = TransactionManagerServices.getConfiguration().buildServerIdArray();
/** * Create 3 XIDs on the resource that are in the journal -> recoverer commits them. * @throws Exception */ public void testIncrementalRecoverCommitting() throws Exception { Xid xid0 = new MockXid(0, UidGenerator.generateUid().getArray(), BitronixXid.FORMAT_ID); xaResource.addInDoubtXid(xid0); Xid xid1 = new MockXid(1, UidGenerator.generateUid().getArray(), BitronixXid.FORMAT_ID); xaResource.addInDoubtXid(xid1); Xid xid2 = new MockXid(2, UidGenerator.generateUid().getArray(), BitronixXid.FORMAT_ID); xaResource.addInDoubtXid(xid2); Set<String> names = new HashSet<String>(); names.add(pds.getUniqueName()); journal.log(Status.STATUS_COMMITTING, new Uid(xid0.getGlobalTransactionId()), names); journal.log(Status.STATUS_COMMITTING, new Uid(xid1.getGlobalTransactionId()), names); journal.log(Status.STATUS_COMMITTING, new Uid(xid2.getGlobalTransactionId()), names); IncrementalRecoverer.recover(pds); assertEquals(0, xaResource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN).length); }
/** * Compare two XIDs for equality. * @param obj the XID to compare to. * @return true if both XIDs have the same format ID and contain exactly the same GTRID and BQUAL. */ public boolean equals(Object obj) { if (!(obj instanceof BitronixXid)) return false; BitronixXid otherXid = (BitronixXid) obj; return FORMAT_ID == otherXid.getFormatId() && globalTransactionId.equals(otherXid.getGlobalTransactionIdUid()) && branchQualifier.equals(otherXid.getBranchQualifierUid()); }
public void testHexaStringEncoder() throws Exception { byte[] result = Encoder.intToBytes(0x80); String hexString = new Uid(result).toString(); assertEquals("00000080", hexString); result = Encoder.longToBytes(0x81); hexString = new Uid(result).toString(); assertEquals("0000000000000081", hexString); result = Encoder.shortToBytes((short) 0xff); hexString = new Uid(result).toString(); assertEquals("00FF", hexString); }
@Override public int compare(BitronixTransaction t1, BitronixTransaction t2) { Long timestamp1 = t1.getResourceManager().getGtrid().extractTimestamp(); Long timestamp2 = t2.getResourceManager().getGtrid().extractTimestamp(); int compareTo = timestamp1.compareTo(timestamp2); if (compareTo == 0 && !t1.getResourceManager().getGtrid().equals(t2.getResourceManager().getGtrid())) { // if timestamps are equal, use the Uid as the tie-breaker. the !equals() check above avoids an expensive string compare() here. return t1.getGtrid().compareTo(t2.getGtrid()); } return compareTo; } };
@Override public int compare(Uid uid1, Uid uid2) { return Integer.valueOf(uid1.extractSequence()).compareTo(uid2.extractSequence()); } });
public void testExtracts() throws Exception { byte[] timestamp = Encoder.longToBytes(System.currentTimeMillis()); byte[] sequence = Encoder.intToBytes(1); byte[] serverId = "my-server-id".getBytes(); int uidLength = serverId.length + timestamp.length + sequence.length; byte[] uidArray = new byte[uidLength]; System.arraycopy(serverId, 0, uidArray, 0, serverId.length); System.arraycopy(timestamp, 0, uidArray, serverId.length, timestamp.length); System.arraycopy(sequence, 0, uidArray, serverId.length + timestamp.length, sequence.length); Uid uid = new Uid(uidArray); assertTrue(Arrays.equals(serverId, uid.extractServerId())); assertEquals(Encoder.bytesToLong(timestamp, 0), uid.extractTimestamp()); assertEquals(Encoder.bytesToInt(sequence, 0), uid.extractSequence()); }
if (xid.getFormatId() != BitronixXid.FORMAT_ID) { if (log.isDebugEnabled()) log.debug("skipping non-bitronix XID " + xid + "(format ID: " + xid.getFormatId() + " GTRID: " + new Uid(xid.getGlobalTransactionId()) + "BQUAL: " + new Uid(xid.getBranchQualifier()) + ")"); continue; byte[] extractedServerId = bitronixXid.getGlobalTransactionIdUid().extractServerId(); byte[] jvmUniqueId = TransactionManagerServices.getConfiguration().buildServerIdArray();
/** * Create 3 XIDs on the resource that are in the journal -> recoverer commits them. * @throws Exception */ public void testIncrementalRecoverCommitting() throws Exception { Xid xid0 = new MockXid(0, UidGenerator.generateUid().getArray(), BitronixXid.FORMAT_ID); xaResource.addInDoubtXid(xid0); Xid xid1 = new MockXid(1, UidGenerator.generateUid().getArray(), BitronixXid.FORMAT_ID); xaResource.addInDoubtXid(xid1); Xid xid2 = new MockXid(2, UidGenerator.generateUid().getArray(), BitronixXid.FORMAT_ID); xaResource.addInDoubtXid(xid2); Set<String> names = new HashSet<String>(); names.add(pds.getUniqueName()); journal.log(Status.STATUS_COMMITTING, new Uid(xid0.getGlobalTransactionId()), names); journal.log(Status.STATUS_COMMITTING, new Uid(xid1.getGlobalTransactionId()), names); journal.log(Status.STATUS_COMMITTING, new Uid(xid2.getGlobalTransactionId()), names); IncrementalRecoverer.recover(pds); assertEquals(0, xaResource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN).length); }
/** * Compare two XIDs for equality. * @param obj the XID to compare to. * @return true if both XIDs have the same format ID and contain exactly the same GTRID and BQUAL. */ public boolean equals(Object obj) { if (!(obj instanceof BitronixXid)) return false; BitronixXid otherXid = (BitronixXid) obj; return FORMAT_ID == otherXid.getFormatId() && globalTransactionId.equals(otherXid.getGlobalTransactionIdUid()) && branchQualifier.equals(otherXid.getBranchQualifierUid()); }
public void testHexaStringEncoder() throws Exception { byte[] result = Encoder.intToBytes(0x80); String hexString = new Uid(result).toString(); assertEquals("00000080", hexString); result = Encoder.longToBytes(0x81); hexString = new Uid(result).toString(); assertEquals("0000000000000081", hexString); result = Encoder.shortToBytes((short) 0xff); hexString = new Uid(result).toString(); assertEquals("00FF", hexString); }
@Override public int compare(BitronixTransaction t1, BitronixTransaction t2) { Long timestamp1 = t1.getResourceManager().getGtrid().extractTimestamp(); Long timestamp2 = t2.getResourceManager().getGtrid().extractTimestamp(); int compareTo = timestamp1.compareTo(timestamp2); if (compareTo == 0 && !t1.getResourceManager().getGtrid().equals(t2.getResourceManager().getGtrid())) { // if timestamps are equal, use the Uid as the tie-breaker. the !equals() check above avoids an expensive string compare() here. return t1.getGtrid().compareTo(t2.getGtrid()); } return compareTo; } };