Did someone face such an error happening in case of some queries execution? (jdbc4.CommunicationsException: Communications link failure)
Generally, this exception means some problem of communication between application and mysql. And you can find a lot of suggestions posted regarding possible reason.
Nothing helped in our case, and after several hours of investigation it turned out that the reason can be completely other.
Maybe the answer below will save someones time :)
So, it turned out that the reason can be a corruption of mysql data file!! Actually, it can be corrupted the way that mysql is normally functioning for the most of queries.
If you find the query which executes application (when CommunicationsException is thrown) and execute it directly, e.g. in SQLyog, you will see:
Error Code : 2013
Lost connection to MySQL server during query
First of all, have a look on domain.err log file of mysql. If you have similar case, there should be lots of errors reported, including message like:
InnoDB: Database page corruption on disk or a failed
What we have done to solve the situation quickly - we set "innodb_force_recovery" to 1. This means directive to MySQL: Let the server run even if it detects a corrupt page.
CommunicationsException disappears after setting this, and what remains - "simply" DB data recovery ;-)
All the best,
Edgar
Related
I made a Java Web Application hosted by Tomcat. It can be found on this URL.
The problem that I am experiencing is that whenever I visit the page the first time it takes about 10s while every time after it it takes only 100-500ms. I would say the speed improvement is due to browser caching, but not really, when I refresh cache too (ctrl+shift+r) I get the same quick response.
Then after some time, about 5 minutes I visit the page again and it's slow again.
You may try some tests yourself on the URL provided by changing the search parameter value to e.g.: 1050,1051,1052,2670,4000,2300,2200.
Also the interesting fact I have spotted is that no matter how big payload (compare 1050 with 2300) the time is almost always the same approx. 9-10s. So what I assume is that something like Java Server has got to get ready and that is what is taking time.
EDIT:
I was first thinking it could be related to Java/Tomcat having to load some resources and then after some time +-3-5mins again because for some reason it unloaded it. But as I wrote above, even if I change the URL query string (that causes a different SQL query during execution), it again loads long. Can the issue be related to the DB? I am using MySQL.
EDIT2:
The reason why it's faster is most likely the server caching. I am 95% sure and that is because I made couple of experiments such as trying it on 2 computers etc. (no it's not browser caching). Then I realized that if it's fast only when it's cached, what takes so long is the actual .executeQuery line of code. It takes 10s even though the exact same request through a client such as WorkBench takes only 0.285s. Therefore I am going to try to use a PreparedStatement or experiment further.
The content is 200kB in size. You need to optimize it in the front and backend.
The main problem is in your backend. Check why it takes so long.
In the frontend you can enable gzip compression. Check the tomcat documentation on how to do it. This will reduce the size for the download.
The second time is probably faster for you due to browser caching.
Check the response code in Firebug, if the response is 304 it is cached. Response 200 means it has been loaded from the server.
ORM systems (like Hibernate) can cause significantly slow startup if you forget to turn off the initial modell-schema sync option in production environment, for example in Spring -> JPA -> Hibernate -> application-[server].yml->
spring:
jpa:
hibernate:
ddl-auto: update
update none
If your model didn't change, switch "update" to "none" in the production environment for faster startup.
I have done a lot of internet searches, and can't find a report of a problem quite like this one, so I'm hoping someone here might have an idea of what is going wrong. In my java code I have a query that is pulling data from the database. I have confirmed that the SQL is well-formed, and all of my other queries in this java file run fine. In fact, even this query runs as it should when I am using the dev test Tomcat server. However, when I try to run this particular query using the dev test Resin server (where it was working perfectly fine up until just recently), or the QA test server, which also uses Tomcat, I get this error:
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '131500'
The '131500' I'm assuming is coming from the time portion of the first datetime value that is returned, which is '13:15:00'.
The particular part of this query that is causing the problem is this line:
CONCAT(DATE_FORMAT((SELECT datenotime), '%Y-%m-%d'),' ',DATE_FORMAT((SELECT appointmenttime FROM appointments WHERE appointmentdate = datenotime AND appointments.service_id = service.id), '%T'))
If I remove this then I experience no problems on any server, so it only occurs when the time is formatted and concatenated. I would think that the issue here must be some server setting? Although there were no recent changes made to the Resin server that I know of. I tried updating Resin's msyql connector jar, but that didn't help. Does anyone know what is going wrong?
Thanks!
My guess is that you are getting this error when datenotime is null.
That would make sense, since you are concatenating datenotime and then appointmenttime. If datenotime is null, then all you have left is time, which simply can't be converted to any known datetime value.
In a recent job interview I was asked a J2EE debugging question. The question was As Follows:
"You are not getting same data as expected from your server how do you debug it?"
What or how should I answered this question that would make the interviewer happy??
Please suggest....
On the top of my head, usually you would
check the request and compare it with API - is the request being done correctly
check the logs for any problems on the server
confirm that the version of server application matches the one expected
check the database data status
if else fails, try to reproduce the problem locally or in a lower environment or step through the server app execution path with a debugger. Increasing the log level or hooking up to debug interface might be relevant as well.
When you have to debug code to server there is a common way on how to debug the code. You see server logs. Now, if you cannot find any errors, you have to see what the API returns at every single step. If you have not logs for every step, put log.debug("Some text that means something"); and rerun. If something is unusual, then you have to check the specific step.
The question is too general and opens a way for you to literally bombard the interviewer with questions and that's probably what he expects you to do.
Usually when sh. hits the fan I want to know: does the user receive any data at all? If not, app log, server log and db log is where I look. Some apps we use got app log located on the disk where the app is running, some are using db based logs and some are using the default log which can be accessed through admin console on the server (Glassfish for example).
On the other hand if the user received incorrect data I start tracking through the app how the data is "made" which usually means going through several db queries and such where I'm trying to determine what's going on. After that I compare the result I expect with the result user received and according to the difference I decide what went wrong.
But hey this question is too general in this environment so you either let the interviewer specify the problem or create your own scenario for him.
I'm building a system with a login. When I was just testing it on my own computer, it worked perfectly fine. Once I uploaded it to our server, we started running into the problem whereby ... it wouldn't log in in the morning, for a few seconds. Works fine the rest of the time.
I've only run into this yesterday and today, and I can only test it once each morning, so it's hard to give too many details yet. Here's the setup:
The front page is an html page using javascript and angular js. It brings up an empty frame, then makes an ajax request for the contents of the page. On any failed ajax request that has a return value of 'insufficient access priviliges' it will un-hide a div holding a login form. That login form blanks out the page and provides a submit button. Once the submit button is clicked on, it sends an ajax login request to the Java server. Once that request is returned, the page hides the login form again, and things move on as usual.
On the back end, we have a java server running something between 1.6 and 1.7 (yes, I know, I should know better - the server reports back that it's 1.7.001, but 1.7 functionality like string-based switch-case statements don't work, so we compile for 1.6 java when uploading. It's a known issue we're working on.) We're using Stripes to do the front-facing code. The database is a mysql database, located on the same server.
When this error occurs, it's always the first login in the morning. I load up the page, type in the user/pass, and click login. The page blinks and comes back to the login screen. I haven't cleared out the user/pass after a login yet, because we're still in a testing phase, so I can just click 'login' again, and again, a dozen times before it finally logs in. This problem has only happened twice: yesterday and today, the first login of the morning.
My co-worker had a similar issue with another similar setup on a previous project, same server. He said he believes the problem has to do with the sql server closing the connection without the java server realizing that the connection has been closed, but he's not sure, and doesn't know how to fix it.
I don't even know what other information to offer, what code to show, or anything like that. The best suggestion I can find anywhere is "Set up a scheduled event to make a sure-fire database request every couple of hours," but this seems so ... kludgy. I'd love to be able to test for a more definitive problem and solution, if anyone could help me out. If anyone can tell me what code they'd like to see to figure this out, I'll gladly paste it up. More information? Just ask. The scope seems so ... big ... that I don't know which pieces might be relevant.
Edit 1: Error code!
[ERROR] - Database Error 1 on verify
java.sql.SQLException: Already closed.
at org.apache.tomcat.dbcp.dbcp.PoolableConnection.close(PoolableConnection.java:114)
at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:191)
Edit 2: Connection Code
This is from an object we keep specifically for all mysql database connections.
private static ConnectionSource coreConnection = null;
private static DataSource coreDataSource = null;
public static ConnectionSource getCoreConnection() throws SQLException, NamingException {
if (coreConnection == null || !coreConnection.isOpen()) {
Context env = (Context)new InitialContext().lookup("java:comp/env");
coreDataSource = (DataSource)env.lookup("webapps/test");
coreConnection = new DataSourceConnectionSource(coreDataSource, new MysqlDatabaseType());
}
return coreConnection;
}
Configure your connection pool to validate connections. The connection pool will then send a simple query (which you specify during configuration) to the DB. If that query fails, it will close the connection and give you a new one, otherwise it will use it in place. That helps solve problems like these as well as problems where the database goes down behind the back of the server.
MySQL closes connections which have been open for a long time, but don't do anything. From what you've described it sounds like this is what you're running in to.
The first login fails because it finds that the used database connection is no longer working, and the driver notices this as well. The driver will then use a new connection for the next request.
The first way to handle this that comes to mind is detecting this SQLException, and handling it by opening a new connection with the same query. There may be other solutions available within the driver that you're using, but unfortunately I am not aware of any.
To aid with detecting this SQLException you can take a look at the docs, and evaluate if the methods listed there return anything unique to this error.
If you are using a connection pool, then this question may contain the answer to keeping the connections alive.
I'm building a website with play! framework, I've finished coding and testing with in memory database, and everything was fine, so I decided to push the code to my server. But I encountered with a strange error, it says, "A database error occured : Cannot connected to the database, Unknown database 'fpn_server'".
I did change the application.conf file in conf folder, I set the application.mode to prod(quite sure this has no connection with database), set the db property to "mysql:root:mypass#fpn_server", and jpa.ddl to "create" to make sure the database got created.
Well, to be honest, I developed a demo website with the same database name, and it was successfully deployed on my server. But this time, the schema changed, I did NOT use the evolution scripts as the documentation said, I simply dropped the database from mysql server. Not quite sure if this is the mistake.
I've been googling around for a while, an no good.
BTW, I'm usin play 1.2.4 not play 2.
Can anyone help me? Any suggestion is welcome!
Thanks in advance.
You are using the shortcut MYSQL5 configuration, which appears fine. However, maybe you should try using the verbose settings.
%production.db.url=jdbc:mysql://localhost/fpn_server
%production.db.driver=com.mysql.jdbc.Driver
%production.db.user=root
%production.db.pass=mypass
If there is anything that looks wrong in the verbose settings, this could be responsible for why your shortcut settings are not making sense.
If the configuration looks fine, I would check that your database is accessible.
For reference, here is the application.conf database options - http://www.playframework.org/documentation/1.2.4/configuration#dbconf