Grocery Sync on Android / Couchbase server on windows

191 views
Skip to first unread message

Milt Grinberg

unread,
Nov 17, 2014, 5:28:41 PM11/17/14
to mobile-c...@googlegroups.com


I am trying to get Grocery Sync to work on my android tablet.  If I use the default SYNC_URL (http://demo.mobile.couchbase.com/grocery-sync, it seems to work fine and I get a set of items from the demo database.

I delete the app from the tablet and will reload a fresh copy of the app (this insures that the local DB is gone);
I set up the SYNC_URL to point to "http://192.168.1.78:4984" which is the ip address of the windows machine

So now I want to test out a local implementation of a couch base server running on a windows pc.
I have downloaded the couchbase server 3.0.1 to my windows machine.  That seems to have gotten started properly.  I have set up 2 data buckets - default and sync_gateway.  
I have started the sync-gateway.  The json file associated with starting the sync-gateway is:
{
   "interface":":4984",
   "adminInterface":":4985",
   "log" : ["REST+", "CRUD+", "Changes+", "Attach+" ],
   "databases":{
      "sync_gateway":{
         "server":"http://192.168.1.78:8091",
         "sync":`function(doc) {channel(doc.channels);}`,
"users": {
              "GUEST":{"disabled":false, "admin_channels":["*"]}
              }
      }
   }
}

I start the sync-gateway with
sync_gateway.exe c:\Users\Milt\run_sync_gateway.json

The sync gateway starts up. The log shows:
C:\Program Files (x86)\Couchbase>sync_gateway.exe c:\Users\Milt\run_sync_gateway.json
14:05:04.203880 Enabling logging: [REST+ CRUD+ Changes+ Attach+]
14:05:04.205880 ==== Couchbase Sync Gateway/1.00 (1.0.1-18; commit 81a69a16) ====
14:05:04.205880 Configured Go to use all 8 CPUs; setenv GOMAXPROCS to override this
14:05:04.205880 WARNING: Error setting MaxFileDescriptors to 5000: Unsupported on Windows -- rest.setMaxFileDescriptors() at config.go:322
14:05:04.205880 Opening db /sync_gateway as bucket "sync_gateway", pool "default", server <http://192.168.1.78:8091>
14:05:04.209880 Opening Couchbase database sync_gateway on <http://192.168.1.78:8091>
2014/11/17 14:05:05 go-couchbase: call to ViewCustom("sync_gateway", "access") in github.com/couchbaselabs/sync_gateway/base.couchbaseBucket.ViewCustom took 681.0389ms
2014/11/17 14:05:05 go-couchbase: call to ViewCustom("sync_gateway", "role_access") in github.com/couchbaselabs/sync_gateway/base.couchbaseBucket.ViewCustom took 217.0124ms
14:05:05.482953     Reset guest user to config
14:05:05.482953 Starting admin server on :4985
14:05:05.489954 Starting server on :4984 ...
14:05:07.309058 Changes+: Notifying that "sync_gateway" changed (keys="{_sync:user:}") count=2
14:05:07.309058 Changes+: Notifying that "sync_gateway" changed (keys="{_sync:user:}") count=3
14:05:20.236797 HTTP:  #001: GET /_changes?feed=normal&heartbeat=300000&style=all_docs
14:06:20.428240 HTTP:  #002: GET /_changes?feed=normal&heartbeat=300000&style=all_docs
14:07:20.526677 HTTP:  #003: GET /_changes?feed=normal&heartbeat=300000&style=all_docs

I then add an new item to the app
14:08:13.639715 HTTP:  #004: POST /_revs_diff
14:08:20.647116 HTTP:  #005: GET /_changes?feed=normal&heartbeat=300000&style=all_docs

I then reloaded app on tablet to see if the data on the server will sync up.
14:09:37.187494 HTTP:  #006: GET /_local/ebd52343d678c9dfd871a82b470b3ce492f679aa
14:09:37.272499 HTTP:  #007: GET /_changes?feed=normal&heartbeat=300000&style=all_docs
14:09:40.087660 HTTP:  #008: GET /_local/ec84eb927b395300b02eb279114fb2e8c71a5c46

After reloading the app on the tablet there are no items showing in the app. 

If I look at the couchbase server,  I don't seem to see any documents in either data bucket.  I do see for documents in the default bucket id'ed as
__flush_marker, _sync:seq, _sync:syncdata, _sync:user.

There are the same documents (except __flush_marker) in the sync_gateway bucket.

None of the documents appear to have anything to do with the grocery sync items.

I must be doing something wrong in setting up the sync gateway or the couchbase server since it works against the default coouchbase server/ sync gateway that couchbase has established testing.
Does anyone have an idea as to what I have done incorrectly.

I'm using this example to figure what needs to be done to my own android app that I am building that uses couchbase  lite and that I want to be able to sync a couchbase server.

Thanks,
Milt

Traun Leyden

unread,
Nov 17, 2014, 7:42:51 PM11/17/14
to mobile-c...@googlegroups.com
Hey Milt,

I think I see the problem.

You need to allow guest access, because GrocerySync does not do an authenticated connection with Sync Gateway.  If you look at the configs we are using on our demo cluster:


you can see that:

"GUEST": {"disabled": false, "all_channels": ["*"], "admin_channels": ["*"]}

So try changing your config to have that line instead of your current GUEST configuration, and hopefully it will work.


--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/8337f95a-e9ff-4972-887b-baef726a2689%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jens Alfke

unread,
Nov 17, 2014, 7:49:40 PM11/17/14
to mobile-c...@googlegroups.com

On Nov 17, 2014, at 4:42 PM, Traun Leyden <traun....@gmail.com> wrote:

"GUEST": {"disabled": false, "all_channels": ["*"], "admin_channels": ["*"]}

So try changing your config to have that line instead of your current GUEST configuration, and hopefully it will work.

That won't make any difference. "all_channels" is ignored when setting user properties (it's returned when you GET a user, but it's a read-only computed value, not something you can change.) Moreover, if this were a user permissions issue, the gateway log would be reporting 401 errors.

As far as I can tell, the config file is correct. So I don't understand why this doesn't work.

—Jens

Jens Alfke

unread,
Nov 17, 2014, 7:50:06 PM11/17/14
to mobile-c...@googlegroups.com

On Nov 17, 2014, at 2:28 PM, Milt Grinberg <milt...@gmail.com> wrote:

I then add an new item to the app
14:08:13.639715 HTTP:  #004: POST /_revs_diff
14:08:20.647116 HTTP:  #005: GET /_changes?feed=normal&heartbeat=300000&style=all_docs

I would have expected to see "POST /_bulk_docs" after request #004. (The _revs_diff call is the client asking "I have these new docs; do you have them already?"; if the docs are new to the server, the client will follow up by sending the docs in a PUT to _bulk_docs.)

My hypothesis is that something's going wrong on the client side before it can upload the document, although that seems weird since Grocery Sync is a very simple app. Unfortunately I don't know the Android version very well; Traun, what sort of logging could Milt enable?

—Jens

Traun Leyden

unread,
Nov 17, 2014, 8:19:27 PM11/17/14
to mobile-c...@googlegroups.com
Oh, my bad.  I looked at his config and thought it said "disabled": true.  Nevermind.

--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.

Traun Leyden

unread,
Nov 17, 2014, 8:22:03 PM11/17/14
to mobile-c...@googlegroups.com
Milt said it was working fine against the demo cluster, which makes me think we should isolate the differences between his local sync gateway and the one running on the demo cluster.

I will push a change to GrocerySync-Android that makes sure all the right logging is enabled by default.

--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.

Milt Grinberg

unread,
Nov 17, 2014, 8:51:04 PM11/17/14
to mobile-c...@googlegroups.com

Should I assume you will send me a link to the code I will need to download?

You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/JczJtquRPGE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/CACSSHCE675fmw9f9cRwhA1Ve5Erp_EMmUJS1eVDdc2tMNxxANg%40mail.gmail.com.

Traun Leyden

unread,
Nov 18, 2014, 1:53:00 PM11/18/14
to mobile-c...@googlegroups.com
Yup.  I just pushed a new commit to:


Run a "git pull" and you should get the changes.

Can you re-run with this version and then post your logs to a gist?  Hopefully that will reveal something.

Traun Leyden

unread,
Nov 18, 2014, 1:58:10 PM11/18/14
to mobile-c...@googlegroups.com
I see another potential problem with your config:

"databases":{
      "sync_gateway":{
         "server":"http://192.168.1.78:8091",
         "sync":`function(doc) {channel(doc.channels);}`,
"users": {
              "GUEST":{"disabled":false, "admin_channels":["*"]}
              }
      }
   }

you are missing a line that specifies which bucket to use, eg, the equivalent of this line:


Can you try adding the bucket to your config and seeing if it makes any difference?

Traun Leyden

unread,
Nov 18, 2014, 2:00:13 PM11/18/14
to mobile-c...@googlegroups.com
When you start sync gateway, you should see this somewhere in the output:

"Opening db /sync_gateway as bucket <etc....> "


Milt Grinberg

unread,
Nov 18, 2014, 2:50:34 PM11/18/14
to mobile-couchbase
Here is the result of starting the sync_gateway.  It seems to have the line you were worried about


C:\Program Files (x86)\Couchbase>sync_gateway.exe c:\Users\Milt\run_sync_gateway.json
11:41:21.549490 Enabling logging: [REST+ CRUD+ Changes+ Attach+]
11:41:21.550490 ==== Couchbase Sync Gateway/1.0.3(81;fa9a6e7) ====
11:41:21.550490 Configured Go to use all 8 CPUs; setenv GOMAXPROCS to override this
11:41:21.551490 WARNING: Error setting MaxFileDescriptors to 5000: Unsupported on Windows -- rest.setMaxFileDescriptors() at config.go:378
11:41:21.551490 Opening db /sync_gateway as bucket "sync_gateway", pool "default", server <http://192.168.1.78:8091>
11:41:21.552490 Opening Couchbase database sync_gateway on <http://192.168.1.78:8091>
11:41:21.926511     Reset guest user to config
11:41:21.927511 Starting admin server on :4985
11:41:21.936512 Starting server on :4984 ...
11:41:23.995630 HTTP:  #001: GET /_changes?feed=normal&heartbeat=300000&style=all_docs


the error I'm seeing in the log is:

11-18 11:24:40.051  27844-27991/com.couchbase.grocerysync E/RemoteRequest﹕ Got error status: 404 for http://192.168.1.78:4984/_local/d56ade8696443c4fbf7baf3fff75c0b454f8e54b.  Reason: Not Found


I posted the entire log to a gist.

Jens Alfke

unread,
Nov 18, 2014, 3:06:28 PM11/18/14
to mobile-c...@googlegroups.com

> On Nov 18, 2014, at 10:58 AM, Traun Leyden <traun....@gmail.com> wrote:
>
> you are missing a line that specifies which bucket to use, eg, the equivalent of this line:

That's alright, it defaults to using the same name as the database, e.g. "sync_gateway" in this case.

—Jens

Jens Alfke

unread,
Nov 18, 2014, 3:09:53 PM11/18/14
to mobile-c...@googlegroups.com

On Nov 18, 2014, at 11:50 AM, Milt Grinberg <milt...@gmail.com> wrote:

the error I'm seeing in the log is:

11-18 11:24:40.051  27844-27991/com.couchbase.grocerysync E/RemoteRequest﹕ Got error status: 404 for http://192.168.1.78:4984/_local/d56ade8696443c4fbf7baf3fff75c0b454f8e54b.  Reason: Not Found

That's not an error, actually (Couchbase Lite on Android shouldn't be logging it as such.)

In replication, URLs with "/_local/" in them are "checkpoint" documents stored on the server by a specific client instance to keep track of the last known state. It's normal for the checkpoint not to exist the first time a client replicates; it will get created later on during the replication.

—Jens

Milt Grinberg

unread,
Nov 18, 2014, 3:42:27 PM11/18/14
to mobile-couchbase
I did post the full log to gist.  There are other errors showing in the log.  

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/JczJtquRPGE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.

Traun Leyden

unread,
Nov 18, 2014, 3:54:26 PM11/18/14
to mobile-c...@googlegroups.com
What are you using for your sync url?

It looks like the db name is missing in your requests.  On this line:


RemoteRequest created, url: http://192.168.1.78:4984/_local/d56ad..

I would expect that to be:

RemoteRequest created, url: http://192.168.1.78:4984/sync_gateway/_local/d56ad..

The default SYNC_URL is 


in your case, you should be using something like 

http://<ip>:4984/sync_gateway

Having said that, there does look like there is a bug in the version of couchbase lite android you are using, because I would have expected the replication to have an error in that case.  I'm looking into it.





--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/CAHqiEJ-1TfN%3Dt%2B4sWBXLDt%3DoF5%3Dyn%2B65gaDyozY1F7_ap6Cs1A%40mail.gmail.com.

Jens Alfke

unread,
Nov 18, 2014, 4:25:13 PM11/18/14
to mobile-c...@googlegroups.com

On Nov 18, 2014, at 12:54 PM, Traun Leyden <traun....@gmail.com> wrote:

It looks like the db name is missing in your requests.

Oh god, you're right. Even in the first post there are lines like
14:08:13.639715 HTTP:  #004: POST /_revs_diff

where I just skimmed past the missing database name in the path without paying attention.

Milt, you've got an incorrect sync URL in Grocery Sync.

Having said that, there does look like there is a bug in the version of couchbase lite android you are using, because I would have expected the replication to have an error in that case.  I'm looking into it.

Hm, there's also a bug in Sync Gateway where it isn't logging HTTP errors when the URL doesn't match any known route — for instance in the above log I quoted, it should have logged the 404 response. If it had, I would have immediately recognized the bad path.

—Jens

Milt Grinberg

unread,
Nov 18, 2014, 4:28:56 PM11/18/14
to mobile-couchbase
That was the problem.  Changed the url to 
http://<ip>:4984/sync_gateway
and I am now seeing the data in the Couchbase server and when I reload the app (uninstall/reinstall), I see the data that was on the server.

Thanks.  I knew I just had some minor issue.  I should have paid more attention to 

Configure Grocery Sync with Sync Gateway URL

  • Configure the hardcoded SYNC_URL in the MainActivity.java file to the URL of your Sync Gateway instance.
Thanks again.  Now I can try and upgrade my app to include syncing to a couchbase server.  Will be doing it locally first.

Milt

Traun Leyden

unread,
Nov 18, 2014, 4:33:52 PM11/18/14
to mobile-c...@googlegroups.com
Glad to hear that fixed it!

I compared the behavior to GrocerySync ios, and it looks like GrocerySync Android is behaving essentially the same in this case (logs an error, replicator goes into idle state)

The ios app was displaying a helpful error message in the UI though, so I updated GrocerySync to do the same:

Inline image 1

Reply all
Reply to author
Forward
0 new messages