Oops, fix a broken part of the patch
[beagle.git] / beagled / Lucene.Net / upstream-changes / 19_no_thread_local_storage.patch
blob842dfeaf5f0cb2e8e6cb6f6f5d11ddb085de0e91
1 From: Joe Shaw <joeshaw@novell.com>
3 Lucene uses thread-local storage for caching some data in a threadsafe way.
4 Mono up through 1.1.13.4 leaks all data set using Thread.SetData(), and this
5 accounts for huge memory spikes in Beagle in the file system backend on
6 inotify events and any time a query is run. Instead we'll just declare the
7 items ThreadStatic.
9 Index: Index/SegmentReader.cs
10 ===================================================================
11 RCS file: /cvs/gnome/beagle/beagled/Lucene.Net/Index/SegmentReader.cs,v
12 retrieving revision 1.3
13 diff -u -p -r1.3 SegmentReader.cs
14 --- Index/SegmentReader.cs 6 Oct 2005 19:29:55 -0000 1.3
15 +++ Index/SegmentReader.cs 3 Apr 2006 17:09:07 -0000
16 @@ -36,8 +36,10 @@ namespace Lucene.Net.Index
17 private FieldsReader fieldsReader;
19 internal TermInfosReader tis;
20 - internal TermVectorsReader termVectorsReaderOrig = null;
21 - internal System.LocalDataStoreSlot termVectorsLocal = System.Threading.Thread.AllocateDataSlot();
22 + internal TermVectorsReader termVectorsReaderOrig = null;
24 + [ThreadStatic]
25 + private TermVectorsReader tvReader;
27 internal BitVector deletedDocs = null;
28 private bool deletedDocsDirty = false;
29 @@ -172,19 +174,6 @@ namespace Lucene.Net.Index
33 - ~SegmentReader()
34 - {
35 - // patch for pre-1.4.2 JVMs, whose ThreadLocals leak
36 - try
37 - {
38 - System.Threading.Thread.SetData(termVectorsLocal, null); // {{Aroush-1.9}} is this required for .NET ?!
39 - }
40 - catch (Exception ex)
41 - {
42 - // System.Console.WriteLine(ex.Message);
43 - }
44 - }
46 protected internal override void DoCommit()
48 if (deletedDocsDirty)
49 @@ -609,11 +598,9 @@ namespace Lucene.Net.Index
50 /// </returns>
51 private TermVectorsReader GetTermVectorsReader()
53 - TermVectorsReader tvReader = (TermVectorsReader) System.Threading.Thread.GetData(termVectorsLocal);
54 if (tvReader == null)
56 tvReader = (TermVectorsReader) termVectorsReaderOrig.Clone();
57 - System.Threading.Thread.SetData(termVectorsLocal, tvReader);
59 return tvReader;
61 Index: Index/TermInfosReader.cs
62 ===================================================================
63 RCS file: /cvs/gnome/beagle/beagled/Lucene.Net/Index/TermInfosReader.cs,v
64 retrieving revision 1.4
65 diff -u -p -r1.4 TermInfosReader.cs
66 --- Index/TermInfosReader.cs 6 Oct 2005 19:29:55 -0000 1.4
67 +++ Index/TermInfosReader.cs 3 Apr 2006 17:09:07 -0000
68 @@ -28,8 +28,10 @@ namespace Lucene.Net.Index
69 private Directory directory;
70 private System.String segment;
71 private FieldInfos fieldInfos;
73 - private System.LocalDataStoreSlot enumerators = System.Threading.Thread.AllocateDataSlot();
75 + [ThreadStatic]
76 + private SegmentTermEnum termEnum;
78 private SegmentTermEnum origEnum;
79 private long size;
81 @@ -50,20 +52,7 @@ namespace Lucene.Net.Index
83 indexEnum = new SegmentTermEnum(directory.OpenInput(segment + ".tii"), fieldInfos, true);
86 - ~TermInfosReader()
87 - {
88 - // patch for pre-1.4.2 JVMs, whose ThreadLocals leak
89 - try
90 - {
91 - System.Threading.Thread.SetData(enumerators, null); // {{Aroush-1.9}} is this required for .NET ?!
92 - }
93 - catch (Exception ex)
94 - {
95 - System.Console.WriteLine(ex.Message);
96 - }
97 - }
100 public int GetSkipInterval()
102 return origEnum.skipInterval;
103 @@ -85,11 +74,9 @@ namespace Lucene.Net.Index
105 private SegmentTermEnum GetEnum()
107 - SegmentTermEnum termEnum = (SegmentTermEnum) System.Threading.Thread.GetData(enumerators);
108 if (termEnum == null)
110 termEnum = Terms();
111 - System.Threading.Thread.SetData(enumerators, termEnum);
113 return termEnum;