Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 08121C366 for ; Thu, 24 Jan 2013 21:15:55 +0000 (UTC) Received: (qmail 99136 invoked by uid 500); 24 Jan 2013 21:15:53 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 99097 invoked by uid 500); 24 Jan 2013 21:15:53 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 99083 invoked by uid 99); 24 Jan 2013 21:15:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Jan 2013 21:15:53 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,SPF_PASS,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of robert.newson@gmail.com designates 209.85.128.170 as permitted sender) Received: from [209.85.128.170] (HELO mail-ve0-f170.google.com) (209.85.128.170) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Jan 2013 21:15:46 +0000 Received: by mail-ve0-f170.google.com with SMTP id ox1so1780109veb.29 for ; Thu, 24 Jan 2013 13:15:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=i69kvKEUetpPBUSjgrUuVBsOUNqJHqtWuIV0W6uoPao=; b=Nq1fgAf+dY0+DYEIRCECOWtH5xTEv0KYj1Vi3YECevncA9SedA5XzHqnTADVjzLc3z XE2O7w7MAk6h0D3VVpzBdvWM8Qdd+9z7P9Tf7/IgrBohmNAkOTayc1smqK3Xs8W80quc aZMiq6tL5sdKuqCbP0lBgEQyqWC+f6wBMGA7ouch9rjoR/GFOsSTHIoETZmdkFyXYt6k LsuCHdTv+Qua9+G/DdXpYFqwFdB5OyK5Orx0AnvYYAYsNMqaI0FrA/23WWIaf20VTH2v Eg+Yh43NqAivr1CtMRhGKkRS30l9ohSw+wzWSz8eEiwR1dsW6lp7RkPNubic5Ctv2DRL gASQ== MIME-Version: 1.0 X-Received: by 10.220.156.197 with SMTP id y5mr3580481vcw.17.1359062126006; Thu, 24 Jan 2013 13:15:26 -0800 (PST) Received: by 10.52.68.209 with HTTP; Thu, 24 Jan 2013 13:15:25 -0800 (PST) In-Reply-To: <1359060545.3327.47.camel@mike.loop.com.br> References: <1359060545.3327.47.camel@mike.loop.com.br> Date: Thu, 24 Jan 2013 21:15:25 +0000 Message-ID: Subject: Re: Unexpected behavior from compacted databases From: Robert Newson To: "user@couchdb.apache.org" Content-Type: multipart/alternative; boundary=f46d042f91103f93d704d40f4ff5 X-Virus-Checked: Checked by ClamAV on apache.org --f46d042f91103f93d704d40f4ff5 Content-Type: text/plain; charset=ISO-8859-1 Couchdb-1415? On Thursday, January 24, 2013, Mike Leddy wrote: > Hi, > > I first noticed this strange behavior inserting documents to restart > replications that had failed and decided to investigate what I > observed. It is probably best to give a reproducible example. > > First for this test I am using 1.2.0 > > $ curl localhost:5984 > {"couchdb":"Welcome","version":"1.2.0"} > > I wrote a trivially simple script to write a sequence of the same > documents in ruby (any ruby should work ensuring the couchrest gem > is installed - 'gem install couchrest') > > require 'couchrest' > > server = CouchRest.new 'http://localhost:5984' > db = server.database!('test') > > doc = db.get('test') rescue nil > doc ||= CouchRest::Document.new(_id: 'test') > > 1.upto(3) do |index| > doc[:index]=index > db.save_doc(doc) > p doc > end > > As this is an email I will do all activities using only this script > and curl. > > 1. make sure we start form zero > > $ curl -X DELETE localhost:5984/test > {"ok":true} > or > {"error":"not_found","reason":"missing"} > > 2. run script > $ ruby testing.rb > # "1-a0814dba083c9453bffa352768a40264"> > # "2-85e66c4f3bb95acc2f133183a7ecc461"> > # "3-38668f9c9bcfdadffa9c8aca593a3001"> > > Perfect, document inserted and updated > > 3. delete the document > > $ curl -X DELETE > localhost:5984/test/test?rev=3-38668f9c9bcfdadffa9c8aca593a3001 > {"ok":true,"id":"test","rev":"4-507344f27f5e55e3e677ae25f1acf587"} > > 4. run the script again > > $ ruby testing.rb > # "5-41c70119c629df492276862b19a990dc"> > # "6-9d9ccd6dbedde3022ef683af3cd3793d"> > # "7-8b1c05d8e10b031c52d54549354da6f5"> > > Perfectly normal behavior, all revision numbers in sequence > > 5 delete the document again > > $ curl -X DELETE > localhost:5984/test/test?rev=7-8b1c05d8e10b031c52d54549354da6f5 > {"ok":true,"id":"test","rev":"8-6065e64dcdcec1acfc0f1fbf331b948e"} > > OK, everything is working as expected. Now compact the database: > > curl -H "Content-Type: application/json" -X POST > http://localhost:5984/test/_compact > {"ok":true} > > 6 run the script again > > $ ruby testing.rb > # "1-a0814dba083c9453bffa352768a40264"> > # "2-85e66c4f3bb95acc2f133183a7ecc461"> > # "3-38668f9c9bcfdadffa9c8aca593a3001"> > > It seems as though everything is fine and we are starting from scratch > again but .... > > 7 check if the document exists > > $ curl http://localhost:5984/test/test > {"error":"not_found","reason":"deleted"} > > Now that is strange, couchdb has responded that the document was created > and updated and > it does not exist in the database !!! > > 8 run the script again > > $ ruby testing.rb > # "9-8979d2a7a845bed3dff9c7c161e95a9e"> > # "10-49162ab87eb1cca98391006242e05c1f"> > # "11-b3012f6391add21ed626dad28a6e2699"> > > Notice the revision sequence numbers continue on as if before the > compaction. > > 9 check if the document exists > > $ curl http://localhost:5984/test/test > {"_id":"test","_rev":"11-b3012f6391add21ed626dad28a6e2699","index":3} > > It would seem that the first run of the script after compaction is > inserting documents > that already are in the tombstone and the deleted document continues as > the latest > version. The second run of the script appends new versions in the way that > would be > expected if the compaction had not been done. > > For completeness here is a dump of the meta info for this document at the > end of the > test: > > $ curl -s http://localhost:5984/test/test?meta=true | json_pp > { > "index" : 3, > "_id" : "test", > "_revs_info" : [ > { > "status" : "available", > "rev" : "11-b3012f6391add21ed626dad28a6e2699" > }, > { > "status" : "available", > "rev" : "10-49162ab87eb1cca98391006242e05c1f" > }, > { > "status" : "available", > "rev" : "9-8979d2a7a845bed3dff9c7c161e95a9e" > }, > { > "status" : "deleted", > "rev" : "8-6065e64dcdcec1acfc0f1fbf331b948e" > }, > { > "status" : "missing", > "rev" : "7-8b1c05d8e10b031c52d54549354da6f5" > }, > { > "status" : "missing", > "rev" : "6-9d9ccd6dbedde3022ef683af3cd3793d" > }, > { > "status" : "missing", > "rev" : "5-41c70119c629df492276862b19a990dc" > }, > { > "status" : "missing", > "rev" : "4-507344f27f5e55e3e677ae25f1acf587" > }, > { > "status" : "available", > "rev" : "3-38668f9c9bcfdadffa9c8aca593a3001" > }, > { > "status" : "available", > "rev" : "2-85e66c4f3bb95acc2f133183a7ecc461" > }, > { > "status" : "available", > "rev" : "1-a0814dba083c9453bffa352768a40264" > } > ], > "_rev" : "11-b3012f6391add21ed626dad28a6e2699" > } > > Any comments ? Can anyone explain this behavior ? > > Thanks in advance, > > Mike > > > > > > > > --f46d042f91103f93d704d40f4ff5--