Problems while connectring app to MongoDB on Azure - mongodb

I tried connectiong to Mongo on Azure and while working on local host everything went fine, here I got this problem
Exception in thread "cluster-ClusterId{value='63d3d50e34b36c0f2a6720cb', description='my corp'}-mongo.cosmos.azure.com:PORT" com.mongodb.MongoInterruptedException: Interrupted waiting for lock
java.base/java.util.concurrent.locks.ReentrantLock$Sync.lockInterruptibly(ReentrantLock.java:159)
at java.base/java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:372)
at com.mongodb.internal.Locks.checkedWithLock(Locks.java:41)
I tried updating pom to latest versions of dependencies etc. but nothing seems to work

As per error stated "mongodb.MongoInterruptedException: Interrupted waiting for lock". Issue may caused due to
some other thread called
MongoClient.close()
same error appear when you open multiple mongodb instances. Make sure that are closing the mongo clients before open a new instance.
MongoClient mongo = new MongoClient ("localhost", 27017);
mongo.close();
I have found sample application tutorial

Related

'No suitable driver found..' on AWS, works locally

I made a ktor application using exposed for db stuff and it works perfectly fine on my desktop, however when I deploy it on an AWS EC2 instance I get following error
Exposed - Transaction attempt #0 failed: No suitable driver found for
jdbc:postgresql://com.com:5432/DBName. Statement(s): null
java.sql.SQLException: No suitable driver found for jdbc:postgresql://
at
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
org.jetbrains.exposed.sql.Database$Companion$connect$10.invoke(Database.kt:206)
org.jetbrains.exposed.sql.Database$Companion$connect$10.invoke(Database.kt:206)
org.jetbrains.exposed.sql.Database$Companion$doConnect$3.invoke(Database.kt:127)
org.jetbrains.exposed.sql.Database$Companion$doConnect$3.invoke(Database.kt:128)
and so on.
Here's the connection:
Database.connect(DB_URL, driver = "org.postgresql.Driver", user = DB_USER, password = B_PW)
I've tried it with both, but no luck.
implementation("com.impossibl.pgjdbc-ng:pgjdbc-ng:0.8.9")
implementation("org.postgresql:postgresql:42.3.3")
I found potential solutions for Spring Boot (e.g. setting SPRING_DATASOURCE_DRIVER_CLASS_NAME) but I have no clue how I can relate this to ktor/exposed if even possible.
nvfm
works now. aws magic, idk
edit:
com.impossibl.postgres.jdbc.PGDriver did not work at all so I tried to switch it but org.postgresql.Driver also did nothing at first. looked at the logs, same error as before.
after a while AWS' health thingy switched to Ok and it seems to work just fine now.

How can I connect to an Atlas cluster with the SRV connection string format using ReactiveMongo?

I have a play scala app and i have an atlas cluster which i am trying to connect. According to the ReactiveMongo this is possible. I can add my connection string gotten from Atlas to my app via
mongodb.uri
In my application.conf file. I have tried everything based on the instructions from reactivemongo and atlas db but i am still unable to connect to the cluster. using my mongoshell however, i am able to connect and have access to my db but it simply refuses to connect via my app.
Mongo simply returns an error "MongoError['No primary node is available! (Supervisor-13/Connection-14)']" } and logs a warning in my console Some options were ignored because they are not supported (yet): w, retryWrites. I am using scala version 2.12 and reactivemongo 0.12.6 with play 2.6.
My connection string is mongodb+srv://<username>:<password>#my-cluster.abo25.mongodb.net/my-db?retryWrites=true&w=majority
Any info or help would be greatly appreciated.
Solved my problem. It turns out the +srv string format works seamlessly from reactivemongo version 0.17 and i was initially on 0.16. After i upgraded (and also upgraded my code), i was able to connect to my cluster. I also found out one of the user credentials i was using was wrong so that plus the upgrade got me up and running.

ReactiveMongo socket disconnect

Logs:
OUT 08:52:27.158 [reactivemongo-akka.actor.default-dispatcher-4] ERROR reactivemongo.core.actors.MongoDBSystem - The primary is unavailable, is there a network problem?
ERR reactivemongo.core.errors.GenericDriverException: MongoError['socket disconnected']
ERR at reactivemongo.core.actors.MongoDBSystem$$anonfun$4$$anonfun$applyOrElse$30.apply(actors.scala:390) ~[org.reactivemongo.reactivemongo_2.11-0.11.6.jar:0.11.6]
Our rest api, written in Scala (utilising the Spray and Akka frameworks) is deployed on a cloud.
We've tried setting the KeepAlive flag in ReactiveMongoOptions and then implemented a Jenkins job to periodically hit the database to keep it alive. However since adding these we've not seen the issue reoccur.
Rather than assume this has fixed it, before pushing to production, we are trying to reproduce the issue. Any ideas on what may be the cause or how we can reproduce this?

OrientDB and PostgreSQL JDBC drivers are clashing (InvocationTargetException): is there an OrientDB JAR with everything except JDBC?

