db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r409374 - /db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/services/cache/Clock.java
Date Thu, 25 May 2006 12:23:02 GMT
Author: kahatlen
Date: Thu May 25 05:23:02 2006
New Revision: 409374

URL: http://svn.apache.org/viewvc?rev=409374&view=rev
Log:
DERBY-704: Large page cache kills initial performance

Merged fix from trunk.

Modified:
    db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/services/cache/Clock.java

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/services/cache/Clock.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/services/cache/Clock.java?rev=409374&r1=409373&r2=409374&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/services/cache/Clock.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/services/cache/Clock.java
Thu May 25 05:23:02 2006
@@ -856,18 +856,39 @@
 		// size() is the number of valid entries in the hash table
 
 
-		// no need to sync on getting the sizes since the if
-		// they are wrong we will just not find a invalid entry in
-		// the lookup below.
+		// no need to sync on getting the sizes since if they are
+		// wrong we will discover it in the loop.
 		if (validItemCount < holders.size()) {
 
 			synchronized (this) {
 
-				for (int i = holders.size() - 1; i >= 0 ; i--) {
+				// 1) find out how many invalid items there are in the
+				//    cache
+				// 2) search for a free invalid item
+				// 3) stop searching when there are no more invalid
+				//    items to find
+
+				int invalidItems = holders.size() - validItemCount;
+
+				// Invalid items might occur in the cache when
+				//   a) a new item is created in growCache(), but it
+				//      is not in use yet, or
+				//   b) an item is deleted (usually when a table is
+				//      dropped)
+
+				// It is critical to break out of the loop as soon as
+				// possible since we are blocking others trying to
+				// access the page cache. New items are added to the
+				// end of the page cache, so the search for invalid
+				// items should start from the end.
+
+				for (int i = holders.size() - 1; (invalidItems > 0) && (i >= 0) ; i--)
{
 					CachedItem item = (CachedItem) holders.get(i);
 
-					if (item.isKept())
+					if (item.isKept()) {
+						if (!item.isValid()) invalidItems--;
 						continue;
+					}
 
 					// found a free item, just use it
 					if (!item.isValid()) {



Mime
View raw message