Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/entry/FindEntryOpInfo.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.entry; | |
2 | |
3 import java.io.IOException; | |
4 | |
5 import org.dancres.blitz.mangler.MangledEntry; | |
6 | |
7 import org.dancres.blitz.txn.TxnState; | |
8 | |
9 import org.dancres.blitz.oid.OID; | |
10 | |
11 import org.dancres.blitz.arc.CacheBlockDescriptor; | |
12 | |
13 class FindEntryOpInfo implements OpInfo { | |
14 static final long serialVersionUID = -7864125234426980910L; | |
15 | |
16 private boolean isTake; | |
17 private OID theOID; | |
18 private String theType; | |
19 | |
20 FindEntryOpInfo(String aType, OID aOID, boolean doTake) { | |
21 isTake = doTake; | |
22 theType = aType; | |
23 theOID = aOID; | |
24 } | |
25 | |
26 public boolean isDebugOp() { | |
27 // Find's are always non-null so never false though they can be aborted | |
28 // | |
29 return false; | |
30 } | |
31 | |
32 public void restore() throws IOException { | |
33 // Nothing to do - a previous write op info will restore the entry | |
34 // or it's already deleted in which case we'll find out at commit | |
35 } | |
36 | |
37 public MangledEntry commit(TxnState aState) throws IOException { | |
38 MangledEntry myEntry = null; | |
39 | |
40 EntryReposRecovery myRepos = | |
41 EntryRepositoryFactory.get().getAdmin(theType); | |
42 | |
43 // System.err.println("Looking for: " + theOID); | |
44 | |
45 CacheBlockDescriptor myCBD = myRepos.load(theOID); | |
46 | |
47 if (myCBD != null) { | |
48 // System.err.println("Got CBD: " + theOID); | |
49 | |
50 EntrySleeveImpl mySleeve = (EntrySleeveImpl) myCBD.getContent(); | |
51 | |
52 boolean isDeleted = mySleeve.getState().test(SleeveState.DELETED); | |
53 | |
54 if (isTake) { | |
55 // System.err.println("Deleted: " + theOID); | |
56 mySleeve.getState().set(SleeveState.DELETED); | |
57 mySleeve.markDirty(); | |
58 | |
59 /* | |
60 We could leave this dead entry sitting in cache and wait | |
61 for it to be aged out but it's better to force the state | |
62 to disk early so as to clean out the database. Of course, | |
63 we only do this for stuff that's come from disk - there's | |
64 no point in doing it for something that's never been on | |
65 disk. | |
66 | |
67 The net effect of this is to improve the ratio of live to | |
68 dead data on the disk in favour of liveness which has | |
69 benefits for out of cache searching by reducing the number | |
70 of disk blocks we scan and skip. | |
71 */ | |
72 if (! mySleeve.getState().test(SleeveState.NOT_ON_DISK)) { | |
73 // System.err.println("On disk - early flush: " + theOID); | |
74 myRepos.flush(myCBD); | |
75 } | |
76 } else { | |
77 if (!isDeleted) | |
78 myEntry = mySleeve.getEntry(); | |
79 } | |
80 | |
81 myCBD.release(); | |
82 | |
83 // Update counters outside lock | |
84 if (isTake) | |
85 myRepos.getCounters().didTake(); | |
86 else | |
87 myRepos.getCounters().didRead(); | |
88 } | |
89 | |
90 return myEntry; | |
91 } | |
92 | |
93 public MangledEntry abort(TxnState aState) throws IOException { | |
94 MangledEntry myEntry = null; | |
95 | |
96 EntryReposRecovery myRepos = | |
97 EntryRepositoryFactory.get().getAdmin(theType); | |
98 | |
99 CacheBlockDescriptor myCBD = myRepos.load(theOID); | |
100 | |
101 if (myCBD != null) { | |
102 | |
103 EntrySleeveImpl mySleeve = (EntrySleeveImpl) myCBD.getContent(); | |
104 | |
105 if (!mySleeve.getState().test(SleeveState.DELETED)) | |
106 myEntry = mySleeve.getEntry(); | |
107 | |
108 myCBD.release(); | |
109 } | |
110 | |
111 return myEntry; | |
112 } | |
113 | |
114 public OID getOID() { | |
115 return theOID; | |
116 } | |
117 | |
118 public String getType() { | |
119 return theType; | |
120 } | |
121 | |
122 public String toString() { | |
123 if (isTake) | |
124 return "T : " + theType + " : " + theOID; | |
125 else | |
126 return "R : " + theType + " : " + theOID; | |
127 } | |
128 } |