My application uses both OrientDB and PostgreSQL databases for different purposes.
It seems they were able to coexist before, but today my code stopped working. Upon debugging, it seems that the OrientDB driver is attempting to connect to my PostgreSQL database when I'm expecting the PostgreSQL driver to connect instead.
Here is the sequence of events:
OrientDB connection is made (using OrientGraphFactory.setupPool()), transaction is started.
Connection attempt is made on PostgreSQL database, error occurs when trying to create the Connection object.
Here is the segment of code that creates the PostgreSQL connection:
Class.forName("org.postgresql.Driver");
Connection connection = DriverManager.getConnection(
"jdbc:postgresql://" + [...]);
return connection;
An InvocationTargetException is thrown at the DriverManager.getConnection() line. Here is the stack trace, clearly indicating that the OrientDB driver was the one trying to connect:
Error on opening database 'jdbc:postgresql://[hostname]/[db_name]'
com.orientechnologies.orient.core.exception.ODatabaseException: Error on opening database 'jdbc:postgresql://[hostname]/[db_name]'
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.<init>(ODatabaseDocumentTx.java:204)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.<init>(ODatabaseDocumentTx.java:168)
at com.orientechnologies.orient.jdbc.OrientJdbcConnection.<init>(OrientJdbcConnection.java:62)
at com.orientechnologies.orient.jdbc.OrientJdbcDriver.connect(OrientJdbcDriver.java:52)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
Indeed it seems the JDBC drivers are clashing.
I don't actually need JDBC functionality with OrientDB in this case. However, I can't find the OrientDB JAR that doesn't contain JDBC. The home page lets you download JDBC-all or JDBC-only. Where can I find a JAR with all dependencies bundled into a single JAR, but without JDBC?
This is probably not caused by the drivers themselves but by the DriverManager getting "confused" which driver handles which URL.
You can bypass the DriverManager by asking the driver directly for a connection:
Driver drv = new org.postgresql.Driver();
Properties props = new Properties();
props.put("username", "foo_user");
props.put("password", "database_password");
Connection connection = drv.getConnection("jdbc:postgresql://dbhost/db_name", props);
Unrelated, but: Class.forName("org.postgresql.Driver"); is longer necessary with current Java and driver versions.
I solved the problem here:
https://github.com/orientechnologies/orientdb/commit/8e0f4bed41999cf68ae9de229b3ff6a4260813da
It was a misunderstanding on how the DriverManager registers drivers and then calls the getConnection method.
Solutions.
My suggestion is to not use the orientdb-jdbc-all jar at all. If you don't need to work with orient embedded in your app AND access to it via JDBC it is really too big.
Instead, use your dependency management framework (maven, gradle?) to import orient jars, maybe only the orientdb-client if you need to interact with a remote db, maybe more if you need to embed orient in your app.
If you need to interact to a remote Orient Server via JDBC, use only che orientdb-jdbc. But you need the fixed one, so you should build it from source, or wait for next 2.1.8 release.
If you want to stay with the jdbc fat jar, again you can build it from source right now, or you can wait next hotfix release (2.1.8).
hope this help,
best regards

Load balancing MySQL ndbcluster

I have successfully setup ndbcluster version 7.1.26.
This contains 2 data nodes[NDBD], 2 mysql [MYSQLD] nodes and one management [MGMD] node.
Replication works successfully.
My Web application is deployed in JBoss-5.0.1 and using JNDI for connection resources which are specified in application specific ds.xml file in load balanced url forms e.g. jbdc:mysql:loadbalance:host1:port1,host2:port2/databaseName.
host1 : refers to first mysqld node and port1 refers the port it is running on.
host2 : refers to second mysqld node and port2 refers the port it is running on.
When both of the [MySQLD] nodes are up and running everything works fine and cluster responds well, replicates data, and data retrieval operations also work properly.
But issues are raised when any of the [MySQLD] nodes goes down. Data gets inserted/updated/replicated but the application is unable to retrieve data from cluster and web page remains busy working which means busy retrieving data. As soon as the node which was down goes up it responds properly and application goes forward and shows up data retrieved from cluster.
At JBoss 5.0.1 startup it showed up a NullPointerException in class LoadBalancingConnectionProxy.invoke(LoadBalancingConnectionProxy.java:439). Tell me if the above Exception plays any role in the above explained issues.
If anyone had faced issues like above and if has any solution regarding the issues please let me know.
Thanks and regards.
I have resolved the issue as it was a bug in the connectorJ's version.
As The project I am working on was already using both the buggy jar mysql-connector-java-5.0.8.jar and the jar version in which the issue is already resolved i.e. mysql-connector-java-5.1.13-bin.jar.
After all the search when I removed the jar mysql-connector-java-5.0.8.jar my issues got resolved.
All that was problematic was that the ConnectorJ/Driver was getting referred from the buggy jar.
The bug id and url which refers to this issue is:
http://bugs.mysql.com/bug.php?id=31053
.
Thanks for considerations.
Are you using different userids and passwords for each of the hosts(host1, host2) specified in the tag ? (Either directly or using tag) ?