[Zope-Checkins] CVS: Zope/lib/python/Products/ZCTextIndex - OkapiIndex.py:1.29.74.1

Casey Duncan casey@zope.com
Wed, 4 Jun 2003 00:27:09 -0400


Update of /cvs-repository/Zope/lib/python/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv20173

Modified Files:
      Tag: casey-zctextindex-fewer-conflicts-branch
	OkapiIndex.py 
Log Message:
Change _totaldoclen to a BTree.Length.Length to avoid write conflicts. Add tests for conflicts on index and reindex. These failed before the change to _totaldoclen, but now pass.


=== Zope/lib/python/Products/ZCTextIndex/OkapiIndex.py 1.29 => 1.29.74.1 ===
--- Zope/lib/python/Products/ZCTextIndex/OkapiIndex.py:1.29	Wed May 29 16:47:44 2002
+++ Zope/lib/python/Products/ZCTextIndex/OkapiIndex.py	Wed Jun  4 00:26:38 2003
@@ -18,6 +18,7 @@
 # understand what's going on.
 
 from BTrees.IIBTree import IIBucket
+from BTrees.Length import Length
 
 from Products.ZCTextIndex.IIndex import IIndex
 from Products.ZCTextIndex.BaseIndex import BaseIndex, \
@@ -50,19 +51,20 @@
         # sum(self._docweight.values()), the total # of words in all docs
         # This is a long for "better safe than sorry" reasons.  It isn't
         # used often enough that speed should matter.
-        self._totaldoclen = 0L
+        # Use a BTree.Length.Length object to avoid concurrent write conflicts
+        self._totaldoclen = Length(0L)
 
     def index_doc(self, docid, text):
         count = BaseIndex.index_doc(self, docid, text)
-        self._totaldoclen += count
+        self._totaldoclen.change(count)
         return count
 
     def _reindex_doc(self, docid, text):
-        self._totaldoclen -= self._docweight[docid]
+        self._totaldoclen.change(-self._docweight[docid])
         return BaseIndex._reindex_doc(self, docid, text)
 
     def unindex_doc(self, docid):
-        self._totaldoclen -= self._docweight[docid]
+        self._totaldoclen.change(-self._docweight[docid])
         BaseIndex.unindex_doc(self, docid)
 
     # The workhorse.  Return a list of (IIBucket, weight) pairs, one pair
@@ -77,7 +79,7 @@
         if not wids:
             return []
         N = float(len(self._docweight))  # total # of docs
-        meandoclen = self._totaldoclen / N
+        meandoclen = self._totaldoclen() / N
         K1 = self.K1
         B = self.B
         K1_plus1 = K1 + 1.0
@@ -121,7 +123,7 @@
         if not wids:
             return []
         N = float(len(self._docweight))  # total # of docs
-        meandoclen = self._totaldoclen / N
+        meandoclen = self._totaldoclen() / N
         #K1 = self.K1
         #B = self.B
         #K1_plus1 = K1 + 1.0