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.impl.store.raw.data.BasePage; 27 28 import org.apache.derby.iapi.store.raw.ContainerHandle; 29 import org.apache.derby.iapi.store.raw.LockingPolicy; 30 import org.apache.derby.iapi.store.raw.Loggable; 31 import org.apache.derby.iapi.store.raw.Page; 32 import org.apache.derby.iapi.store.raw.RePreparable; 33 import org.apache.derby.iapi.store.raw.Transaction; 34 import org.apache.derby.iapi.store.raw.PageKey; 35 36 import org.apache.derby.iapi.store.raw.xact.RawTransaction; 37 import org.apache.derby.iapi.store.raw.data.RawContainerHandle; 38 import org.apache.derby.iapi.store.raw.log.LogInstant; 39 import org.apache.derby.iapi.store.raw.RawStoreFactory; 40 41 import org.apache.derby.iapi.error.StandardException; 42 import org.apache.derby.iapi.services.sanity.SanityManager; 43 44 import org.apache.derby.iapi.types.DataValueDescriptor; 45 46 import org.apache.derby.iapi.services.io.CompressedNumber; 47 import org.apache.derby.iapi.util.ByteArray; 48 import org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream; 49 import org.apache.derby.iapi.services.property.PropertyUtil; 50 51 import java.io.InputStream ; 52 import java.io.ObjectOutput ; 53 import java.io.ObjectInput ; 54 import java.io.IOException ; 55 import org.apache.derby.iapi.services.io.LimitObjectInput; 56 57 81 82 public abstract class PageBasicOperation implements Loggable, RePreparable 83 { 84 85 86 87 private PageKey pageId; 88 private long pageVersion; 89 90 91 92 transient protected BasePage page; 93 transient protected RawContainerHandle containerHdl; 94 transient protected boolean foundHere; 95 96 protected PageBasicOperation(BasePage page) 97 { 98 if (SanityManager.DEBUG) 99 { 100 SanityManager.ASSERT( 101 page != null, 102 "cannot create page operation on a null page pointer"); 103 } 104 105 this.page = page; 107 108 pageId = page.getPageId(); 110 pageVersion = page.getPageVersion(); 111 } 112 113 public PageBasicOperation() 115 { 116 } 117 118 public String toString() 119 { 120 if (SanityManager.DEBUG) 121 { 122 return "Page Operation: " + pageId.toString() + 123 " pageVersion " + pageVersion + " : "; 124 } 125 else 126 return null; 127 } 128 129 132 133 134 public void writeExternal(ObjectOutput out) throws IOException 135 { 136 pageId.writeExternal(out); 137 CompressedNumber.writeLong(out, pageVersion); 138 } 139 140 public void readExternal(ObjectInput in) 141 throws IOException , ClassNotFoundException 142 { 143 pageId = PageKey.read(in); 144 145 pageVersion = CompressedNumber.readLong(in); 146 } 147 148 151 152 157 public final boolean needsRedo(Transaction xact) 158 throws StandardException 159 { 160 if (findpage(xact) == null) return false; 162 163 long pversion = page.getPageVersion(); 164 if (pversion == pageVersion) 165 return true; 166 167 releaseResource(xact); 168 169 if (pversion > pageVersion) 170 return false; 171 else 172 throw StandardException.newException( 173 SQLState.DATA_MISSING_LOG, pageId, 174 new Long (pversion), 175 new Long (pageVersion)); 176 } 177 178 188 public void releaseResource(Transaction xact) 189 { 190 if (!foundHere) return; 192 193 if (page != null) 194 { 195 page.unlatch(); 196 page = null; 197 } 198 199 if (containerHdl != null) 200 { 201 containerHdl.close(); 202 containerHdl = null; 203 } 204 205 foundHere = false; 206 } 207 208 211 public int group() 212 { 213 return(Loggable.RAWSTORE | Loggable.XA_NEEDLOCK); 214 } 215 216 225 public ByteArray getPreparedLog() throws StandardException 226 { 227 return (ByteArray) null; 228 } 229 230 234 235 241 public void reclaimPrepareLocks( 242 Transaction t, 243 LockingPolicy locking_policy) 244 throws StandardException 245 { 246 if (SanityManager.DEBUG) 247 SanityManager.DEBUG_PRINT("", "PageBasicOperation.reclaimPrepareLocks()."); 248 } 249 250 253 254 257 protected final void resetPageNumber(long pageNumber) 258 { 259 pageId = new PageKey(pageId.getContainerId(), pageNumber); 260 } 261 262 protected final PageKey getPageId() { 263 return pageId; 264 } 265 266 275 public final BasePage findpage(Transaction xact) throws StandardException 276 { 277 releaseResource(xact); 278 279 RawTransaction rtran = (RawTransaction)xact; 280 containerHdl = rtran.openDroppedContainer(pageId.getContainerId(), 281 (LockingPolicy) null); 282 283 if (containerHdl == null) 284 { 285 throw StandardException.newException( 286 SQLState.DATA_CONTAINER_VANISHED, pageId.getContainerId()); 287 } 288 289 foundHere = true; 290 291 if (containerHdl.getContainerStatus() == RawContainerHandle.COMMITTED_DROP) 294 { 295 releaseResource(xact); 296 return null; 297 } 298 299 StandardException getPageException = null; 300 try 301 { 302 page = (BasePage)(containerHdl.getAnyPage(pageId.getPageNumber())); 305 } 306 catch (StandardException se) 307 { 308 getPageException = se; 309 } 310 311 if (page == null && getPageException != null && pageVersion == 0) 315 if (PropertyUtil.getSystemBoolean(RawStoreFactory.PATCH_INITPAGE_RECOVER_ERROR)) 316 page = getPageForRedoRecovery(xact); 317 318 if (page == null && getPageException != null) 321 { 322 327 if (rtran.inRollForwardRecovery()) 328 { 329 if (SanityManager.DEBUG) 330 if(SanityManager.DEBUG_ON("LoadTran")) 331 SanityManager.DEBUG_PRINT( 332 "Trace", "got null page " + pageId + 333 " and getPageException, attempt last ditch effort"); 334 335 page = getPageForRedoRecovery(xact); 336 337 if (SanityManager.DEBUG) 338 if(SanityManager.DEBUG_ON("LoadTran")) 339 SanityManager.DEBUG_PRINT( 340 "Trace"," getPageForRedoRecovery, got page=" + 341 (page != null)); 342 } 343 } 344 345 if (page == null) 346 { 347 if (getPageException != null) 348 { 349 throw getPageException; } 351 else 352 { 353 throw StandardException.newException( 354 SQLState.DATA_MISSING_PAGE, pageId); 355 } 356 } 357 358 return page; 359 } 360 361 367 protected BasePage getPageForRedoRecovery(Transaction xact) 368 throws StandardException 369 { 370 return null; 371 } 372 373 public final Page getPage() { 374 return page; 375 } 376 377 public final long getPageVersion() { 378 return pageVersion; 379 } 380 381 382 402 abstract public void restoreMe(Transaction xact, BasePage undoPage, 403 LogInstant CLRinstant, LimitObjectInput in) 404 throws StandardException, IOException ; 405 406 407 } 408 | Popular Tags |