Thursday, 29 August 2013

Updating a document in sharded document store- ravendb

Updating a document in sharded document store- ravendb

Here updating a document in ravendb sharded document store seems to be
hectic since i am using sess.store with the id to update any given
document, I am using store to avoid concurrent updates I am using the
following code to update.
This is the document structure
public class DistributorRechargePayment:IPOCOLogInfo
{
[JsonIgnore]
public Guid? Etag;
public String Id { get; set; }
public String ReceiptNo { get; set; }
public TransactionTypes TransactionType { get; set; }
public String PaymentId { get; set; }
}
here is the code for update
sess.Store(distbpayment, myguid1, distbpayment.Id);
and in my shard strategy i have referred to a shard key with the some
other value as follows
var shards = new Dictionary<string, IDocumentStore>
{
{"zero", new DocumentStore {Url = "http://localhost:8080"}},
{"one", new DocumentStore {Url = "http://localhost:8081"}},
{"two", new DocumentStore {Url = "http://localhost:8082"}},
};
shardStrategy = new
ShardStrategy(shards).ShardingOn<DistributorRechargePayment>(x =>
x.ReceiptNo);
Now wat happens here is when i store for the first time the document is
moved to the correct shard for example if receiptno is one-123455 this
document goes to the correct shard. And when i update through the store
again when i already have the document id as
one-DistributorRechargePayment-1 so id is re-written as
one-one-DistributorRechargePayment-1 which throws an error.
Here i could have used sess.saveshanges(). But to ensure optimistic
concurrency i need sess.store(). I need a solution to use optimistic
concurrency and also achieve sharded store

No comments:

Post a Comment