1 21 22 package org.apache.derby.impl.store.access.btree.index; 23 24 import org.apache.derby.iapi.reference.SQLState; 25 26 import org.apache.derby.iapi.services.io.ArrayInputStream; 27 28 import org.apache.derby.iapi.services.sanity.SanityManager; 29 30 import org.apache.derby.iapi.services.io.Formatable; 31 import org.apache.derby.iapi.services.io.FormatIdUtil; 32 import org.apache.derby.iapi.services.io.StoredFormatIds; 33 import org.apache.derby.iapi.error.StandardException; 34 35 import org.apache.derby.iapi.store.access.conglomerate.LogicalUndo; 36 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager; 37 38 import org.apache.derby.iapi.store.access.RowUtil; 39 import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo; 40 import org.apache.derby.iapi.store.access.Qualifier; 41 import org.apache.derby.iapi.store.access.ScanController; 42 import org.apache.derby.iapi.store.access.TransactionController; 43 44 import org.apache.derby.iapi.store.raw.ContainerHandle; 45 import org.apache.derby.iapi.store.raw.FetchDescriptor; 46 import org.apache.derby.iapi.store.raw.LockingPolicy; 47 import org.apache.derby.iapi.store.raw.LogicalUndoable; 48 import org.apache.derby.iapi.store.raw.Page; 49 import org.apache.derby.iapi.store.raw.RecordHandle; 50 import org.apache.derby.iapi.store.raw.Transaction; 51 52 import org.apache.derby.iapi.types.DataValueDescriptor; 53 54 import org.apache.derby.impl.store.access.btree.BTree; 56 import org.apache.derby.impl.store.access.btree.BTreeLockingPolicy; 57 import org.apache.derby.impl.store.access.btree.ControlRow; 58 import org.apache.derby.impl.store.access.btree.OpenBTree; 59 import org.apache.derby.impl.store.access.btree.SearchParameters; 60 61 import java.io.ObjectInput ; 62 import java.io.IOException ; 63 import java.io.ObjectOutput ; 64 import org.apache.derby.iapi.services.io.LimitObjectInput; 65 66 import org.apache.derby.iapi.services.io.FormatableBitSet; 67 68 81 82 96 public class B2IUndo implements LogicalUndo, Formatable 97 { 98 117 public Page findUndo( 118 Transaction rawtran, 119 LogicalUndoable pageOp, 120 LimitObjectInput in) 121 throws StandardException, IOException 122 { 123 ControlRow root = null; 124 ControlRow control_row = null; 125 DataValueDescriptor[] logged_index_row_template = null; 126 DataValueDescriptor[] template = null; 127 Page ret_page = null; 128 ContainerHandle container = pageOp.getContainer(); 129 RecordHandle rechandle = pageOp.getRecordHandle(); 130 boolean ok_exit = false; 131 int compare_result = 1; 132 B2I btree = null; 133 134 137 138 try 139 { 140 141 root = ControlRow.Get(container, BTree.ROOTPAGEID); 143 144 if (SanityManager.DEBUG) 145 SanityManager.ASSERT(root.getPage().isLatched()); 146 147 btree = (B2I) root.getConglom(B2I.FORMAT_NUMBER); 148 149 if (SanityManager.DEBUG) 150 SanityManager.ASSERT(btree instanceof B2I); 151 152 logged_index_row_template = btree.createTemplate(); 154 155 template = btree.createTemplate(); 157 } 158 finally 159 { 160 if (root != null) 161 root.release(); 162 } 163 164 pageOp.restoreLoggedRow(logged_index_row_template, in); 166 167 171 ok_exit = false; 172 try 173 { 174 OpenBTree open_btree = new OpenBTree(); 176 177 open_btree.init( 178 (TransactionManager) null, (TransactionManager) null, pageOp.getContainer(), rawtran, 182 false, 183 ContainerHandle.MODE_FORUPDATE, 184 TransactionManager.MODE_NONE, 187 (BTreeLockingPolicy) null, btree, 189 (LogicalUndo) null, (DynamicCompiledOpenConglomInfo) null); 192 193 198 control_row = ControlRow.Get(open_btree, rechandle.getPageNumber()); 201 202 compare_result = 1; 204 205 if (control_row.getPage().recordExists(rechandle, true)) 206 { 207 208 if (SanityManager.DEBUG) 209 { 210 SanityManager.ASSERT( 211 control_row.getPage().fetchNumFields(rechandle) == 212 logged_index_row_template.length); 213 } 214 215 RecordHandle ret_rechandle = 217 control_row.getPage().fetchFromSlot( 218 (RecordHandle) null, 219 control_row.getPage().getSlotNumber(rechandle), 220 template, 221 (FetchDescriptor) null, 222 true); 223 224 compare_result = ControlRow.CompareIndexRowToKey( 228 template, logged_index_row_template, 229 logged_index_row_template.length, 1, 230 open_btree.getColumnSortOrderInfo()); 231 } 232 233 if (compare_result == 0) 234 { 235 ret_page = control_row.getPage(); 236 } 237 else 238 { 239 243 SearchParameters sp = new SearchParameters( 245 logged_index_row_template, ScanController.GE, 246 template, open_btree, false); 247 248 control_row.release(); 249 control_row = null; 250 control_row = 251 ControlRow.Get(open_btree, BTree.ROOTPAGEID).search(sp); 252 253 if (!sp.resultExact) 254 { 255 if (SanityManager.DEBUG) 256 { 257 SanityManager.THROWASSERT( 258 "B2IUndo - could not find key being searched for:" + 259 ";key = " + 260 RowUtil.toString(logged_index_row_template) + 261 ";sp = " + sp + 262 "control_row = " + control_row + 263 "control_row.debugPage() = " + 264 control_row.debugPage(open_btree) + 265 "control_row.getPage() = " + 266 control_row.getPage()); 267 } 268 269 throw StandardException.newException( 270 SQLState.BTREE_ROW_NOT_FOUND_DURING_UNDO); 271 } 272 else 273 { 274 RecordHandle rh = 275 control_row.getPage().fetchFromSlot( 276 (RecordHandle) null, 277 sp.resultSlot, new DataValueDescriptor[0], 278 (FetchDescriptor) null, 279 true); 280 281 pageOp.resetRecordHandle(rh); 282 283 ret_page = control_row.getPage(); 284 } 285 } 286 ok_exit = true; 287 } 288 finally 289 { 290 if ((!ok_exit) && (control_row != null)) 293 control_row.release(); 294 } 295 296 return(ret_page); 297 } 298 299 304 public int getTypeFormatId() 305 { 306 return StoredFormatIds.ACCESS_B2IUNDO_V1_ID; 307 } 308 309 311 312 public void writeExternal(ObjectOutput out) throws IOException 313 { 314 return; 315 } 316 317 326 public void readExternal(ObjectInput in) 327 throws IOException , ClassNotFoundException 328 { 329 return; 330 } 331 public void readExternal(ArrayInputStream in) 332 throws IOException , ClassNotFoundException 333 { 334 return; 335 } 336 } 337 | Popular Tags |