Query with WaitForNonStaleResults

831 views
Skip to first unread message

Erik

unread,
Oct 17, 2010, 3:31:29 PM10/17/10
to ravendb
Hi,

I'm using RavenDB as embedded DB and noticed that I can't use
Session.Query<T> because of the problem
that stale object is not returned. That means that everytime I have to
call "LuceneQuery" with WaitForNonStaleResults. So my question is the
following, instead of writing each time:

return
Session.Advanced.LuceneQuery<Appointment>("AppointmentsWithRepeatersAll")
.WaitForNonStaleResults()
.ToList()

Can I somehow specify that:

return
Session.Query<Appointment>("AppointmentsWithRepeatersAll")
.ToList()

sould be with WaitForNonStaleResults?

Thanks in advance

Ayende Rahien

unread,
Oct 17, 2010, 4:28:08 PM10/17/10
to rav...@googlegroups.com
Session.Query<Foo>().Customize(x=>x.WaitForNonStaleResults())

Please note that it isn't recommended to use this.
At a minimum, use WaitForNonStaleResultsAsOfNow

Erik

unread,
Oct 18, 2010, 1:15:29 AM10/18/10
to ravendb
Thanks! Can you clarify it a little bit more? Is it not recommended to
use WaitForNonStaleResults/WaitForNonStaleResultsAsOfNow or just
only WaitForNonStaleResults - because otherwise I get empty result
set.
> > Thanks in advance- Hide quoted text -
>
> - Show quoted text -

Ayende Rahien

unread,
Oct 18, 2010, 2:16:43 AM10/18/10
to rav...@googlegroups.com
WaitForNonStaleResults is the one that isn't recommended.
WaitForNonStaleResultsAsOfNow is useful when you need current results, but you should also consider when you can skip that.

Erik

unread,
Oct 18, 2010, 2:34:56 AM10/18/10
to ravendb
Maybe I got that wrong, but what I'm trying to achieve is to create
small scheduler application with
the list of appointments which retrieved on the startup time. Without
WaitForNonStateRsults*
I always get the empty list of appointments - so I don't see other
ways how not to use WaitForNonStaleResults/
WaitForNonStaleResultsAsOfNow.
Did I miss anything?

Thanks!
> > > - Show quoted text -- Hide quoted text -

Ayende Rahien

unread,
Oct 18, 2010, 2:50:00 AM10/18/10
to rav...@googlegroups.com
Erik,
How are you creating the index / data?
It is recommended to avoid using the WaitFor* because it means that you have to wait, while generally with Raven we avoid waiting.
Reads / queries in Raven are cheap, especially when you can take advantage on reading potentially stale data.

Erik

unread,
Oct 18, 2010, 5:00:55 AM10/18/10
to ravendb
Using the PutIndex as shown in examples,this is the complete source
code:

