No problem with code configuration. Why not roll back the transaction (understand Mysql database engine)

Source: Internet
Author: User
I encountered a problem during development a few days ago. During the debugging process, I found that the transaction configured on the service layer does not work. After an exception is thrown, the database is updated successfully and the transaction is not rolled back, then begin various checks to check whether the spring transaction is correctly configured and whether the transaction is enabled when the update method is started. After the check, everything is normal,

I encountered a problem during development a few days ago. During the debugging process, I found that the transaction configured on the service layer does not work. After an exception is thrown, the database is updated successfully and the transaction is not rolled back, then begin various checks to check whether the spring transaction is correctly configured and whether the transaction is enabled when the update method is started. After the check, everything is normal,

I encountered a problem during development a few days ago. During the debugging process, I found that the transaction configured on the service layer does not work. After an exception is thrown, the database is updated successfully and the transaction is not rolled back, then we start various checks to check whether spring transactions are correctly configured and whether transactions are enabled when the update method is started. After the check, we find that everything is normal. Why does the transaction not roll back? The problem lies in a difficult place to consider (the tables created in the database do not support transactions ).

The default engine for creating tables in Mysql databases is MYISAM, which is highly efficient but does not support transactions, therefore, it is best to manually specify the required engine when creating a table. The following is a table creation SQL statement that supports transactions. For more information, see:

CREATE TABLE   test (id varchar(32)  PRIMARY KEY, name varchar(32), create_time datetime, create_user varchar(32) ,address varchar(20) NOT NULL ,remark varchar(100)) ENGINE = InnoDB DEFAULT CHARSET=utf8
Note: ENGINE = InnoDB is the ENGINE to be selected. InnoDB supports transactions.

The following is a description of several common engines in Mysql databases. For more information, we can select an appropriate engine when creating a table.

ISAM: Index Sequential Access Mode)

ISAM is a well-defined and time-tested data table management method. It is designed to take into account that the number of database queries is much larger than the number of updates. Therefore, ISAM performs read operations quickly without occupying a large amount of memory and storage resources. The two major shortcomings of ISAM are that they do not support transaction processing or fault tolerance. If your hard disk crashes, data files cannot be recovered. If you are using ISAM in a key task application, you must always back up all your real-time data. With its copy feature, MYSQL can support such backup applications.
MyISAM: the default storage engine of Mysql

MyISAM is the MySQL ISAM extension format and default database engine. In addition to providing a large number of functions for indexing and field management not available in ISAM, MyISAM also uses a table lock mechanism to optimize multiple concurrent read/write operations, the cost is that you need to run the optimize table command frequently to restore the space wasted by the update mechanism. MyISAM also has some useful extensions, such as the MyISAMCHK tool used to fix database files and the MyISAMPACK tool used to restore wasted space. MYISAM emphasizes fast read operations, which may be the main reason why MySQL is so favored by WEB development: In WEB development, a large number of data operations you perform are read operations. Therefore, most VM providers and INTERNET platform providers only allow MYISAM format. An important defect in MyISAM format is that data cannot be restored after the table is damaged.

HEAP:

HEAP allows only temporary tables in memory. HEAP is faster than ISAM and MYISAM in the memory, but the data it manages is unstable. If it is not saved before shutdown, all the data will be lost. When a row is deleted, HEAP does not waste much space. HEAP tables are useful when you need to use SELECT expressions to SELECT and manipulate data. Remember to delete the table after the table is used up.

InnoDB:

The InnoDB database engine is a direct product that creates MySQL flexibility. This technology is MYSQL ++ API. When using MYSQL, almost every challenge you face comes from the fact that the ISAM and MyISAM database engines do not support transaction processing or foreign keys. Although it is much slower than ISAM and MyISAM engines, InnoDB includes support for transaction processing and Foreign keys, both of which are not available in the first two engines. If your design requires one or both of these features, you will be forced to use one of the INNODB and BERKLEY engines. We often use InnoDB.

InnoDB provides MySQL with an ACID-compatible transaction storage engine with the capabilities of commit, rollback, and crash recovery. InnoDB locks row-level and also provides an Oracle-style non-locked read in SELECT statements. These features increase multi-user deployment and performance. There is no need to expand locking in InnoDB, because row-level locking in InnoDB is suitable for very small space. InnoDB also supports foreign key forcing. In SQL queries, You can freely mix InnoDB tables with other MySQL tables, or even in the same query. This is an official description of mysql.

If you want to know more, go to the Internet and check more...

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.