Problem with replication using sync gateway + CBLite in Phonegap application

188 views
Skip to first unread message

Jaime Lopez Carratala

unread,
Mar 26, 2015, 4:44:44 PM3/26/15
to mobile-c...@googlegroups.com
Hello to everybody,

I have a problem regarding the replication of a Phonegap/Cordova application, but before a little bit of background:
- I have an external web application that is used by some users to save data in a couchbase server bucket in JSON format (bucket name: 'oliclinomel'). 
- I have a sync gateway which it is shadowing the previous bucket. The purpose is to have the data of the shadowed bucket available for the people who install the mobile application in order to use it offline. The mobile users will just consume the data, they won't create new documents in the sync_gateway, the data just goes in one direction. This is the configuration:

{
  "interface": ":5984",
  "adminInterface": ":5985",
  "log": [    "CRUD",    "CRUD+",    "HTTP",    "HTTP+",    "Access",    "Cache",    "Shadow",    "Shadow+",    "Changes",    "Changes+",    "SG"  ],
  "databases": {
    "oliclinomel_sync": {
      "server": "http://localhost:8091",
      "bucket": "oliclinomel_sync",
      "sync": "function(doc) {channel(doc.channels);}",
      "users": {
        "GUEST": {"disabled": false, "admin_channels": ["*"], "all_channels": ["*"] },
        "oliclinomel": {
          "disabled": false,
          "admin_channels": ["*"],
          "password": "password",
          "admin_roles": [],
          "roles": [],
          "all_channels": ["*"]
        }
      },
      "shadow": {
        "server": "http://localhost:8091",
        "bucket": "oliclinomel"
      }
    }
  }
}

For the moment I am using guest access as all the information stored in the couchbase server buckets in public, maybe later I will route the information in several channels depending on the content of the JSON documents.

When I start the sync_gateway it seems that all the documents are properly synchronized (you can see it in the attached log). So far so good, so the next step is to create the local CBLite database which should be synchronized with the sync gateway, and here is where my problems start.

When my application is loaded I make post request in order to replicate the bucket from the gateway:

var remote = {
 url
: 'http://' + GATEWAY_HOST + BUCKET
 
};


var pullInfo = {
 create_target
: true,
 source
: remote,
 target
: dbName,
 continuous
: false,
 cancel
: false
};
$log
.debug('[COUCHBASE]: Pulling changes from ', pullInfo.source);
return $http.post(cbUrl + '_replicate', pullInfo).then(function (res) {
 $log
.debug('[COUCHBASE_HOST]: Replication successful with session id ', res.data.session_id);
 
return res.data;
}, function (res) {
 $log
.debug('[COUCHBASE_HOST]: Replication failed: ', res);
});

As far as I know the previous request is a one shot replication, which is ok as I don't need a frequent synchronization, and if you take a look to the attached logs (line 60), you can see that all the documents are identified and sent to the local DB, but the problem is that when I retrieve the _all_docs from the CBLite DB in the app I get the documents in the below screenshot (2 design docs created in the setup of the local database and just 2 of the retrieved documents from the replication)



And if I make a second the replication request, the missing documents in the DB are retrieved by the gateway (as you can see in the log file) but the documents are not saved into CBLite and the local document that it is create to track the replications never is updated:

_sync:local:01202cb351fa162c38927bbcbf7ee22354f91089
{
  "_rev": "0-1",
  "lastSequence": "4"
}

I have tried also with continuous replication instead of one shot but I have the same problem, do you have any clue why this is happening to me?

Thanks and best regards.
Jaime

gateway_log.txt

Jens Alfke

unread,
Mar 26, 2015, 5:14:40 PM3/26/15
to mobile-c...@googlegroups.com
Jaime—

You need to specify which implementation of Couchbase Lite (iOS? Java? .NET?) you’re using.

Also turning on logging on the client side would be the best way to track the progress of replication. (The details of doing that differ by platform, that’s one reason we need to know what you’re using.)

—Jens

Jaime Lopez Carratala

unread,
Mar 27, 2015, 4:13:00 AM3/27/15
to mobile-c...@googlegroups.com
Hi Jens,

I use the Phonegap Couchbase Lite plugin:

And the problems I have them with Android (in both device and emulator), I haven't tested it on iOS yet.

Thanks for the fast reply.

Best regards.
Jaime

Jaime Lopez Carratala

unread,
Mar 27, 2015, 6:55:02 AM3/27/15
to mobile-c...@googlegroups.com
About versions, I am using Couchbase server 3.0.1, sync gateway 1.0.3 (I am about to install the 1.0.4 to see if it gets better) and 1.0.3 of the Phonegap plugin for CBLite.

And also sometimes I get this error when I start the gateway:

11:50:22.092581 WARNING: Error from Incr in _reserveSequences(1): MCResponse status=DELTA_BADVAL, opcode=INCREMENT, opaque=0, msg: Non-numeric server-side value for incr or decr -- db.(*sequenceAllocator)._reserveSequences() at sequence_allocator.go:59
11:50:22.093581 FATAL: Error opening database: Couldn't create user "GUEST": MCResponse status=DELTA_BADVAL, opcode=INCREMENT, opaque=0, msg: Non-numeric server-side value for incr or decr -- rest.RunServer() at config.go:415

But usually after the 2nd or third try it works, I don't know if it is related.

Best regards.
Jaime

Jaime Lopez Carratala

unread,
Mar 30, 2015, 6:02:59 AM3/30/15
to mobile-c...@googlegroups.com
Does anybody have any clue why I am getting this strange behaviour?

Also how can I enable the logging using the Phonegapp CBLite plugin?

Thanks and best regards.
Jaime

Jaime Lopez Carratala

unread,
Apr 1, 2015, 11:37:07 AM4/1/15
to mobile-c...@googlegroups.com

I have finally fixed my issue, after install in my emulator a program to see the logs of the device, I noticed that this error was appearing every time the replication was done:

03-31 10:39:32.112 E/CBLite  (3968): Database: Invalid top-level key '_class' in document to be inserted
03-31 10:39:32.112 I/CBLite  (3968): CBLManagerWorkExecutor CANCEL transaction (level 2)
03-31 10:39:32.112 W/Sync    (3968): com.couchbase.lite.replicator.PullerInternal@5cbee10: failed to write {Document-t_c-in-en #1-054356dc8a11d1fec32cff12df3d1688}: status=400
03-31 10:39:32.112 E/Sync    (3968): com.couchbase.lite.replicator.PullerInternal@5cbee10: Progress: set error = org.apache.http.client.HttpResponseException

So it seems that the documents that have that attributes aren't replicated to CBLite. This '_class' attribute is added by the spring-data-couchbase library when saving some documents to the shadowed bucket in Couchbase Server, so I had to avoid saving the documents with that library and use the methods in the CocuhbaseClient instead. I don't know if this behaviour is correct but I think that the replication shouldn't fail if an attribute like that is saved to the document.

I think I will file an issue in github

Best regards.

Jens Alfke

unread,
Apr 1, 2015, 12:50:16 PM4/1/15
to mobile-c...@googlegroups.com
Please don’t post the same messages to both the web forum and this mailing list; it’s confusing!

As I wrote on the forum, this sounds like a Sync Gateway bug. The bucket-shadowing code shouldn’t be importing properties with reserved/invalid names (starting with an underscore.)

—Jens
Reply all
Reply to author
Forward
0 new messages