Error in shadowing bucket in sync gateway

I am trying to connect sync gateway to couchbase server with following config.json file

{
   "interface":":4984",
   "adminInterface":":4985",
   "log":["REST"],
   "databases":{
      "sync_gateway":{
         "server":"http://localhost:8091",
         "bucket":"sync_gateway",
         "sync":`function(doc) {channel(doc.channels);}`,

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

         "shadow": {
            "server": "http://localhost:8091",
            "bucket": "copy"
         }
      }`enter code here`
   }
}

but I am not able to do shadowing…showing following error

2016-06-30T17:54:57.013+05:30 WARNING: Database "sync_gateway": unable to connec t to external bucket for shadowing: 502 Unable to connect to shadow bucket: No b ucket named copy -- rest.(*ServerContext)._getOrAddDatabaseFromConfig() at serve r_context.go:793

That’s the error you’d see if there wasn’t a bucket named ‘copy’ on the Couchbase Server running at your server location (localhost:8091).

I have created bucket namd as ‘copy’ in same database . it is already present overthere…but still it is showing error like that only

Is my config.json file is correct or not??

@shriram.punde

I have used your config on my local dev machine and it correctly connects to a CBS bucket sync_gateway and a shadow bucket copy

There is one error in your config as pasted above the “enter code here”, but I suspect this is a cut-and-paste error as SG would not have started.

As @adamf suggested it looks like the copy bucket is missing or maybe misspelled?

I have placed ‘copy’ bucket in same place where ‘sync_gateway’ bucket is placed…so is it ok ?

I am not clear about flow of working…
What I considered is

we will connect sync gateway to the Couchbase server by above config file…then thro’ java code API we’ll try to connect couchbase lite to sync gate way…thro’ following methods we’ll try to replication … :

private URL createSyncURL(boolean isEncrypted){
URL syncURL = null;
String host = “https://10.0.2.2”; //sync gateway ip
String port = “4984”; //sync gateway port
String dbName = “couchbaseevents”;
try {
syncURL = new URL(host + “:” + port + “/” + dbName);
} catch (MalformedURLException me) {
me.printStackTrace();
}
return syncURL;
}

//-------------------------and
private void startReplications() throws CouchbaseLiteException {
Replication pull = this.getDatabaseInstance().createPullReplication(this.createSyncURL(false));
Replication push = this.getDatabaseInstance().createPushReplication(this.createSyncURL(false));
pull.setContinuous(true);
push.setContinuous(true);
pull.start();
push.start();
}

i need a clear and simple picture how flow is going on …

@andy @adamf @jnordberg @fredericb

@shriram.punde

Having the sync_gateway and copy buckets in the same CBS cluster is fine.

You are correct that your mobile clients will replicate with Sync Gateway, your client code looks OK at first glance.

You would only want to consider using shadow bucketing if you already have a Couchbase Server based application with a populated bucket that you now want to use with a mobile App.

If this is a greenfield project I would avoid using a shadow bucket and recommend that you only use Sync gateway backed by a Couchbase Server bucket then use Couchbase Lite for mobile clients and the Sync Gateway REST API for Web browser clients.

@shriram.punde

Here are a couple of links to mobile documentation

An overview

First mobile app(iOS)

thanx it hepled lot :slight_smile: @andy

I have a doubt , what is the significance of database in couchbase lite?? how to find that which database we are using?? because i have created directly the buckets so how should i mention the database names in config.json file…??

@shriram.punde

I’m not sure I have understood your question properly, but I’ll try to answer.

There is no direct correlation between local DB names on Couchbase Lite and remote DB names on Sync Gateway.

You link a CBL database to a Sync Gateway database when you create a replication in your CBL code. You create the replication on the local CBL database and pass it the URL of the remote Sync Gateway database.

If this does not answer your question, can you provide a more detailed explanation of the issue you are facing.

what i did is icreated bucket named as sync_gateway,
and conected with couchbase server by below config.json


{
“interface”:":4984",
“adminInterface”:":4985",
“databases”:{
“db”:{
“server”:“http://localhost:8091”,
“bucket”:“sync_gateway”,
“sync”:function(doc) { channel(doc.channels); }
}
}
}

this had created metadata in sync_gateway bucket on server,
the n i have written sample java code for local database CBL , and wrote functions for push pull operations …
code:


package com.Testing_couchbaseLite;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import javax.naming.ldap.ManageReferralControl;

import org.apache.http.cookie.Cookie;

import com.couchbase.lite.Context;
import com.couchbase.lite.CouchbaseLiteException;
import com.couchbase.lite.Database;
import com.couchbase.lite.Document;
import com.couchbase.lite.JavaContext;
import com.couchbase.lite.Manager;
import com.couchbase.lite.ManagerOptions;
import com.couchbase.lite.QueryOptions;
import com.couchbase.lite.replicator.Replication;
import com.couchbase.lite.support.HttpClientFactory;

public class Test_syncGateWay {

	private URL createSyncURL(boolean isEncrypted){
	    URL syncURL = null;
	    String host = "https://localhost";  //sync gateway ip
	    String port = "4984";              //sync gateway port
	    String dbName = "db";
	    try {
	        syncURL = new URL(host + ":" + port + "/" + dbName);
	    } catch (MalformedURLException me) {
	        me.printStackTrace();
	    }
	    return syncURL;
	}

	private void startReplications() throws CouchbaseLiteException {
		
		
		try {
			
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", "1");
			map.put("name","ram");
			
			Manager man = new Manager(new JavaContext(), Manager.DEFAULT_OPTIONS);
			Database db = man.getDatabase("sync_gateway");
			Document doc = db.createDocument();
			doc.putProperties(map);
			
			System.out.println("-------------done------------");
			
			
			
			System.out.println(man.getAllDatabaseNames());
			System.out.println(man.getDatabase("sync_gateway").getDocumentCount());
			
	  	System.out.println(db.getDocument("1").getCurrentRevisionId());			
			
			System.out.println(db.exists());
			
			
			  Replication pull = db.createPullReplication(this.createSyncURL(true));
		    Replication push = db.createPushReplication(this.createSyncURL(true));
		   pull.setContinuous(true);
		    push.setContinuous(true);
		   pull.start();
		    push.start();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
	
	private void createDatabase() throws CouchbaseLiteException, IOException {
		// TODO Auto-generated method stub
		
		
		
		
	}
	
	public static void main(String[] args) throws CouchbaseLiteException, IOException {
		new Test_syncGateWay().startReplications();
		
	
		
	}

}

now i am stating sync gateway by that config file and running java code to create document on CBL and CB server by push pull operation.

bt it is showing error as

Jul 08, 2016 10:27:21 AM com.couchbase.lite.util.SystemLogger e
SEVERE: RemoteRequest: RemoteRequest{GET, https://localhost:4984/db/_local/2eafda901c4de2fe022af262d5cc7d1c0cb5c2d2}: executeRequest() Exception: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated. url: https://localhost:4984/db/_local/2eafda901c4de2fe022af262d5cc7d1c0cb5c2d2


so is there any misunderstanding in my concept??? and how do i resolve this problem??

got the mistake…just change host adress as http://localhost
instead of https://localhost :stuck_out_tongue:

if another solution or sugestion is there please tell me…