--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
WaitForLastWrite will wait until the last write _from this process_ will be indexed.
I totally agree with Chris on this topic, and not only this :-)
The only thing I’d like to add to the conversation, beside the fact that it should work as expected, is that the really difficult thing is the mindset switch, we have been used for years to a consistent world that does not mimic at all the real world, in real life we are used to staleness and I’ll add that we can perfectly live without transactions :-) we compensate every single moment of the day.
I tried to explain to my mug that the action of drinking is transactional not to change the t-shirt when something goes wrong… :-P
.m
--
:-) the reality is that I do not know the meaning of them I only use WaitFor* in tests in order to block the test engine to be sure that data are where the test expects to find them :-)
This is only a part of the problem, and cannot be applied in most situation where you really need to scale out, if you are living in an eventually consistent world you need to fully embrace that world, period, and live with it :-)
I simplify things down for the topic, we have been used, due to the consistency behavior or relational db, to:
1. Handle the user request;
2. Connect to the db;
3. Do something interesting with the data;
4. Read the result from the db;
5. Since by default transactions are “serialized” we are sure that the read data are consistent with what we wrote;
The above is the typical single thread situation where the caller is blocked waiting for the operation to complete, right now if you introduce another thread at step 3 you are in eventually consistent world, a sort of, where the caller is freed before the end of the operation thus if the caller tries to read data can find something unexpected :-)
For the sake of the sample let us say that the indexing behavior of RavenDB is like a thread at step 3, so if you need to read the data you have just written you need a way to wait, well I do not see this as a solution, see below, but as a compromise if the situation allows it, and the various WaitFor, as per Chris sample, are there for this. So:
1. Handle the user request;
2. Connect to the db;
3. Do something interesting with the data;
4. Wait for the index to have your own data indexed
5. Read the result from the index;
6. Return to the user;
Now the question is: what happens if we introduce the “consistency” problem, or a sort of, before? For example at step 1? I’m working on an application where the flow can be summarized like this:
1. A SPA (single page html application) issues a request to the WebAPI backend;
2. WebAPI does nothing, simply transform the incoming request into something that can be sent over a bus (Azure Service Bus);
3. Return to the user;
4. Another process, a worker role, handles the request
a. Connects to the db;
b. Does something interesting with the data
c. Send an event on the bus again to notify that something interesting is completed;
5. The WebAPI backend waits for the event and transform if to something deliverable via SignalR to the originating SPA;
6. The SPA can now read its own written data;
In the above situation having an eventually consistent db or not is the same, it does not change the problem at all, because the caller is freed at step 2 where nothing has happened yet.
My experience start saying that embracing eventual consistency leads you to embrace events sourcing and embracing events sourcing brilliantly solves the whole problem, exactly as in real life there are situations where you need to wait for something (block the UI and wait for the event) or situation where you are only interested the something is happened (simply wait for the event without blocking the UI) or even situation where you are not interested at all in the event (fire and forget).
When you are in a line at the bank, waiting for your operation to get completed, you are not lying on the casher knees continuously asking him “have you finished?”, you are simply waiting for him to tell you (event) the result of the operation, but in the meanwhile you can do something else, you are blocking the line behind you.
And last: embrace a world with no transaction but with compensations, everything is much easier :-)
.m
From: rav...@googlegroups.com [mailto:rav...@googlegroups.com]
On Behalf Of devm...@hotmail.com
Sent: giovedì 15 agosto 2013 08.10
To: rav...@googlegroups.com
Subject: Re: [RavenDB] Re: WaitFor...AsOfLastWrite vs. WaitFor...AsOfNow
Chirs, this is eye opening for me, could you please confirm my understanding ?
what you mean is edit record, call SaveChanges() then immediately after that query and user waitforlastwrite then redirect the user to list page ?
somethings i am wondering about :
-what exactly do you mean by "makes the uncommon operations, writes, to have to wait. "
-is this a normal solution to use or just for extreme situations ?
-the thing which i still don't understand, when you add or update a new record, does the whole index recompute or just modified records, and if it just the modified records, why peopel are so worried as i don't image this will take more than seconds to update the index.
thanks for your input
On Thursday, August 15, 2013 1:12:56 AM UTC+4, Chris Marisic wrote:
This is, but not on reading the list. You want to write this record, then in the same request query that index with waitforlastwrite, then redirect the user to the list after the index is synchronized. This avoids making the common operation, reads, from always waiting, and makes the uncommon operations, writes, to have to wait.
+1 to changing your pov. Most if these problems disappear if you 'bend the spoon'. As Mircea pointed out in his post script about unique user names, just have docs that have the names as keys and store in a transaction with your main doc(s). No waiting. Most situations can be repositioned to simply avoid the decisions you're facing. Believe me, it's not easy when you're starting out because we're so used to relational dbs. In that world, you start with 3nf or whatever and then figure out how the heck you get what you need out. In document modeling, you figure out what you need and build that. In practice, that means that all the pain and frustration you normally feel at the end of a relational db project is experienced up front in a document db project. IMO, this is a good thing, but it is definitely challenging to our 'training'.