📄 heapcontroller.java
字号:
// pre-existing data with unlogged rows because nobody is going to wipe // out these rows if the transaction rolls back. We are counting on // the allocation page rollback to obliterate these rows if the // transaction fails, or, in the CREAT_UNLOGGED case, the whole // container to be removed. Page page = open_conglom.getContainer().addPage(); boolean callbackWithRowLocation = rowSource.needsRowLocation(); RecordHandle rh; HeapRowLocation rowlocation; if (callbackWithRowLocation) rowlocation = new HeapRowLocation(); else rowlocation = null; FormatableBitSet validColumns = rowSource.getValidColumns(); try { // get the next row and its valid columns from the rowSource DataValueDescriptor[] row; while ((row = rowSource.getNextRowFromRowSource()) != null) { num_rows_loaded++; if (SanityManager.DEBUG) { // Make sure valid columns are in the list. The RowUtil // call is too expensive to make in a released system for // every insert. int invalidColumn = RowUtil.columnOutOfRange( row, validColumns, heap.format_ids.length); if (invalidColumn >= 0) { throw(StandardException.newException( SQLState.HEAP_TEMPLATE_MISMATCH, new Long(invalidColumn), new Long(heap.format_ids.length))); } } // Insert it onto this page as long as it can fit more rows. if ((rh = page.insert( row, validColumns, Page.INSERT_DEFAULT, AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD)) == null) { // Insert faied, row did not fit. Get a new page. page.unlatch(); page = null; page = open_conglom.getContainer().addPage(); // RESOLVE (mikem) - no long rows yet so the following code // will get an exception from the raw store for a row that // does not fit on a page. // // Multi-thread considerations aside, the raw store will // guarantee that any size row will fit on an empty page. rh = page.insert( row, validColumns, Page.INSERT_OVERFLOW, AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD); } // Else, the row fit. If we are expected to call back with the // row location, do so. All the while keep the page latched // and go for the next row. if (callbackWithRowLocation) { rowlocation.setFrom(rh); rowSource.rowLocation(rowlocation); } } page.unlatch(); page = null; // Done with the container, now we need to flush it to disk since // it is unlogged. if (!heap.isTemporary()) open_conglom.getContainer().flushContainer(); } finally { // If an error happened here, don't bother flushing the // container since the changes should be rolled back anyhow. close(); } return(num_rows_loaded); } protected boolean lockRow( RecordHandle rh, int lock_oper, boolean wait, int lock_duration) throws StandardException { boolean ret_val; boolean forUpdate = ((ConglomerateController.LOCK_UPD & lock_oper) != 0); boolean forUpdateLock = ((ConglomerateController.LOCK_UPDATE_LOCKS & lock_oper) != 0); if (forUpdate && !forUpdateLock) { boolean forInsert = ((ConglomerateController.LOCK_INS & lock_oper) != 0); boolean forInsertPrevKey = ((ConglomerateController.LOCK_INS_PREVKEY & lock_oper) != 0); if (SanityManager.DEBUG) { SanityManager.ASSERT(!(forInsertPrevKey && forInsert)); } if (lock_duration == TransactionManager.LOCK_INSTANT_DURATION) { ret_val = open_conglom.getContainer().getLockingPolicy(). zeroDurationLockRecordForWrite( open_conglom.getRawTran(), rh, forInsertPrevKey, wait); } else { ret_val = open_conglom.getContainer().getLockingPolicy(). lockRecordForWrite( open_conglom.getRawTran(), rh, forInsert, wait); } } else { if (SanityManager.DEBUG) { SanityManager.ASSERT( (ConglomerateController.LOCK_INS & lock_oper) == 0); SanityManager.ASSERT( (ConglomerateController.LOCK_INS_PREVKEY & lock_oper) == 0); } ret_val = open_conglom.getContainer().getLockingPolicy().lockRecordForRead( open_conglom.getRawTran(), open_conglom.getContainer(), rh, wait, forUpdate); } return(ret_val); } protected Page getUserPageNoWait(long pageno) throws StandardException { return(open_conglom.getContainer().getUserPageNoWait(pageno)); } protected Page getUserPageWait(long pageno) throws StandardException { return(open_conglom.getContainer().getUserPageWait(pageno)); } protected boolean lockRowAtSlotNoWaitExclusive(RecordHandle rh) throws StandardException { return( open_conglom.getContainer().getLockingPolicy(). lockRecordForWrite( open_conglom.getRawTran(), rh, false, false)); } protected void removePage(Page page) throws StandardException { open_conglom.getContainer().removePage(page); } /************************************************************************** * Public Methods of This class: ************************************************************************** */ public int insert(DataValueDescriptor[] row) throws StandardException { if (open_conglom.isClosed()) { if (open_conglom.getHold()) { open_conglom.reopen(); } else { throw(StandardException.newException( SQLState.HEAP_IS_CLOSED, open_conglom.getConglomerate().getId())); } } doInsert(row); return(0); } public void insertAndFetchLocation( DataValueDescriptor[] row, RowLocation templateRowLocation) throws StandardException { if (open_conglom.isClosed()) { if (open_conglom.getHold()) { open_conglom.reopen(); } else { throw(StandardException.newException( SQLState.HEAP_IS_CLOSED, open_conglom.getConglomerate().getId())); } } RecordHandle rh = doInsert(row); if (SanityManager.DEBUG) { SanityManager.ASSERT( templateRowLocation instanceof HeapRowLocation); } HeapRowLocation hrl = (HeapRowLocation) templateRowLocation; hrl.setFrom(rh); } /** * Lock the given row location. * <p> * Should only be called by access. * <p> * This call can be made on a ConglomerateController that was opened * for locking only. * <p> * RESOLVE (mikem) - move this call to ConglomerateManager so it is * obvious that non-access clients should not call this. * * @return true if lock was granted, only can be false if wait was false. * * @param loc The "RowLocation" which describes the exact row to lock. * @param wait Should the lock call wait to be granted? * * @exception StandardException Standard exception policy. **/ public boolean lockRow( RowLocation loc, int lock_operation, boolean wait, int lock_duration) throws StandardException { RecordHandle rh = ((HeapRowLocation) loc).getRecordHandle( open_conglom.getContainer()); return(lockRow(rh, lock_operation, wait, lock_duration)); } /** * UnLock the given row location. * <p> * Should only be called by access. * <p> * This call can be made on a ConglomerateController that was opened * for locking only. * <p> * RESOLVE (mikem) - move this call to ConglomerateManager so it is * obvious that non-access clients should not call this. * * @param loc The "RowLocation" which describes the row to unlock. * @param forUpdate Row was previously Locked the record for read or update. * * @exception StandardException Standard exception policy. **/ public void unlockRowAfterRead( RowLocation loc, boolean forUpdate, boolean row_qualified) throws StandardException { RecordHandle rh = ((HeapRowLocation) loc).getRecordHandle( open_conglom.getContainer()); open_conglom.getContainer().getLockingPolicy(). unlockRecordAfterRead( open_conglom.getRawTran(), open_conglom.getContainer(), rh, open_conglom.isForUpdate(), row_qualified); } /** * Lock the given record id/page num pair. * <p> * Should only be called by access, to lock "special" locks formed from * the Recordhandle.* reserved constants for page specific locks. * <p> * This call can be made on a ConglomerateController that was opened * for locking only. * <p> * RESOLVE (mikem) - move this call to ConglomerateManager so it is * obvious that non-access clients should not call this. * * @return true if lock was granted, only can be false if wait was false. * * @param page_num Page number of row to lock. * @param record_id Record id of row on page_num to lock. * @param lock_operation Desc of what to lock for, ie. update, insert ... * @param wait Should the lock call wait to be granted? * * @exception StandardException Standard exception policy. **/ public boolean lockRow( long page_num, int record_id, int lock_operation, boolean wait, int lock_duration) throws StandardException { boolean ret_val; RecordHandle rh = open_conglom.getContainer().makeRecordHandle(page_num, record_id); return(lockRow(rh, lock_operation, wait, lock_duration)); } public RowLocation newRowLocationTemplate() throws StandardException { if (open_conglom.isClosed()) { if (open_conglom.getHold()) { open_conglom.reopen(); } else { throw(StandardException.newException( SQLState.HEAP_IS_CLOSED, open_conglom.getConglomerate().getId())); } } return new HeapRowLocation(); } /************************************************************************** * Public Methods of XXXX class: ************************************************************************** */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -