Replicators both go idle multiple times, but database hasn't finished replicating

I’m having an issue that only occurs on a fresh install of our app. The replicators go idle after being active for a while, however when trying to access a document that should be available, the document isn’t being found. Once the app is restarted, the issue is gone and the document can be found without any problems.

I’ll add that it doesn’t appear to matter how long you wait, the file is never available on the first run of the app.

Here is my initialisation code for the replicators:

Push = db.CreatePushReplication(uri);
Pull = db.CreatePullReplication(uri);
var auth = AuthenticatorFactory.CreateBasicAuthenticator(username, password);
Pull.Channels = GetAllChannels();
Push.Authenticator = auth;
Pull.Authenticator = auth;
Push.Continuous = true;
Pull.Continuous = true;
Push.Changed += OnReplicationChanged;
Pull.Changed += OnReplicationChanged;
Push.Start();
Pull.Start();

Here is my replicator event changed handler:

private void OnReplicationChanged(object sender, ReplicationChangeEventArgs e)
{
// Check if offline
if (Pull.Status == ReplicationStatus.Offline || Push.Status == ReplicationStatus.Offline)
{
 UserId = _userId;
 AuthEvent(new AuthEventArgs(AuthStatus.Offline, _progressPercent));
}
// Check if active
else if (Pull.Status == ReplicationStatus.Active || Push.Status == ReplicationStatus.Active)
{
 var total = Pull.CompletedChangesCount + Push.CompletedChangesCount;
 var progress = Pull.ChangesCount + Push.ChangesCount;
 _progressPercent = (double)progress / total;
 AuthEvent(new AuthEventArgs(AuthStatus.Active, _progressPercent));
}
// Check if error
else if (e.LastError != null)
{
 Exception error = e.LastError;
 if (error is HttpResponseException)
 {
  HttpResponseException exception = (HttpResponseException)error;
  if (exception.StatusCode == HttpStatusCode.Unauthorized)
 {
 AuthEvent(new AuthEventArgs(AuthStatus.AuthenticationError, _progressPercent));
}
}
// weird error happening
else
{
 AuthEvent(new AuthEventArgs(AuthStatus.FatalError, _progressPercent));
}
}
// if idle then replicators have finished and therefore connected.
else if (Pull.Status == ReplicationStatus.Idle && Push.Status == ReplicationStatus.Idle)
{
 UserId = _userId;
 AuthEvent(new AuthEventArgs(AuthStatus.Success, _progressPercent));
}
else if (Pull.Status == ReplicationStatus.Stopped || Push.Status == ReplicationStatus.Stopped)
{
 AuthEvent(new AuthEventArgs(AuthStatus.Stopped, _progressPercent));
}
}

I have a similar problem with the sync behavior on a fresh install as well. Few documents are synced when the replicator runs at first before going to rest and it takes a while (about 5 seconds) before pull starts again and the documents are synced.

Also, I get the same values for e.CompletedChangesCount and e.ChangesCount

Going idle before finishing is not unusual. Idle simply means that the replication has caught up with all the changes it has received. If it is processing them faster than it is receiving from the network then it will go idle before it is “finished” (because after all, in a continuous replication, what does “finished” mean?)

As far as the first message goes. What do the logs say? Are there any errors or warnings? Is replication running more on the second run.

Here is the log from launch all the way up to the last time the replicators both go idle:

[0:] INFO) DATABASE (Database): [5] 2017-4-13 09:51:49.239+08:00 Opening 
Database[/data/user/0/com./files/.local/share/d88e0c64c631ee370f7e101a5822433b6.cblite2]
[0:] INFO) DATABASE (Database): [7] 2017-4-13 09:51:49.244+08:00 Using Couchbase.Lite.Storage.SystemSQLite.SqliteCouchStore for SQLite implementation
[0:] INFO) DATABASE (SqliteCouchStore): [5] 2017-4-13 09:51:49.259+08:00 Initialized SQLite store (version 3.8.10.2 (2015-05-20 18:17:19 2ef4f3a5b1d1d0c4338f8243d40a2452cc1f7fe4))
[0:] INFO) DATABASE (Database): [7] 2017-4-13 09:51:49.263+08:00 Using Couchbase.Lite.Storage.SystemSQLite.SqliteCouchStore for db at /data/user/0/com./files/.local/share/d88e0c64c631ee370f7e101a5822433b6.cblite2; upgrade=False
[0:] INFO) TASK SCHEDULING (SingleThreadScheduler): [5] 2017-4-13 09:51:49.278+08:00 New single thread task scheduler created with private thread
Thread started: Database Thread #8
[0:] INFO) DATABASE (SqlitePCLRawStorageEngine): [7] 2017-4-13 09:51:49.301+08:00 Open /data/user/0/com./files/.local/share/d88e0c64c631ee370f7e101a5822433b6.cblite2/db.sqlite3 (flags=2162694)
[0:] INFO) DATABASE (SqlitePCLRawStorageEngine): [5] 2017-4-13 09:51:49.457+08:00 Open /data/user/0/com./files/.local/share/d88e0c64c631ee370f7e101a5822433b6.cblite2/db.sqlite3 (flags=2162689)
[0:] INFO) DATABASE (SqlitePCLRawStorageEngine): [7] 2017-4-13 09:51:49.470+08:00 Open /data/user/0/com./files/.local/share/d88e0c64c631ee370f7e101a5822433b6.cblite2/db.sqlite3 (flags=2162689)
[0:] INFO) DATABASE (SqlitePCLRawStorageEngine): [7] 2017-4-13 09:51:49.473+08:00 Open /data/user/0/com./files/.local/share/d88e0c64c631ee370f7e101a5822433b6.cblite2/db.sqlite3 (flags=2162689)
Loaded assembly: System.Runtime.Extensions.dll [External]
[0:] INFO) TASK SCHEDULING (SingleTaskThreadpoolScheduler): [7] 2017-4-13 09:51:49.704+08:00 New scheduler created
Loaded assembly: System.Dynamic.Runtime.dll [External]
Loaded assembly: System.ObjectModel.dll [External]
Loaded assembly: System.Linq.Expressions.dll [External]
Loaded assembly: System.IO.dll [External]
Loaded assembly: System.Runtime.Serialization.Formatters.dll [External]
Loaded assembly: System.Runtime.Numerics.dll [External]
Loaded assembly: System.Numerics.dll [External]
Loaded assembly: System.Runtime.Serialization.dll [External]
Loaded assembly: Anonymously Hosted DynamicMethods Assembly [External]
Loaded assembly: System.ComponentModel.TypeConverter.dll [External]
Loaded assembly: System.Reflection.Primitives.dll [External]
[0:] INFO) TASK SCHEDULING (SingleTaskThreadpoolScheduler): [7] 2017-4-13 09:51:50.502+08:00 New scheduler created
Thread finished:  #7
Thread started: <Thread Pool> #10
Thread started: <Thread Pool> #11
[0:] INFO) SYNC (Replication): [11] 2017-4-13 09:51:50.667+08:00 Attempting to start puller (1311d4cc-a017-4a4a-a98c-19ca7f4dd944)
[0:] INFO) SYNC (Replication): [11] 2017-4-13 09:51:50.670+08:00 Attempting to start pusher (e33e99c6-a085-41a1-b5b0-16ec5bbf5ab9)
The thread 'Unknown' (0x7) has exited with code 0 (0x0).
[0:] INFO) SYNC (Replication): [12] 2017-4-13 09:51:50.854+08:00 Beginning replication process...
[0:] INFO) SYNC (Replication): [12] 2017-4-13 09:51:50.931+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 successfully logged in!
[0:] INFO) SYNC (Replication): [11] 2017-4-13 09:51:50.966+08:00 Beginning replication process...
[0:] INFO) SYNC (Replication): [12] 2017-4-13 09:51:50.978+08:00 Pusher e33e99c6-a085-41a1-b5b0-16ec5bbf5ab9 successfully logged in!
[0:] INFO) SYNC (Replication): [12] 2017-4-13 09:51:50.983+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 no local checkpoint, not getting remote one
[0:] INFO) SYNC (Replication): [12] 2017-4-13 09:51:50.986+08:00 Pusher e33e99c6-a085-41a1-b5b0-16ec5bbf5ab9 no local checkpoint, not getting remote one
[0:] INFO) SYNC (Puller): [11] 2017-4-13 09:51:50.991+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 will use MaxOpenHttpConnections(8), MaxRevsToGetInBulk(50)
[0:] INFO) CHANGE TRACKER (WebSocketChangeTracker): [11] 2017-4-13 09:51:51.034+08:00 Starting WebSocketChangeTracker[sync_gateway]...
Thread started: <Thread Pool> #12
Thread started:  #13
[0:] INFO) CHANGE TRACKER (ChunkedChanges): [12] 2017-4-13 09:51:51.421+08:00 Parse found 1 changes
[0:] INFO) CHANGE TRACKER (ChunkedChanges): [11] 2017-4-13 09:51:51.497+08:00 Parsed [{"seq":"6626:4","id":"5367e22cc83172bf6f2d746fc7d09c26","changes":[{"rev":"1-85e3f84c72032c5a81017a8ef589ffed"}]}] (nested count: 0)
[0:] INFO) SYNC (Puller): [7] 2017-4-13 09:51:51.503+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 caught up with changes
[0:] INFO) CHANGE TRACKER (WebSocketChangeTracker): [11] 2017-4-13 09:51:51.508+08:00 WebSocketChangeTracker[sync_gateway] switching to non-active mode
[0:] INFO) SYNC (Puller): [7] 2017-4-13 09:51:51.548+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 queued 1 remote revisions from seq=6626:4 (1 in bulk, 0 individually)
04-13 09:51:51.645 I/System.out( 6899): (HTTPLog)-Static: Hongbao
04-13 09:51:51.700 I/System.out( 6899): (HTTPLog)-Static: isSBSettingEnabled false
04-13 09:51:51.700 I/System.out( 6899): (HTTPLog)-Static: Hongbao
04-13 09:51:51.700 I/System.out( 6899): (HTTPLog)-Static: isSBSettingEnabled false
[0:] INFO) DATABASE (Database): [7] 2017-4-13 09:51:52.124+08:00 Database[/data/user/0/com./files/.local/share/d88e0c64c631ee370f7e101a5822433b6.cblite2] posting change notifications: seq [1]
[0:] INFO) SYNC (Puller): [11] 2017-4-13 09:51:52.139+08:00 Inserted 1 revs in 183.389 milliseconds
[0:] INFO) SYNC (Replication): [7] 2017-4-13 09:51:52.148+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 checkpointing sequence=6626:4
04-13 09:51:53.465 W/System.err( 6899): remove failed: ENOENT (No such file or directory) : /data/user/0/com./shared_prefs/com._preferences.xml.bak
[0:] INFO) DATABASE (Database): [7] 2017-4-13 09:51:53.489+08:00 No pending doc expirations
04-13 09:51:53.500 I/Timeline( 6899): Timeline: Activity_launch_request id:com. time:8784139
04-13 09:51:53.520 I/Choreographer( 6899): Skipped 79 frames!  The application may be doing too much work on its main thread.
04-13 09:51:53.525 D/ViewRootImpl( 6899): #1 mView = android.widget.LinearLayout{77a1464 V.E...... ......I. 0,0-0,0}
04-13 09:51:53.530 I/System.out( 6899): (HTTPLog)-Static: Hongbao
[0:] ERROR) SYNC (Replication): [12] 2017-4-13 09:51:53.528+08:00 Exception in Changed callback, this will cause instability unless corrected!:
System.ArgumentException: document does not exist.
Parameter name: g@g.com
  at (wrapper delegate-invoke) System.EventHandler`1[Couchbase.Lite.ReplicationChangeEventArgs]:invoke_void_object_TEventArgs (object,Couchbase.Lite.ReplicationChangeEventArgs)
  at Couchbase.Lite.Replication+<NotifyChangeListeners>c__AnonStorey8.<>m__0 () [0x000a2] in <bb3bb8c4fbb54f939fa09402030f6081>:0 
04-13 09:51:54.340 I/Choreographer( 6899): Skipped 48 frames!  The application may be doing too much work on its main thread.
04-13 09:51:54.345 I/System.out( 6899): (HTTPLog)-Static: isSBSettingEnabled false
04-13 09:51:54.345 I/System.out( 6899): (HTTPLog)-Static: Hongbao
04-13 09:51:54.345 I/System.out( 6899): (HTTPLog)-Static: isSBSettingEnabled false
[0:] ERROR) SYNC (Replication): [6] 2017-4-13 09:51:54.345+08:00 Exception in Changed callback, this will cause instability unless corrected!:
System.ArgumentException: document does not exist.
Parameter name: g@g.com
  at (wrapper delegate-invoke) System.EventHandler`1[Couchbase.Lite.ReplicationChangeEventArgs]:invoke_void_object_TEventArgs (object,Couchbase.Lite.ReplicationChangeEventArgs)
  at Couchbase.Lite.Replication+<NotifyChangeListeners>c__AnonStorey8.<>m__0 () [0x000a2] in <bb3bb8c4fbb54f939fa09402030f6081>:0 
