📄 reclaimspacehelper.java
字号:
if (SanityManager.DEBUG) SanityManager.ASSERT(container_rlock != null); ContainerHandle containerHdl = openContainerNW(tran, container_rlock, work.getContainerId()); if (containerHdl == null) { tran.abort(); if (SanityManager.DEBUG) { if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace)) { SanityManager.DEBUG( DaemonService.DaemonTrace, " aborted " + work + " because container is locked or dropped"); } } if (work.incrAttempts() < 3) // retry this for serveral times return Serviceable.REQUEUE; else return Serviceable.DONE; } // At this point, container is opened with IX lock. if (work.reclaimWhat() == ReclaimSpace.PAGE) { // Reclaiming a page - called by undo of insert which purged the // last row off an overflow page. It is safe to reclaim the page // without first locking the head row because unlike post commit // work, this is post abort work. Abort is guarenteed to happen // and to happen only once, if at all. Page p = containerHdl.getPageNoWait(work.getPageId().getPageNumber()); if (p != null) containerHdl.removePage(p); tran.commit(); return Serviceable.DONE; } // We are reclaiming row space or long column. First get an xlock on the // head row piece. RecordHandle headRecord = work.getHeadRowHandle(); if (!container_rlock.lockRecordForWrite( tran, headRecord, false /* not insert */, false /* nowait */)) { // cannot get the row lock, retry tran.abort(); if (work.incrAttempts() < 3) return Serviceable.REQUEUE; else return Serviceable.DONE; } // The exclusive lock on the head row has been gotten. if (work.reclaimWhat() == ReclaimSpace.ROW_RESERVE) { // This row may benefit from compaction. containerHdl.compactRecord(headRecord); // This work is being done - post commit, there is no user // transaction that depends on the commit being sync'd. It is safe // to commitNoSync() This do as one of 2 things will happen: // // 1) if any data page associated with this transaction is // moved from cache to disk, then the transaction log // must be sync'd to the log record for that change and // all log records including the commit of this xact must // be sync'd before returning. // // 2) if the data page is never written then the log record // for the commit may never be written, and the xact will // never make to disk. This is ok as no subsequent action // depends on this operation being committed. // tran.commitNoSync(Transaction.RELEASE_LOCKS); return Serviceable.DONE; } else { if (SanityManager.DEBUG) SanityManager.ASSERT(work.reclaimWhat() == ReclaimSpace.COLUMN_CHAIN); // Reclaiming a long column chain due to update. The long column // chain being reclaimed is the before image of the update // operation. // long headPageId = ((PageKey)headRecord.getPageId()).getPageNumber(); StoredPage headRowPage = (StoredPage)containerHdl.getPageNoWait(headPageId); if (headRowPage == null) { // Cannot get page no wait, try again later. tran.abort(); if (work.incrAttempts() < 3) return Serviceable.REQUEUE; else return Serviceable.DONE; } try { headRowPage.removeOrphanedColumnChain(work, containerHdl); } finally { headRowPage.unlatch(); } // This work is being done - post commit, there is no user // transaction that depends on the commit being sync'd. It is safe // to commitNoSync() This do as one of 2 things will happen: // // 1) if any data page associated with this transaction is // moved from cache to disk, then the transaction log // must be sync'd to the log record for that change and // all log records including the commit of this xact must // be sync'd before returning. // // 2) if the data page is never written then the log record // for the commit may never be written, and the xact will // never make to disk. This is ok as no subsequent action // depends on this operation being committed. // tran.commitNoSync(Transaction.RELEASE_LOCKS); return Serviceable.DONE; } } private static int reclaimContainer(BaseDataFileFactory dataFactory, RawTransaction tran, ReclaimSpace work) throws StandardException { // when we want to reclaim the whole container, gets an exclusive // XLock on the container, wait for the lock. LockingPolicy container_xlock = tran.newLockingPolicy(LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_SERIALIZABLE, true /* stricter OK */ ); if (SanityManager.DEBUG) SanityManager.ASSERT(container_xlock != null); // Try to just get the container thru the transaction. // Need to do this to transition the transaction to active state. RawContainerHandle containerHdl = tran.openDroppedContainer( work.getContainerId(), container_xlock); // if it can get lock but it is not deleted or has already been // deleted, done work if (containerHdl == null || containerHdl.getContainerStatus() == RawContainerHandle.NORMAL || containerHdl.getContainerStatus() == RawContainerHandle.COMMITTED_DROP) { if (containerHdl != null) containerHdl.close(); tran.abort(); // release xlock, if any if (SanityManager.DEBUG) { if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace)) { SanityManager.DEBUG( DaemonService.DaemonTrace, " aborted " + work); } } } else { // we got an xlock on a dropped container. Must be committed. // Get rid of the container now. ContainerOperation lop = new ContainerOperation(containerHdl, ContainerOperation.REMOVE); // mark the container as pre-dirtied so that if a checkpoint // happens after the log record is sent to the log stream, the // cache cleaning will wait for this change. containerHdl.preDirty(true); try { tran.logAndDo(lop); } finally { // in case logAndDo fail, make sure the container is not // stuck in preDirty state. containerHdl.preDirty(false); } containerHdl.close(); tran.commit(); if (SanityManager.DEBUG) { if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace)) { SanityManager.DEBUG( DaemonService.DaemonTrace, " committed " + work); } } } return Serviceable.DONE; } /** Open container shared no wait */ private static ContainerHandle openContainerNW(Transaction tran, LockingPolicy rlock, ContainerKey containerId) throws StandardException { ContainerHandle containerHdl = tran.openContainer (containerId, rlock, ContainerHandle.MODE_FORUPDATE | ContainerHandle.MODE_LOCK_NOWAIT); return containerHdl; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -