TransactionManager getTxnMgr() throws IOException { if ( transactionsDisabled ) { throw new IllegalStateException( "Transactions are disabled." ); } if ( transactionManager == null ) { transactionManager = new TransactionManager( this ); } return transactionManager; }
/** * Use the disk-based transaction log to synchronize the data file. * Outstanding memory logs are discarded because they are believed * to be inconsistent. */ void synchronizeLogFromDisk() throws IOException { close(); for ( int i=0; i < _maxTxns; i++ ) { if (txns[i] == null) continue; discardBlocks(txns[i]); txns[i] = null; } recover(); open(); }
/** * Force closing the file and underlying transaction manager. * Used for testing purposed only. */ void forceClose() throws IOException { txnMgr.forceClose(); file.close(); }
/** * Shutdowns the transaction manager. Resynchronizes outstanding * logs. */ void shutdown() throws IOException { synchronizeLogFromMemory(); close(); }
/** Synchs in-core transactions to data file and opens a fresh log */ private void synchronizeLogFromMemory() throws IOException { close(); TreeSet<BlockIo> blockList = new TreeSet<BlockIo>( new BlockIoComparator() ); int numBlocks = 0; int writtenBlocks = 0; for (int i = 0; i < _maxTxns; i++) { if (txns[i] == null) continue; // Add each block to the blockList, replacing the old copy of this // block if necessary, thus avoiding writing the same block twice for (Iterator<BlockIo> k = txns[i].iterator(); k.hasNext(); ) { BlockIo block = k.next(); if ( blockList.contains( block ) ) { block.decrementTransactionCount(); } else { writtenBlocks++; boolean result = blockList.add( block ); } numBlocks++; } txns[i] = null; } // Write the blocks from the blockList to disk synchronizeBlocks(blockList, true); owner.sync(); open(); }
/** * Commits the transaction to the log file. */ void commit() throws IOException { oos.writeObject(txns[curTxn]); sync(); // set clean flag to indicate blocks have been written to log setClean(txns[curTxn]); // reset ObjectOutputStream in order to store // newer states of BlockIo oos = new ObjectOutputStream(fos); oos.reset(); }
String logName = makeLogName(); File logFile = new File(logName); if (!logFile.exists()) synchronizeBlocks(blocks, false);
/** Opens the log file */ private void open() throws IOException { fos = new FileOutputStream(makeLogName()); oos = new DataOutputStream(new BufferedOutputStream(fos)); oos.writeShort(Magic.LOGFILE_HEADER); oos.flush(); curTxn = -1; }
/** Synchs in-core transactions to data file and opens a fresh log */ private void synchronizeLogFromMemory() throws IOException { close(); TreeSet blockList = new TreeSet( new BlockIoComparator() ); for ( int i = 0; i < _maxTxns; i++ ) { if ( txns[i] == null ) continue; // Add each block to the blockList, replacing the old copy of this // block if necessary, thus avoiding writing the same block twice for ( Iterator k = txns[i].iterator(); k.hasNext(); ) { BlockIo block = ( BlockIo ) k.next(); if ( blockList.contains( block ) ) { block.decrementTransactionCount(); } else { blockList.add( block ); } } txns[i] = null; } // Write the blocks from the blockList to disk synchronizeBlocks( blockList.iterator(), true ); owner.sync(); open(); }
/** * Shutdowns the transaction manager. Resynchronizes outstanding * logs. */ void shutdown() throws IOException { synchronizeLogFromMemory(); close(); }
/** * Commits the transaction to the log file. */ void commit() throws IOException { Serialization.writeObject(oos, txns[curTxn]); sync(); // set clean flag to indicate blocks have been written to log setClean(txns[curTxn]); // open a new ObjectOutputStream in order to store // newer states of BlockIo oos = new DataOutputStream(new BufferedOutputStream(fos)); }
String logName = makeLogName(); File logFile = new File(logName); if (!logFile.exists()) synchronizeBlocks(blocks.iterator(), false);
/** Opens the log file */ private void open() throws IOException { fos = new FileOutputStream(makeLogName()); oos = new ObjectOutputStream(fos); oos.writeShort(Magic.LOGFILE_HEADER); oos.flush(); curTxn = -1; }
/** * Use the disk-based transaction log to synchronize the data file. * Outstanding memory logs are discarded because they are believed * to be inconsistent. */ void synchronizeLogFromDisk() throws IOException { close(); for ( int i=0; i < _maxTxns; i++ ) { if (txns[i] == null) continue; discardBlocks(txns[i]); txns[i] = null; } recover(); open(); }
close(); synchronizeBlocks(blockList.iterator(), true); open();