Re: [RavenDB] Data Model & its queries questions

31 views
Skip to first unread message

Oren Eini (Ayende Rahien)

unread,
Jul 17, 2012, 6:34:37 PM7/17/12
to rav...@googlegroups.com
1) I don't understand the question.

2) If you have session.Advanced.UseOptimisticConcurrency = true; it will throw a concurrency exception, otherwise, last write wins.

3) It uses http mechanism and 304 to detect that.

On Tue, Jul 17, 2012 at 12:31 PM, Mohammad Habbab <moh.h...@gmail.com> wrote:
Since this is my first time writing Raven Database code, i wanted to make sure that my model isn't messing things up and my queries are possible and Valid.Here's my model ( It's a CMS project designed for weird-customer needs -_-  )

class DenormalizedUserInfo
{
    public string EmailAddress {get;set;}
    public string FirstName {get;set;}
    public string LastName {get;set;}
}

class Comment
{
    public string Id {get;set;}
    public string Url {get;set;}
    public string Content {get;set;}
    public DateTime CreationTime {get;set;}
    public DenormalizedUserInfo UserInfo{get;set;}
    public int LikesCount {get;set;}
    public int DisLikesCount {get;set;} 
}

class CommentCollection
{
     public string Url {get;set;}
     public SortedSet<Comment> Comments {get;set;}
}

class Post 
{
    public string Id {get;set;}
    public string Url {get;set;}
    public string Content {get;set;}
    public DateTime CreationTime {get;set;}
    public DenormalizedUserInfo UserInfo {get;set;}
    public int LikesCount {get;set;}
    public int DisLikeCount {get;set;}
    public SortedSet<Comments> RelatedComments {get;set;}
}

The user usecases are: 1- add/remove/modify posts (according to ID). 2- Add/remove/like/dislike comment on a Post (according to [PostID,CommentID] pair).
3-Add/remove/like/dislike comment on a CommentCollection (according to (Url,CommentID) pairs).
I was able to create Indexing classes for: getting a post by Id, post by URL, post by user, commentcollection by Url.
Hah ... that was alot of talk (sorry for talking so long) .. anyway .. my concerns are :

1- In usecases (2) i have to have two pieces of information (namely, postId and CommentId) inorder to get the right object. is there a way to get it using only CommentId by indexing and querying on commentId somehow ? This also applies to usecase (3).

2- Access to my data objects is multi-threaded. Do i need some locking mechanism for my fields when they're modified by multiple threads at the same time (say, two users wanted to add a comment to a post at the same time), or does raven handle this by itself? if so, then how !?

3- I'm using Raven Server over Http (because you recommended this for production). I've read that it provides caching of objects in memory. How does raven alter this cache when i modify a document that is currently in cache ?
 
Thanx .. 

Mohammad Habbab

unread,
Jul 17, 2012, 7:04:56 PM7/17/12
to rav...@googlegroups.com
don't mind question (1), I found similar issue u answered on another thread .. thank you.
But about (2) .. does "last write wins" means that if user (A) requested a Post Document and Added a comment (Ac1), and mean while user (B) also requested the same post document and Added a comment (Bc1). then the one who last commits between them is the one who'll have his comment Added, while the other will be overwritten ? If that's the case ... how can i overcome this in my code? Is there some locking mechanism or API i can utilize ?

Cheers !

Mohammad Habbab

unread,
Jul 17, 2012, 7:05:45 PM7/17/12
to rav...@googlegroups.com

Kijana Woodard

unread,
Jul 17, 2012, 9:11:50 PM7/17/12
to rav...@googlegroups.com
You can Patch ( http://ravendb.net/docs/client-api/partial-document-updates ) values into the comments list or you can keep the comments as their own independent documents without the list in post. Either way will mitigate concurrency issues.

Oren Eini (Ayende Rahien)

unread,
Jul 18, 2012, 1:13:07 AM7/18/12
to rav...@googlegroups.com
 If you have session.Advanced.UseOptimisticConcurrency = true; it will throw a concurrency exception 
Ore you can use patching.

Mohammad Habbab

unread,
Jul 18, 2012, 4:11:54 AM7/18/12
to rav...@googlegroups.com
Ok .. great .. sounds like patching is very suitable ( specially with the blog example :) )  thank you for the help !
Reply all
Reply to author
Forward
0 new messages