[MySQL] production environment MySQL database transaction has been running

Source: Internet
Author: User

Objective:

The operator reflected that a single submission had jammed and the page had not been returned.


1, just started to suspect that the application server or DB pressure is too high hang, immediately to check the application server and the load of the DB, looks OK, pretty low, should not be DB performance issues.


2, the last to see if the table is locked, check to see that there are 2 transactions have been running, no end. ,

Mysql> select * from Innodb_trx\g;
1. Row ***************************
trx_id:28573155
Trx_state:running
Trx_started:2014-08-12 15:27:57
Trx_requested_lock_id:null
Trx_wait_started:null
trx_weight:0
trx_mysql_thread_id:1662333
Trx_query:null
Trx_operation_state:null
trx_tables_in_use:0
trx_tables_locked:0
trx_lock_structs:0
trx_lock_memory_bytes:376
trx_rows_locked:0
trx_rows_modified:0
trx_concurrency_tickets:0
Trx_isolation_level:read COMMITTED
Trx_unique_checks:1
Trx_foreign_key_checks:1
Trx_last_foreign_key_error:null
trx_adaptive_hash_latched:0
trx_adaptive_hash_timeout:7188
trx_is_read_only:0
trx_autocommit_non_locking:0


2. Row ***************************
trx_id:28573065
Trx_state:running
Trx_started:2014-08-12 15:27:51
Trx_requested_lock_id:null
Trx_wait_started:null
Trx_weight:11
trx_mysql_thread_id:1662332
Trx_query:null
Trx_operation_state:null
trx_tables_in_use:0
trx_tables_locked:0
Trx_lock_structs:6
trx_lock_memory_bytes:1248
Trx_rows_locked:1
Trx_rows_modified:5
trx_concurrency_tickets:0
Trx_isolation_level:read COMMITTED
Trx_unique_checks:1
Trx_foreign_key_checks:1
Trx_last_foreign_key_error:null
trx_adaptive_hash_latched:0
trx_adaptive_hash_timeout:9995
trx_is_read_only:0
trx_autocommit_non_locking:0
2 rows in Set (0.00 sec)


ERROR:
No query specified


Mysql>


3, by trx_mysql_thread_id:1662332 query information_schema.processlist find the SQL thread that executes the client request for the transaction


Mysql> SELECT * from Information_schema.processlist where id=1662333;
+---------+--------------+-------------------+-------------+---------+------+-------+------+
| ID | USER | HOST | DB | COMMAND | Time | State | INFO |
+---------+--------------+-------------------+-------------+---------+------+-------+------+
| 1662333 | Business_web | 10.2xx.3.xx:23452 | business_db | Sleep |       1780 | | NULL |
+---------+--------------+-------------------+-------------+---------+------+-------+------+
1 row in Set (0.00 sec)



4, through the SQL thread, find the IP address of the application and port 10.2xx.3.xx:23452

go to Application server, retrieve port 23452 via netstat to find the PID of a running application project
[Email protected] ~]# NETSTAT-NLATP |grep 23452
TCP 0 0:: ffff:10.xx.3.2x:23452:: ffff:10.xx4.3.x1:3306 established 12059/java
[Email protected] ~]# Ps-eaf|grep 12059
Tomcat 12059 1 1 Aug09? 01:19:36/usr/java/jdk1.6.0_45/jre/bin/java-djava.util.logging.config.file=/usr/local/app/apache-tomcat-6.0.37_ 7000/conf/logging.properties-djava.util.logging.manager=org.apache.juli.classloaderlogmanager-xms4096m- XMX4096M-XSS2048K-XX:PERMSIZE=256M-XX:MAXPERMSIZE=512M-XX:NEWSIZE=1536M-XX:MAXNEWSIZE=3072M- djava.endorsed.dirs=/usr/local/app/apache-tomcat-6.0.37_7000/endorsed-classpath/usr/local/app/ apache-tomcat-6.0.37_7000/bin/bootstrap.jar-dcatalina.base=/usr/local/app/apache-tomcat-6.0.37_7000- Dcatalina.home=/usr/local/app/apache-tomcat-6.0.37_7000-djava.io.tmpdir=/usr/local/app/apache-tomcat-6.0.37_ 7000/temp org.apache.catalina.startup.Bootstrap Start
Root 21039 21007 0 16:00 pts/2 00:00:00 grep 12059
[Email protected] ~]# cd/usr/local/app/apache-tomcat-6.0.37_7000/webapps/
[email protected] webapps]# LL
Total dosage 68292
Drwxrwxr-x. 6 Tomcat Tomcat 4096 August 5 21:33 Shopadminweb
-rw-r--r--. 1 Tomcat Tomcat 39126457 August 5 21:33 Shopadminweb.war
Drwxrwxr-x. 4 Tomcat Tomcat 4096 August 5 21:33 Shop_service
-rw-r--r--. 1 Tomcat Tomcat 30792513 August 5 21:33 Shop_service.war
[Email protected] webapps]#



