private void checkValid() { if (!isValid) throw new TDBTransactionException("StoreConnection inValid (issued before a StoreConnection.release?)") ; }
private void releaseWriterLock() { int x = writerPermits.availablePermits() ; if ( x != 0 ) throw new TDBTransactionException("TransactionCoordinator: Probably mismatch of enableWriters/blockWriters calls") ; writerPermits.release() ; }
private boolean acquireWriterLock(boolean canBlock) { if ( ! canBlock ) return writerPermits.tryAcquire() ; try { writerPermits.acquire() ; return true; } catch (InterruptedException e) { throw new TDBTransactionException(e) ; } }
@Override public void commitPrepare(Transaction txn) { if ( ! inTransaction ) throw new TDBTransactionException("Not in a transaction for a commit to happen") ; transObjects.sync() ; }
@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 ; }
/** Get the current DatasetGraphTDB */ @Override public DatasetGraphTDB get() { if ( isInTransaction() ) { DatasetGraphTxn dsgTxn = dsgtxn.get() ; if ( dsgTxn == null ) throw new TDBTransactionException("In a transaction but no transactional DatasetGraph") ; return dsgTxn.getView() ; } if ( sConn.haveUsedInTransaction() ) throw new TDBTransactionException("Not in a transaction") ; // Never been used in a transaction - return underlying database for old // style (non-transactional) usage. return sConn.getBaseDataset() ; }
@Override public void enterCriticalSection(boolean readLockRequested) { if ( state != TxNONE ) throw new TDBTransactionException("Illegal state: "+state) ; if ( readLockRequested ) { state = TxREAD ; dsg.begin(ReadWrite.READ) ; } else { state = TxWRITE ; dsg.begin(ReadWrite.WRITE) ; } }
case WRITE : if ( state != TxnState.ACTIVE ) throw new TDBTransactionException("Transaction has already committed or aborted") ; try { forAllComponents(x->x.abort(this)) ; SystemTDB.errlog.warn("Exception during 'abort'", ex) ; throw new TDBTransactionException("Exception during abort - transaction did abort", ex) ; SystemTDB.errlog.warn("Exception during post-abort (transaction did abort)", ex) ; throw new TDBTransactionException("Exception after abort point - transaction did abort", ex) ;
throw new TDBTransactionException("Read off the end of a journal file") ; lenRead = channel.read(bb) ; if ( lenRead != len) throw new TDBTransactionException("Failed to read the journal entry: wanted "+len+" bytes, got "+lenRead) ; adler.update(bb.array()) ; bb.rewind() ; lenRead = channel.read(crcTrailer) ; if ( lenRead != SizeofCRC ) throw new TDBTransactionException("Failed to read block checksum (got "+lenRead+" bytes, not "+SizeofCRC+").") ; int checksum = Bytes.getInt(crcTrailer.array()) ; if ( checksum != (int)adler.getValue() ) throw new TDBTransactionException("Checksum error reading from the Journal.") ;
@Override public void enactCommitted(Transaction txn) { if ( ! inTransaction ) throw new TDBTransactionException("Not in a transaction for a commit to happen") ; append() ; base.sync() ; transObjects.reposition(0) ; }
case WRITE: if ( state != TxnState.ACTIVE ) throw new TDBTransactionException("Transaction has already committed or aborted") ; throw new TDBTransactionException("Abort during prepare - transaction did not commit", ex) ; else SystemTDB.errlog.warn("Exception during 'commit' : transaction status not known (but not a partial commit): ",ex) ; throw new TDBTransactionException("Exception at commit point", ex) ; else SystemTDB.errlog.warn("Exception during 'committed': "+ex.getMessage(), ex) ; throw new TDBTransactionException("Exception during 'committed' - transaction did commit", ex) ; else SystemTDB.errlog.warn("Exception after commit point : transaction commited but internal status not recorded properly", ex) ; throw new TDBTransactionException("Exception after commit point - transaction did commit", ex) ;
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 ; }
/** Stop managing a location. Use with great care (testing only). */ public static synchronized void expel(Location location, boolean force) { StoreConnection sConn = cache.get(location) ; if (sConn == null) return ; if (!force && sConn.transactionManager.activeTransactions()) throw new TDBTransactionException("Can't expel: Active transactions for location: " + location) ; // No transactions at this point (or we don't care and are clearing up forcefully.) sConn.transactionManager.closedown() ; sConn.baseDSG.close() ; sConn.isValid = false ; cache.remove(location) ; ChannelManager.release(sConn.transactionManager.getJournal().getFilename()) ; // Release the lock if (SystemTDB.DiskLocationMultiJvmUsagePrevention) { if (location.getLock().isOwned()) { location.getLock().release(); } else if (location.getLock().canLock()) { SystemTDB.errlog.warn("Location " + location.getDirectoryPath() + " was not locked, if another JVM accessed this location simultaneously data corruption may have occurred"); } } }
Transaction txn = dsgtxn.getTransaction() ; if ( txn.getState() != TxnState.ACTIVE ) throw new TDBTransactionException("promote: transaction is not active") ; if ( txn.getTxnMode() == ReadWrite.WRITE ) return dsgtxn ;