count of unsync'd docs on the device?

98 views
Skip to first unread message

Jeremy Kelley

unread,
Sep 8, 2014, 11:19:12 AM9/8/14
to mobile-c...@googlegroups.com
I've searched the docs and I can't seem to find a way to get a count
of unsync'd documents.

Is there an obvious way?

-j

--
The Christian ideal has not been tried and found wanting;
it has been found difficult and left untried – G. K. Chesterton

Jens Alfke

unread,
Sep 8, 2014, 12:28:39 PM9/8/14
to mobile-c...@googlegroups.com

On Sep 8, 2014, at 8:19 AM, Jeremy Kelley <jer...@33ad.org> wrote:

I've searched the docs and I can't seem to find a way to get a count
of unsync'd documents.

There isn't really a notion of "unsynced", because you can set up any number of replications on a database, which could push to different servers. (Yes, this does happen, mostly in P2P systems.) So any given document might currently be synced to one server but not another. Also, a filtered replication won't push all documents, so it's unclear whether the documents it skips should be counted as synced or not.

In the future we might figure out a clear way to provide some sort of information about which docs have been synced to which servers. For now, all you can tell is that when a push replication stops (or goes idle) without errors, everything's been synced.

—Jens

Jeremy Kelley

unread,
Sep 8, 2014, 1:10:35 PM9/8/14
to mobile-c...@googlegroups.com
That was my fear... So with a continuous sync running, this is a bit
complicated.

I'll dig into it and stew on it a bit more. Thanks Jens.

-j
> --
> 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/5C70FEE7-8E6C-4CAC-B964-2874FE81999C%40couchbase.com.
> For more options, visit https://groups.google.com/d/optout.

Jens Alfke

unread,
Sep 8, 2014, 2:25:36 PM9/8/14
to mobile-c...@googlegroups.com

On Sep 8, 2014, at 10:10 AM, Jeremy Kelley <jer...@33ad.org> wrote:

That was my fear...  So with a continuous sync running, this is a bit complicated.

When the replication status changes to idle, all docs have been synced.

—Jens

Zack Gramana

unread,
Sep 9, 2014, 11:10:59 AM9/9/14
to <mobile-couchbase@googlegroups.com>
> When the replication status changes to idle, all docs have been synced.

A number of users are struggling to build user interfaces which indicate to users which items are not yet sync'ed to a server. This is especially true for devs that are using one-shot replications to limit radio battery drain, or during significant partition events (airplane mode one, no usable wifi, etc).

Traun Leyden

unread,
Sep 9, 2014, 12:39:55 PM9/9/14
to mobile-c...@googlegroups.com

On Tue, Sep 9, 2014 at 8:10 AM, Zack Gramana <za...@couchbase.com> wrote:
> When the replication status changes to idle, all docs have been synced.

A number of users are struggling to build user interfaces which indicate to users which items are not yet sync'ed to a server. This is especially true for devs that are using one-shot replications to limit radio battery drain, or during significant partition events (airplane mode one, no usable wifi, etc).
--
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.

Jens Alfke

unread,
Sep 9, 2014, 5:33:00 PM9/9/14
to mobile-c...@googlegroups.com

On Sep 9, 2014, at 8:10 AM, Zack Gramana <za...@couchbase.com> wrote:

A number of users are struggling to build user interfaces which indicate to users which items are not yet sync'ed to a server. This is especially true for devs that are using one-shot replications to limit radio battery drain, or during significant partition events (airplane mode one, no usable wifi, etc).

