Sync Gateway Config.json from 1.0 use in 2.1 makes it run out of memory?


#1

Hi,

I’m trying to upgrade from Sync Gateway 1.0 to 2.1

I have the following config.json file from 1.0 I’m using for 2.1
My couchbase is 6.0 community.

Once I start the sgw, my ubuntu box runs out of memory

Would you point out what I’m doing to cause this?

{
“interface” : “:4984”
,“adminInterface” : “:4985”
,“SSLCert”: “…/certs/sync-dev_forksandbridges_com.crt”
,“SSLKey”: “…/certs/example.key”
,“log”: [""],
“databases”: {
“default”: {
“server”: “http://localhost:8091”,
“bucket”: “default”,
“username”: “sync_gateway”,
“password”: “1234abcd”,
“enable_shared_bucket_access”: true,
“import_docs”: “continuous”,
“users”: { “GUEST”: { “disabled”: false, “admin_channels”: ["
"] } }
,“num_index_replicas”:0
,“sync” : `

function(doc, old_doc) {
    var i, n, e, domain;
    var is_owner = false, is_in_domain = false;
    var roles = doc.roles;
    var unhandled_role = true;

    if (old_doc) { // update old doc
		if (old_doc.owner) {
			try {
			  requireUser(old_doc.owner); // only owners can modify
			  is_owner = true;
			} catch (e) {

			}
	    }

		if (!is_owner) {
			requireRole("admin"); // only admin users can modify
		}
    } else { // create new doc
		if (roles) {
			if (roles.indexOf("Contact") != -1 ||
			roles.indexOf("Credential") != -1 ||
			roles.indexOf("Account") != -1 ||
			roles.indexOf("Persona") != -1) {
			  // creation of these roles can only be done
			  // by the admin
			  requireRole("admin");
			}
		}
    }
if (old_doc && doc._deleted) { // delete request

} else if (!old_doc && doc._attachments) { // create attachments

    } else { // create documents (old_doc) or update attachments or documents (!old_doc && !doc._attachments)
        // general type check
        if (!doc.owner && !doc.domain) {
            throw ({forbidden: "Document must have an owner or be part of a domain"});
        }


        if (doc.domain && typeof(doc.domain) != typeof([])) {
            throw("domain must be a list");
        }


		if (roles) {
            // role-based type check
			if (roles.indexOf("Contact") != -1 ||
				roles.indexOf("Credential") != -1 ||
				roles.indexOf("Account") != -1) {
					// updating these roles only allowed to admins
					requireRole("admin");

					if (roles.indexOf("Account") != -1) {
						if (!doc.name) {
						  throw({forbidden: "Account must have a name"});
						} else if (!doc.credential) {
						  throw({forbidden: "Account must have a credential"});
						}
					} else if (roles.indexOf("Credential") != -1) {
						access(doc._id, "public"); // give user access to public channel
					}

				unhandled_role = false;
			}

			if (roles.indexOf("Persona") != -1) {
				unhandled_role = false;
			}

			if (roles.indexOf("Containee") != -1) {
				unhandled_role = false;
			}

			if (roles.indexOf("Artifact") != -1) {
				if (!doc.weight || isNaN(doc.weight)) {
					throw ({forbidden: "weight must be a number bigger than 0"});
				}

				if (!doc.type) {
					throw ({forbidden: "artifact type must be specified"});
				}

				unhandled_role = false;
			}
		if (roles.indexOf("Appearance") != -1) {
				channel("!"); // appearance is routed to the public channel

				unhandled_role = false;
			}

			if (roles.indexOf("Mapping") != -1) {
                if (!doc.map_from || !doc.map_to) {
                    throw ({forbidden: "Mapping must have a from and a to"});
                }

                //channel(doc.map_to["id"]); // route to the target of the mapping

				unhandled_role = false;
			}

			if (roles.indexOf("Collection") != -1) {

				unhandled_role = false;
			}

			if (roles.indexOf("Conversation") != -1) {
				if (!doc.space) {
					throw ({forbidden: "Conversation must happen in a space"});
				}

				//channel(doc.space); // route conversation to space channel

				unhandled_role = false;
			}

			if (roles.indexOf("Space") != -1) {
				if (!doc.name) {
				  throw ({forbidden: "Space must have a name"});
				}

				//channel(doc._id); // route doc to space channel
				//access(doc.owner, doc._id); // give owner access to space channel

				if (doc.domain) {
                    n = doc.domain.length;

                    for (i = 0; i < n; i ++) {
                        domain = doc.domain[i];
                        //channel(domain);
                        access("role:" + domain
                              ,doc._id); /* give the roles
                                            access to space channel */
                    }
				}

				unhandled_role = false;
			}

  	 		if (roles.indexOf("Textscrap") != -1) {
				if (roles.indexOf("Remark") != -1) {
					if (!doc.space) {
				    	throw ({forbidden: "Remark must happen in a space"});
					}

					if (!doc.conversation) {
				    	throw({forbidden: "Remark must be made by during a conversation"});
					}

					if (!doc.appearance) {
				    	throw({forbidden: "Remark must be made by someone visible"});
					}

					if (!doc.created) {
						throw ({forbidden: "Remark must happen at a time"});
					}

					//channel(doc.space); // route remark to space channel
				}

				if (roles.indexOf("Reply") != -1) {
					if (!doc.reply_to) {
						throw({forbidden: "Reply must be a reply to something"});
					}
				}

				unhandled_role = false;
			}

			if (roles.indexOf("Domain") != -1) {
                //channel(doc._id) // route domain to domain channel

				unhandled_role = false;
			}

			if (roles.indexOf("Request") != -1) {
				if (!doc.request_type) {
					throw("Request must be of a specific type");
				}

				if (!doc.recipient) {
					throw("Request must have a recipient");
				}

				unhandled_role = false;
			}

			if (unhandled_role) {
				throw ({forbidden: "Role [" + roles + "] not implemented by gateway."});
			}
        } else {
	  //	    if (!doc.admin_roles) { // hack
			if (!doc.recipient) {
					throw("Request must have a recipient");
				}

				unhandled_role = false;
			}

			if (unhandled_role) {
				throw ({forbidden: "Role [" + roles + "] not implemented by gateway."});
			}
        } else {
	  //	    if (!doc.admin_roles) { // hack
            throw ({forbidden: "Roles must be speficied on all documents."});
	  //	    }
        }

		if (doc.owner) {
			channel(doc.owner); // route to user channel
			access(doc.owner, doc.owner); // give owner access to user channel
		}

		if (doc.domain) {
            n = doc.domain.length;

            for (i = 0; i < n; i ++) {
                domain = doc.domain[i];
                channel(domain);
                access("role:" + domain, domain); /* give the domain(role) access to all
                                                         domain(role) channels */
            }

            if (doc.domain.indexOf("fa5f5a7f0ff64c908845aa25647b1654") != -1) {// public domain
                channel("!"); // add to public channel
            }
		}

        if (doc.domains) {
			throw ("domains deprecated - use domain");
		}
    }


}

`
}
}
,“CORS”: {
“Origin”: ["*"]
,“Headers”: [“DNT”,“X-Mx-ReqToken”,“Keep-Alive”,“User-Agent”,“X-Requested-With”,“If-Modified-Since”,“Cache-Control”,“Content-Type”]
,“MaxAge”:1728000
}
}


#2

Nothing stands out from your config. How many docs are you syncing? Does the problem repeat if you restart SG?