[Zope-Checkins] CVS: Zope2 - BTreeItemsTemplate.c:1.3.6.4 BTreeModuleTemplate.c:1.4.6.5 BTreeTemplate.c:1.9.6.4 BucketTemplate.c:1.6.6.4 SetOpTemplate.c:1.3.6.3 SetTemplate.c:1.6.6.4 TreeSetTemplate.c:1.5.6.5

Jim Fulton jim@digicool.com
Tue, 20 Mar 2001 08:14:02 -0500 (EST)


Update of /cvs-repository/Zope2/lib/python/BTrees
In directory korak:/tmp/cvs-serv7020

Modified Files:
      Tag: zope-2_3-branch
	BTreeItemsTemplate.c BTreeModuleTemplate.c BTreeTemplate.c 
	BucketTemplate.c SetOpTemplate.c SetTemplate.c 
	TreeSetTemplate.c 
Log Message:
Added logic to updated the access time on BTree data structures as
they are used. This is important to keep used data structures in
memory when the ZODB garbage collector is busy.




--- Updated File BTreeItemsTemplate.c in package Zope2 --
--- BTreeItemsTemplate.c	2001/03/20 01:24:17	1.3.6.3
+++ BTreeItemsTemplate.c	2001/03/20 13:14:01	1.3.6.4
@@ -143,11 +143,13 @@
 
       Py_INCREF(next);
       PER_ALLOW_DEACTIVATION(b);
+      PER_ACCESSED(b);
       Py_DECREF(b);
       b=next;
       PER_USE_OR_RETURN(b, -1);
     }
   PER_ALLOW_DEACTIVATION(b);
+  PER_ACCESSED(b);
   Py_DECREF(b);
 
   return r >= 0 ? r : 0;
@@ -257,6 +259,7 @@
                 if (b==NULL) goto no_match;
               
                 PER_ALLOW_DEACTIVATION(currentbucket);
+                PER_ACCESSED(currentbucket);
                 ASSIGNB(currentbucket, b);
                 UNLESS (PER_USE(currentbucket)) goto err;
 
@@ -296,6 +299,7 @@
                     pseudoindex += (currentbucket->len - currentoffset);
                     Py_INCREF(b);
                     PER_ALLOW_DEACTIVATION(currentbucket);
+                    PER_ACCESSED(currentbucket);
                     ASSIGNB(currentbucket, b);
                     UNLESS (PER_USE(currentbucket)) goto err;
                     currentoffset = 0;

--- Updated File BTreeModuleTemplate.c in package Zope2 --
--- BTreeModuleTemplate.c	2001/03/20 01:26:24	1.4.6.4
+++ BTreeModuleTemplate.c	2001/03/20 13:14:01	1.4.6.5
@@ -96,8 +96,12 @@
  ? (((O)->state==cPersistent_UPTODATE_STATE) \
     ? ((O)->state=cPersistent_STICKY_STATE) : 1) : 0)
 
+#define PER_ACCESSED(O) ((O)->atime=((long)(time(NULL)/3))%65536) 
+
+
 #endif
 /***************************************************************/
+
 #else
 #include "ExtensionClass.h"
 #define PER_USE_OR_RETURN(self, NULL)
@@ -105,9 +109,11 @@
 #define PER_PREVENT_DEACTIVATION(self)
 #define PER_DEL(self)
 #define PER_USE(O) 1
+#define PER_ACCESSED(O) 1
 #define PER_CHANGED(O) 0
 #endif
 
+
 static PyObject *sort_str, *reverse_str, *items_str, *__setstate___str;
 
 static void PyVar_Assign(PyObject **v, PyObject *e) { Py_XDECREF(*v); *v=e;}
@@ -208,6 +214,7 @@
       if (first->next==current) 
         {
           PER_ALLOW_DEACTIVATION(first);
+          PER_ACCESSED(first);
           return first;
         }
       else if (first->next)
@@ -215,12 +222,14 @@
           Bucket *next = first->next;
           Py_INCREF(next);
           PER_ALLOW_DEACTIVATION(first);
+          PER_ACCESSED(first);
           Py_DECREF(first);
           first=next;
         }
       else
         {
           PER_ALLOW_DEACTIVATION(first);
+          PER_ACCESSED(first);
           Py_DECREF(first);
           IndexError(i);
           return NULL;

--- Updated File BTreeTemplate.c in package Zope2 --
--- BTreeTemplate.c	2001/03/20 01:24:17	1.9.6.3
+++ BTreeTemplate.c	2001/03/20 13:14:01	1.9.6.4
@@ -134,6 +134,7 @@
     }
 
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return r;
 }    
 
@@ -170,13 +171,15 @@
       next->firstbucket = BTREE(next->data->value)->firstbucket;
       Py_XINCREF(next->firstbucket);
       PER_ALLOW_DEACTIVATION(BTREE(next->data->value));
+      PER_ACCESSED(BTREE(next->data->value));
     }
   else
     {
       next->firstbucket = BUCKET(next->data->value);
       Py_XINCREF(next->firstbucket);
     }
-  
+
+  PER_CHANGED(self);
   return 0;
 }
 
@@ -362,7 +365,8 @@
   PER_USE_OR_RETURN(self, NULL);
   ASSIGN(o, OBJECT(BTree_lastBucket(self)));
   PER_ALLOW_DEACTIVATION(self);
-  
+  PER_ACCESSED(self);
+
   return BUCKET(o);
 }
 
@@ -375,7 +379,10 @@
 
   UNLESS (b=BTree_lastBucket(self)) goto err;
   if (Bucket_deleteNextBucket(b) < 0) goto err;
-  
+
+  PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
+
   return 0;
 
  err:
@@ -513,6 +520,7 @@
                                 BTREE(self->data->value)->firstbucket);
                         Py_XINCREF(self->firstbucket);
                         PER_ALLOW_DEACTIVATION(BTREE(self->data->value));
+                        PER_ACCESSED(BTREE(self->data->value));
                       }
                     else
                       {
@@ -546,10 +554,12 @@
           
   
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return grew;
 
 err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return -1;
 }
 
@@ -644,12 +654,14 @@
     }
 
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
 
   Py_INCREF(Py_None); 
   return Py_None;
 
 err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return NULL;
 }
 
@@ -703,11 +715,13 @@
     }  
 
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
 
   return r;
 
 err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return NULL;
 }
 
@@ -807,6 +821,7 @@
   PER_PREVENT_DEACTIVATION(self); 
   r=_BTree_setstate(self, args, 0);
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
 
   if (r < 0) return NULL;
   Py_INCREF(Py_None);
@@ -884,6 +899,7 @@
       PER_USE_OR_RETURN(self, -1);
       i = BTree_findRangeEnd(self, keyarg, low, bucket, offset);
       PER_ALLOW_DEACTIVATION(self);
+      PER_ACCESSED(self);
     }
   else
     {
@@ -918,6 +934,7 @@
           goto empty;
         } 
       PER_ALLOW_DEACTIVATION(self);
+      PER_ACCESSED(self);
       PER_USE_OR_RETURN(bucket, NULL);
     }
   else if (min)
@@ -925,6 +942,7 @@
       bucket = self->firstbucket;
       Py_INCREF(bucket);
       PER_ALLOW_DEACTIVATION(self);
+      PER_ACCESSED(self);
       PER_USE_OR_RETURN(bucket, NULL);
       offset = 0;
       if (offset >= bucket->len)
@@ -940,6 +958,7 @@
     {
       bucket = BTree_lastBucket(self);
       PER_ALLOW_DEACTIVATION(self);
+      PER_ACCESSED(self);
       PER_USE_OR_RETURN(bucket, NULL);
       if (bucket->len)
         offset = bucket->len - 1; 
@@ -955,6 +974,7 @@
   
   COPY_KEY_TO_OBJECT(key, bucket->keys[offset]);
   PER_ALLOW_DEACTIVATION(bucket);
+  PER_ACCESSED(bucket);
   Py_DECREF(bucket);
 
   return key;
@@ -964,9 +984,11 @@
 
  err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   if (bucket)  
     {
       PER_ALLOW_DEACTIVATION(bucket);
+      PER_ACCESSED(bucket);
       Py_DECREF(bucket);
     }
   return NULL;
@@ -1041,9 +1063,11 @@
       UNLESS (PER_USE(highbucket)) goto err;
       highoffset = highbucket->len - 1; 
       PER_ALLOW_DEACTIVATION(highbucket);      
+      PER_ACCESSED(highbucket);
     }
   
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   
   f=newBTreeItems(type, lowbucket, lowoffset, highbucket, highoffset);
   Py_DECREF(lowbucket);
@@ -1052,10 +1076,12 @@
   
  err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return NULL;
 
  empty:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return newBTreeItems(type, 0, 0, 0, 0);
 }
 
@@ -1143,10 +1169,12 @@
   Py_DECREF(item);
 
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return r;
 
  err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   Py_XDECREF(r);
   Py_XDECREF(it.set);
   Py_XDECREF(item);
@@ -1260,6 +1288,7 @@
   b = self->firstbucket;
   Py_XINCREF(b);
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
 
   while (b != NULL) 
     {
@@ -1269,12 +1298,14 @@
         {
           /* Short-circuit if all we care about is nonempty */
           PER_ALLOW_DEACTIVATION(b);
+          PER_ACCESSED(b);
           Py_DECREF(b);
           return 1;
         }
       n = b->next;
       Py_XINCREF(n);
       PER_ALLOW_DEACTIVATION(b);
+      PER_ACCESSED(b);
       ASSIGNB(b, n);
     }
 

--- Updated File BucketTemplate.c in package Zope2 --
--- BucketTemplate.c	2001/03/20 01:24:17	1.6.6.3
+++ BucketTemplate.c	2001/03/20 13:14:02	1.6.6.4
@@ -119,12 +119,14 @@
               COPY_VALUE_TO_OBJECT(r, self->values[i]);
 	    }
 	  PER_ALLOW_DEACTIVATION(self);
+          PER_ACCESSED(self);
 	  return r;
 	}
       else max=i;
     }
 
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   if (has_key) return PyInt_FromLong(0);
   PyErr_SetObject(PyExc_KeyError, keyarg);
   return NULL;
@@ -215,6 +217,7 @@
                   if (VALUE_SAME(self->values[i], value))
                     { /* short-circuit if no change */
                       PER_ALLOW_DEACTIVATION(self);
+                      PER_ACCESSED(self);
                       return 0;
                     }
 #endif
@@ -225,6 +228,7 @@
                   if (PER_CHANGED(self) < 0) goto err;
                 }
 	      PER_ALLOW_DEACTIVATION(self);
+              PER_ACCESSED(self);
 	      return 0;
 	    }
 	  else			/* There's no value so remove the item */
@@ -259,6 +263,7 @@
 
 	      if (PER_CHANGED(self) < 0) goto err;
 	      PER_ALLOW_DEACTIVATION(self);
+              PER_ACCESSED(self);
 	      return 1;
 	    }
 	}
@@ -299,10 +304,12 @@
 
   if (PER_CHANGED(self) < 0) goto err;
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return 1;
 
 err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return -1;
 }
 
@@ -422,6 +429,8 @@
   Py_INCREF(next);
   self->next = next;
 
+  PER_CHANGED(self);
+
   return 0;
 }
 
@@ -432,6 +441,7 @@
   *r=self->next;
   Py_XINCREF(*r);
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return 0;
 }
 