I was thinking about this yesterday (in a background task that didn't block access to my forebrain ;-)

The push replicator's checkpoint is the sequence number below which all revisions have been uploaded to the server. So we can test whether a doc has been pushed by comparing its current revision's sequence number to the checkpoint. The push replicator already runs a query of all revisions with sequence > checkpoint, to find out which revisions to push — we could expose an API to such a query.

I started hacking on it on the train this morning. It's not much code at all. I've provisionally added a new property Replication.unpushedDocumentIDs that returns an NSSet of the IDs of all documents with un-pushed revisions. I'll check it in on a branch today.

—Jens

Jens Alfke

unread,
Sep 10, 2014, 6:27:27 PM9/10/14
to mobile-c...@googlegroups.com
I'm curious to know what form people need this information in, because it has an impact on what the API and implementation would be like.

I think the two questions are:
  • Do you need just the total number of un-pushed docs, or the individual doc IDs?
  • Are you OK with a one-shot call to retrieve this, or do you need change notifications (as with LiveQuery)?
In each of these, the second alternative (doc IDs, change notifications) will be harder to implement efficiently.

(FYI, this is being tracked as issue #442 in the iOS repo, although we recognize it's cross-platform.)

—Jens

Zack Gramana

unread,
Sep 10, 2014, 8:34:45 PM9/10/14
to mobile-c...@googlegroups.com
The people I’ve talked to want this as a boolean property on Document.

--
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.

Zack Gramana

unread,
Sep 10, 2014, 8:47:22 PM9/10/14
to mobile-c...@googlegroups.com
On Sep 10, 2014, at 3:27 PM, Jens Alfke <je...@couchbase.com> wrote:
  • Do you need just the total number of un-pushed docs, or the individual doc IDs?

Individual doc IDs, or...

  • Are you OK with a one-shot call to retrieve this, or do you need change notifications (as with LiveQuery)?
In each of these, the second alternative (doc IDs, change notifications) will be harder to implement efficiently.

Perhaps just a simple sync event handler/callback, added to Document, the is invoked when the item has been pushed.

This would be enough to let the UI update from “unsynced” to “synced” state. The remote URL might be passed to the callback, letting the application developer decide if a given endpoint should “count” as the official sync endpoint if multiple replication endpoints a being use for the same device. In peer to peer applications, you could even list which peers the document has been directly synced to, or if sync has only happened locally but not a sync gateway endpoint, for example. This could be done at the end of UploadBulkDocs, for example.

Jens Alfke

unread,
Sep 10, 2014, 9:04:01 PM9/10/14
to mobile-c...@googlegroups.com

On Sep 10, 2014, at 5:34 PM, Zack Gramana <za...@couchbase.com> wrote:

The people I’ve talked to want this as a boolean property on Document.

That's understandable, but as I've said, this doesn't make sense in the general case where there are multiple replications. Any actual API for this this will need to take both of the document and the replication as input.

Perhaps just a simple sync event handler/callback, added to Document, the is invoked when the item has been pushed.

It could be tricky to make use of that, though. By the time you get notified that one revision's been pushed, you might already have created another revision, which hasn't been pushed yet, so the actual state of the document will still be "unpushed".

—Jens

Zack Gramana

unread,
Sep 10, 2014, 9:29:47 PM9/10/14
to <mobile-couchbase@googlegroups.com>
If the Boolean property is added to the DocumentChange class, then that is already accounted for.

Sent from my iPhone
--
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.

Jeremy Kelley

unread,
Sep 10, 2014, 10:28:05 PM9/10/14
to mobile-c...@googlegroups.com
For my case, just a simple count of unsync'd / local-only docs is
fine. A one shot is fine.

-j
> --
> 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/506EDCD5-CE8C-45FE-8A67-F2605153D0A8%40couchbase.com.

Jens Alfke

unread,
Sep 11, 2014, 11:43:02 AM9/11/14
to mobile-c...@googlegroups.com

On Sep 10, 2014, at 6:29 PM, Zack Gramana <za...@couchbase.com> wrote:

If the Boolean property is added to the DocumentChange class, then that is already accounted for.

There's no DocumentChange (or change notification) associated with pushing a document, because push doesn't change the document.

—Jens

Jens Alfke

unread,
Sep 11, 2014, 11:44:50 AM9/11/14
to mobile-c...@googlegroups.com

On Sep 10, 2014, at 7:28 PM, Jeremy Kelley <jer...@33ad.org> wrote:

For my case, just a simple count of unsync'd / local-only docs is
fine.  A one shot is fine.

OK — you can get that much from the new API I checked in on the feature/unpushed branch. If you're willing to check out and build that, I'd appreciate feedback on how it worked for you.

—Jens

Jeremy Kelley

unread,
Sep 11, 2014, 2:15:57 PM9/11/14
to mobile-c...@googlegroups.com
Jens - I can do this first thing in the morning. Will get back to you
then. Thanks for jumping on this! -j
> --
> 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/3108DA71-54E8-4688-A0C8-C47D0E7C1EA3%40couchbase.com.

Zack Gramana

unread,
Sep 11, 2014, 2:19:45 PM9/11/14
to mobile-c...@googlegroups.com
The proposal, implied above, is to invoke it on documents that are are part of a push sync session.

Marcus Roberts

unread,
Sep 17, 2014, 7:18:01 AM9/17/14
to mobile-c...@googlegroups.com
This will be really useful for me too - my use case is that the user can "logout" of the device which removes the local database.  I don't want to allow this (without a warning) if there are any documents still on the device not synched.  I'll try out the new branch, thanks!

Jeremy Kelley

unread,
Sep 17, 2014, 6:14:03 PM9/17/14
to mobile-c...@googlegroups.com
On Wed, Sep 17, 2014 at 6:18 AM, Marcus Roberts
<marcus....@gmail.com> wrote:
> This will be really useful for me too - my use case is that the user can
> "logout" of the device which removes the local database. I don't want to
> allow this (without a warning) if there are any documents still on the
> device not synched. I'll try out the new branch, thanks!
>

This is exactly my use case. When a user is "logging out", I want to
warn them that the local copy of the db has unsync'd changes.

Sorry haven't tried the branch yet, been covered up with other things.
Will soon.

-j
Reply all
Reply to author
Forward
0 new messages