Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Couchbase Server 2.0

stale=false not working?

12 replies [Last post]
  • Login or register to post comments
Tue, 09/18/2012 - 23:41
cachvico
Offline
Joined: 06/21/2012
Groups:

I believe I have found a bug using 2.0.0-1672-rel-community and python sdk couchbase-0.8.0.

The attached code deletes all docs in a view, then creates a doc and runs a view that should emit it.

The first time the program is run on an empty bucket, the doc is not emitted by the view (an empty array is printed). I think this is a bug. Subsequent runs will emit the doc as expected. But each time if I manually delete the doc in the web interface and then run the program again, the empty list is printed.

This is despite stale=False being set in the view call, which should force the index to be up-to-date?

import couchbase, json
cb = couchbase.Server('acid:8091', username='Administrator', password='password')
bucket = cb['default']
 
bucket.save({
    '_id' : '_design/test',
    'views' : { 'v': { 'map': 'function(doc, meta) { emit(doc.b, doc); }' } }
})
design = '_design/test/_view/v'
 
rows = bucket.view(design, stale=False)
if rows:
    for r in rows:
        bucket.delete(r['id'])
 
bucket.set('a', 0, 0, json.dumps({ 'b':'c' }))
 
print bucket.view(design, key='c', stale=False)

The following shows 3 consecutive runs, with the empty list being printed for the first execution:

$ python simple-cb.py 
[]
$ python simple-cb.py 
[{u'value': {u'b': u'c'}, u'id': u'a', u'key': u'c'}]
$ python simple-cb.py 
[{u'value': {u'b': u'c'}, u'id': u'a', u'key': u'c'}]

Top
  • Login or register to post comments
Wed, 09/19/2012 - 03:26
SkeLLLa
Offline
Joined: 06/22/2012
Groups: None

I also saw such bug, especially, after start/restart it returns empty results. Sometimes some views, that created before the data was stored to bucket always return empty result, but if you copy same map/reduce functions code in new view it returns correct results.

I use 1672 build and beta build. Bug reproduced on both instances.

Top
  • Login or register to post comments
Wed, 09/19/2012 - 08:01
ingenthr
Offline
Joined: 03/16/2010
Groups:

Yes, it sounds like a bug. We'll need to get one filed at couchbase.com/issues

Top
  • Login or register to post comments
Wed, 09/19/2012 - 08:50
cachvico
Offline
Joined: 06/21/2012
Groups:

(Just tried to file one but I don't have permission).

Top
  • Login or register to post comments
Wed, 09/19/2012 - 09:30
ingenthr
Offline
Joined: 03/16/2010
Groups:

We've just filed one. I'll update the thread with it soon.

On filing, what kind of permission issue? Everyone with a couchbase.com login should be able to file. Can you give me the message. Or a. Screenshot?

Thanks!

Top
  • Login or register to post comments
Wed, 09/19/2012 - 11:24
cachvico
Offline
Joined: 06/21/2012
Groups:

I can't quite remember, it was along the lines of 'no permission', and it said 'or new issues disabled' or something along those lines. I was filing it under Python Client Library project.

Side-note; can you show me how to find the issue that you created so I can track it? I can't actually find it.

Top
  • Login or register to post comments
Wed, 09/19/2012 - 11:44
Iryna
Offline
Joined: 05/29/2012
Groups: None

Hey
I investigated the case and I think this particular situation is not a bug:
We have following scenario according to code:
1. create view
2. delete all items that exist
3. add an item
4. query view with stale=false

Actions on site of couchbase, lets say we have default bucket and doc1 in it with revision 1:
1. view is created successfully, now doc has revision 1, we query view and we see it
2. Items are marked as deleted, now revision of our document is 2 and it is marked as deleted, drain to disk is started
3. Item doc1 is created again, revision is 3 now but it is in ram, is not drained yet
4. We query view with stale=false, it builds index with drained updates, it founds revision 2 (doc1 is deleted) and it returns empty results
5. If we query once again it will return revision 3 that already is drained and result has document

So is just depends on how fast items are drained to disk.

Top
  • Login or register to post comments
Wed, 09/19/2012 - 12:33
cachvico
Offline
Joined: 06/21/2012
Groups:

Hi Iryna,

Sorry, your repro steps do not follow the supplied test-case. There is no initial document when the view is created.

In addition, modifying the program to remove the delete results in the same behaviour. So this is not deletion-related. I've simplified it to the following:

setup:

import couchbase, json
cb = couchbase.Server('acid:8091', username='Administrator', password='password')
bucket = cb['default']
bucket.save({
    '_id' : '_design/test',
    'views' : { 'v': { 'map': 'function(doc, meta) { emit(meta.id, doc); }' } }
})
test:
design = '_design/test/_view/v'
 
print bucket.view(design, stale=False)            #1
bucket.set('c', 0, 0, json.dumps({ 'b':'c' }))
print bucket.view(design, stale=False)            #2

$ python test.py 
[]
[]   # there should be a document printed here
$ python test.py 
[{u'value': {u'b': u'c'}, u'id': u'c', u'key': u'c'}]
[{u'value': {u'b': u'c'}, u'id': u'c', u'key': u'c'}]

It appears to be the first execution of the view (#1) that causes the incorrect result to be returned by the second execution of the view, as removing that line causes #2 to behave correctly.

Regardless, surely stale=False should return always up-to-date data? Is this not the case in the special case of deletion; is this documented? But this is not directly related to this bug it seems.

Thank you,

Darren

Top
  • Login or register to post comments
Wed, 09/19/2012 - 13:14
Iryna
Offline
Joined: 05/29/2012
Groups: None

stale=false returns up-to-date items that are already persisted to disk. If items are still in ram or persisting is in progress index will not include those items. So for current screnario we have:
1. we created view successfully
2. we got an empty result as we expected
3. we put a document, persisting is started, but not finished yet. To observe this you can look into 'disk write queue' diagram, once queue is empty the document is drained and will be included in index
So if we try your script with delay between setting an item and then querying with stale=false we should get the document in the results

Top
  • Login or register to post comments
Wed, 09/19/2012 - 13:41
cachvico
Offline
Joined: 06/21/2012
Groups:

ah. Thank you for your explanation.

So there is no way of ensuring we have the most up-to-date results, i.e. to include in-memory results, or to ensure all data is persisted to disk, first?

Top
  • Login or register to post comments
Wed, 09/19/2012 - 13:53
Iryna
Offline
Joined: 05/29/2012
Groups: None

you can observe it,
please find additional information about observe here: http://www.couchbase.com/docs/couchbase-devguide-2.0/monitoring-data.html

Top
  • Login or register to post comments
Wed, 09/19/2012 - 14:58
ingenthr
Offline
Joined: 03/16/2010
Groups:

Unfortunately, the Python client does not yet have support for the observe command. We'll be adding that shortly.

You can probably just insert a brief pause if it's okay for now during development.

Top
  • Login or register to post comments
Wed, 09/19/2012 - 22:09
cachvico
Offline
Joined: 06/21/2012
Groups:

Ok - thank you for the info + correction of my misunderstanding.

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker