You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by gi...@git.apache.org on 2017/08/30 11:41:51 UTC

[GitHub] S-Aggarwal opened a new issue #782: Using custom revision numbers when creating documents

S-Aggarwal opened a new issue #782: Using custom revision numbers when creating documents
URL: https://github.com/apache/couchdb/issues/782
 
 
   <!--- Provide a general summary of the issue in the Title above -->
   
   We were using our own revision numbers with couchDB 1.6 to mask the number of edits made on a document. This was achieved by adding a "_rev" property to the JSON document we inserted into the database and making an API request with a _rev parameter (as if performing an update). The revision number was generated using the following Go code:
   
   ```go
   // randomRev produces a deterministic revision number from the plaintext, 1-2^16, and a hash
   // After compaction, the number of revisions for a doc is now masked on the server
   // Input should be the document
   func randomRev(doc interface{}) string {
   	encoded, err := json.Marshal(doc)
   	if err != nil {
   		log.Error(errors.Trace(err))
   		return ""
   	}
   	multihash, err := mh.Sum(append([]byte("revsalt"), encoded...), mh.SHA1, 16)
   	if err != nil {
   		log.Error(errors.Trace(err))
   		return ""
   	}
   	revNum := binary.BigEndian.Uint16(multihash[15:17]) // two bytes ie 0-2^16
   	return strconv.Itoa(int(revNum)) + "-" + multihash.HexString()[4:]
   }
   ```
   
   In Couch 1.6, couch treated the document creation as an update and then the revision number was just an increment of what we provided (eg if we gave _rev=41543-c1a310b73245bfac2a69583319a2470c, then after completion the stored document had _rev=41544-<some hash value hexstring>).
   
   In Couch 2.1, this generally doesn't work for the most part and Couch gives us a Document update conflict but what's strange is it seems to work sometimes. 
   Eg
   While inserting 
   ```json
   {
   	"_id": "randomid10",
   	"_rev": "64769-1a0347892643024c68e945015bfd0141",
   	"par" : "test"
   }
   ```
   we get a 409: Document update conflict.
   
   But when inserting
   ```json
   {
   	"_id": "randomid123",
   	"_rev": "41543-c1a310b73245bfac2a69583319a2470c",
   	"par": "test"
   }
   ```
   the document is successfully created. Also adding this same document to a different database (or even the same one after wiping it completely) gives back an update conflict.
   
   I am not sure what is happening behind the scenes here but there seems to be some kind of bug here.
   
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services