Ticket #143: oldpatch

File oldpatch, 8.5 KB (added by Richard Boulton, 18 years ago)

Pre-patch, needs to be reapplied before patch 77.

Line 
1Index: ChangeLog
2===================================================================
3--- ChangeLog (revision 8425)
4+++ ChangeLog (revision 8426)
5@@ -1,3 +1,19 @@
6+Thu May 03 00:05:23 BST 2007 Richard Boulton <richard@lemurconsulting.com>
7+
8+ * backends/flint/: Remove unused (and unimplemented) declarations
9+ of begin_transaction_(), commit_transaction_() and
10+ cancel_transaction_() from FlintWritableDatabase class. Tidy up
11+ handling of metainfo (total_length and lastdocid) to avoid
12+ repeatedly parsing the special record, and make it easier to
13+ store additional metainfo in future.
14+ Also, remove code which ensures that there is always a special
15+ record - this was added in revision 5459 when the special record
16+ was stored in the record table, so that the number of documents
17+ in the database could always be calculated by subtracting 1 from
18+ the number of entries in the record table. Now that the special
19+ record is stored in the postlist table, this is no longer
20+ necessary.
21+
22 Wed May 02 17:56:39 BST 2007 Olly Betts <olly@survex.com>
23
24 * backends/dbfactory_remote.cc,include/xapian/dbfactory.h:
25Index: backends/flint/flint_database.h
26===================================================================
27--- backends/flint/flint_database.h (revision 8425)
28+++ backends/flint/flint_database.h (revision 8426)
29@@ -94,6 +94,14 @@
30 /// Lock object.
31 FlintLock lock;
32
33+ /** Total length of all documents including unflushed modifications.
34+ */
35+ flint_totlen_t total_length;
36+
37+ /** Highest document ID ever allocated by this database.
38+ */
39+ Xapian::docid lastdocid;
40+
41 /** Return true if a database exists at the path specified for this
42 * database.
43 */
44@@ -301,9 +309,6 @@
45 PositionList * open_position_list(Xapian::docid did,
46 const string & tname) const;
47 TermList * open_allterms() const;
48- void begin_transaction_();
49- void commit_transaction_();
50- void cancel_transaction_();
51 //@}
52 };
53
54Index: backends/flint/flint_database.cc
55===================================================================
56--- backends/flint/flint_database.cc (revision 8425)
57+++ backends/flint/flint_database.cc (revision 8426)
58@@ -87,6 +87,7 @@
59 }
60 // Can still allow searches even if recovery is needed
61 open_tables_consistent();
62+ postlist_table.get_metainfo_entry(total_length, lastdocid);
63 } else {
64 if (!dbexists) {
65 // FIXME: if we allow Xapian::DB_OVERWRITE, check it here
66@@ -143,9 +144,7 @@
67 value_table.commit(new_revision);
68 record_table.commit(new_revision);
69 }
70- if (record_table.get_doccount() == 0) {
71- postlist_table.set_total_length_and_lastdocid(0, postlist_table.get_lastdocid());
72- }
73+ postlist_table.get_metainfo_entry(total_length, lastdocid);
74 }
75 }
76
77@@ -196,7 +195,11 @@
78 revision != postlist_table.get_open_revision_number()) {
79 throw Xapian::DatabaseCreateError("Newly created tables are not in consistent state");
80 }
81- postlist_table.set_total_length_and_lastdocid(0, 0);
82+
83+ // Set metainfo
84+ total_length = 0;
85+ lastdocid = 0;
86+ postlist_table.set_metainfo_entry(total_length, lastdocid);
87 }
88
89 void
90@@ -306,6 +309,7 @@
91 DEBUGCALL(DB, void, "FlintDatabase::reopen", "");
92 if (readonly) {
93 open_tables_consistent();
94+ postlist_table.get_metainfo_entry(total_length, lastdocid);
95 }
96 }
97
98@@ -392,7 +396,7 @@
99 FlintDatabase::get_lastdocid() const
100 {
101 DEBUGCALL(DB, Xapian::docid, "FlintDatabase::get_lastdocid", "");
102- RETURN(postlist_table.get_lastdocid());
103+ RETURN(lastdocid);
104 }
105
106 Xapian::doclength
107@@ -401,7 +405,7 @@
108 DEBUGCALL(DB, Xapian::doclength, "FlintDatabase::get_avlength", "");
109 Xapian::doccount docs = record_table.get_doccount();
110 if (docs == 0) RETURN(0);
111- RETURN(double(postlist_table.get_total_length()) / docs);
112+ RETURN(double(total_length) / docs);
113 }
114
115 Xapian::doclength
116@@ -532,12 +536,11 @@
117 doclens(),
118 mod_plists(),
119 database_ro(dir, action, block_size),
120- total_length(database_ro.postlist_table.get_total_length()),
121- lastdocid(database_ro.get_lastdocid()),
122 changes_made(0)
123 {
124 DEBUGCALL(DB, void, "FlintWritableDatabase", dir << ", " << action << ", "
125 << block_size);
126+ database_ro.postlist_table.get_metainfo_entry(total_length, lastdocid);
127 if (flush_threshold == 0) {
128 const char *p = getenv("XAPIAN_FLUSH_THRESHOLD");
129 if (p) flush_threshold = atoi(p);
130@@ -567,8 +570,7 @@
131 database_ro.postlist_table.merge_changes(mod_plists, doclens, freq_deltas);
132
133 // Update the total document length and last used docid.
134- database_ro.postlist_table.set_total_length_and_lastdocid(total_length,
135- lastdocid);
136+ database_ro.postlist_table.set_metainfo_entry(total_length, lastdocid);
137 database_ro.apply();
138 freq_deltas.clear();
139 doclens.clear();
140@@ -1070,8 +1072,7 @@
141 FlintWritableDatabase::cancel()
142 {
143 database_ro.cancel();
144- total_length = database_ro.postlist_table.get_total_length();
145- lastdocid = database_ro.get_lastdocid();
146+ database_ro.postlist_table.get_metainfo_entry(total_length, lastdocid);
147 freq_deltas.clear();
148 doclens.clear();
149 mod_plists.clear();
150Index: backends/flint/flint_postlist.cc
151===================================================================
152--- backends/flint/flint_postlist.cc (revision 8425)
153+++ backends/flint/flint_postlist.cc (revision 8426)
154@@ -30,55 +30,40 @@
155 // next free docid and total length of all documents
156 static const string METAINFO_KEY("", 1);
157
158-Xapian::docid
159-FlintPostListTable::get_lastdocid() const
160+void
161+FlintPostListTable::get_metainfo_entry(flint_totlen_t & totlen,
162+ Xapian::docid & did) const
163 {
164- DEBUGCALL(DB, Xapian::docid, "FlintPostListTable::get_lastdocid", "");
165+ DEBUGCALL(DB, void, "FlintPostListTable::get_metainfo_entry", "");
166
167 string tag;
168- if (!get_exact_entry(METAINFO_KEY, tag)) RETURN(0u);
169+ if (!get_exact_entry(METAINFO_KEY, tag)) {
170+ totlen = 0;
171+ did = 0;
172+ return;
173+ }
174
175- Xapian::docid did;
176 const char * data = tag.data();
177 const char * end = data + tag.size();
178 if (!unpack_uint(&data, end, &did)) {
179 throw Xapian::DatabaseCorruptError("Record containing meta information is corrupt.");
180 }
181- RETURN(did);
182+ if (!unpack_uint_last(&data, end, &totlen)) {
183+ throw Xapian::DatabaseCorruptError("Record containing meta information is corrupt.");
184+ }
185 }
186
187 void
188-FlintPostListTable::set_total_length_and_lastdocid(flint_totlen_t totlen,
189- Xapian::docid did)
190+FlintPostListTable::set_metainfo_entry(flint_totlen_t totlen,
191+ Xapian::docid did)
192 {
193- DEBUGCALL(DB, void, "FlintPostListTable::set_total_length_and_lastdocid",
194+ DEBUGCALL(DB, void, "FlintPostListTable::set_metainfo_entry",
195 totlen << ", " << did);
196 string tag = pack_uint(did);
197 tag += pack_uint_last(totlen);
198 add(METAINFO_KEY, tag);
199 }
200
201-flint_totlen_t
202-FlintPostListTable::get_total_length() const
203-{
204- DEBUGCALL(DB, flint_totlen_t, "FlintPostListTable::get_total_length", "");
205-
206- string tag;
207- if (!get_exact_entry(METAINFO_KEY, tag)) RETURN(0);
208-
209- Xapian::docid did;
210- flint_totlen_t totlen;
211- const char * data = tag.data();
212- const char * end = data + tag.size();
213- if (!unpack_uint(&data, end, &did)) {
214- throw Xapian::DatabaseCorruptError("Record containing meta information is corrupt.");
215- }
216- if (!unpack_uint_last(&data, end, &totlen)) {
217- throw Xapian::DatabaseCorruptError("Record containing meta information is corrupt.");
218- }
219- RETURN(totlen);
220-}
221-
222 /// Make a key for accessing the postlist.
223 static void
224 make_key(const string & tname, Xapian::docid did, string & key)
225Index: backends/flint/flint_postlist.h
226===================================================================
227--- backends/flint/flint_postlist.h (revision 8425)
228+++ backends/flint/flint_postlist.h (revision 8426)
229@@ -67,18 +67,15 @@
230 Xapian::docid did, bool adding,
231 PostlistChunkReader ** from, PostlistChunkWriter **to);
232
233- /** Return the total length of all the records in the table.
234+ /** Get the total length, last document ID used, and metadata.
235 */
236- flint_totlen_t get_total_length() const;
237+ void get_metainfo_entry(flint_totlen_t & totlen,
238+ Xapian::docid & lastdocid) const;
239
240- /** Get the last document id used.
241+ /** Set the total length, last document ID used, and metadata.
242 */
243- Xapian::docid get_lastdocid() const;
244-
245- /** Set the total length and last document ID used.
246- */
247- void set_total_length_and_lastdocid(flint_totlen_t totlen,
248- Xapian::docid did);
249+ void set_metainfo_entry(flint_totlen_t totlen,
250+ Xapian::docid lastdocid);
251 };
252
253 /** A postlist in a flint database.