I’m trying to figure out this for weeks: Sometimes changes are synced immediately via PushAndPull replicator in Couchbase Lite and sometimes they aren’t synced at all. I don’t have a clue what’s going wrong.
Here is my replication code:
dbRecplication = new Database("replication2");
// Create replicators to push & pull changes to & from Sync Gateway.
var url = new Uri(syncGatewayURL);
var replConfig = new ReplicatorConfiguration(CouchServices.DbRecplication, new Couchbase.Lite.Sync.URLEndpoint(url))
{
Continuous = true,
Authenticator = new Couchbase.Lite.Sync.BasicAuthenticator("fahrer1", "letmein"),
//Authenticator = new Couchbase.Lite.Sync.BasicAuthenticator("tms1", "letmein"),
//Authenticator = new Couchbase.Lite.Sync.BasicAuthenticator("test", "couchbAse3"),
ReplicatorType = ReplicatorType.PushAndPull
};
replication = new Replicator(replConfig);
Database.SetLogLevel(LogDomain.All, LogLevel.Verbose);
replication.AddChangeListener((sender, args) =>
{
string s = "";
switch (args.Status.Activity)
{
case ReplicatorActivityLevel.Stopped: s = "The replication is finished or hit a fatal error."; break;
case ReplicatorActivityLevel.Offline: s = "The replicator is offline as the remote host is unreachable."; break;
case ReplicatorActivityLevel.Connecting: s = " The replicator is connecting to the remote host."; break;
case ReplicatorActivityLevel.Idle: s = "The replication caught up with all the changes available from the server.The IDLE state is only used in continuous replications."; break;
case ReplicatorActivityLevel.Busy:
s = "The replication is actively transferring data.";
break;
}
Debug.WriteLine("REPLICATOR STATUS CHANGE: " + s);
if (args.Status.Error != null)
{
Console.WriteLine($"REPLICATOR ERROR: {args.Status.Error.Message}");
}
EventHandler<ReplicatorStatusChangedEventArgs> temp = ReplicationEvent;
temp?.Invoke(replication, args);
});
replication.Start();
This is my SyncGateway config:
{
"log": ["*"],
"adminInterface": "127.0.0.1:4985",
"interface": "0.0.0.0:4984",
"databases": {
"test": {
"server": "http://127.0.0.1:8091",
"bucket": "test",
"username": "test",
"password": "XXXX",
"users": {
"GUEST": {"disabled": true},
"tms1": { "password": "XXXX", "admin_channels": ["tms1"], "admin_roles": ["tms"] },
"tms2": { "password": "XXXX", "admin_channels": ["tms2"], "admin_roles": ["tms"] },
"fahrer1": { "password": "XXXX", "admin_channels": ["fahrer1"] },
"fahrer2": { "password": "XXXX", "admin_channels": ["fahrer2"] },
"fahrer3": { "password": "XXXX", "admin_channels": ["fahrer3"] },
"test": { "password": "XXXX", "admin_channels": ["*"] }
},
"enable_shared_bucket_access": true,
"import_docs": "continuous",
"sync":`
function (doc, oldDoc) {
// Required properties:
//if (!doc.createdAt) throw({forbidden: "Missing required createdAt property"});
//if (!doc.channels) throw({forbidden: "Missing required channels property"});
//if (!doc.type) throw({forbidden: "Missing required type property"});
// new document created?
/*if (oldDoc == null) {
//requireRole("role:tms"); // only TMSes are allowed to create new documents
requireAccess(doc.channels); // make sure the TMS has added its own channel
}
else // document changed?
if (!doc._deleted)
{ // make sure metadata is not changed maliciously
if (doc.channels != oldDoc.channels) // only TMSes may change (driver) channels
//requireRole("role:tms");
if (doc.type != oldDoc.type)
throw({forbidden: "Type property may not be changed"}); // unless document gets deleted
if (doc.createdAt != oldDoc.createdAt)
throw({forbidden: "createdAt property may not be changed"}); // unless document gets deleted
}
*/
// Allowed data types:
//if (doc.type != "Address" && doc.type != "Instruction" && doc.type != "InstructionStation"
// && doc.type != "LocationDateTime" && doc.type != "Transport" && doc.type != "TransportItem") {
// throw({forbidden: "Missing type property"});
//}
channel (doc.channels);
}`
}
}
}
Here is the log:
2018-03-23T14:23:16.312+01:00 Enabling logging: [*]
2018-03-23T14:23:16.366+01:00 ==== Couchbase Sync Gateway/2.0.0(773;5a497fd) ====
2018-03-23T14:23:16.366+01:00 Opening db /test as bucket "test", pool "default", server <http://127.0.0.1:8091>
2018-03-23T14:23:16.367+01:00 GoCBCustomSGTranscoder Opening Couchbase database test on <http://127.0.0.1:8091> as user "test"
2018-03-23T14:23:16.391+01:00 Design docs for current SG view version (2.0) found.
2018-03-23T14:23:16.391+01:00 Verifying view availability for bucket test...
2018-03-23T14:23:16.693+01:00 Views ready for bucket test.
2018-03-23T14:23:16.696+01:00 Cache: Initializing changes cache with options {ChannelCacheOptions:{ChannelCacheMinLength:0 ChannelCacheMaxLength:0 ChannelCacheAge:0s} CachePendingSeqMaxWait:5s CachePendingSeqMaxNum:10000 CacheSkippedSeqMaxWait:1h0m0s}
2018-03-23T14:23:16.696+01:00 Initializing changes cache for database test with sequence: 8
2018-03-23T14:23:16.696+01:00 Feed: Starting mutation feed on bucket test due to either channel cache mode or doc tracking (auto-import/bucketshadow)
2018-03-23T14:23:16.696+01:00 Feed: Using DCP feed for bucket: "test" (based on feed_type specified in config file)
2018-03-23T14:23:16.754+01:00 WARNING: Invalid range provided for DCP backfill tracking - tracking disabled. len(start):1024 len(end):13 -- base.(*backfillStatus).init() at dcp_feed.go:643
2018-03-23T14:23:16.755+01:00 Feed+: Initializing DCP feed based on persisted checkpoints
2018-03-23T14:23:16.821+01:00 WARNING: Invalid range provided for DCP backfill tracking - tracking disabled. len(start):1024 len(end):13 -- base.(*backfillStatus).init() at dcp_feed.go:643
2018-03-23T14:23:16.821+01:00 Feed+: Initializing DCP feed based on persisted checkpoints
2018-03-23T14:23:16.834+01:00 Feed+: Connecting to new bucket datasource. URLs:[http://127.0.0.1:8091], pool:default, bucket:test
2018-03-23T14:23:16.853+01:00 Using metadata purge interval of 3.00 days for tombstone compaction.
2018-03-23T14:23:16.867+01:00 Access: Computed channels for "fahrer2": !:1,fahrer2:6
_time=2018-03-23T14:23:16.886+01:00 _level=INFO _msg=Using plain authentication for user test
2018-03-23T14:23:16.905+01:00 DCP: Backfill in progress: 3% (1 / 27)
2018-03-23T14:23:16.905+01:00 Changes+: Notifying that "test" changed (keys="{_sync:user:test}") count=2
2018-03-23T14:23:16.970+01:00 Changes+: Notifying that "test" changed (keys="{_sync:user:tms1}") count=3
2018-03-23T14:23:16.970+01:00 Changes+: Notifying that "test" changed (keys="{_sync:user:fahrer3}") count=4
2018-03-23T14:23:16.970+01:00 Changes+: Notifying that "test" changed (keys="{_sync:user:fahrer1}") count=5
2018-03-23T14:23:16.970+01:00 Changes+: Notifying that "test" changed (keys="{_sync:user:fahrer2}") count=6
2018-03-23T14:23:16.970+01:00 DCP: Backfill complete
2018-03-23T14:23:16.970+01:00 Changes+: Notifying that "test" changed (keys="{_sync:user:tms2}") count=7
2018-03-23T14:23:16.971+01:00 DCP+: Persisting checkpoint for vbno 228
2018-03-23T14:23:17.042+01:00 Access: Computed channels for "fahrer3": !:1,fahrer3:1
2018-03-23T14:23:17.043+01:00 DCP+: Persisting checkpoint for vbno 878
2018-03-23T14:23:17.044+01:00 Changes+: Notifying that "test" changed (keys="{_sync:user:fahrer3}") count=8
2018-03-23T14:23:17.200+01:00 Access: Computed channels for "test": !:1,*:2
2018-03-23T14:23:17.200+01:00 Reset guest user to config
2018-03-23T14:23:17.200+01:00 DCP+: Persisting checkpoint for vbno 12
2018-03-23T14:23:17.201+01:00 Changes+: Notifying that "test" changed (keys="{_sync:user:test}") count=9
2018-03-23T14:23:17.397+01:00 Access: Computed channels for "tms1": !:1,tms1:3
2018-03-23T14:23:17.419+01:00 Access: Computed roles for "tms1": tms:3
2018-03-23T14:23:17.421+01:00 DCP+: Persisting checkpoint for vbno 169
2018-03-23T14:23:17.422+01:00 Changes+: Notifying that "test" changed (keys="{_sync:user:tms1}") count=10
2018-03-23T14:23:17.836+01:00 Access: Computed channels for "tms2": !:1,tms2:4
2018-03-23T14:23:17.862+01:00 Access: Computed roles for "tms2": tms:4
2018-03-23T14:23:17.863+01:00 Starting admin server on 127.0.0.1:4985
2018-03-23T14:23:17.863+01:00 DCP+: Persisting checkpoint for vbno 416
2018-03-23T14:23:17.864+01:00 Changes+: Notifying that "test" changed (keys="{_sync:user:tms2}") count=11
2018-03-23T14:23:17.872+01:00 Starting server on 0.0.0.0:4984 ...
2018-03-23T14:23:36.057+01:00 HTTP: #001: GET /test/_blipsync (as GUEST)
2018-03-23T14:23:36.057+01:00 HTTP: #001: --> 401 Login required (0.6 ms)
2018-03-23T14:23:36.288+01:00 HTTP: #002: GET /test/_blipsync (as fahrer1)
2018-03-23T14:23:36.288+01:00 HTTP+: #002: --> 101 [3fbed7cb] Upgraded to BLIP+WebSocket protocol (as fahrer1). (0.0 ms)
2018-03-23T14:23:36.288+01:00 Sync: [3fbed7cb] Start BLIP/Websocket handler
2018-03-23T14:23:36.344+01:00 Sync: [3fbed7cb] MSG#1 "getCheckpoint" ... (as fahrer1)
2018-03-23T14:23:36.345+01:00 Sync+: [3fbed7cb] MSG#1 "getCheckpoint" --> OK ... (as fahrer1)
2018-03-23T14:23:36.345+01:00 DCP+: Persisting checkpoint for vbno 833
2018-03-23T14:23:36.392+01:00 Sync: [3fbed7cb] MSG#2 "subChanges" ... (as fahrer1)
2018-03-23T14:23:36.392+01:00 Sync: [3fbed7cb] MSG#3!~ "changes" ... (as fahrer1)
2018-03-23T14:23:36.393+01:00 Sync+: [3fbed7cb] MSG#2 "subChanges" --> OK ... (as fahrer1)
2018-03-23T14:23:36.393+01:00 Sync: [3fbed7cb] Sending changes since 8 ... (as fahrer1)
2018-03-23T14:23:36.393+01:00 Sync: [3fbed7cb] Received 1 changes from client ... (as fahrer1)
2018-03-23T14:23:36.393+01:00 Changes+: Int sequence multi changes feed...
2018-03-23T14:23:36.393+01:00 Changes: MultiChangesFeed(channels: {*}, options: {Since:8 Limit:0 Conflicts:true IncludeDocs:false Wait:true Continuous:true Terminator:0xc042046480 HeartbeatMs:0 TimeoutMs:0 ActiveOnly:false}) ... (to fahrer1)
2018-03-23T14:23:36.393+01:00 Changes+: MultiChangesFeed: channels expand to "!:1,fahrer1:5" ... (to fahrer1)
2018-03-23T14:23:36.393+01:00 Sync+: [3fbed7cb] MSG#3!~ "changes" --> OK ... (as fahrer1)
2018-03-23T14:23:36.393+01:00 Cache: Initialized cache for channel "!" with options: &{ChannelCacheMinLength:50 ChannelCacheMaxLength:500 ChannelCacheAge:1m0s}
2018-03-23T14:23:36.393+01:00 Cache: getCachedChanges("!", 8) --> 0 changes valid from #9
2018-03-23T14:23:36.393+01:00 Changes+: [changesFeed] Found 0 changes for channel !
2018-03-23T14:23:36.394+01:00 Cache: Initialized cache for channel "fahrer1" with options: &{ChannelCacheMinLength:50 ChannelCacheMaxLength:500 ChannelCacheAge:1m0s}
2018-03-23T14:23:36.394+01:00 Cache: getCachedChanges("fahrer1", 8) --> 0 changes valid from #9
2018-03-23T14:23:36.394+01:00 Changes+: [changesFeed] Found 0 changes for channel fahrer1
2018-03-23T14:23:36.394+01:00 Changes+: MultiChangesFeed waiting... (to fahrer1)
2018-03-23T14:23:36.395+01:00 Changes+: No new changes to send to change listener. Waiting for "test"'s count to pass 5
2018-03-23T14:23:36.395+01:00 Sync+: [3fbed7cb] Sending 0 changes ... (as fahrer1)
2018-03-23T14:23:36.395+01:00 Sync: [3fbed7cb] Sent all changes to client. ... (as fahrer1)
2018-03-23T14:23:36.450+01:00 Sync: [3fbed7cb] MSG#4~ "rev" ... (as fahrer1)
2018-03-23T14:23:36.451+01:00 Sync+: [3fbed7cb] Inserting rev "b2a17504-a7e1-4ad1-b040-896260024f6c" 2-bca0ef2d6144589d92534a04df735a968d9225f2 history="1-20abb74307811ba29f7e55176e54661da02a0d66", array = []string{"2-bca0ef2d6144589d92534a04df735a968d9225f2", "1-20abb74307811ba29f7e55176e54661da02a0d66"} ... (as fahrer1)
2018-03-23T14:23:36.452+01:00 CRUD+: Invoking sync on doc "b2a17504-a7e1-4ad1-b040-896260024f6c" rev 2-bca0ef2d6144589d92534a04df735a968d9225f2
2018-03-23T14:23:36.469+01:00 CRUD+: Saving old revision "b2a17504-a7e1-4ad1-b040-896260024f6c" / "1-20abb74307811ba29f7e55176e54661da02a0d66" (508 bytes)
2018-03-23T14:23:36.470+01:00 CRUD+: Backed up obsolete rev "b2a17504-a7e1-4ad1-b040-896260024f6c"/"1-20abb74307811ba29f7e55176e54661da02a0d66"
2018-03-23T14:23:36.470+01:00 CRUD+: Saving doc (seq: #9, id: b2a17504-a7e1-4ad1-b040-896260024f6c rev: 2-bca0ef2d6144589d92534a04df735a968d9225f2)
2018-03-23T14:23:36.470+01:00 DCP+: Persisting checkpoint for vbno 520
2018-03-23T14:23:36.471+01:00 CRUD: Stored doc "b2a17504-a7e1-4ad1-b040-896260024f6c" / "2-bca0ef2d6144589d92534a04df735a968d9225f2"
2018-03-23T14:23:36.471+01:00 Sync+: [3fbed7cb] MSG#4~ "rev" --> OK ... (as fahrer1)
2018-03-23T14:23:36.472+01:00 DCP+: Persisting checkpoint for vbno 627
2018-03-23T14:23:36.473+01:00 Cache: Received #9 after 1ms ("b2a17504-a7e1-4ad1-b040-896260024f6c" / "2-bca0ef2d6144589d92534a04df735a968d9225f2")
2018-03-23T14:23:36.473+01:00 Cache: #9 ==> channel "fahrer1"
2018-03-23T14:23:36.473+01:00 Cache: Initialized cache for channel "fahrer2" with options: &{ChannelCacheMinLength:50 ChannelCacheMaxLength:500 ChannelCacheAge:1m0s}
2018-03-23T14:23:36.473+01:00 Cache: #9 ==> channel "fahrer2"
2018-03-23T14:23:36.473+01:00 Cache: Initialized cache for channel "fahrer3" with options: &{ChannelCacheMinLength:50 ChannelCacheMaxLength:500 ChannelCacheAge:1m0s}
2018-03-23T14:23:36.473+01:00 Cache: #9 ==> channel "fahrer3"
2018-03-23T14:23:36.473+01:00 Cache: Initialized cache for channel "tms1" with options: &{ChannelCacheMinLength:50 ChannelCacheMaxLength:500 ChannelCacheAge:1m0s}
2018-03-23T14:23:36.473+01:00 Cache: #9 ==> channel "tms1"
2018-03-23T14:23:36.473+01:00 Cache: Initialized cache for channel "*" with options: &{ChannelCacheMinLength:50 ChannelCacheMaxLength:500 ChannelCacheAge:1m0s}
2018-03-23T14:23:36.473+01:00 Cache: #9 ==> channel "*"
2018-03-23T14:23:36.473+01:00 Changes+: Notifying that "test" changed (keys="{*, fahrer1, fahrer2, fahrer3, tms1}") count=12
2018-03-23T14:23:36.473+01:00 Changes+: MultiChangesFeed: channels expand to "!:1,fahrer1:5" ... (to fahrer1)
2018-03-23T14:23:36.473+01:00 Cache: getCachedChanges("!", 8) --> 0 changes valid from #9
2018-03-23T14:23:36.473+01:00 Changes+: [changesFeed] Found 0 changes for channel !
2018-03-23T14:23:36.473+01:00 Cache: getCachedChanges("fahrer1", 8) --> 1 changes valid from #9
2018-03-23T14:23:36.473+01:00 Changes+: [changesFeed] Found 1 changes for channel fahrer1
2018-03-23T14:23:36.473+01:00 Changes+: Channel feed processing seq:9 in channel fahrer1 (to fahrer1)
2018-03-23T14:23:36.473+01:00 Changes+: MultiChangesFeed sending {Seq:9, ID:b2a17504-a7e1-4ad1-b040-896260024f6c, Changes:[map[rev:2-bca0ef2d6144589d92534a04df735a968d9225f2]]} (to fahrer1)
2018-03-23T14:23:36.474+01:00 Changes+: MultiChangesFeed waiting... (to fahrer1)
2018-03-23T14:23:36.474+01:00 Changes+: No new changes to send to change listener. Waiting for "test"'s count to pass 12
2018-03-23T14:23:36.474+01:00 Changes: sending 1 change(s)
2018-03-23T14:23:36.474+01:00 Sync+: [3fbed7cb] Sending 1 changes ... (as fahrer1)
2018-03-23T14:23:36.504+01:00 Sync: [3fbed7cb] Sent 1 changes to client, from seq 9 ... (as fahrer1)
2018-03-23T14:23:36.504+01:00 Sync+: [3fbed7cb] Sending 0 changes ... (as fahrer1)
2018-03-23T14:23:41.544+01:00 Sync: [3fbed7cb] MSG#5 "setCheckpoint" ... (as fahrer1)
2018-03-23T14:23:41.546+01:00 Sync+: [3fbed7cb] MSG#5 "setCheckpoint" --> OK ... (as fahrer1)
2018-03-23T14:23:41.547+01:00 DCP+: Persisting checkpoint for vbno 833
2018-03-23T14:28:39.768+01:00 DCP+: Persisting checkpoint for vbno 275
2018-03-23T14:31:11.874+01:00 Sync: [3fbed7cb] MSG#6!~ "changes" ... (as fahrer1)
2018-03-23T14:31:11.875+01:00 Sync: [3fbed7cb] Received 1 changes from client ... (as fahrer1)
2018-03-23T14:31:11.875+01:00 Sync+: [3fbed7cb] MSG#6!~ "changes" --> OK ... (as fahrer1)
Any help is much appreciated.