04-13 09:51:54.365 D/mali_winsys( 6899): new_window_surface returns 0x3000,  [254x88]-format:1
04-13 09:51:54.395 D/AbsListView( 6899): Get MotionRecognitionManager
04-13 09:51:54.395 E/MotionRecognitionManager( 6899): mSContextService = null
04-13 09:51:54.395 E/MotionRecognitionManager( 6899): motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@f7a188e
04-13 09:51:54.405 D/AbsListView( 6899): Get MotionRecognitionManager
04-13 09:51:54.450 D/adh_common( 6899): Screen Width: 768dp.
04-13 09:51:54.450 D/adh_common( 6899): Screen Height: 1024dp.
[0:] INFO) SYNC (RemoteSession): [7] 2017-4-13 09:51:54.455+08:00 [Couchbase Sync Gateway: Version=1.3.1]: Server Version: [Couchbase Sync Gateway: Version=1.3.1]
[0:] INFO) SYNC (Replication): [11] 2017-4-13 09:51:54.477+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 saved remote checkpoint '6626:4' (_rev=0-1)
04-13 09:51:54.555 D/HA-MetricsManager( 6899): Checking if we have to renew a session, time difference is: 1027
04-13 09:51:54.560 D/SecWifiDisplayUtil( 6899): Metadata value : SecSettings2
04-13 09:51:54.560 D/ViewRootImpl( 6899): #1 mView = com.android.internal.policy.PhoneWindow$DecorView{91e35e4 I.E...... R.....ID 0,0-0,0}
04-13 09:51:54.575 V/RenderScript( 6899): 0x901fb000 Launching thread(s), CPUs 8
04-13 09:51:54.590 D/mali_winsys( 6899): new_window_surface returns 0x3000,  [1536x2048]-format:1
04-13 09:51:54.740 D/ViewRootImpl( 6899): MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
04-13 09:51:54.820 D/ViewRootImpl( 6899): MSG_RESIZED_REPORT: ci=Rect(0, 48 - 0, 0) vi=Rect(0, 48 - 0, 0) or=1
04-13 09:51:54.850 I/Timeline( 6899): Timeline: Activity_idle id: android.os.BinderProxy@85afb76 time:8785486
04-13 09:51:54.965 D/ViewRootImpl( 6899): #3 mView = null
04-13 09:51:55.530 D/ViewRootImpl( 6899): #1 mView = android.widget.LinearLayout{4f3056a V.E...... ......I. 0,0-0,0}
04-13 09:51:55.550 D/ViewRootImpl( 6899): #3 mView = null
04-13 09:51:55.610 D/mali_winsys( 6899): new_window_surface returns 0x3000,  [420x88]-format:1
04-13 09:51:55.650 D/ViewRootImpl( 6899): MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
[0:] INFO) CHANGE TRACKER (WebSocketChangeTracker): [5] 2017-4-13 09:51:56.576+08:00 Starting WebSocketChangeTracker[sync_gateway]...
[0:] INFO) CHANGE TRACKER (ChunkedChanges): [6] 2017-4-13 09:51:56.588+08:00 Parse found 4 changes
[0:] INFO) SYNC (Puller): [12] 2017-4-13 09:51:56.612+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 queued 1 remote revisions from seq=6626:5 (1 in bulk, 0 individually)
04-13 09:51:56.615 I/System.out( 6899): (HTTPLog)-Static: Hongbao
04-13 09:51:56.620 I/System.out( 6899): (HTTPLog)-Static: isSBSettingEnabled false
04-13 09:51:56.620 I/System.out( 6899): (HTTPLog)-Static: Hongbao
04-13 09:51:56.620 I/System.out( 6899): (HTTPLog)-Static: isSBSettingEnabled false
Thread started:  #14
[0:] INFO) CHANGE TRACKER (ChunkedChanges): [5] 2017-4-13 09:51:56.661+08:00 Parse found 1 changes
Thread finished:  #13
[0:] WARN) SYNC (Puller): [12] 2017-4-13 09:51:56.708+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 Failed to add {<redacted> #1-619f989b5178163ac3ee64da4c609d22} to inbox, probably already added.  Marking completed
[0:] INFO) CHANGE TRACKER (ChunkedChanges): [11] 2017-4-13 09:51:56.731+08:00 Parse found 4 changes
[0:] WARN) SYNC (Puller): [6] 2017-4-13 09:51:56.749+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 Failed to add {<redacted> #1-0acc3836aee74e8fe5c82fde5a499810} to inbox, probably already added.  Marking completed
The thread 'Unknown' (0xd) has exited with code 0 (0x0).
[0:] INFO) CHANGE TRACKER (ChunkedChanges): [11] 2017-4-13 09:51:56.795+08:00 Parsed [{"seq":"6626:11","id":"c8d7d7f160fe682548718fdb80a4944e","changes":[{"rev":"1-619f989b5178163ac3ee64da4c609d22"}]}][{"seq":"6626:12","id":"aaron@gmail.com","changes":[{"rev":"1-0acc3836aee74e8fe5c82fde5a499810"}]},{"seq":"6626:19","id":"e8381eecdd8dfd99e039fb08965384c3","changes":[{"rev":"1-85e3f84c72032c5a81017a8ef589ffed"}]},{"seq":"6626:21","id":"739ea6291610d2e8e2722015c5fb8df8","changes":[{"rev":"1-153f3d764cabe350d56c3f4cafaa22ae"}]},{"seq":"6626:22","id":"229c8e4df3d5f37dcb0c72d76846eecc","changes":[{"rev":"1-468e7f2ac03506f1a14d208bc4c22d5e"}]}] (nested count: 0)
[0:] INFO) CHANGE TRACKER (ChunkedChanges): [6] 2017-4-13 09:51:56.803+08:00 Parse found 9 changes
[0:] INFO) DATABASE (Database): [5] 2017-4-13 09:51:56.834+08:00 Database[/data/user/0/com./files/.local/share/d88e0c64c631ee370f7e101a5822433b6.cblite2] posting change notifications: seq [2]
[0:] INFO) SYNC (Puller): [11] 2017-4-13 09:51:56.841+08:00 Inserted 1 revs in 78.719 milliseconds
04-13 09:51:56.875 I/art     ( 6899): Starting a blocking GC Explicit
04-13 09:51:56.895 I/art     ( 6899): Explicit concurrent mark sweep GC freed 2352(235KB) AllocSpace objects, 2(40KB) LOS objects, 36% free, 28MB/44MB, paused 415us total 16.418ms
[0:] INFO) CHANGE TRACKER (ChunkedChanges): [12] 2017-4-13 09:51:56.924+08:00 Parsed [{"seq":"6626:24","id":"guy@guy.com","changes":[{"rev":"17-c2f0b618ab9801092ea4ebf4b21b10c4"},{"rev":"9-fbee9b19e17602a569360da86cbc4c95"}]},{"seq":"6626:574","id":"9c19e346025fb47effc244f38d80f26b","changes":[{"rev":"1-0ee079e3247495a0655f3a72a42ed755"}]},{"seq":"6626:2615","id":"s3CredentialsGlobal","changes":[{"rev":"3-d6fc7076b06ed0307e56202ce317e030"}]},{"seq":6626,"id":"_user/g@g.com","changes":[]},{"seq":6627,"id":"f49becf707c5b1f16c20902c30e74843","changes":[{"rev":"1-e23231d8b4c4abedcd6ff82f6212c5c9"}]},{"seq":6630,"id":"g@g.com","changes":[{"rev":"3-1a395ccc0ae4ddf770abfebfdbebabe2"}]},{"seq":6655,"id":"recording::::TEZPIfCb1kSeC9G7vS0Q1Q==","changes":[{"rev":"25-08622310831dc5823923f611a3b32ad9"}]},{"seq":6662,"id":"recording::::Y988c+nO10OO9A1EpF4lqg==","changes":[{"rev":"3-fbdff5a685bb33de8a248cef232cf697"}]},{"seq":6670,"id":"recording::::mh87a45dpkK8Q9/k3Nznbg==","changes":[{"rev":"8-f67132e91e3b7ff64db62dade09eb363"}]}] (nested count: 0)
04-13 09:51:56.960 W/art     ( 6899): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
04-13 09:51:56.970 D/HockeyApp( 6899): Writing unhandled exception to: /data/user/0/com./files/524778f4-00b5-48df-b4a8-832c9e47c9d4.stacktrace
[0:] INFO) SYNC (Puller): [7] 2017-4-13 09:51:57.145+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 queued 15 remote revisions from seq=6626:10 (15 in bulk, 0 individually)
[0:] INFO) SYNC (Puller): [6] 2017-4-13 09:51:57.189+08:00 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 bulk-fetching 15 remote revisions...
[0:] INFO) SYNC (Replication): [7] 2017-4-13 09:51:57.244+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 checkpointing sequence=6626:5
04-13 09:51:57.270 I/System.out( 6899): (HTTPLog)-Static: Hongbao
04-13 09:51:57.270 I/System.out( 6899): (HTTPLog)-Static: Hongbao
04-13 09:51:57.275 I/System.out( 6899): (HTTPLog)-Static: isSBSettingEnabled false
04-13 09:51:57.275 I/System.out( 6899): (HTTPLog)-Static: Hongbao
04-13 09:51:57.275 I/System.out( 6899): (HTTPLog)-Static: isSBSettingEnabled false
04-13 09:51:57.275 I/System.out( 6899): (HTTPLog)-Static: isSBSettingEnabled false
04-13 09:51:57.275 I/System.out( 6899): (HTTPLog)-Static: Hongbao
04-13 09:51:57.275 I/System.out( 6899): (HTTPLog)-Static: isSBSettingEnabled false
[0:] INFO) SYNC (RemoteSession): [7] 2017-4-13 09:51:57.343+08:00 [Couchbase Sync Gateway: Version=1.3.1]: Server Version: [Couchbase Sync Gateway: Version=1.3.1]
[0:] INFO) SYNC (Replication): [5] 2017-4-13 09:51:57.365+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 saved remote checkpoint '6626:5' (_rev=0-2)
04-13 09:51:57.535 D/ViewRootImpl( 6899): #3 mView = null
04-13 09:51:57.770 I/art     ( 6899): Starting a blocking GC Explicit
04-13 09:51:57.785 I/art     ( 6899): Explicit concurrent mark sweep GC freed 2135(2MB) AllocSpace objects, 32(2MB) LOS objects, 36% free, 28MB/44MB, paused 337us total 14.242ms
[0:] INFO) DATABASE (Database): [12] 2017-4-13 09:51:58.151+08:00 Database[/data/user/0/com./files/.local/share/d88e0c64c631ee370f7e101a5822433b6.cblite2] posting change notifications: seq [3,4,5,6,7,8,25,34,35,37,38,41,61,64,72]
[0:] INFO) SYNC (Puller): [12] 2017-4-13 09:51:58.160+08:00 Inserted 15 revs in 276.927 milliseconds
[0:] INFO) SYNC (Replication): [11] 2017-4-13 09:51:58.200+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 checkpointing sequence=6670
04-13 09:51:59.420 I/Choreographer( 6899): Skipped 70 frames!  The application may be doing too much work on its main thread.
04-13 09:51:59.425 I/System.out( 6899): (HTTPLog)-Static: Hongbao
04-13 09:51:59.435 I/System.out( 6899): (HTTPLog)-Static: isSBSettingEnabled false
04-13 09:51:59.435 I/System.out( 6899): (HTTPLog)-Static: Hongbao
04-13 09:51:59.435 I/System.out( 6899): (HTTPLog)-Static: isSBSettingEnabled false
04-13 09:52:00.370 I/Choreographer( 6899): Skipped 54 frames!  The application may be doing too much work on its main thread.
[0:] INFO) SYNC (RemoteSession): [7] 2017-4-13 09:52:00.409+08:00 [Couchbase Sync Gateway: Version=1.3.1]: Server Version: [Couchbase Sync Gateway: Version=1.3.1]
[0:] INFO) SYNC (Replication): [11] 2017-4-13 09:52:00.429+08:00 Puller 1311d4cc-a017-4a4a-a98c-19ca7f4dd944 saved remote checkpoint '6670' (_rev=0-3)

