Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling Couchbase N1QL engine with node.js

I'm trying to run some N1QL queries using couchbase npm package. Here's the steps I took before running the code:

  1. Installed and executed Couchbase on OSX
  2. Navigated to :8091 and set up the credentials as well as the beer-sample bucket
  3. Downloaded the N1QL DP4 to a folder
  4. Enabled cbq-engine like so: ./cbq-engine -datastore=http://localhost:8091
  5. Created a primary index as per the documentation

At this point I have localhost:8091 (primary Couchbase cluster) and localhost:8093 (DP4 engine) both live.

Here's the code I'm using from the node.js client to try to run a simple N1QL query:

var colors = require('colors'); // for console.log
var couchbase = require('couchbase');
var N1qlQuery = require('couchbase').N1qlQuery; // get query object
var myCluster = new couchbase.Cluster('couchbase://localhost:8091'); // connect to live local cluster
var myBucket = myCluster.openBucket(); // open bucket
myBucket.enableN1ql(['http://localhost:8093/']); // enable n1ql as per documentation (http://docs.couchbase.com/developer/node-2.0/n1ql-queries.html) - I also tried :8091, same result
var query = N1qlQuery.fromString('SELECT * FROM `beer-sample` LIMIT 10');

setTimeout(function() {
  myBucket.query(query, function(err, res) {
    if (err) {
      console.log('query failed'.red, err);
      return;
    }
    console.log('success!', res);
  });
}, 2000); // just in case connecting takes a second or something?

Here's the result:

query failed { [Error: failed to connect to bucket] code: 24 }

I've tried seemingly everything and I can't find any documentation to troubleshoot this. What's going on?

Edit: Apparently LCB_LOGLEVEL environment variable will allow the underlying C library to pump out some logs. Here they are:

LCB_LOGLEVEL=5 node web.js
0ms [I0] {1299} [INFO] (instance - L:372) Version=2.4.0, Changeset=0ac7fc4
0ms [I0] {1299} [INFO] (instance - L:373) Effective connection string: couchbase://127.0.0.1/beer-sample. Bucket=beer-sample
0ms [I0] {1299} [DEBUG] (instance - L:63) Adding host 127.0.0.1:8091 to initial HTTP bootstrap list
0ms [I0] {1299} [DEBUG] (instance - L:63) Adding host 127.0.0.1:11210 to initial CCCP bootstrap list
             Starting...            