5, find the project, then go to see the Tomcat application error message, as follows:
---Check the Select ID, Shop_name, shop_classification_id, Legal_person, CORPORATION, Shop_tel, ADDRESS, Zip_c ODE, Legal_person_mobile, STAT, authenticate, credits, level, score, License_path, Bussiness_range, mall_id, Floor, B Is_company, Store_no, Manager_name, Manager_tel, BRIEF, LOGO, Favour_num, Has_warehouse, Description_fit, SERVICE, S Peed, BACKGROUND, bis_cont_id,bis_shop_id, Created_date, updated_date,english_pref from shop where Shop_name   = ? .
---Check the SQL Statement (preparation failed).
---Cause:org.springframework.transaction.TransactionTimedOutException:Transaction timed out:deadline was Tue 12 1 5:31:00 CST 2014
2014-08-12 16:23:57,746 [Http-7000-6:error] Com.plocc.framework.exception.handler.impl.LogHandlerImpl- A system exception or unhandled exception is required for maintenance personnel to handle! Exception information: Database Exception!
Com.plocc.framework.exception.SystemException: Database Exception!
At Com.plocc.shop.service.impl.ShopServiceImpl.selectShopByShopName (shopserviceimpl.java:200)
At Com.plocc.shop.web.admin.ShopManagerController.addShop (shopmanagercontroller.java:338)
At Sun.reflect.GeneratedMethodAccessor639.invoke (Unknown Source)
At Sun.reflect.DelegatingMethodAccessorImpl.invoke (delegatingmethodaccessorimpl.java:25)
At Java.lang.reflect.Method.invoke (method.java:597)
At Org.springframework.web.method.support.InvocableHandlerMethod.invoke (invocablehandlermethod.java:219)
At Org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest (Invocablehandlermethod.java : 132)
At Org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle ( SERVLETINVOCABLEHANDLERMETHOD.JAVA:104)
At Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod ( requestmappinghandleradapter.java:745)
At Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal ( requestmappinghandleradapter.java:686)
At Org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle ( ABSTRACTHANDLERMETHODADAPTER.JAVA:80)
At Org.springframework.web.servlet.DispatcherServlet.doDispatch (dispatcherservlet.java:925)
At Org.springframework.web.servlet.DispatcherServlet.doService (dispatcherservlet.java:856)
At Org.springframework.web.servlet.FrameworkServlet.processRequest (frameworkservlet.java:936)
At Org.springframework.web.servlet.FrameworkServlet.doPost (frameworkservlet.java:838)
At Javax.servlet.http.HttpServlet.service (httpservlet.java:643)
At Org.springframework.web.servlet.FrameworkServlet.service (frameworkservlet.java:812)
At Javax.servlet.http.HttpServlet.service (httpservlet.java:723)
At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:290)
At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:206)
At Com.plocc.auth.filter.AuthenticationFilter.doFilter (authenticationfilter.java:110)
At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:235)
At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:206)
At Com.plocc.sso.filter.SingleSingOnFilter.doFilter (singlesingonfilter.java:85)
At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:235)
At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:206)
At Org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal (characterencodingfilter.java:88)
At Org.springframework.web.filter.OncePerRequestFilter.doFilter (onceperrequestfilter.java:107)
At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:235)
At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:206)
At Org.apache.catalina.core.StandardWrapperValve.invoke (standardwrappervalve.java:233)
At Org.apache.catalina.core.StandardContextValve.invoke (standardcontextvalve.java:191)
At Org.apache.catalina.core.StandardHostValve.invoke (standardhostvalve.java:127)
At Org.apache.catalina.valves.ErrorReportValve.invoke (errorreportvalve.java:103)
At Org.apache.catalina.core.StandardEngineValve.invoke (standardenginevalve.java:109)
At Org.apache.catalina.connector.CoyoteAdapter.service (coyoteadapter.java:293)
At Org.apache.coyote.http11.Http11Processor.process (http11processor.java:861)
At Org.apache.coyote.http11.http11protocol$http11connectionhandler.process (http11protocol.java:606)
At Org.apache.tomcat.util.net.jioendpoint$worker.run (jioendpoint.java:489)
At Java.lang.Thread.run (thread.java:662)




6, now it is clear that the transaction should not be submitted, with the development to check all the Java code, found that there are 2 places, in exception e forgot to write rollback.
} catch (SQLException e) {
TODO auto-generated Catch block
E.printstacktrace ();
There is a lack of rollback.

}


Summary: Developers, write database transactions, remember when the exception handling exception, do not forget the rollback.

[MySQL] production environment MySQL database transaction has been running

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.