Mercurial > hg > blitz_condensed
diff src/org/dancres/blitz/txn/PersistentReboot.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/dancres/blitz/txn/PersistentReboot.java Sat Mar 21 11:00:06 2009 +0000 @@ -0,0 +1,79 @@ +package org.dancres.blitz.txn; + +import java.util.logging.Level; + +import org.dancres.blitz.meta.Registry; +import org.dancres.blitz.meta.RegistryFactory; + +import org.dancres.blitz.config.PersistentBase; + +import org.dancres.blitz.BootContext; + +import org.dancres.blitz.disk.DiskTxn; + +/** + Certain steps need to be carried out as part of a reboot of a persistent + (normal or time-barrier) instance of Blitz. Those steps are the + responsibility of this class. + */ +class PersistentReboot { + private static final String BOOT_STATE = "BootState"; + + private static final byte[] MAX_LOGS_KEY = {0x00, 0x00, 0x00, 0x01}; + + private PersistentBase theBaseStorageModel; + + PersistentReboot(PersistentBase aBaseModel) { + theBaseStorageModel = aBaseModel; + } + + public void execute() throws Exception { + int myCurrentMaxLogsBeforeSync = + theBaseStorageModel.getMaxLogsBeforeSync(); + + Registry myRegistry = RegistryFactory.get(BOOT_STATE, null); + + UnsyncdOps myBarrier = null; + + // Recover the old barrier information and use that for BootContext + // + DiskTxn myTxn = DiskTxn.newTxn(); + + try { + myBarrier = (UnsyncdOps) + myRegistry.getAccessor().load(MAX_LOGS_KEY); + + if (myBarrier != null) { + TxnManager.theLogger.log(Level.INFO, + "Restoring UnsyncdOps state: " + + myBarrier.getOpsSinceLastCheckpoint()); + + BootContext.add(myBarrier); + } + } finally { + myTxn.commit(); + } + + // Update recovery barrier - this can only ever increase, we can't + // decrease it due to recovery constraints + // + if ((myBarrier == null) || + (myCurrentMaxLogsBeforeSync > + myBarrier.getOpsSinceLastCheckpoint())) { + + // System.err.println("Updating UnsyncdOps to: " + + // myCurrentMaxLogsBeforeSync); + + myTxn = DiskTxn.newTxn(); + + try { + myRegistry.getAccessor().save(MAX_LOGS_KEY, + new UnsyncdOps(myCurrentMaxLogsBeforeSync)); + } finally { + myTxn.commit(); + } + } + + myRegistry.close(); + } +}