/*package*/ void setActiveDataset(DatasetGraphTxn activedsg) { this.activedsg = activedsg ; if ( activedsg.getTransaction() != this ) Log.warn(this, "Active DSG does not point to this transaction; "+this) ; }
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 ; }
@Override public TxnType transactionType() { checkNotClosed() ; if ( ! isInTransaction() ) return null; return dsgtxn.get().getTransaction().getTxnType(); }
@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 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 DatasetGraph getW() { if ( isInTransaction() ) { DatasetGraphTxn dsgTxn = dsgtxn.get() ; if ( dsgTxn.getTransaction().isRead() ) { TxnType txnType = dsgTxn.getTransaction().getTxnType(); Promote mode; switch(txnType) { TransactionManager txnMgr = dsgTxn.getTransaction().getTxnMgr() ; DatasetGraphTxn dsgTxn2 = txnMgr.promote(dsgTxn, txnType, mode) ; if ( dsgTxn2 == null )
synchronized private DatasetGraphTxn begin$(TxnType txnType, TxnType originalTxnType, String label) { Objects.requireNonNull(txnType); if ( txnType == TxnType.WRITE && activeWriters.get() > 0 ) // Guard throw new TDBTransactionException("Existing active write transaction") ; if ( DEBUG ) switch ( txnType ) { case READ : System.out.print("r") ; break ; case WRITE : System.out.print("w") ; break ; case READ_COMMITTED_PROMOTE : System.out.print("r(cp)") ; break ; case READ_PROMOTE : System.out.print("rp") ; break ; } DatasetGraphTDB dsg = determineBaseDataset() ; Transaction txn = createTransaction(dsg, txnType, originalTxnType, label) ; log("begin$", txn) ; ReadWrite mode = initialMode(txnType); DatasetGraphTxn dsgTxn = createDSGTxn(dsg, txn, mode); txn.setActiveDataset(dsgTxn) ; dsgTxn.getTransaction().forAllComponents(component->component.begin(dsgTxn.getTransaction())) ; return dsgTxn ; }
private DatasetGraphTxn beginInternal(TxnType txnType, TxnType originalTxnType, String label) { // The exclusivitylock surrounds the entire transaction cycle. // Paired with notifyCommit, notifyAbort. startNonExclusive(); // Not synchronized (else blocking on semaphore will never wake up // because Semaphore.release is inside synchronized). // Allow only one active writer. if ( txnType == TxnType.WRITE ) { // Writers take a WRITE permit from the semaphore to ensure there // is at most one active writer, else the attempt to start the // transaction blocks. acquireWriterLock(true) ; } // entry synchronized part DatasetGraphTxn dsgtxn = begin$(txnType, originalTxnType, label) ; noteTxnStart(dsgtxn.getTransaction()) ; return dsgtxn; }
Transaction txn = dsgtxn.getTransaction() ; if ( txn.getState() != TxnState.ACTIVE ) throw new TDBTransactionException("promote: transaction is not active") ;