[Xapian-discuss] Node.js binding

Liam xapian at networkimprov.net
Thu Oct 20 18:11:45 BST 2011


On Thu, Oct 20, 2011 at 3:51 AM, Richard Boulton <richard at tartarus.org>wrote:

> On 20 October 2011 06:31, Liam <xapian at networkimprov.net> wrote:
> > Do any of these potentially hit the disk? I'd guessed that none of them
> > did...
> >  Enquire::Enquire(database)
> >  Query::Query(...);
> >  Enquire::set_query(query);
> >  MSet::size()
> Pretty sure all the above are safe.
>
> >  MSetIterator:: operator *(), get_percent(), get_document()
> get_document() is not safe here - the documents can be lazily loaded
> into the MSet object, so this can hit disk or network.
>

Document::get_data() does I/O, so what does MSetIterator::get_document() do?


...
> One concern about putting some Xapian accesses into a subthread; it is
> not safe to call methods on Xapian API objects concurrently, so you'll
> need to protect calls with some locking scheme, or some convention to
> avoid this.  Seems very tricky to do right, to me, and might therefore
> be safer to just do everything in a subthread.
>

While it is possible to "parallelize" I/O functions as below, typically you
sequence them in nested callbacks as in my prior example code. All
Javascript code is confined to the main thread -- which makes it possible to
hang everything with while(true) {} :-P

// check for existence of two files
fs.stat('file1', done); // these can execute simultaneously, but
fs.stat('file2', done); // the callback only runs in the main thread
var count = 2, ok = true
function done(err, stats) {
  if (err && err.errno !== process.ENOENT) throw err;
  ok = ok && !err;
  if (--count === 0 && ok)
    console.log('both files found')
}


More information about the Xapian-discuss mailing list