View doesn't seems to be persisted to disk

8 views
Skip to first unread message

nicolas...@zenika.com

unread,
Jul 4, 2017, 1:53:33 PM7/4/17
to Couchbase Mobile
Hi all,
i'm currently writing an application using Couchbase Lite on Android.
And I have quite a mystery bug.
At startup, I try to write a document to Couchbase, and have it published in a view.
My map function is correctly called but, when i restart the application, the document doesn't appear in the view.

I've tried to export my application sqlite DB and open it in DBeaver, and the table mapping the view is empty after I run the application. As a consequence, and since my map code is called during application run, it seems to me that the view is not correctly persisted to disk.

Am I wrong ? (I guess so, but I don't understand how)
If I'm right, how can I make sure my couchbase DB is correctly persisted to disk ?
If I'm wrong, there must be something I don't understand, but what ? In other words, can someone explain to me the way a document is persisted ? To my mind, the new revision is written, then if a query is made on a view, the view index is updated (and at that time only the view is persisted to disk). I must be wrong, no ?

Jens Alfke

unread,
Jul 4, 2017, 2:34:44 PM7/4/17
to mobile-c...@googlegroups.com

On Jul 4, 2017, at 12:47 AM, nicolas...@zenika.com wrote:

At startup, I try to write a document to Couchbase, and have it published in a view.
My map function is correctly called but, when i restart the application, the document doesn't appear in the view.

Are you re-registering the map function on restart? Everything about a view is persistent except the map function.

Are you using a legal map function? Remember, it needs to be a “pure” function, i.e the output depends only on the input document, not on any global data or captured variables.

Is there anything else (e.g. a pull replication) that might be updating the document later, such that the map function won’t emit anything from it?
If you get the document on the second run of the app, does it still have the expected contents?

I've tried to export my application sqlite DB and open it in DBeaver, and the table mapping the view is empty after I run the application. As a consequence, and since my map code is called during application run, it seems to me that the view is not correctly persisted to disk.

Any rows you read from a query have been persisted to disk. The view indexer first calls the map function and then writes the emitted rows to the database. The query code reads the rows from the database. There’s no code path that goes from the map function to your query without hitting the database in between.

Can you describe the sequence of what happens? It sounds like
  1. Register view and map function
  2. Create document
  3. Query database; get a row from that document
  4. Quit & relaunch app
  5. Re-register map function (?)
  6. Query database; get no results
(Actually the order of steps 1 and 2 doesn’t matter.)

—Jens

Nicolas Delsaux

unread,
Jul 5, 2017, 3:14:32 AM7/5/17
to mobile-c...@googlegroups.com
Like it is always the case, I found the solution not so long after asking the question.
it appeared that my document was submitted 3 times to the map function.
During the first two submits, it correctly emits the expected value.
But, on the third call, no value is emitted. As a consequence, the document is removed from the view and no more appears in my query.

Fixing my map function fixed the whole problem.
Thanks anyway for your answer.

--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/BF24FE4B-73B1-4702-B8C6-53AB11003DC7%40mooseyard.com.
For more options, visit https://groups.google.com/d/optout.
--
-- 
Nicolas Delsaux
Consultant
Mobile: 07 69 99 61 17 

Zenika Lille
6 rue Jean Roisin 59000 Lille
Standard : +33(0)3 66 72 50 30 
   
Reply all
Reply to author
Forward
0 new messages