M
M
max_mara2013-02-15 00:41:28
NoSQL
max_mara, 2013-02-15 00:41:28

CouchDB: Frequent Update

Good evening, Khabrovites. I'm trying to attach

CouchDB to one of our projects and, in principle, I'm very pleased with everything.
I really like the fact that 100 million records, on a modest 8 Cores x 32GB RAM server, turn over without problems.

But there is one small detail

{
   "_id": "_design/funcs",
   "updates": {
       "addUid": "function(doc,req) {
       		if(doc!==null) {
       			req.body=JSON.parse(req.body);
       			var uids=req.body.uids;
       			for(var uid in uids) {
       				uid=uids[uid];
       				doc.uids[uid] = true
       			} 
       			
       			delete doc._rev
       		}
       		return[doc,JSON.stringify(doc)]
       	}"
   }
}


I have an update handler inside my database, which should add unique identifiers to the document several times a second.
The problem is that if I start calling this handler very often, I get 409: Document update conflict

CouchDB 1.0.2

What am I missing and how can I fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
1nd1go, 2013-02-15
@1nd1go

I could be wrong, but first, every time you update a document, a new version of it is created. This means that when the id is added, there will be a new version of the document. Due to frequent additions, the B+ tree of records can be rebuilt, which can affect the performance
. By the way, did I understand correctly that the id is updated in objects belonging to the same document? It may also be that once you write down the id thread to someone, you are trying to refer to an even old document in a cycle.

H
hellboy1981, 2015-11-03
@hellboy1981

and how it is necessary to handle the "Document update conflict" exception correctly? In a loop, get a new version of the document, apply changes to it, and then repeat?
wouldn't there be an infinite loop here?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question