Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RavenDB and stale indexes on application startup

I have an application that:

  • Uses an embedded RavenDB database
  • With the Monotonic read option
  • With static indexes

I've noticed that when the application starts up, the indexes are all temporarily stale even if they weren't stale when the application shutdown (cleanly) the previous run.

For example, I run the app, insert 10 records, and wait for the indexes to be up to date. I query it and see the results I expect. Then I close the app, start it again, and query, and I get no results. A second later the indexes have updated and I can now get results back. If I repeat this, sometimes I get 10 results, sometimes 0 results, sometimes 2 results.

My assumption was that when querying an index at time T, I would always see "at least as consistent" results at T + 1. However if the server restarts during this time I seem to see less consistent results at T + 1. This isn't eventual consistency, it's eventual inconsistency! :)

My questions are:

  1. Was my assumption wrong/stupid?
  2. Is there a way to prevent this from happening?
  3. Is this behavior just a starting up thing, or could this potentially happen at any time? For example, could I render 10 results, then on refresh 0 results, and then again 10 results the next refresh just because Raven decided it wanted to re-index everything?
like image 973
Paul Stovell Avatar asked Jun 24 '13 10:06

Paul Stovell


1 Answers

To answer your questions,

Was my assumption wrong/stupid?

No, as i understand it your assumption is correct, you may see stale results, but shouldn't see less stale results, unless the index was rebuilt from scratch between T & T+1 and you hit it just after the index was reset.

Is there a way to prevent this from happening?

The only way i know of is to be very sure that the indexes were cleanly closed. There are usually lock files left in the index folders that indicate if this isn't the case. The debug level logs from Raven will indicate if a rebuild is initiated as well.

If all else fails, you may need to have a process that blocks until all indexes (or the ones you care about) are fresh before proceeding with the rest of the application start-up process.

Is this behavior just a starting up thing, or could this potentially happen at any time? For example, could I render 10 results, then on refresh 0 results, and then again 10 results the next refresh just because Raven decided it wanted to re-index everything?

Yes, this is possible if the index is reset, but as far as i know that will only happen (after startup) if manually triggered through the API or management studio.

like image 71
Thomas James Avatar answered Nov 04 '22 07:11

Thomas James