[Xapian-discuss] Threaded test (in C++) to reproduce our database problems

Eric B. Ridge ebr@tcdi.com
Wed, 16 Jun 2004 21:24:50 -0400


> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--B_3170265892_25193571
Content-type: text/plain;
	charset="US-ASCII"
Content-transfer-encoding: 7bit

Okay, we finally broke down and write a quickie threaded test in C++ to
reproduce the database problems we've been having.  On my dual-processor Mac
running OS X, this test fails every time.

The code is below, and should be fairly straight forward.  1 writer thread
that constantly add's documents to a Xapian::WritableDatabase, and a bunch
of reader threads that execute queries.

Ignoring the lack of synchronization around stderr/stdout, here's the
output:

--------------------------------------------
$ ./build/xapian_threads
Writer:  flush()
Reader: started
RRReeeaaadddeeerrrs::   ssstttaaarrrttteeeddd


Reader:  ERROR=Error reading all bytes: Bad file descriptor (fd=7)
Reader:  ERROR=Error reading block 40: Bad file descriptor (fd=5)
Writer:  flush()
Reader:  ERROR=Db block overwritten
Writer:  ERROR=Db block overwritten
Writer thread unexpectedly exited...
--------------------------------------------

So you can see, our reader threads bomb out, then the writer thread dies
too.  :(

Any ideas?  We wrote this little C++ test pretty quickly (could be buggy),
but it reproduces what we're seeing from the Java-side.

eric


--B_3170265892_25193571
Content-type: application/octet-stream; name="xapian_threads.cpp"
Content-disposition: attachment;
	filename="xapian_threads.cpp"
Content-transfer-encoding: base64

I2luY2x1ZGUgPHhhcGlhbi5oPgojaW5jbHVkZSA8cHRocmVhZC5oPgojaW5jbHVkZSA8dW5p
c3RkLmg+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgInhhcGlhbl90aHJlYWRzLmgi
CgojZGVmaW5lIERBVEFCQVNFICIvdG1wL3hhcGlhbl90aHJlYWRzLmRiIgojZGVmaW5lIE1B
WF9USFJFQURTIDMKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpwdGhyZWFkX3QgX3dyaXRlcjsK
cHRocmVhZF90IF9yZWFkZXJzW01BWF9USFJFQURTXTsKCnZvaWQgZG9f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