Cassandra driver for nodejs Helenus - node.js

I am having problems with cassandra driver for nodejs - helenus. I crated function loop that insert records into table, and I am calling with ab tool. The problem is after 10-20 insert the driver throws error:
This is the coffee code:
helenus = require 'helenus'
pool = new helenus.ConnectionPool(
hosts: ["mybalancer:9160"]
keyspace: "stats"
timeout: 90000
)
pool.on "error", (err) ->
console.error err.name, err.message
pool.connect (err, keyspace) ->
if err
throw (err)
else
vals = [uuid.v4(), uuid.v4()]
#insert_statement = "INSERT INTO test2 (id, name) values(%s, %s)"
console.log(vals)
pool.cql insert_statement, vals, (err, results) ->
console.log err, results
And This is the error:
/home/udev/development/project/U/hubber/app/controllers/event_logger_cassandra.js:98
throw err;
^
HelenusNoAvailableNodesException: Could Not Connect To Any Nodes
at replyNotAvailable (/home/udev/development/project/U/hubber/node_modules/helenus/lib/pool.js:16:25)
at onConnect (/home/udev/development/project/U/hubber/node_modules/helenus/lib/pool.js:98:9)
at /home/udev/development/project/U/hubber/node_modules/helenus/lib/pool.js:120:7
at null.<anonymous> (/home/udev/development/project/U/hubber/node_modules/helenus/lib/connection.js:199:5)
at EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (/home/udev/development/project/U/hubber/node_modules/helenus/node_modules/helenus-thrift/lib/thrift/connection.js:56:10)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:830:16
at process._tickCallback (node.js:415:13)
I have cassandra cluster of three nodes(large servers on amazon) behind load balancer.
I have monitor on the servers and the nodes are always up and work fine.
What do I missing here?
Thanks.

Related

Using mariadb nodeJS connector with multiple queries

I've got a server running Node.js connecting to a MariaDb database. I'm using the Node.js connector and it's working fine for single queries. However, when I try to do multiple queries it's throwing this error:
{ Error: (conn=8439, no: 1064, SQLState: 42000) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT 2' at line 1
sql: SELECT 1; SELECT 2; - parameters:[]
at Object.module.exports.createError (\node_modules\mariadb\lib\misc\errors.js:55:10)
at Packet.readError (\node_modules\mariadb\lib\io\packet.js:506:19)
at Query.readResponsePacket (\node_modules\mariadb\lib\cmd\resultset.js:47:28)
at PacketInputStream.receivePacket (\node_modules\mariadb\lib\io\packet-input-stream.js:73:9)
at PacketInputStream.onData (\node_modules\mariadb\lib\io\packet-input-stream.js:129:20)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
fatal: false,
errno: 1064,
sqlState: '42000',
code: 'ER_PARSE_ERROR' }
The current test code I'm using is:
conn = await pool.getConnection({multipleStatements: true});
conn.query({
multipleStatements: true,
sql: "SELECT 1; SELECT 2;"
}).then((data: any) => {
console.log(data);
conn.end();
});
The documentation suggests multipleStatements is an option, but looking through the GitHub Repo, the only places I've found it is under lib/config/connection-options.js and the GitHub documentation. I also noticed the batch option but that seems to be specifically for a load of inserts.
Is there a way to use the mariadb-connector-nodejs to run multiple queries in a single query call? If so, what else could I be doing wrong that only multi-statement queries are not working?
Versions:
- MariaDb: 10.1.34-MariaDB
- Node.js: v10.14.2
- mariadb-connector-nodejs: mariadb#2.0.2-rc
multipleStatements is the good option, but as #rolandstarke indicate, that is a connection option.
When using creating pool, you indicate pool + connection options, since pool will handle connection creation. see related documentation
Example:
const mariadb = require("mariadb");
const pool = mariadb.createPool({ multipleStatements: true });
pool.query("select 1; select 2")
.then(results => {
//select 1 results
console.log(results[0]); //{ '1': 1 }
//select 2 results
console.log(results[1]); //{ '2': 2 }
})
.catch(err => {
//handle error
});

Following tutorial to connect postgres db to node project - failing at running script to create table

i am following a guide on how to use postgres + node. I have gotten to the point of creating table creation script.
here is the code I am using from the tutorial:
var pg = require('pg');
var connectionString = process.env.DATABASE_URL || 'postgres://postgres:postgres#localhost:5432/todo';
var client = new pg.Client(connectionString);
client.connect();
var query = client.query('CREATE TABLE items(id SERIAL PRIMARY KEY, text VARCHAR(40) not null, complete BOOLEAN)');
query.on('end', function() { client.end(); });
However, when I do the step of node models/database.js, I receive the following error:
ram#ram-windows-xp-ubuntu:~/Development/Web/Projects/node-postgres$ node models/database.js
events.js:85
throw er; // Unhandled 'error' event
^
error: password authentication failed for user "postgres"
at Connection.parseE (/home/ram/Development/Web/Projects/node-postgres/node_modules/pg/lib/connection.js:539:11)
at Connection.parseMessage (/home/ram/Development/Web/Projects/node-postgres/node_modules/pg/lib/connection.js:366:17)
at Socket.<anonymous> (/home/ram/Development/Web/Projects/node-postgres/node_modules/pg/lib/connection.js:105:22)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)
I am new to using the ubuntu and I tried to follow the steps from this guide but confused. Sorry for the bother friends please if you can do the needful I will be humbled.

MongoDB: Server sockets closed after a few minutes

