1 21 22 package org.apache.derby.impl.store.access.heap; 23 24 25 30 31 import org.apache.derby.iapi.reference.SQLState; 32 33 import org.apache.derby.iapi.services.sanity.SanityManager; 34 35 import org.apache.derby.iapi.services.io.Storable; 36 37 import org.apache.derby.iapi.error.StandardException; 38 39 import org.apache.derby.iapi.store.access.conglomerate.Conglomerate; 40 import org.apache.derby.iapi.store.access.conglomerate.LogicalUndo; 41 import org.apache.derby.iapi.store.access.conglomerate.ScanManager; 42 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager; 43 44 import org.apache.derby.iapi.store.access.ConglomerateController; 45 import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo; 46 import org.apache.derby.iapi.store.access.Qualifier; 47 import org.apache.derby.iapi.store.access.RowUtil; 48 import org.apache.derby.iapi.store.access.ScanInfo; 49 import org.apache.derby.iapi.store.access.ScanController; 50 import org.apache.derby.iapi.store.access.SpaceInfo; 51 import org.apache.derby.iapi.store.access.TransactionController; 52 53 import org.apache.derby.iapi.types.RowLocation; 54 55 import org.apache.derby.iapi.store.raw.ContainerHandle; 56 import org.apache.derby.iapi.store.raw.LockingPolicy; 57 import org.apache.derby.iapi.store.raw.Transaction; 58 import org.apache.derby.iapi.store.raw.Page; 59 import org.apache.derby.iapi.store.raw.RecordHandle; 60 61 import org.apache.derby.iapi.types.DataValueDescriptor; 62 63 import org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil; 64 import org.apache.derby.impl.store.access.conglomerate.GenericScanController; 65 import org.apache.derby.impl.store.access.conglomerate.RowPosition; 66 67 import org.apache.derby.iapi.store.access.BackingStoreHashtable; 68 import org.apache.derby.iapi.services.io.FormatableBitSet; 69 70 import java.util.Hashtable ; 71 import java.util.Vector ; 72 73 class HeapCompressScan 74 extends HeapScan 75 { 76 77 81 82 86 private long pagenum_to_start_moving_rows = -1; 87 88 89 90 94 95 99 100 public HeapCompressScan() 101 { 102 } 103 104 109 110 public int fetchNextGroup( 111 DataValueDescriptor[][] row_array, 112 RowLocation[] old_rowloc_array, 113 RowLocation[] new_rowloc_array) 114 throws StandardException 115 { 116 return(fetchRowsForCompress( 117 row_array, old_rowloc_array, new_rowloc_array)); 118 } 119 120 127 private int fetchRowsForCompress( 128 DataValueDescriptor[][] row_array, 129 RowLocation[] oldrowloc_array, 130 RowLocation[] newrowloc_array) 131 throws StandardException 132 { 133 int ret_row_count = 0; 134 DataValueDescriptor[] fetch_row = null; 135 136 if (SanityManager.DEBUG) 137 { 138 SanityManager.ASSERT(row_array != null); 139 SanityManager.ASSERT(row_array[0] != null, 140 "first array slot in fetchNextGroup() must be non-null."); 141 } 142 143 if (getScanState() == SCAN_INPROGRESS) 144 { 145 positionAtResumeScan(scan_position); 146 } 147 else if (getScanState() == SCAN_INIT) 148 { 149 SpaceInfo info = 154 open_conglom.getContainer().getSpaceInfo(); 155 156 pagenum_to_start_moving_rows = info.getNumAllocatedPages(); 157 158 positionAtStartForForwardScan(scan_position); 159 } 160 else if (getScanState() == SCAN_HOLD_INPROGRESS) 161 { 162 reopenAfterEndTransaction(); 163 164 if (SanityManager.DEBUG) 165 { 166 SanityManager.ASSERT( 167 scan_position.current_rh != null, this.toString()); 168 } 169 170 open_conglom.latchPageAndRepositionScan(scan_position); 176 177 setScanState(SCAN_INPROGRESS); 178 } 179 else if (getScanState() == SCAN_HOLD_INIT) 180 { 181 reopenAfterEndTransaction(); 182 183 positionAtStartForForwardScan(scan_position); 184 185 } 186 else 187 { 188 if (SanityManager.DEBUG) 189 SanityManager.ASSERT(getScanState() == SCAN_DONE); 190 191 return(0); 192 } 193 194 199 204 while (scan_position.current_page != null) 205 { 206 while ((scan_position.current_slot + 1) < 207 scan_position.current_page.recordCount()) 208 { 209 if (fetch_row == null) 211 { 212 if (row_array[ret_row_count] == null) 214 { 215 row_array[ret_row_count] = 216 open_conglom.getRuntimeMem().get_row_for_export(); 217 } 218 219 fetch_row = row_array[ret_row_count]; 220 } 221 222 scan_position.positionAtNextSlot(); 224 225 this.stat_numrows_visited++; 226 227 if (scan_position.current_page.isDeletedAtSlot( 228 scan_position.current_slot)) 229 { 230 scan_position.current_page.purgeAtSlot( 235 scan_position.current_slot, 1, false); 236 237 scan_position.positionAtPrevSlot(); 241 continue; 242 } 243 244 if (scan_position.current_page.getPageNumber() > 245 pagenum_to_start_moving_rows) 246 { 247 RecordHandle[] old_handle = new RecordHandle[1]; 249 RecordHandle[] new_handle = new RecordHandle[1]; 250 long[] new_pageno = new long[1]; 251 252 if (scan_position.current_page.moveRecordForCompressAtSlot( 253 scan_position.current_slot, 254 fetch_row, 255 old_handle, 256 new_handle) == 1) 257 { 258 scan_position.positionAtPrevSlot(); 264 265 ret_row_count++; 266 stat_numrows_qualified++; 267 268 269 setRowLocationArray( 270 oldrowloc_array, ret_row_count - 1, old_handle[0]); 271 setRowLocationArray( 272 newrowloc_array, ret_row_count - 1, new_handle[0]); 273 274 fetch_row = null; 275 276 } 277 } 278 } 279 280 this.stat_numpages_visited++; 281 282 if (scan_position.current_page.recordCount() == 0) 283 { 284 scan_position.current_pageno = 286 scan_position.current_page.getPageNumber(); 287 288 open_conglom.getContainer().removePage( 289 scan_position.current_page); 290 291 scan_position.current_page = null; 294 } 295 else 296 { 297 positionAfterThisPage(scan_position); 298 scan_position.unlatch(); 299 } 300 301 302 if (ret_row_count > 0) 303 { 304 return(ret_row_count); 307 } 308 else 309 { 310 319 positionAtResumeScan(scan_position); 320 321 } 322 } 323 324 positionAtDoneScan(scan_position); 326 327 this.stat_numpages_visited--; 329 330 return(ret_row_count); 331 } 332 333 345 protected void positionAtResumeScan( 346 RowPosition pos) 347 throws StandardException 348 { 349 open_conglom.latchPageAndRepositionScan(scan_position); 354 } 355 356 369 protected void positionAtStartForForwardScan( 370 RowPosition pos) 371 throws StandardException 372 { 373 if (pos.current_rh == null) 374 { 375 pos.current_page = 381 open_conglom.getContainer().getNextPage( 382 ContainerHandle.FIRST_PAGE_NUMBER); 383 384 pos.current_slot = Page.FIRST_SLOT_NUMBER - 1; 387 } 388 else 389 { 390 392 open_conglom.latchPageAndRepositionScan(pos); 397 398 pos.current_slot -= 1; 401 } 402 403 pos.current_rh = null; 404 this.stat_numpages_visited = 1; 405 this.setScanState(SCAN_INPROGRESS); 406 } 407 408 409 413 414 428 private void positionAfterThisPage( 429 RowPosition pos) 430 throws StandardException 431 { 432 pos.current_rh = null; 433 pos.current_pageno = pos.current_page.getPageNumber(); 434 } 435 436 439 440 } 441 | Popular Tags |