if (force || !
CheckIndexExistence("AppointmentsWithRepeatersAll"))
{

SessionFactory.DatabaseCommands.PutIndex("AppointmentsWithRepeatersAll",
new IndexDefinition<Appointment>
{
Map = appointments => from a in appointments
where a.RepeatAction !=
null
select new { a.RepeatAction,
a.CompletedDateTime }
});

Ayende Rahien

unread,
Oct 18, 2010, 7:56:27 AM10/18/10
to ravendb
Is it possible that you are always creating that?

Erik

unread,
Oct 19, 2010, 2:53:32 AM10/19/10
to ravendb
No, if I create indexe with PutIndex and index already exists - I'll
get exception. That's why I've added
CheckIndexExistence method.

Thomas Freudenberg

unread,
Oct 19, 2010, 2:58:12 AM10/19/10
to rav...@googlegroups.com
PutIndex has an overload, so you can override an existing index. If the index definition is the same, Raven does nothing - it's an no-op then.

Erik

unread,
Oct 19, 2010, 12:46:24 PM10/19/10
to ravendb
Good to know, thanks! But that doesn't expain why I can't use Query
without WaitFor*...

On Oct 19, 9:58 am, Thomas Freudenberg <i...@thomasfreudenberg.com>
wrote:

Ayende Rahien

unread,
Oct 19, 2010, 12:50:10 PM10/19/10
to ravendb
Can you try creating a repro?

Chris Marisic

unread,
Oct 19, 2010, 1:05:34 PM10/19/10
to ravendb
Unless you found an extremely large bug what you're stating that's
occurring shows you must be doing something that causes raven to
reindex stuff such as inserting new documents, or creating new
indexes. It seems most likely that your code is forcing the index to
be created which is why you get no results unless you do wait for
nonstale results.

Benny Thomas

unread,
Oct 20, 2010, 3:24:26 AM10/20/10
to ravendb
Should RavenDB.Samples stop using WaitForNonStaleResults?

Ayende Rahien

unread,
Oct 20, 2010, 3:30:31 AM10/20/10
to ravendb
Yes

Erik

unread,
Oct 29, 2010, 8:07:14 AM10/29/10
to ravendb
Sorry for late response - was busy with different issues. Had time to
investigate it a little bit more.
The picture is the following:
WaitForNonStaleResults
Still needed for me even with build #189. Steps to reproduce it -

1. Create domain object and then save it then, call:
session.SaveChanges();
2. Try to get list of all objects without WaitForNonStaleResults - the
object won't appear.

I suppose because beckground thread is not finished yet.


On 19 okt., 20:05, Chris Marisic <ch...@marisic.com> wrote:
> Unless you found an extremely large bug what you're stating that's
> occurring shows you must be doing something that causes raven to
> reindex stuff such as inserting new documents, or creating new
> indexes. It seems most likely that your code is forcing the index to
> be created which is why you get no results unless you do wait for
> nonstale results.
>
> On Oct 18, 2:34 am, Erik <erikf...@gmail.com> wrote:
>
>
>
> > Maybe I got that wrong, but what I'm trying to achieve is to create
> > small scheduler application with
> > the list of appointments which retrieved on the startup time. Without
> > WaitForNonStateRsults*
> > I always get the empty list of appointments - so I don't see other
> > ways how not to useWaitForNonStaleResults/
> > WaitForNonStaleResultsAsOfNow.
> > Did I miss anything?
>
> > Thanks!
>
> > On Oct 18, 9:16 am, Ayende Rahien <aye...@ayende.com> wrote:
>
> > >WaitForNonStaleResultsis the one that isn't recommended.
> > > WaitForNonStaleResultsAsOfNow is useful when you need current results, but
> > > you should also consider when you can skip that.
>
> > > On Mon, Oct 18, 2010 at 7:15 AM, Erik <erikf...@gmail.com> wrote:
> > > > Thanks! Can you clarify it a little bit more? Is it not recommended to
> > > > useWaitForNonStaleResults/WaitForNonStaleResultsAsOfNow or just
> > > > onlyWaitForNonStaleResults- because otherwise I get empty result
> > > > set.
>
> > > > On Oct 17, 11:28 pm, Ayende Rahien <aye...@ayende.com> wrote:
> > > > > Session.Query<Foo>().Customize(x=>x.WaitForNonStaleResults())
>
> > > > > Please note that it isn't recommended to use this.
> > > > > At a minimum, use WaitForNonStaleResultsAsOfNow
>
> > > > > On Sun, Oct 17, 2010 at 9:31 PM, Erik <erikf...@gmail.com> wrote:
> > > > > > Hi,
>
> > > > > > I'm using RavenDB as embedded DB and noticed that I can't use
> > > > > > Session.Query<T> because of the problem
> > > > > > that stale object is not returned. That means that everytime I have to
> > > > > > call "LuceneQuery" withWaitForNonStaleResults. So my question is the
> > > > > > following, instead of writing each time:
>
> > > > > >            return
>
> > > > Session.Advanced.LuceneQuery<Appointment>("AppointmentsWithRepeatersAll")
> > > > > >                .WaitForNonStaleResults()
> > > > > >                .ToList()
>
> > > > > > Can I somehow specify that:
>
> > > > > >            return
> > > > > > Session.Query<Appointment>("AppointmentsWithRepeatersAll")
> > > > > >                .ToList()
>
> > > > > > sould be withWaitForNonStaleResults?
>
> > > > > > Thanks in advance- Hide quoted text -
>
> > > > > - Show quoted text -- Hide quoted text -
>
> > > - Show quoted text -- Paslēpt citēto tekstu -
>
> - Rādīt citēto tekstu -

Matt Warren

unread,
Oct 29, 2010, 8:19:25 AM10/29/10
to ravendb
I think that point is that WaitForNonStaleResults isn't best-practice
outside of small code samples or unit tests.

If you need to see the most up to date results possible you will
always have to use WaitForNonStaleResultsAsOfNow(), but for best-
practice code samples you should only use this sparingly as it really
hurts performance. Plus it a lot of situations, a stale index isn't a
problem.

You're right, in that because the background thread hasn't finished,
you won't see the new items.

But I think the main point is that the samples have to be rewritten to
explain or show this clearly. Just putting WaitForNonStaleResults() in
every sample makes people think that it's needed and/or good practice.

Erik

unread,
Oct 29, 2010, 8:33:15 AM10/29/10
to ravendb
Yup, this is what I understood either. WaitForNonStaleResults should
be used only when you need the latest result. Actually that
also pointed in the samples around the web space.
Thanks!

On 29 okt., 15:19, Matt Warren <mattd...@gmail.com> wrote:
> I think that point is thatWaitForNonStaleResultsisn't best-practice
> outside of small code samples or unit tests.
>
> If you need to see the most up to date results possible you will
> always have to use WaitForNonStaleResultsAsOfNow(), but for best-
> practice code samples you should only use this sparingly as it really
> hurts performance. Plus it a lot of situations, a stale index isn't a
> problem.
>
> You're right, in that because the background thread hasn't finished,
> you won't see the new items.
>
> But I think the main point is that the samples have to be rewritten to
> explain or show this clearly. Just puttingWaitForNonStaleResults() in
> every sample makes people think that it's needed and/or good practice.
>
> On Oct 29, 1:07 pm, Erik <erikf...@gmail.com> wrote:
>
>
>
> > Sorry for late response - was busy with different issues. Had time to
> > investigate it a little bit more.
> > The picture is the following:
> >                WaitForNonStaleResults
> > Still needed for me even with build #189. Steps to reproduce it -
>
> > 1. Create domain object and then save it then, call:
> > session.SaveChanges();
> > 2. Try to get list of all objects withoutWaitForNonStaleResults- the
> > > - Rādīt citēto tekstu -- Paslēpt citēto tekstu -
Reply all
Reply to author
Forward
0 new messages