📄 heappostcommit.java
字号:
/* Derby - Class org.apache.derby.impl.store.access.heap.HeapPostCommit Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.impl.store.access.heap;import org.apache.derby.iapi.services.context.ContextManager;import org.apache.derby.iapi.services.daemon.Serviceable;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;import org.apache.derby.iapi.store.access.AccessFactory;import org.apache.derby.iapi.store.access.AccessFactoryGlobals;import org.apache.derby.iapi.store.access.ConglomerateController;import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;import org.apache.derby.iapi.store.access.Qualifier;import org.apache.derby.iapi.store.access.RowUtil;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.store.raw.ContainerHandle;import org.apache.derby.iapi.store.raw.FetchDescriptor;import org.apache.derby.iapi.store.raw.LockingPolicy;import org.apache.derby.iapi.store.raw.Page;import org.apache.derby.iapi.store.raw.RecordHandle;import org.apache.derby.iapi.store.raw.Transaction;import org.apache.derby.iapi.reference.SQLState;/**The HeapPostCommit class implements the Serviceable protocol. In it's role as a Serviceable object, it stores the state necessary to find a page in a heap that may have committed delete's to reclaim.It looks up the page described, and reclaims space in the conglomerate. It first trys to clean up any deleted commits on the page. It will then deallocate the page if no rows remain on the page. All work is done whileholding the latch on the page, and locks are never "waited" on while holdingthis latch.This implementation uses record level locking to reclaim the space. For the protocols to work correctly all other heap methods must be prepared for a record or a page to "disappear" if they don't hold a latch and/ora lock. An example of the problem case is a scan which does not hold lockson it's current position (group scan works this way), which is positionedon a row deleted by another xact, it must be prepared to continue the scan after getting an error if the current page/row disapppears.**/class HeapPostCommit implements Serviceable{ /************************************************************************** * Fields of the class ************************************************************************** */ private AccessFactory access_factory = null; private Heap heap = null; private long page_number = ContainerHandle.INVALID_PAGE_NUMBER; /************************************************************************** * Constructors for This class: ************************************************************************** */ HeapPostCommit( AccessFactory access_factory, Heap heap, long input_page_number) { this.access_factory = access_factory; this.heap = heap; this.page_number = input_page_number; } /************************************************************************** * Private/Protected methods of This class: ************************************************************************** */ /** * Reclaim space taken up by committed deleted rows. * <p> * This routine assumes it has been called by an internal transaction which * has performed no work so far, and that it has an exclusive intent table * lock. It will attempt obtain exclusive row locks on deleted rows, where * successful those rows can be reclaimed as they must be "committed * deleted" rows. * <p> * This routine will latch the page and hold the latch due to interface * requirement from Page.purgeAtSlot. * * @param heap_control The heap, already opened. * @param pageno number of page to look for committed deletes. * * @see Page#purgeAtSlot * @exception StandardException Standard exception policy. **/ private final void purgeCommittedDeletes( HeapController heap_control, long pageno) throws StandardException { // The following can fail either if it can't get the latch or // somehow the page requested no longer exists. //resolve - what will happen if the user page doesnt exist // wait to get the latch on the page Page page = heap_control.getUserPageWait(pageno); boolean purgingDone = false; if (page != null) { try { // The number records that can be reclaimed is: // total recs - recs_not_deleted int num_possible_commit_delete = page.recordCount() - page.nonDeletedRecordCount(); if (num_possible_commit_delete > 0) { // loop backward so that purges which affect the slot table // don't affect the loop (ie. they only move records we // have already looked at). for (int slot_no = page.recordCount() - 1; slot_no >= 0; slot_no--) { boolean row_is_committed_delete = page.isDeletedAtSlot(slot_no); if (row_is_committed_delete) { // At this point we only know that the row is // deleted, not whether it is committed. // see if we can purge the row, by getting an // exclusive lock on the row. If it is marked // deleted and we can get this lock, then it // must be a committed delete and we can purge // it. RecordHandle rh = page.fetchFromSlot( (RecordHandle) null, slot_no, RowUtil.EMPTY_ROW, RowUtil.EMPTY_ROW_FETCH_DESCRIPTOR, true); row_is_committed_delete = heap_control.lockRowAtSlotNoWaitExclusive(rh); if (row_is_committed_delete) { purgingDone = true; page.purgeAtSlot(slot_no, 1, false); if (SanityManager.DEBUG) { if (SanityManager.DEBUG_ON( "verbose_heap_post_commit")) { SanityManager.DEBUG_PRINT( "HeapPostCommit", "Purging row[" + slot_no + "]" + "on page:" + pageno + ".\n"); } } } } } } if (page.recordCount() == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -