1 21 22 package org.apache.derby.impl.store.raw.data; 23 24 import org.apache.derby.iapi.reference.SQLState; 25 26 import org.apache.derby.iapi.store.raw.ContainerKey; 27 28 import org.apache.derby.iapi.store.raw.ContainerHandle; 29 import org.apache.derby.iapi.store.raw.Loggable; 30 import org.apache.derby.iapi.store.raw.LockingPolicy; 31 import org.apache.derby.iapi.store.raw.Transaction; 32 33 import org.apache.derby.iapi.store.raw.xact.RawTransaction; 34 import org.apache.derby.iapi.store.raw.data.RawContainerHandle; 35 36 import org.apache.derby.iapi.error.StandardException; 37 import org.apache.derby.iapi.services.sanity.SanityManager; 38 39 import org.apache.derby.iapi.services.io.CompressedNumber; 40 import org.apache.derby.iapi.util.ByteArray; 41 42 import java.io.OutputStream ; 43 import java.io.ObjectInput ; 44 import java.io.ObjectOutput ; 45 import java.io.IOException ; 46 47 51 52 public abstract class ContainerBasicOperation implements Loggable 53 { 54 55 private long containerVersion; 56 protected ContainerKey containerId; 57 58 transient protected RawContainerHandle containerHdl = null; 59 transient private boolean foundHere = false; 60 61 protected ContainerBasicOperation(RawContainerHandle hdl) throws StandardException 62 { 63 containerHdl = hdl; 64 containerId = hdl.getId(); 65 containerVersion = hdl.getContainerVersion(); 66 } 67 68 71 72 public ContainerBasicOperation() { super(); } 74 75 public void writeExternal(ObjectOutput out) throws IOException 76 { 77 containerId.writeExternal(out); 78 CompressedNumber.writeLong(out, containerVersion); 79 } 80 81 public void readExternal(ObjectInput in) 82 throws IOException , ClassNotFoundException 83 { 84 containerId = ContainerKey.read(in); 85 containerVersion = CompressedNumber.readLong(in); 86 } 87 88 89 92 93 100 public ByteArray getPreparedLog() 101 { 102 return (ByteArray) null; 103 } 104 105 public void releaseResource(Transaction tran) 106 { 107 if (!foundHere) 108 return; 109 110 if (containerHdl != null) 111 { 112 containerHdl.close(); 113 containerHdl = null; 114 } 115 116 foundHere = false; 117 } 118 119 122 public int group() 123 { 124 return Loggable.RAWSTORE; 125 } 126 127 130 131 139 protected RawContainerHandle findContainer(Transaction tran) 140 throws StandardException 141 { 142 releaseResource(tran); 143 144 RawTransaction rtran = (RawTransaction)tran; 145 containerHdl = rtran.openDroppedContainer( 146 containerId, (LockingPolicy) null); 147 148 if (rtran.inRollForwardRecovery()) 152 { 153 if (containerHdl == null) 154 { 155 if (SanityManager.DEBUG) 156 { 157 if(SanityManager.DEBUG_ON("LoadTran")) 158 { 159 SanityManager.DEBUG_PRINT( 160 "Trace", 161 "cannot find container " + containerId + 162 ", now attempt last ditch effort"); 163 } 164 } 165 166 167 containerHdl = findContainerForRedoRecovery(rtran); 168 169 if (SanityManager.DEBUG) 170 { 171 if(SanityManager.DEBUG_ON("LoadTran")) 172 { 173 SanityManager.DEBUG_PRINT("Trace", 174 " findContainerForRedoRecovery, got container=" + 175 (containerHdl != null)); 176 } 177 } 178 179 } 180 } 181 182 if (containerHdl == null) 183 { 184 throw StandardException.newException( 185 SQLState.DATA_CONTAINER_VANISHED, containerId); 186 } 187 188 foundHere = true; 189 return containerHdl; 190 } 191 192 199 protected RawContainerHandle findContainerForRedoRecovery( 200 RawTransaction tran) 201 throws StandardException 202 { 203 return null; 204 } 205 206 207 210 public boolean needsRedo(Transaction xact) 211 throws StandardException 212 { 213 findContainer(xact); 214 215 long cVersion = containerHdl.getContainerVersion(); 216 217 if (cVersion == containerVersion) 218 return true; 219 220 releaseResource(xact); 221 222 if (cVersion > containerVersion) 223 return false; 224 else 225 { 226 if (SanityManager.DEBUG) 228 { 229 SanityManager.THROWASSERT("log corrupted, missing log record: "+ 230 "log container version = " + 231 containerVersion + 232 " container header version " + cVersion); 233 } 234 return false; 235 } 236 } 237 238 239 public String toString() 240 { 241 if (SanityManager.DEBUG) 242 { 243 return "Space Operation: " + containerId ; 244 } 245 else 246 return null; 247 } 248 249 } 250 251 252 | Popular Tags |