[Xapian-discuss] Terminating a Xapian query

Olly Betts olly at survex.com
Fri Sep 25 17:28:55 BST 2009


On Fri, Sep 25, 2009 at 04:24:02PM +0100, James Aylett wrote:
> On Fri, Sep 25, 2009 at 04:19:39PM +0100, Olly Betts wrote:
> 
> > If you just kill the thread, you're likely to leak memory.  The same
> > goes if you try to use alarm(), setjmp() and longjmp() for similar
> > reasons, but you can probably manage to close the database if you scope
> > the jump correctly, so no fd leaks.
> 
> I was actually thinking of having the database held open by another
> thread, so the searching thread is never responsible for its final
> destruction.

OK, that sounds plausible and would solve the fd part but you'll still
get leaks from not calling destructors of objects with automatic scope.

> > I think the best current approach would be to run the search in a child
> > process.  You could achieve this without having to write much code if
> > you run the search using the remote backend and xapian-progsrv.  If you
> > only have one database and it is remote, recent versions of Xapian just
> > run the match remotely and then serialise the results across the link,
> > so you only add a small overhead.  The bit I can't see how to cleanly
> > implement is finding the pid of the xapian-progsrv so you can kill it...
> 
> progsrv will have to be started by something, won't it?

It's run when you call Remote::open().

You could start xapian-tcpsrv yourself in one-shot mode on a chosen port
and then easily kill it, but the port management would be kind of icky.

Cheers,
    Olly



More information about the Xapian-discuss mailing list