Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBLReplicator.isDocumentPending is inaccurate when replicator is offline #1132

Closed
PaulCapestany opened this issue Feb 19, 2016 · 4 comments
Closed

Comments

@PaulCapestany
Copy link
Contributor

It seems likeisDocumentPending might not be working as one would expect it to when a device is completely offline.

Setup to reproduce

Follow these instructions in order to use Apple's "Network Link Conditioner" to test different connectivity qualities on both the simulator and on actual physical iOS devices.

In the ToDoLite-iOS project, change the kSyncGatewayUrl in AppDelegate.m if need be. Also, make sure that the FacebookAppID and URL Scheme in Info.plist is usable/accurate as well.

Expected behavior

  1. When on a good wifi connection, newly added or edited items in any of the tableViews should have black text.
  2. When switching to the "Very Bad Network" setting in Apple's "Network Link Conditioner", newly added or edited items in any of the tableViews should have grey text if they haven't been successfully synced within 1.5 seconds (they should turn black again once the replication properly executes however).
  3. When putting the testing device in 'Airplane Mode', newly added or edited items in any of the tableViews should have grey text since they're unable to sync, and should turn black again when back on a network connection.

Actual behavior

  1. Works as expected.
  2. Works as expected.
  3. Unexpected behavior. The text of newly added or edited items stays black even though items have not synced due to being in 'Airplane Mode' (and therefore should be grey).
@snej
Copy link
Contributor

snej commented Feb 19, 2016

Seems like the replicator isn't considering anything as pending while it's in the offline state. I wonder why...

@snej
Copy link
Contributor

snej commented Feb 19, 2016

Oh, actually it's a simple logic error in CBLReplication. It keeps a cached set of _pendingDocIDs and invalidates it when the replicator's progress changes. But that set should also be invalidated whenever the database changes, because any changed document becomes part of the set.

@snej
Copy link
Contributor

snej commented Feb 19, 2016

It would be more efficient for CBLReplication to cache the push replicator's lastSequence (an integer.) Then it can implement isDocumentPending: just by comparing the doc's sequence number against that lastSequence.

pendingDocumentIDs requires a query to compute, so maybe it should still be cached. In that case CBLReplication should also keep track of the database's lastSequence at the time it ran the query. Then if lastSequence changes, it means the set is invalidated.

@snej snej changed the title Potential isDocumentPending bug? CBLReplicator.isDocumentPending is inaccurate when replicator is offline Feb 19, 2016
@tleyden
Copy link
Contributor

tleyden commented Feb 19, 2016

It would be more efficient for CBLReplication to cache the push replicator's lastSequence (an integer.) Then it can implement isDocumentPending: just by comparing the doc's sequence number against that lastSequence.

That sounds familiar .. from your previous comment #442 (comment):

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.

@zgramana zgramana added this to the 1.3 milestone Feb 19, 2016
snej added a commit that referenced this issue Feb 22, 2016
Now tracking replicator's lastSequence and caching it in an ivar.
-isDocumentPending: just compares the doc's sequence with that.
pendingDocumentIDs does basically what it used to do, but it doesn't
need to do it on a background thread.

Also, the bug-fix portion of this is that pendingDocumentIDs remembers
the database's lastSequenceNumber when it's cached; if that changes,
the cached value is invalidated.

Fixes #1132
@snej snej added review and removed in progress labels Feb 23, 2016
snej added a commit that referenced this issue Feb 29, 2016
Now tracking replicator's lastSequence and caching it in an ivar.
-isDocumentPending: just compares the doc's sequence with that.
pendingDocumentIDs does basically what it used to do, but it doesn't
need to do it on a background thread.

Also, the bug-fix portion of this is that pendingDocumentIDs remembers
the database's lastSequenceNumber when it's cached; if that changes,
the cached value is invalidated.

Fixes #1132
@snej snej closed this as completed in f7dc8dc Feb 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants