db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r551933 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/store/raw/Page.java impl/store/access/btree/index/B2IRowLocking3.java impl/store/raw/data/BasePage.java
Date Fri, 29 Jun 2007 16:03:21 GMT
Author: kahatlen
Date: Fri Jun 29 09:03:21 2007
New Revision: 551933

URL: http://svn.apache.org/viewvc?view=rev&rev=551933
Log:
DERBY-2878 (partial) Scan protection handle could be cached in BasePage

This patch is the first step towards eliminating the allocation of
protection handles. It adds a method to Page/BasePage called
getProtectionRecordHandle(). This method creates a new record handle
if it hasn't been called before and returns a cached value
otherwise. B2IRowLocking3.lockScan() and lockScanForReclaimSpace()
have been modified to use the new method.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/Page.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLocking3.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BasePage.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/Page.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/Page.java?view=diff&rev=551933&r1=551932&r2=551933
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/Page.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/Page.java Fri Jun 29 09:03:21
2007
@@ -139,6 +139,14 @@
 	public RecordHandle getInvalidRecordHandle();
 
     /**
+     * Get a record id protection handle.
+     *
+     * @return a record id protection handle
+     * @see RecordHandle#RECORD_ID_PROTECTION_HANDLE
+     */
+    public RecordHandle getProtectionRecordHandle();
+
+    /**
      * Return a record handle for the given constant record id.
      * <p>
      * Return a record handle that doesn't represent a record but rather has 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLocking3.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLocking3.java?view=diff&rev=551933&r1=551932&r2=551933
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLocking3.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLocking3.java
Fri Jun 29 09:03:21 2007
@@ -665,8 +665,7 @@
         // The scan page lock is implemented as a row lock on the reserved
         // row id on the page (RecordHandle.RECORD_ID_PROTECTION_HANDLE).
         RecordHandle scan_lock_rh = 
-            current_leaf.getPage().makeRecordHandle(
-                RecordHandle.RECORD_ID_PROTECTION_HANDLE);
+            current_leaf.getPage().getProtectionRecordHandle();
 
         // First try to get the lock NOWAIT, while latch is held.
         boolean ret_status = 
@@ -730,8 +729,7 @@
         // The scan page lock is implemented as a row lock on the reserved
         // row id on the page (RecordHandle.RECORD_ID_PROTECTION_HANDLE).
         RecordHandle scan_lock_rh = 
-            current_leaf.getPage().makeRecordHandle(
-                RecordHandle.RECORD_ID_PROTECTION_HANDLE);
+            current_leaf.getPage().getProtectionRecordHandle();
 
         // First try to get the lock NOWAIT, while latch is held.
         return(

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BasePage.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BasePage.java?view=diff&rev=551933&r1=551932&r2=551933
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BasePage.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BasePage.java Fri
Jun 29 09:03:21 2007
@@ -106,6 +106,13 @@
 	private int   recordCount;
 
 	/**
+	 * A record handle that, when locked, protects all the record ids on the
+	 * page.
+	 * @see RecordHandle#RECORD_ID_PROTECTION_HANDLE
+	 */
+	private RecordId protectionHandle;
+
+	/**
 		Page owner during exclusive access.
 
 		MT - mutable : single thread required, provided by Lockable single thread required. 
@@ -219,6 +226,7 @@
 	{
 		setAuxObject(null);
 		identity = null;
+		protectionHandle = null;
 		recordCount = 0;
 		clearLastLogInstant();
 
@@ -260,6 +268,7 @@
 	protected void fillInIdentity(PageKey key) {
 		if (SanityManager.DEBUG) {
 			SanityManager.ASSERT(identity == null);
+			SanityManager.ASSERT(protectionHandle == null);
 		}
 
 		identity = key;
@@ -283,6 +292,7 @@
 	protected void cleanPageForReuse()
 	{
 		setAuxObject(null);
+		protectionHandle = null;
 		recordCount = 0;
 	}
 
@@ -309,6 +319,29 @@
 		// a static invalid record handle
 		return InvalidRecordHandle;
 	}
+
+    /**
+     * Get the record id protection handle for the page.
+     *
+     * @return protection handle
+     * @see RecordHandle#RECORD_ID_PROTECTION_HANDLE
+     */
+    public final RecordHandle getProtectionRecordHandle() {
+        // only allocate a new handle the first time the method is called
+        if (protectionHandle == null) {
+            protectionHandle =
+                new RecordId(getPageId(),
+                             RecordHandle.RECORD_ID_PROTECTION_HANDLE);
+        }
+
+        if (SanityManager.DEBUG) {
+            SanityManager.ASSERT(
+                getPageId().equals(protectionHandle.getPageId()),
+                "PageKey for cached protection handle doesn't match identity");
+        }
+
+        return protectionHandle;
+    }
 
 	public static final RecordHandle MakeRecordHandle(PageKey pkey, int recordHandleConstant)
 		 throws StandardException



Mime
View raw message