/** * Get the GTRID of the XID. * @return the XID global transaction ID. */ @Override public byte[] getGlobalTransactionId() { return globalTransactionId.getArray(); }
/** * Get the BQUAL of the XID. * @return the XID branch qualifier. */ @Override public byte[] getBranchQualifier() { return branchQualifier.getArray(); }
/** * Get the GTRID of the XID. * @return the XID global transaction ID. */ public byte[] getGlobalTransactionId() { return globalTransactionId.getArray(); }
/** * Get the BQUAL of the XID. * @return the XID branch qualifier. */ public byte[] getBranchQualifier() { return branchQualifier.getArray(); }
/** * Length of all the fixed size fields part of the record length header except status and record length. * @return fixedRecordLength */ private int getFixedRecordLength() { return 4 + 8 + 4 + 4 + 1 + gtrid.getArray().length + 4 + 4; // record header length + current time + sequence number + checksum + GTRID size + GTRID + unique names count + end record marker }
/** * Get the GTRID of the XID. * @return the XID global transaction ID. */ @Override public byte[] getGlobalTransactionId() { return globalTransactionId.getArray(); }
/** * Get the BQUAL of the XID. * @return the XID branch qualifier. */ @Override public byte[] getBranchQualifier() { return branchQualifier.getArray(); }
/** * Get the BQUAL of the XID. * @return the XID branch qualifier. */ public byte[] getBranchQualifier() { return branchQualifier.getArray(); }
/** * Get the GTRID of the XID. * @return the XID global transaction ID. */ public byte[] getGlobalTransactionId() { return globalTransactionId.getArray(); }
/** * Length of all the fixed size fields part of the record length header except status and record length. * @return fixedRecordLength */ private int getFixedRecordLength() { return 4 + 8 + 4 + 4 + 1 + gtrid.getArray().length + 4 + 4; // record header length + current time + sequence number + checksum + GTRID size + GTRID + unique names count + end record marker }
/** * 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); }
/** * 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); }
/** * Create 3 XIDs on the resource that are in the journal -> recoverer commits them. * @throws Exception */ public void testRecoverCommitting() 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); TransactionManagerServices.getRecoverer().run(); assertEquals(3, TransactionManagerServices.getRecoverer().getCommittedCount()); assertEquals(0, TransactionManagerServices.getRecoverer().getRolledbackCount()); assertEquals(0, xaResource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN).length); }
/** * Create 3 XIDs on the resource that are in the journal -> recoverer commits them. * @throws Exception */ public void testRecoverCommitting() 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); TransactionManagerServices.getRecoverer().run(); assertEquals(3, TransactionManagerServices.getRecoverer().getCommittedCount()); assertEquals(0, TransactionManagerServices.getRecoverer().getRolledbackCount()); assertEquals(0, xaResource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN).length); }
/** * Create 3 XIDs on the resource that are not in the journal -> recoverer presumes they have aborted and rolls * them back. * @throws Exception */ public void testIncrementalRecoverPresumedAbort() throws Exception { byte[] gtrid = UidGenerator.generateUid().getArray(); xaResource.addInDoubtXid(new MockXid(0, gtrid, BitronixXid.FORMAT_ID)); xaResource.addInDoubtXid(new MockXid(1, gtrid, BitronixXid.FORMAT_ID)); xaResource.addInDoubtXid(new MockXid(2, gtrid, BitronixXid.FORMAT_ID)); IncrementalRecoverer.recover(pds); assertEquals(0, xaResource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN).length); }
/** * Create 3 XIDs on the resource that are not in the journal -> recoverer presumes they have aborted and rolls * them back. * @throws Exception */ public void testIncrementalRecoverPresumedAbort() throws Exception { byte[] gtrid = UidGenerator.generateUid().getArray(); xaResource.addInDoubtXid(new MockXid(0, gtrid, BitronixXid.FORMAT_ID)); xaResource.addInDoubtXid(new MockXid(1, gtrid, BitronixXid.FORMAT_ID)); xaResource.addInDoubtXid(new MockXid(2, gtrid, BitronixXid.FORMAT_ID)); IncrementalRecoverer.recover(pds); assertEquals(0, xaResource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN).length); }
public void testSkipInFlightRollback() throws Exception { BitronixTransactionManager btm = TransactionManagerServices.getTransactionManager(); Uid uid0 = UidGenerator.generateUid(); Xid xid0 = new MockXid(0, uid0.getArray(), BitronixXid.FORMAT_ID); xaResource.addInDoubtXid(xid0); assertNull(btm.getCurrentTransaction()); Thread.sleep(30); // let the clock run a bit so that in-flight TX is a bit older than the journaled one btm.begin(); Xid xid1 = new MockXid(1, UidGenerator.generateUid().getArray(), BitronixXid.FORMAT_ID); xaResource.addInDoubtXid(xid1); TransactionManagerServices.getRecoverer().run(); btm.rollback(); assertEquals(0, TransactionManagerServices.getRecoverer().getCommittedCount()); assertEquals(1, TransactionManagerServices.getRecoverer().getRolledbackCount()); assertEquals(1, xaResource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN).length); btm.shutdown(); TransactionManagerServices.getJournal().open(); TransactionManagerServices.getRecoverer().run(); assertEquals(0, TransactionManagerServices.getRecoverer().getCommittedCount()); assertEquals(1, TransactionManagerServices.getRecoverer().getRolledbackCount()); assertEquals(0, xaResource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN).length); }
public void testSkipInFlightRollback() throws Exception { BitronixTransactionManager btm = TransactionManagerServices.getTransactionManager(); Uid uid0 = UidGenerator.generateUid(); Xid xid0 = new MockXid(0, uid0.getArray(), BitronixXid.FORMAT_ID); xaResource.addInDoubtXid(xid0); assertNull(btm.getCurrentTransaction()); Thread.sleep(30); // let the clock run a bit so that in-flight TX is a bit older than the journaled one btm.begin(); Xid xid1 = new MockXid(1, UidGenerator.generateUid().getArray(), BitronixXid.FORMAT_ID); xaResource.addInDoubtXid(xid1); TransactionManagerServices.getRecoverer().run(); btm.rollback(); assertEquals(0, TransactionManagerServices.getRecoverer().getCommittedCount()); assertEquals(1, TransactionManagerServices.getRecoverer().getRolledbackCount()); assertEquals(1, xaResource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN).length); btm.shutdown(); TransactionManagerServices.getJournal().open(); TransactionManagerServices.getRecoverer().run(); assertEquals(0, TransactionManagerServices.getRecoverer().getCommittedCount()); assertEquals(1, TransactionManagerServices.getRecoverer().getRolledbackCount()); assertEquals(0, xaResource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN).length); }
/** * Create 3 XIDs on the resource that are not in the journal -> recoverer presumes they have aborted and rolls * them back. * @throws Exception */ public void testRecoverPresumedAbort() throws Exception { byte[] gtrid = UidGenerator.generateUid().getArray(); xaResource.addInDoubtXid(new MockXid(0, gtrid, BitronixXid.FORMAT_ID)); xaResource.addInDoubtXid(new MockXid(1, gtrid, BitronixXid.FORMAT_ID)); xaResource.addInDoubtXid(new MockXid(2, gtrid, BitronixXid.FORMAT_ID)); TransactionManagerServices.getRecoverer().run(); assertEquals(0, TransactionManagerServices.getRecoverer().getCommittedCount()); assertEquals(3, TransactionManagerServices.getRecoverer().getRolledbackCount()); assertEquals(0, xaResource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN).length); }
/** * Create 3 XIDs on the resource that are not in the journal -> recoverer presumes they have aborted and rolls * them back. * @throws Exception */ public void testRecoverPresumedAbort() throws Exception { byte[] gtrid = UidGenerator.generateUid().getArray(); xaResource.addInDoubtXid(new MockXid(0, gtrid, BitronixXid.FORMAT_ID)); xaResource.addInDoubtXid(new MockXid(1, gtrid, BitronixXid.FORMAT_ID)); xaResource.addInDoubtXid(new MockXid(2, gtrid, BitronixXid.FORMAT_ID)); TransactionManagerServices.getRecoverer().run(); assertEquals(0, TransactionManagerServices.getRecoverer().getCommittedCount()); assertEquals(3, TransactionManagerServices.getRecoverer().getRolledbackCount()); assertEquals(0, xaResource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN).length); }