@@ -447,9 +457,11 @@
       PER_CHANGED(self);
     }
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return 0;
  err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return -1;
 }
 /*
@@ -488,6 +500,7 @@
       else if (cmp == 0)
         {
           PER_ALLOW_DEACTIVATION(self);
+          PER_ACCESSED(self);
           *offset=i;
           return 1;
         } 
@@ -518,6 +531,7 @@
     }
 
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
 
   return i;
 }
@@ -548,6 +562,7 @@
 
   COPY_KEY_TO_OBJECT(key, self->keys[offset]);
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
 
   return key;
   
@@ -556,6 +571,7 @@
 
  err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return NULL;
 }
 
@@ -640,10 +656,12 @@
     }
 
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return r;
 
  err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   Py_XDECREF(r);
   return NULL;
 }
@@ -678,10 +696,12 @@
     }
 
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return r;
 
  err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   Py_XDECREF(r);
   return NULL;
 }
@@ -726,10 +746,12 @@
     }
 
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return r;
 
  err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   Py_XDECREF(r);
   Py_XDECREF(item);
   return NULL;
@@ -789,10 +811,12 @@
   Py_DECREF(item);
 
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return r;
 
  err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   Py_XDECREF(r);
   Py_XDECREF(item);
   return NULL;
@@ -858,11 +882,13 @@
       if (PER_CHANGED(self) < 0) goto err;
     }
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   Py_INCREF(Py_None); 
   return Py_None;
 
 err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return NULL;
 }
 
@@ -911,11 +937,13 @@
     ASSIGN(items, Py_BuildValue("(O)", items));
   
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
 
   return items;
 
 err:
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   Py_XDECREF(items);
   return NULL;
 }
@@ -983,6 +1011,7 @@
     }
 
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
 
   return 0;
 }
@@ -997,6 +1026,7 @@
   PER_PREVENT_DEACTIVATION(self); 
   r=_bucket_setstate(self, args);
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
 
   if (r < 0) return NULL;
   Py_INCREF(Py_None);
@@ -1162,6 +1192,7 @@
   PER_USE_OR_RETURN(self, -1);
   r=self->len;
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
   return r;
 }
 
@@ -1227,10 +1258,10 @@
 static int 
 nextBucket(SetIteration *i)
 {
-  UNLESS(PER_USE(BUCKET(i->set))) return -1;
-          
   if (i->position >= 0)
     {
+      UNLESS(PER_USE(BUCKET(i->set))) return -1;
+          
       if (i->position)
         {
           DECREF_KEY(i->key);
@@ -1246,10 +1277,14 @@
           i->position ++;
         }
       else
-        i->position = -1;
+        {
+          i->position = -1;
+          PER_ACCESSED(BUCKET(i->set));
+        }
+
+      PER_ALLOW_DEACTIVATION(BUCKET(i->set));
     }
 
-  PER_ALLOW_DEACTIVATION(BUCKET(i->set));
           
   return 0;
 }

--- Updated File SetOpTemplate.c in package Zope2 --
--- SetOpTemplate.c	2001/03/20 01:24:17	1.3.6.2
+++ SetOpTemplate.c	2001/03/20 13:14:02	1.3.6.3
@@ -92,21 +92,25 @@
 #ifdef INTSET_H
 static int 
 nextIntSet(SetIteration *i)
-{
-  UNLESS(PER_USE(INTSET(i->set))) return -1;
-          
+{    
   if (i->position >= 0)
     {
+      UNLESS(PER_USE(INTSET(i->set))) return -1;
+
       if (i->position < INTSET(i->set)->len)
         {
           i->key = INTSET(i->set)->data[i->position];
           i->position ++;
         }
       else
-        i->position = -1;
+        {
+          i->position = -1;
+          PER_ACCESSED(INTSET(i->set));
+        }
+
+      PER_ALLOW_DEACTIVATION(INTSET(i->set));
     }
 
-  PER_ALLOW_DEACTIVATION(INTSET(i->set));
           
   return 0;
 }

--- Updated File SetTemplate.c in package Zope2 --
--- SetTemplate.c	2001/03/20 01:24:17	1.6.6.3
+++ SetTemplate.c	2001/03/20 13:14:02	1.6.6.4
@@ -205,6 +205,7 @@
   PER_PREVENT_DEACTIVATION(self); 
   r=_set_setstate(self, args);
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
 
   if (r < 0) return NULL;
   Py_INCREF(Py_None);
@@ -273,6 +274,7 @@
   PER_USE_OR_RETURN(self, -1);
   r = self->len;
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
 
   return r;
 }
@@ -291,6 +293,7 @@
     IndexError(index);
 
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
 
   return r;
 }
@@ -341,10 +344,11 @@
 static int 
 nextSet(SetIteration *i)
 {
-  UNLESS(PER_USE(BUCKET(i->set))) return -1;
           
   if (i->position >= 0)
     {
+      UNLESS(PER_USE(BUCKET(i->set))) return -1;
+
       if (i->position)
         {
           DECREF_KEY(i->key);
@@ -357,10 +361,14 @@
           i->position ++;
         }
       else
-        i->position = -1;
+        {
+          i->position = -1;
+          PER_ACCESSED(BUCKET(i->set));
+        }
+
+      PER_ALLOW_DEACTIVATION(BUCKET(i->set));
     }
 
-  PER_ALLOW_DEACTIVATION(BUCKET(i->set));
           
   return 0;
 }

--- Updated File TreeSetTemplate.c in package Zope2 --
--- TreeSetTemplate.c	2001/03/20 01:24:17	1.5.6.4
+++ TreeSetTemplate.c	2001/03/20 13:14:02	1.5.6.5
@@ -153,6 +153,7 @@
   PER_PREVENT_DEACTIVATION(self); 
   r=_BTree_setstate(self, args, 1);
   PER_ALLOW_DEACTIVATION(self);
+  PER_ACCESSED(self);
 
   if (r < 0) return NULL;
   Py_INCREF(Py_None);