THIS IS NEARLY ONE MONTH I AM TRYING TO ACHIEVE SYNCING OR REPLICATION
Let me explain everything in details.
Firstly,
I use Windows 10 pro 64-bit, I have a NativeScript app that uses this Couchbase Lite plugin
I would like to provide replication for app in a local network. Lets say there are two persons who use this app, whenever one adds an item, the item gets replicated to other user.
I followed this guide Install Sync Gateway | Couchbase Docs
There, I installed Sync Gateway 2.5 community edition, then I disabled “Couchbase Sync Gateway” in services.msc because otherwise I get an ERROR when running sync_gateway, that is what the docs told me.
Then, I installed Couchbase Server 6.0.0 community edition, I created a new cluster, then installed with default configuration, then I created a bucket with name “stock-database”, then I created a username as the guide told me. In short I did what the docs told me.
And this is my sync-gateway-config.json file:
{
“log”: [“* “],
“databases”: {
“stock-database”: {
“server”: “http://localhost:8091”,
“bucket”: “stock-database”,
“username”: “sync_gateway”,
“password”: “123456”,
“num_index_replicas”:0,
“enable_shared_bucket_access”: true,
“import_docs”: “continuous”,
“users”: {
“GUEST”: { “disabled”: false, “admin_channels”: [”*”] }
},
“sync”:function (doc, oldDoc) { if (doc.sdk) { channel(doc.sdk); } }
}
}
}
As you can see I added “num_index_replicas”:0, because I have one server (I googled I found this to be a solution to an error).
Then after these, I added this code to my app, in app.js file which acts as initial file and singleton to other app pages and modules:
const Couchbase = require(‘nativescript-couchbase-plugin’).Couchbase;
const stock = new Couchbase(‘stock-database’);
const push = stock.createPushReplication(
‘ws://localhost:4984/stock-database’
);
push.setUserNameAndPassword(“sync_gateway”,“123456”);
const pull = stock.createPullReplication(
‘ws://localhost:4984/stock-database’
);
pull.setSessionId(“SomeId”);
pull.setSessionIdAndCookieName(“SomeId”,“SomeCookieName”);push.setContinuous(true);
pull.setContinuous(true);
push.start();
pull.start();module.exports.stock = stock;
In the documentation of the Couchbase Lite plugin it was using ‘ws://sync-gateway-host:4984/stock-database’
but I changed it to ‘ws://localhost:4984/stock-database’
both did not worked though, but I just changed it because in the official Couchbase tutorial it was localhost and not sync-gateway-host (what is their differences?)
And finally, I ran the sync_gateway command in my CMD:
cd C:\Program Files\Couchbase\Sync Gateway
sync_gateway C:\Users\HomeUser\Desktop\sync-gateway-config.json
This was the result:
2019-05-17T00:19:59.842-08:00 [WRN] Using deprecated config option: “log”. Use “logging.console.log_keys” instead. – rest.(*ServerConfig).deprecatedConfigLoggingFallback.func5() at config.go:674
2019-05-17T00:19:59.842-08:00 [INF] Logging: Console to stderr
2019-05-17T00:19:59.842-08:00 [INF] Logging: Files disabled
2019-05-17T00:19:59.842-08:00 [ERR] No log_file_path property specified in config, and --defaultLogFilePath command line flag was not set. Log files required for product support are not being generated. – base.(LoggingConfig).Init.func1() at logging_config.go:62
2019-05-17T00:19:59.842-08:00 [INF] Logging: Console level: info
2019-05-17T00:19:59.842-08:00 [INF] Logging: Console keys: [ HTTP]
2019-05-17T00:19:59.842-08:00 [INF] Logging: Redaction level: none
2019-05-17T00:19:59.842-08:00 [INF] Logging stats with frequency: 1m0s
2019-05-17T00:19:59.842-08:00 [INF] Opening db /stock-database as bucket “stock-database”, pool “default”, server http://localhost:8091
2019-05-17T00:19:59.842-08:00 [INF] GoCBCustomSGTranscoder Opening Couchbase database stock-database on http://localhost:8091 as user “sync_gateway”
2019-05-17T00:19:59.842-08:00 [INF] Auth: Attempting credential authentication http://localhost:8091?http_idle_conn_timeout=90000&http_max_idle_conns=64000&http_max_idle_conns_per_host=256&n1ql_timeout=75000
2019-05-17T00:19:59.865-08:00 [ERR] gocb: memdClient read failure: read tcp [::1]:55517->[::1]:11210: use of closed network connection – base.GoCBCoreLogger.Log() at logger_external.go:47
2019-05-17T00:19:59.865-08:00 [ERR] gocb: Failed to shut down client connection (close tcp [::1]:55517->[::1]:11210: use of closed network connection) – base.GoCBCoreLogger.Log() at logger_external.go:47
2019-05-17T00:19:59.866-08:00 [INF] Successfully opened bucket stock-database
2019-05-17T00:19:59.866-08:00 [INF] Set query timeouts for bucket stock-database to cluster:1m15s, bucket:1m15s
2019-05-17T00:19:59.876-08:00 [INF] Initializing indexes with numReplicas: 0…
2019-05-17T00:20:00.323-08:00 [INF] Verifying index availability for bucket stock-database…
2019-05-17T00:20:00.396-08:00 [INF] Indexes ready for bucket stock-database.
2019-05-17T00:20:00.396-08:00 [INF] delta_sync enabled=false with rev_max_age_seconds=86400 for database stock-database
2019-05-17T00:20:00.397-08:00 [INF] Cache: Initializing changes cache with options {ChannelCacheOptions:{ChannelCacheMinLength:50 ChannelCacheMaxLength:500 ChannelCacheAge:1m0s} CachePendingSeqMaxWait:5s CachePendingSeqMaxNum:10000 CacheSkippedSeqMaxWait:1h0m0s}
2019-05-17T00:20:00.397-08:00 [INF] Initializing changes cache for database stock-database
2019-05-17T00:20:00.398-08:00 [INF] DCP: Starting mutation feed on bucket stock-database due to either channel cache mode or doc tracking (auto-import/bucketshadow)
2019-05-17T00:20:00.398-08:00 [INF] DCP: Using DCP feed for bucket: “stock-database” (based on feed_type specified in config file)
2019-05-17T00:20:00.522-08:00 [INF] DCP: Previously persisted backfill sequences found - will resume
2019-05-17T00:20:00.522-08:00 [INF] DCP: Restarting vb 0 using metadata sequence 0 (backfill 0 not in [0-0])
2019-05-17T00:20:00.522-08:00 [INF] DCP: Restarting vb 1 using metadata sequence 0 (backfill 0 not in [0-0])
2019-05-17T00:20:00.523-08:00 [INF] DCP: Restarting vb 2 using metadata sequence 0 (backfill 0 not in [0-0])
2019-05-17T00:20:00.523-08:00 [INF] DCP: Restarting vb 3 using
2019-05-17T00:20:01.038-08:00 [INF] DCP: Restarting vb 1022 using metadata sequence 0 (backfill 0 not in [0-0])
2019-05-17T00:20:01.038-08:00 [INF] DCP: Restarting vb 1023 using metadata sequence 0 (backfill 0 not in [0-0])
2019-05-17T00:20:02.074-08:00 [INF] Using metadata purge interval of 3.00 days for tombstone compaction.
2019-05-17T00:20:02.083-08:00 [INF] Reset guest user to config
2019-05-17T00:20:02.083-08:00 [INF] Starting admin server on 127.0.0.1:4985
2019-05-17T00:20:02.085-08:00 [INF] Starting server on :4984 …
2019-05-17T00:20:02.097-08:00 [INF] CBGoUtilsLogger: Using plain authentication for user sync_gateway
2019-05-17T00:20:02.229-08:00 [INF] DCP: Backfill in progress: 11% (3 / 27)
Why it stops there? It freezesin backfill inn progress: 11% (or sometimes the number is lower or higher)?
Shouldn’t it tell me whether a device connected or how many devices are connected?
Also, when I create a new document in the app on the smartphone, nothing appears to be added in the bucket on the PC.
I have opened these ports both outbound and inbound 8091, 8092, 8093, 8094, 11207, 11210, 11211, 18091, 18092, 18093
in case that would be a cause.
I am testing the app on real device, not emulator.
Here are log files generated by Sync Gateway
logs.zip (8.8 KB)
Why there is no syncing or any sign of successful connection between the server and the mobile phones? What am I doing wrong? What information should I provide furthur?
SOLVED:
The mistake I had was using 127.0.0.1 as the IP address for the server, which now realized it is not reachable by other devices.
I reinstalled Couchbase Server and created a server using the local network IP address of the computer, like 192.168.10.134
And using that IP address in sync-gateway-config.json and app.js of the mobile app.
Thanks a lot. Now it syncs and replications sweetly.