107ms [I1] {1299} [INFO] (instance - L:372) Version=2.4.0, Changeset=0ac7fc4
107ms [I1] {1299} [INFO] (instance - L:373) Effective connection string: couchbase://localhost:8091/default. Bucket=default
107ms [I1] {1299} [DEBUG] (instance - L:63) Adding host localhost:8091 to initial CCCP bootstrap list
107ms [I1] {1299} [DEBUG] (confmon - L:89) Preparing providers (this may be called multiple times)
108ms [I1] {1299} [DEBUG] (confmon - L:99) Provider FILE is DISABLED
108ms [I1] {1299} [DEBUG] (confmon - L:96) Provider CCCP is ENABLED
108ms [I1] {1299} [DEBUG] (confmon - L:96) Provider HTTP is ENABLED
108ms [I1] {1299} [DEBUG] (confmon - L:99) Provider MCRAW is DISABLED
108ms [I1] {1299} [TRACE] (confmon - L:292) Start refresh requested
108ms [I1] {1299} [TRACE] (confmon - L:271) Current provider is CCCP
108ms [I1] {1299} [INFO] (cccp - L:118) Requesting connection to node localhost:8091 for CCCP configuration
108ms [I1] {1299} [DEBUG] (lcbio_mgr - L:416) <localhost:8091> (HE=0x103803800) Creating new connection because none are available in the pool
108ms [I1] {1299} [DEBUG] (lcbio_mgr - L:321) <localhost:8091> (HE=0x103803800) Starting connection on I=0x10311dc70
108ms [I1] {1299} [INFO] (connection - L:441) <localhost:8091> (SOCK=0x10311da10) Starting. Timeout=2000000us
110ms [I0] {1299} [DEBUG] (confmon - L:89) Preparing providers (this may be called multiple times)
110ms [I0] {1299} [DEBUG] (confmon - L:99) Provider FILE is DISABLED
110ms [I0] {1299} [DEBUG] (confmon - L:96) Provider CCCP is ENABLED
110ms [I0] {1299} [DEBUG] (confmon - L:96) Provider HTTP is ENABLED
110ms [I0] {1299} [DEBUG] (confmon - L:99) Provider MCRAW is DISABLED
110ms [I0] {1299} [TRACE] (confmon - L:292) Start refresh requested
110ms [I1] {1299} [TRACE] (connection - L:335) <localhost:8091> (SOCK=0x10311da10) Received completion handler. Status=0. errno=0
110ms [I1] {1299} [INFO] (connection - L:116) <localhost:8091> (SOCK=0x10311da10) Connected 
110ms [I1] {1299} [DEBUG] (lcbio_mgr - L:271) <localhost:8091> (HE=0x103803800) Received result for I=0x10311dc70,C=0x10311da10; E=0x0
110ms [I1] {1299} [DEBUG] (lcbio_mgr - L:223) <localhost:8091> (HE=0x103803800) Assigning R=0x10311da50 SOCKET=0x10311da10
110ms [I1] {1299} [DEBUG] (ioctx - L:101) <localhost:8091> (CTX=0x100f012c0,unknown) Pairing with SOCK=0x10311da10
110ms [I0] {1299} [TRACE] (confmon - L:271) Current provider is CCCP
110ms [I0] {1299} [INFO] (cccp - L:118) Requesting connection to node 127.0.0.1:11210 for CCCP configuration
110ms [I0] {1299} [DEBUG] (lcbio_mgr - L:416) <127.0.0.1:11210> (HE=0x10280e600) Creating new connection because none are available in the pool
110ms [I0] {1299} [DEBUG] (lcbio_mgr - L:321) <127.0.0.1:11210> (HE=0x10280e600) Starting connection on I=0x100f01760
110ms [I0] {1299} [INFO] (connection - L:441) <127.0.0.1:11210> (SOCK=0x100f01890) Starting. Timeout=2000000us
110ms [I0] {1299} [TRACE] (connection - L:335) <127.0.0.1:11210> (SOCK=0x100f01890) Received completion handler. Status=0. errno=0
110ms [I0] {1299} [INFO] (connection - L:116) <127.0.0.1:11210> (SOCK=0x100f01890) Connected 
110ms [I0] {1299} [DEBUG] (lcbio_mgr - L:271) <127.0.0.1:11210> (HE=0x10280e600) Received result for I=0x100f01760,C=0x100f01890; E=0x0
110ms [I0] {1299} [DEBUG] (lcbio_mgr - L:223) <127.0.0.1:11210> (HE=0x10280e600) Assigning R=0x100f01540 SOCKET=0x100f01890
110ms [I0] {1299} [DEBUG] (ioctx - L:101) <127.0.0.1:11210> (CTX=0x100d00ca0,unknown) Pairing with SOCK=0x100f01890
110ms [I0] {1299} [DEBUG] (ioctx - L:151) <127.0.0.1:11210> (CTX=0x100d00ca0,sasl) Destroying. PND=0,ENT=1,SORC=1
110ms [I0] {1299} [DEBUG] (ioctx - L:101) <127.0.0.1:11210> (CTX=0x10311dda0,unknown) Pairing with SOCK=0x100f01890
110ms [I0] {1299} [DEBUG] (ioctx - L:151) <127.0.0.1:11210> (CTX=0x10311dda0,bc_cccp) Destroying. PND=0,ENT=1,SORC=1
110ms [I0] {1299} [INFO] (lcbio_mgr - L:491) <127.0.0.1:11210> (HE=0x10280e600) Placing socket back into the pool. I=0x100f01760,C=0x100f01890
111ms [I0] {1299} [INFO] (confmon - L:174) Setting new configuration. Received via CCCP
111ms [I0] {1299} [DEBUG] (bootstrap - L:55) Instance configured!
2112ms [I1] {1299} [ERROR] (negotiation - L:178) <localhost:8091> (SASLREQ=0x100f01180) Error: 0x17, Negotiation timed out
2112ms [I1] {1299} [ERROR] (cccp - L:133) <NOHOST:NOPORT> Got I/O Error=0x17
2112ms [I1] {1299} [INFO] (confmon - L:202) Provider 'CCCP' failed
2112ms [I1] {1299} [DEBUG] (confmon - L:236) Will try next provider in 0us
2112ms [I1] {1299} [DEBUG] (ioctx - L:151) <localhost:8091> (CTX=0x100f012c0,sasl) Destroying. PND=1,ENT=0,SORC=1
2112ms [I1] {1299} [TRACE] (confmon - L:271) Current provider is HTTP
2112ms [I1] {1299} [TRACE] (htconfig - L:395) Starting HTTP Configuration Provider 0x103875a00
2112ms [I1] {1299} [ERROR] (htconfig - L:400) Not scheduling HTTP provider since no nodes have been configured for HTTP bootstrap
2112ms [I1] {1299} [INFO] (confmon - L:202) Provider 'HTTP' failed
2112ms [I1] {1299} [TRACE] (confmon - L:226) Maximum provider reached. Resetting index
2112ms [I1] {1299} [ERROR] (bootstrap - L:100) Failed to bootstrap client=0x10311bb00. Code=0xa, Message=No more bootstrap providers remain
query failed { [Error: failed to connect to bucket] code: 24 }
10112ms [I0] {1299} [DEBUG] (lcbio_mgr - L:464) <127.0.0.1:11210> (HE=0x10280e600) Idle connection expired
like image 568
dsp_099 Avatar asked Oct 19 '22 14:10

dsp_099


2 Answers

Instead of

myBucket.enableN1ql(['http://1.1.1.1:8093/'])

Put

myBucket.enableN1ql(['1.1.1.1:8093'])

It worked for me.

like image 86
tdebroc Avatar answered Oct 27 '22 09:10

tdebroc


couchbase://localhost:8091 is wrong. You should not specify an initial port for the server unless the server is listening on an alternate port (and the server is configured to do so). In such cases you would specify the http:// scheme if the alternate port is the REST API, and couchbase:// if the alternate port is the data (memcached) port.

Internally, the client may connect to different endpoint types in a sequence (Trying more prererable to less preferable types).

like image 37
Mark Nunberg Avatar answered Oct 27 '22 10:10

Mark Nunberg