willholley opened a new issue, #6199:
URL: https://github.com/apache/couchdb/issues/6199

   ### Version
   
   3.5.3
   
   ### Describe the problem you're encountering
   
   If a document has one live leaf and one deleted leaf, and the live leaf is 
purged, the document is effectively deleted: `GET` returns 
`{"error":"not_found","reason":"deleted"}` and `_all_docs` no longer lists it. 
But the database still counts it as a live document (`doc_count` stays 1, 
`doc_del_count` stays 0), so `_all_docs` reports `total_rows: 1` with no rows.
   
   ### Expected Behaviour
   
   A purge removes the named revisions from the database as if it had never 
seen them. It doesn't remove the document. As long as one revision is left, the 
document counts as live or deleted according to its remaining leaves, and when 
none are left it isn't counted at all. This is what each case should give for 
the document above:
   
   | Purge request | Leaves left | `doc_count` | `doc_del_count` | `main` |
   |---|---|---|---|---|
   | `2-bbbb` (the only live leaf) | `2-cccc` (deleted) | 0 | 1 | 1 / 0, 
**wrong** |
   | `2-cccc` (the deleted leaf) | `2-bbbb` (live) | 1 | 0 | 1 / 0, correct |
   | `2-bbbb` and `2-cccc` in one request | none | 0 | 0 | 0 / 0, correct |
   | `2-bbbb`, then `2-cccc` in a second request | none | 0 | 0 | 0 / 0, 
correct |
   
   Only the first row is wrong. In the last two rows the document is removed 
from the id tree altogether, so the counts drop correctly.
   
   ### Steps to Reproduce
   
   
   Single-node dev cluster:
   
   ```sh
   COUCH=http://admin:[email protected]:15984
   post() { curl -s -X POST $COUCH/pd/_bulk_docs -H 'Content-Type: 
application/json' -d "$1"; }
   stats() { curl -s $COUCH/pd | python3 -c 'import sys,json; 
d=json.load(sys.stdin); print("doc_count", d["doc_count"], "doc_del_count", 
d["doc_del_count"])'; }
   
   curl -s -X PUT "$COUCH/pd?n=1&q=1"
   
   # two conflicting leaves: 2-bbbb is live, 2-cccc is deleted
   post '{"new_edits":false,"docs":[{"_id":"doc","_rev":"2-bbbb",
     "_revisions":{"start":2,"ids":["bbbb","aaaa"]},"v":1}]}'
   post 
'{"new_edits":false,"docs":[{"_id":"doc","_rev":"2-cccc","_deleted":true,
     "_revisions":{"start":2,"ids":["cccc","aaaa"]}}]}'
   
   stats
   curl -s $COUCH/pd/_all_docs
   
   # purge the live leaf
   curl -s -X POST $COUCH/pd/_purge -H 'Content-Type: application/json' -d 
'{"doc":["2-bbbb"]}'
   
   stats
   curl -s $COUCH/pd/_all_docs
   curl -s $COUCH/pd/doc
   ```
   
   Before the purge:
   
   ```
   doc_count 1 doc_del_count 0
   
{"total_rows":1,"offset":0,"rows":[{"id":"doc","key":"doc","value":{"rev":"2-bbbb"}}]}
   ```
   
   After the purge:
   
   ```
   doc_count 1 doc_del_count 0
   {"total_rows":1,"offset":1,"rows":[]}
   {"error":"not_found","reason":"deleted"}
   ```
   
   
   ### Your Environment
   
   _No response_
   
   ### Additional Context
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to