Mercurial > hg > blitz_condensed
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.blitz.txn; | |
2 | |
3 import java.util.logging.Level; | |
4 | |
5 import org.dancres.blitz.meta.Registry; | |
6 import org.dancres.blitz.meta.RegistryFactory; | |
7 | |
8 import org.dancres.blitz.config.PersistentBase; | |
9 | |
10 import org.dancres.blitz.BootContext; | |
11 | |
12 import org.dancres.blitz.disk.DiskTxn; | |
13 | |
14 /** | |
15 Certain steps need to be carried out as part of a reboot of a persistent | |
16 (normal or time-barrier) instance of Blitz. Those steps are the | |
17 responsibility of this class. | |
18 */ | |
19 class PersistentReboot { | |
20 private static final String BOOT_STATE = "BootState"; | |
21 | |
22 private static final byte[] MAX_LOGS_KEY = {0x00, 0x00, 0x00, 0x01}; | |
23 | |
24 private PersistentBase theBaseStorageModel; | |
25 | |
26 PersistentReboot(PersistentBase aBaseModel) { | |
27 theBaseStorageModel = aBaseModel; | |
28 } | |
29 | |
30 public void execute() throws Exception { | |
31 int myCurrentMaxLogsBeforeSync = | |
32 theBaseStorageModel.getMaxLogsBeforeSync(); | |
33 | |
34 Registry myRegistry = RegistryFactory.get(BOOT_STATE, null); | |
35 | |
36 UnsyncdOps myBarrier = null; | |
37 | |
38 // Recover the old barrier information and use that for BootContext | |
39 // | |
40 DiskTxn myTxn = DiskTxn.newTxn(); | |
41 | |
42 try { | |
43 myBarrier = (UnsyncdOps) | |
44 myRegistry.getAccessor().load(MAX_LOGS_KEY); | |
45 | |
46 if (myBarrier != null) { | |
47 TxnManager.theLogger.log(Level.INFO, | |
48 "Restoring UnsyncdOps state: " + | |
49 myBarrier.getOpsSinceLastCheckpoint()); | |
50 | |
51 BootContext.add(myBarrier); | |
52 } | |
53 } finally { | |
54 myTxn.commit(); | |
55 } | |
56 | |
57 // Update recovery barrier - this can only ever increase, we can't | |
58 // decrease it due to recovery constraints | |
59 // | |
60 if ((myBarrier == null) || | |
61 (myCurrentMaxLogsBeforeSync > | |
62 myBarrier.getOpsSinceLastCheckpoint())) { | |
63 | |
64 // System.err.println("Updating UnsyncdOps to: " + | |
65 // myCurrentMaxLogsBeforeSync); | |
66 | |
67 myTxn = DiskTxn.newTxn(); | |
68 | |
69 try { | |
70 myRegistry.getAccessor().save(MAX_LOGS_KEY, | |
71 new UnsyncdOps(myCurrentMaxLogsBeforeSync)); | |
72 } finally { | |
73 myTxn.commit(); | |
74 } | |
75 } | |
76 | |
77 myRegistry.close(); | |
78 } | |
79 } |