⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basepage.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		// first copy num_rows into destination page		dpage.copyInto(this, src_slot, num_rows, dest_slot);		// Now purge num_rows from this page		// Do NOT purge overflow rows, if it has such a thing.  This operation		// is called by split and if the key has overflow, spliting the head		// page does not copy over the remaining pieces, i.e.,the new head page		// still points to those pieces.		owner.getActionSet().actionPurge(            t, this, src_slot, num_rows, recordIds, true);	}	/**		Unlatch the page.		@see Page#unlatch	*/	public void unlatch() {		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched());		}	   releaseExclusive();	}	/** @see Page#isLatched */	public boolean isLatched() {		if (SanityManager.DEBUG) {			synchronized(this)			{				SanityManager.ASSERT(identity != null);				if (owner != null) {					if (owner != myLatch.getQualifier())						SanityManager.THROWASSERT("Page incorrectly latched - " + owner + " " + myLatch.getQualifier());				}			}		}		return owner != null;	}	/** @see Page#recordCount */	public final int recordCount() {		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched());		}		return recordCount;	}	/**		get record count without checking for latch	*/	protected abstract int internalDeletedRecordCount();	/**		get record count without checking for latch	*/	protected int internalNonDeletedRecordCount()	{		// deallocated or freed page, don't count		if (pageStatus != VALID_PAGE)			return 0;		int deletedCount = internalDeletedRecordCount();		if (deletedCount == -1) {			int count = 0;			int	maxSlot = recordCount;			for (int slot = FIRST_SLOT_NUMBER ; slot < maxSlot; slot++) {				if (!isDeletedOnPage(slot))					count++;			}			return count;		} else  {			if (SanityManager.DEBUG) {				int delCount = 0;				int	maxSlot = recordCount;				for (int slot = FIRST_SLOT_NUMBER ; slot < maxSlot; slot++) {					if (recordHeaderOnDemand(slot).isDeleted())						delCount++;				}				if (delCount != deletedCount)					SanityManager.THROWASSERT("incorrect deleted row count.  Should be: "						+ delCount + ", instead got: " + deletedCount						+ ", maxSlot = " + maxSlot + ", recordCount = " + recordCount);			}			return (recordCount - deletedCount);		}	}	/** @see Page#nonDeletedRecordCount */	public int nonDeletedRecordCount() {		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched());		}		return internalNonDeletedRecordCount();	}	// no need to check for slot on page, call already checked	protected final boolean isDeletedOnPage(int slot)	{		return getHeaderAtSlot(slot).isDeleted();	}	/** @see Page#isDeletedAtSlot		@exception StandardException Standard exception policy. 	 */	public boolean isDeletedAtSlot(int slot)		 throws StandardException	{		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched());		}		checkSlotOnPage(slot);		return isDeletedOnPage(slot);	}	/**		Set the aux object.		<BR> MT - single thread required. Calls via the Page interface will have the			page latched, thus providing single threadedness. Otherwise calls via this class			are only made when the class has no-identity, thus only a single thread can see the object. 		@see Page#setAuxObject	*/	public void setAuxObject(AuxObject obj)	{		if (SanityManager.DEBUG) {			SanityManager.ASSERT((identity == null) || isLatched());		}		if (auxObj != null) {			auxObj.auxObjectInvalidated();		}		auxObj = obj;	}	/**		Get the aux object.		<BR> MT - latched - It is required the caller throws away the returned reference		when the page is unlatched.		@see Page#getAuxObject	*/	public AuxObject getAuxObject()	{		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched());		}		return auxObj;	}	/*	** Methods from Lockable, just require a single exclusive locker	*/	/**		Latch me.		<BR>		MT - single thread required (methods of Lockable)		@see Lockable#lockEvent	*/	public void lockEvent(Latch lockInfo) {		if (SanityManager.DEBUG) {			SanityManager.ASSERT(owner == null, "Should only be called when not locked");		}		synchronized (this) {			myLatch = lockInfo;            // Move page state from UNLATCHED to PRELATCH, setExclusiveNo*()            // routines do the work of completing the latch - using the             // preLatch status.  This is so that            // we don't have to wait for a clean() initiated I/O here while            // holding the locking system monitor.			(owner = (BaseContainerHandle) lockInfo.getQualifier()).addObserver(this);            preLatch = true;		}	}	/**		Is another request compatible, no never.		<BR> MT - single thread required (methods of Lockable)		@see Lockable#requestCompatible	*/	public boolean requestCompatible(Object requestedQualifier, Object grantedQualifier) {		if (SanityManager.DEBUG) {			SanityManager.ASSERT(owner != null, "Should only be called when locked");		}		return false;	}	/**		Is another request compatible, no never.		<BR> MT - single thread required (methods of Lockable)		@see Lockable#requestCompatible	*/	public boolean lockerAlwaysCompatible() {		if (SanityManager.DEBUG) {			SanityManager.ASSERT(owner != null, "Should only be called when locked");		}		return false;	}	/**		Unlatch me, only to be called from lock manager.		<BR> MT - single thread required (methods of Lockable)		@see Lockable#requestCompatible	*/	public void unlockEvent(Latch lockInfo) {		if (SanityManager.DEBUG) {			SanityManager.ASSERT(owner != null, "Should only be called when locked");		}		synchronized (this) {			if (SanityManager.DEBUG) {				if (nestedLatch != 0)					SanityManager.THROWASSERT("nestedLatch is non-zero on unlockEvent - value = " + nestedLatch);			}			owner.deleteObserver(this);			owner = null;			myLatch = null;			if (inClean)				notifyAll();		}	}	/*	** Methods of Observer.	*/	/**		This object is set to observe the BaseContainerHandle it was obtained by,		that handle will notify its observers when it is being closed. In that case		we will release the latch on the page held by that container.		<BR>		MT - latched		@see Observer#update	*/	public void update(Observable obj, Object arg) {		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched());			SanityManager.ASSERT(obj == owner);		}		releaseExclusive();	}	/*	** Implementation specific methods	*/	/**		Get the Page identifer		<BR> MT - RESOLVE	*/	public PageKey getPageId() {		if (SanityManager.DEBUG) {			SanityManager.ASSERT(identity != null);		}		return identity;	}	/**		Get an exclusive latch on the page.		<BR>		MT - thread safe		@exception StandardException Standard Cloudscape policy.	*/	public void setExclusive(BaseContainerHandle requester) 		throws StandardException {		RawTransaction t = requester.getTransaction();		// In some cases latches are held until after a commit or an abort		// (currently internal and nested top transactions.		// If this is the case then during an abort a latch		// request will be made for a latch that is already held.		// We do not allow the latch to be obtained multiple times		// because i) lock manager might assume latches are exclusive for		// performance, ii) holding a page latched means that the page is		// on the container handle's obervers list, if we latched it twice		// then the paeg would have to be on the list twice, which is not supported		// since the page has value equality. To be on the list twice reference		// equality would be required, which would mean pushing a ReferenceObservable		// object for every latch; iii) other unknown reasons :-)		synchronized (this)		{			// need synchronized block because owner may be set to null in the			// middle if another thread is in the process of unlatching the			// page 			if ((owner != null) && (t == owner.getTransaction())) {				if (t.inAbort()) {					//					nestedLatch++;					return;				}			}			// just deadlock out ...		}		// Latch the page, owner is set through the Lockable call backs.		t.getLockFactory().latchObject(            t, this, requester, C_LockFactory.WAIT_FOREVER);		        // latch granted, but cleaner may "own" the page.  		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched(), "page not latched");		}        synchronized (this)        {            // lockEvent() will grant latch, even if cleaner "owns" the page.            // Wait here unil cleaner is done.  This is safe as now we own the            // latch, and have yet to do anything to the in-memory data             // structures.            //             // Previously we would wait in lockEvent, but that caused the code             // to block on I/O while holding the locking system monitor.            while (inClean)             {                try                 {                    // Expect notify from clean() routine.                    wait();                }                 catch (InterruptedException ie)                 {                }            }            // no clean taking place, so safe to move to full LATCHED state.            preLatch = false;        }	}	/**		Get an exclusive latch on the page, but only if I don't have to wait.		<BR>		MT - thread safe	*/	boolean setExclusiveNoWait(BaseContainerHandle requester) throws StandardException {		RawTransaction t = requester.getTransaction();		// comment in setExclusive()		synchronized (this)		{			if ((owner != null) && (t == owner.getTransaction())) {				if (t.inAbort()) {					//					nestedLatch++;					return true;				}			}			// just deadlock out ...		}		// Latch the page, owner is set through the Lockable call backs.		boolean gotLatch = t.getLockFactory().latchObject(t, this, requester, C_LockFactory.NO_WAIT);		if (!gotLatch)			return false;        synchronized (this)        {            // lockEvent() will grant latch, even if cleaner "owns" the page.            // Wait here unil cleaner is done.  This is safe as now we own the            // latch, and have yet to do anything to the in-memory data             // structures.            //             // Previously we would wait in lockEvent, but that caused the code             // to block on I/O while holding the locking system monitor.            while (inClean)             {                //if (SanityManager.DEBUG)                 //   SanityManager.DEBUG_PRINT("setExclusiveNoWait", "in while loop.");                try                 {                    // Expect notify from clean() routine.                    wait();                }                 catch (InterruptedException ie)                 {                }            }            // no clean taking place, so safe to move to full LATCHED state.            preLatch = false;        }		if (SanityManager.DEBUG) {			SanityManager.ASSERT(isLatched(), "page not latched");		}		return true;	}	/**		Release the exclusive latch on the page.		<BR>		MT - latched	*/	protected void releaseExclusive() /* throws StandardException */ {		if (SanityManager.DEBUG) {            if (!isLatched())            {                SanityManager.THROWASSERT(                    "releaseExclusive failed, nestedLatch = " + nestedLatch);            }		}		if (nestedLatch > 0) {			nestedLatch--;			return;		}		RawTransaction t = owner.getTransaction();		t.getLockFactory().unlatch(myLatch);	}	/*	** Manipulation of the in-memory version of the slot table.	*/	/**		Must be called by any non-abstract sub-class to initialise the slot		table.	*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -