Ticket #675: the_error.cpp

File the_error.cpp, 6.8 KB (added by German M. Bravo, 9 years ago)
Line 
1/*
2
3 # http://trac.xapian.org/ticket/675
4 # Exception in [Chert/Glass]Cursor::find_entry()
5
6 # This script triggers an exception when using in both chert and glass databases.
7 g++ -I/usr/local/include/xapian-1.3 -lxapian-1.3 the_error.cpp -o the_error
8
9 # Chert:
10 unset XAPIAN_PREFER_GLASS
11 rm -rf db_the_error
12 ./the_error
13
14 # Glass:
15 export XAPIAN_PREFER_GLASS=1
16 rm -rf db_the_error
17 ./the_error
18
19*/
20
21#include <xapian.h>
22#include <stdio.h>
23#include <string>
24#include <string.h>
25
26
27#define ITEMS 10
28#define DATABASE "db_the_error"
29
30
31int process_all(const Xapian::Database &db, int offset, int limit, bool datas, bool values) {
32 Xapian::Enquire enq(db);
33 enq.set_query(Xapian::Query(""));
34 Xapian::MSet m = enq.get_mset(offset, limit);
35 Xapian::MSetIterator mi(m.begin());
36 int i = 1;
37 for ( ; mi != m.end(); mi++, i++) {
38 Xapian::docid docid = *mi;
39 Xapian::Document document = mi.get_document();
40 std::string data, value;
41 if (datas) {
42 data = document.get_data();
43 }
44 if (values) {
45 value = document.get_value(0);
46 }
47 // printf("docid: %u, value: %s\n", docid, value.c_str());
48 }
49 return i;
50}
51
52
53void index(Xapian::WritableDatabase &wdb, Xapian::doccount next_id) {
54 Xapian::Document doc;
55 std::string id = std::to_string(next_id);
56 std::string doc_id = "Q" + id;
57 doc.add_value(0, id);
58 /* When using valgrind and glass, uncommenting the following line, triggers a different problem:
59 "Signal 11 being dropped from thread 0's queue being dropped" */
60 // doc.set_data(doc_id);
61 doc.add_boolean_term(doc_id);
62 wdb.replace_document(doc_id, doc);
63 // printf("indexed: %s\n", doc_id.c_str());
64}
65
66
67void run() {
68 Xapian::WritableDatabase wdb = Xapian::WritableDatabase(DATABASE, Xapian::DB_CREATE_OR_OPEN);
69 Xapian::Database db = Xapian::Database(DATABASE);
70
71 Xapian::doccount free_id = db.get_doccount();
72
73 int offset = free_id > (ITEMS * 2) ? free_id - (ITEMS * 2) : 0;
74 int limit = offset + (ITEMS * 2);
75
76 /* If the next line is commented, the exception isn't thrown; a read is needed before the reopen() */
77 process_all(db, offset, limit, false, true);
78
79 for (Xapian::doccount next_id = free_id; next_id <= free_id + ITEMS; next_id++) {
80 index(wdb, next_id);
81 }
82 wdb.commit();
83
84 db.reopen();
85
86 /* The next line will throw the exception on get_value()! */
87 process_all(db, offset, limit, false, true);
88}
89
90int main() {
91 for (int i = 0; i < 100; i++) {
92 run();
93 }
94}
95
96/*
97
98CHERT backtace (more often)
99===========================
100
101All documents after reopen():
102Process 17442 stopped
103* thread #1: tid = 0x1add6, 0x00007fff927301b5 libsystem_platform.dylib`_platform_memmove$VARIANT$Unknown + 533, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x1007ffff3)
104 frame #0: 0x00007fff927301b5 libsystem_platform.dylib`_platform_memmove$VARIANT$Unknown + 533
105libsystem_platform.dylib`_platform_memmove$VARIANT$Unknown:
106-> 0x7fff927301b5 <+533>: vmovups -0x40(%rsi), %ymm2
107 0x7fff927301ba <+538>: subq $0x40, %rsi
108 0x7fff927301be <+542>: subq $0x40, %rdx
109 0x7fff927301c2 <+546>: ja 0x7fff927301a2 ; <+514>
110(lldb) bt
111* thread #1: tid = 0x1add6, 0x00007fff927301b5 libsystem_platform.dylib`_platform_memmove$VARIANT$Unknown + 533, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x1007ffff3)
112 * frame #0: 0x00007fff927301b5 libsystem_platform.dylib`_platform_memmove$VARIANT$Unknown + 533
113 frame #1: 0x00007fff9bd7ee8d libc++.1.dylib`std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__grow_by_and_replace(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, char const*) + 193
114 frame #2: 0x00007fff9bd7e581 libc++.1.dylib`std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::assign(char const*, unsigned long) + 113
115 frame #3: 0x000000010005741c libxapian-1.3.3.dylib`ChertCursor::find_entry(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 588
116 frame #4: 0x0000000100085eed libxapian-1.3.3.dylib`ChertValueManager::get_chunk_containing_did(unsigned int, unsigned int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const + 301
117 frame #5: 0x000000010008812e libxapian-1.3.3.dylib`ChertValueManager::get_value(unsigned int, unsigned int) const + 174
118 frame #6: 0x000000010006d3ec libxapian-1.3.3.dylib`ChertDocument::do_get_value(unsigned int) const + 28
119 frame #7: 0x00000001000161c8 libxapian-1.3.3.dylib`Xapian::Document::get_value(unsigned int) const + 104
120 frame #8: 0x0000000100001861 the_error`process_all(Xapian::Database const&, int, int) + 561
121 frame #9: 0x00000001000021a1 the_error`main + 881
122 frame #10: 0x00007fff9288f5c9 libdyld.dylib`start + 1
123 frame #11: 0x00007fff9288f5c9 libdyld.dylib`start + 1
124
125
126GLASS backtrace
127===============
128
129Process 17306 stopped
130* thread #1: tid = 0x1ab68, 0x00000001000c0fe7 libxapian-1.3.3.dylib`GlassTable::find_in_block(unsigned char const*, Glass::Key, bool, int) + 39, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x9)
131 frame #0: 0x00000001000c0fe7 libxapian-1.3.3.dylib`GlassTable::find_in_block(unsigned char const*, Glass::Key, bool, int) + 39
132libxapian-1.3.3.dylib`GlassTable::find_in_block:
133-> 0x1000c0fe7 <+39>: movzbl 0x9(%rsi), %eax
134 0x1000c0feb <+43>: shll $0x8, %eax
135 0x1000c0fee <+46>: movzbl 0xa(%rsi), %r13d
136 0x1000c0ff3 <+51>: orl %eax, %r13d
137(lldb) bt
138* thread #1: tid = 0x1ab68, 0x00000001000c0fe7 libxapian-1.3.3.dylib`GlassTable::find_in_block(unsigned char const*, Glass::Key, bool, int) + 39, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x9)
139 * frame #0: 0x00000001000c0fe7 libxapian-1.3.3.dylib`GlassTable::find_in_block(unsigned char const*, Glass::Key, bool, int) + 39
140 frame #1: 0x00000001000c12ff libxapian-1.3.3.dylib`GlassTable::find(Glass::Cursor*) const + 111
141 frame #2: 0x000000010009ac54 libxapian-1.3.3.dylib`GlassCursor::find_entry(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 164
142 frame #3: 0x00000001000c8f8d libxapian-1.3.3.dylib`GlassValueManager::get_chunk_containing_did(unsigned int, unsigned int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const + 301
143 frame #4: 0x00000001000cb1ce libxapian-1.3.3.dylib`GlassValueManager::get_value(unsigned int, unsigned int) const + 174
144 frame #5: 0x00000001000aff8c libxapian-1.3.3.dylib`GlassDocument::do_get_value(unsigned int) const + 28
145 frame #6: 0x00000001000161c8 libxapian-1.3.3.dylib`Xapian::Document::get_value(unsigned int) const + 104
146 frame #7: 0x0000000100001861 the_error`process_all(Xapian::Database const&, int, int) + 561
147 frame #8: 0x00000001000021a1 the_error`main + 881
148 frame #9: 0x00007fff9288f5c9 libdyld.dylib`start + 1
149 frame #10: 0x00007fff9288f5c9 libdyld.dylib`start + 1
150*/