I am working with multiple AWS intances connected to the same mongo database (inside Compose.io Elastic deployment) but I keep getting the error server <url>:<port> sockets closed after a few minutes. Can anyone give me any hint about what may be wrong with the connection code?
CONNECTION CODE
var url = "mongodb://<user>:<password>#<url1>:<port1>,<url2>:<port2>/<dbName>?replicaSet=<replicaSetName>";
var options = {
server : {"socketOptions.keepAlive": 1},
replSet : { "replicaSet": <replicaSetName>, "socketOptions.keepAlive": 1 }
};
MongoClient.connect(url, options, function(err, db) { ... });
ERROR MESSAGE
Potentially unhandled rejection [2] MongoError: server <url>:<port> sockets closed
at null. (/var/app/current/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:328:47)
at g (events.js:199:16)
at emit (events.js:110:17)
at null. (/var/app/current/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:101:12)
at g (events.js:199:16)
at emit (events.js:110:17)
at Socket. (/var/app/current/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:142:12)
at Socket.g (events.js:199:16)
at Socket.emit (events.js:107:17)
at TCP.close (net.js:485:12)

Count method throws syntax error when used with where clause in loopback

I am using loopback/strong loop in node.js.
I am trying to use where clause in count method for paginition purpose. Whenever I try to use where clause, it gives me a mysql syntax error for as simple query as below.
Ride.count({
where:{"id":20}
},function(err,totalCount){
if (err) {
log.info("Total error ", err);
fn(err);
}else {
log.info("Total count ", totalCount);
}
});
this is the error I get.
Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '20' at line 1\n at Query.Sequence._packetToError (D:\Code\liftee\rest-services\node_modules\loopback-connector-mysql\node_modules\mysql\lib\protocol\sequences\Sequence.js:48:14)\n at Query.ErrorPacket (D:\Code\liftee\rest-services\node_modules\loopback-connector-mysql\node_modules\mysql\lib\protocol\sequences\Query.js:83:18)\n at Protocol._parsePacket (D:\Code\liftee\rest-services\node_modules\loopback-connector-mysql\node_modules\mysql\lib\protocol\Protocol.js:271:23)\n at Parser.write (D:\Code\liftee\rest-services\node_modules\loopback-connector-mysql\node_modules\mysql\lib\protocol\Parser.js:77:12)\n at Protocol.write (D:\Code\liftee\rest-services\node_modules\loopback-connector-mysql\node_modules\mysql\lib\protocol\Protocol.js:39:16)\n at Socket. (D:\Code\liftee\rest-services\node_modules\loopback-connector-mysql\node_modules\mysql\lib\Connection.js:92:28)\n at Socket.emit (events.js:107:17)\n at readableAddChunk (_stream_readable.js:163:16)\n at Socket.Readable.push (_stream_readable.js:126:10)\n at TCP.onread (net.js:529:20)\n --------------------\n at Protocol._enqueue (D:\Code\liftee\rest-services\node_modules\loopback-co
Try without using where clause. I have tested this on my model and it works.
Ride.count(
{"id":20},
function(err,totalCount){
if (err) {
log.info("Total error ", err);
fn(err);
}else {
log.info("Total count ", totalCount);
}
}
);
Have a look at the strongloop API explorer. You only need to pass value to count function.

Trouble with reading nodes with node-neo4j & Debugging skills with neo4j-shell

I'm new to Neo4J. So far, I successfully installed and started the Neo4J server and I checked it by running the command neo4j status.
By using node-neo4j driver to add & update nodes to the database.
In my nodejs server, I create a new database:
db = new neo4j("http://127.0.0.1:7474");
Next, I insert a new node:
db.insertNode( {"name": "Darth Vader","sex": "male"}, (err, node) ->
if err then throw err
console.log "Insert node"
console.log node
)
I face no error when inserting a new node. However, when I try to read this node
db.readNode( {"name": "Darth Vader"}, (err, node) ->
if err then throw err; # 48th line of server.js
console.log "Read node"
console.log node
)
ReadNode function throws the following exception at 48th line( you can find the 48th line at the code snippet given above).
server.js:48
throw err;
^
Error: HTTP Error 500 occurred while reading a node.
at node_modules/node-neo4j/main.js:151:15
at Request.callback (node_modules/node-neo4j/node_modules/superagent/lib/node/index.js:656:3)
at Request.<anonymous> (node_modules/node-neo4j/node_modules/superagent/lib/node/index.js:131:10)
at Request.emit (events.js:95:17)
at IncomingMessage.<anonymous> (node_modules/node-neo4j/node_modules/superagent/lib/node/index.js:802:12)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:929:16
at process._tickCallback (node.js:419:13)
Then, I tried to debug my process by checking my database and tried neo4j-shell and typed dbinfo on the command line, I expected to see my database and the Darth Vader node that already inserted.
However, dbinfo returns nothing at all!
How can I find my databases, and nodes in this database with neo4j-shell?
How can I make sure that I successfully inserted the node? How can I read the node that I already inserted?
Do you have any idea?
Thank you in advance!
To make things clear: There are two node-neo4j version out there:
https://github.com/philippkueng/node-neo4j
https://github.com/thingdom/node-neo4j
You are using the philippkueng version: db.readNode will work with nodeId's only. I think you should use db.cypherQuery() with a cypher statement instead for querying the neo4j database.
For example:
db.cypherQuery('MATCH (n {name: "Darth Vader"}) RETURN n',
function(err, result){
if(err) throw err;
console.log(result.data); // delivers an array of query results
console.log(result.columns); // delivers an array of names of objects getting returned
});
Is you want to use labels and indexes without Cypher to lookup the node you could use this:
// add Darth Vader with the label Person
db.insertNode( {name: 'Darth Vader',sex: 'male'}, 'Person',
function(err, node) {})
db.readNodesWithLabelsAndProperties('Person', {name: 'Darth Vader'},
function (err, result) {})
For debugging as #codewithcheese already mentions use the Neo4j browser at:
http://localhost:7474

Resources