private DatasetGraphTxn promoteExec$(DatasetGraphTxn dsgtxn, TxnType originalTxnType) { // Use begin$ (not beginInternal) // We have the writers lock. // We keep the exclusivity lock. Transaction txn = dsgtxn.getTransaction() ; DatasetGraphTxn dsgtxn2 = begin$(TxnType.WRITE, originalTxnType, txn.getLabel()) ; noteTxnPromote(txn, dsgtxn2.getTransaction()); return dsgtxn2 ; }
private void noteTxnCommit(Transaction transaction) { switch (transaction.getTxnMode()) { case READ : readerFinishes(transaction) ; break ; case WRITE : writerCommits(transaction) ; break ; } transactionFinishes(transaction) ; }
/** The stage in a commit after committing - make the changes permanent in the base data */ private void enactTransaction(Transaction transaction) { transaction.forAllComponents(x->x.enactCommitted(transaction)); transaction.forAllComponents(x->x.clearupCommitted(transaction)); transaction.signalEnacted() ; }
synchronized public long writeJournal(JournalEntry entry) { long posn = write(entry.getType(), entry.getFileRef(), entry.getBlock()) ; if ( entry.getPosition() < 0 ) { entry.setPosition(posn) ; entry.setEndPosition(position) ; } return posn ; }
@Test public void journal_02() { JournalEntry entry1 = new JournalEntry(JournalEntryType.Buffer, testRef, bb1) ; long x = journal.writeJournal(entry1) ; assertEquals(0, x) ; JournalEntry entry9 = journal.readJournal(x) ; assertTrue(equal(entry1, entry9)) ; }
@Override protected boolean _promote(Promote promoteMode) { // Promotion (TDB1) is a reset of the DatasetGraphTxn. checkNotClosed() ; DatasetGraphTxn dsgTxn = dsgtxn.get(); Transaction transaction = dsgTxn.getTransaction(); DatasetGraphTxn dsgTxn2 = transaction.getTxnMgr().promote(dsgTxn, transaction.getTxnType(), promoteMode); if ( dsgTxn2 == null ) return false; dsgtxn.set(dsgTxn2) ; return true; }
@Override public void leaveCriticalSection() { switch (state) { case TxNONE : throw new TDBTransactionException("Illegal state: "+state) ; case TxREAD : dsg.close() ; break ; case TxWRITE : dsg.commit() ; break ; } state = TxNONE ; }
private void noteTxnStart(Transaction transaction) { switch (transaction.getTxnMode()) { case READ : readerStarts(transaction) ; break ; case WRITE : writerStarts(transaction) ; break ; } transactionStarts(transaction) ; }
private void noteTxnAbort(Transaction transaction) { switch (transaction.getTxnMode()) { case READ : readerFinishes(transaction) ; break ; case WRITE : writerAborts(transaction) ; break ; } transactionFinishes(transaction) ; }
@Override public ReadWrite transactionMode() { checkNotClosed() ; if ( ! isInTransaction() ) return null; return dsgtxn.get().getTransaction().getTxnMode(); }
synchronized private DatasetGraphTxn promoteSync$(DatasetGraphTxn dsgtxn, TxnType originalTxnType) { Transaction txn = dsgtxn.getTransaction() ; // Writers may have happened between the first check of the active writers may have committed. if ( txn.getVersion() != version.get() ) { releaseWriterLock(); return null; } return promoteExec$(dsgtxn, originalTxnType); }
@Override public TxnType transactionType() { checkNotClosed() ; if ( ! isInTransaction() ) return null; return dsgtxn.get().getTransaction().getTxnType(); }
/** Highly risky! */ public void printJournal() { JournalControl.print(transactionManager.getJournal()); }
@Override public void endIterator(Iterator<?> iterator) { checkIfClosed() ; transaction.removeIterator(iterator) ; // Don't pass down the beginIterator call - we track and manage here, not lower down. //blockMgr.endIterator(iterator) ; }
synchronized public void closedown() { processDelayedReplayQueue(null) ; journal.close() ; }
@Override public void beginIterator(Iterator<?> iterator) { checkIfClosed() ; transaction.addIterator(iterator) ; // Don't pass down the beginIterator call - we track and manage here, not lower down. //blockMgr.beginIterator(iterator) ; }
private void prepare() { state = TxnState.PREPARING ; forAllComponents(x->x.commitPrepare(this)); }
/** Try to flush the delayed write queue - only happens if there are no active transactions */ synchronized public void flush() { processDelayedReplayQueue(null) ; }
/** Set, or reset, this BlockMgr. */ private void reset(Transaction txn, FileRef fileRef, BlockMgr underlyingBlockMgr) { this.fileRef = fileRef ; this.blockMgr = underlyingBlockMgr ; this.active = true ; clear(txn) ; }
@Test public void journal_02() { JournalEntry entry1 = new JournalEntry(JournalEntryType.Buffer, testRef, bb1) ; long x = journal.writeJournal(entry1) ; assertEquals(0, x) ; JournalEntry entry9 = journal.readJournal(x) ; assertTrue(equal(entry1, entry9)) ; }