And here is the code I’m using to pull a document:

public Credentials GetCredentials()
{
return GetExistingDocument("CredentialsGlobal").Properties.ToObject<Credentials>();
}

I found the issue, it was in a different section of code handling the events.

I still don’t understand this implementation though, shouldn’t the pullers and pushers do an initial call to get the total number of document they need to sync? The examples in the documentation regarding a progress bar make no sense either if that is how replication works. The only way to know if the two databases are synced up is by polling the document I want until it becomes available?

I agree about the documentation. I think it may be out of date, but for a long time it has been this way. The problem is that there is no way to determine the total number of documents for a given replication (it is a little easier for the pusher, but the puller is hard). The documents for a given replication are not static, and can be affected by things like which user is requesting the data, which channels they want, etc, and so the results are calculated on demand and streamed to the client. So I guess more accurately…we could do it but it would require calculating the entire set twice (as the sets get bigger you can’t fit them all into memory).

The one way to be sure you are done with a replication is to run a one-shot replication. That is because a one-shot replication will close the connection and stop when it has completed the set of changes that were calculated for it (versus continuous, which will keep accepting them as they come).

If you are just interested in getting a certain set of documents, you could watch the database changed event that will fire as the documents come in as well.

1 Like

CBL user here

Here’s how I do the initial replication:

  • Start pusher and puller in continuous mode
  • Check every couple of seconds if completedCount == totalCount and sync is IDLE
  • if that’s not true, then wait a few seconds and check again
  • if that’s true, wait another few seconds and proceed with custom code

The one-shot replication sounds like a good idea for the initial sync. And when finished start the continuous sync. Will this behavior change in CBL 2.0?

Best, Ben G.