Simple talk about the four characteristics of things, implement the principles of the four properties.

Four characteristics of things? 
    The ACID
     1 . Atomicity atomicity 
        a thing is an indivisible unit of work, which operate either do or do not do. Intermediate state does not exist. 
    2 . Consisitency consistency 
        before and after the execution of things, the data must be in a legal state. (You can define your own, to maintain data consistency.)
     3 . Isolation lsolation 
        more things when concurrent execution, operation and other things inside things are isolated, concurrently, without disturbing each other. 
    4 Persistent Durability 
        things once submitted, changes to the database permanent. It is not affected. 

The principle of the four characteristics? 
    1 .mysql how to ensure consistency? 
        Two levels. 
/ *         
        1. Database by atom, durability, barrier properties, to ensure consistency. 
                    AID three characteristics, is a prerequisite. 
        2. Application-level database through code to determine whether the data is valid, then decide whether to roll back or to submit data. 
* /
 
    2 .mysql how how to ensure atomicity?
    / * 
1. innodb using the undo log. Called the rollback log

        When the transaction is rolled back, and be able to withdraw all SQL statements have been executed successfully, you need to roll back the recorded response log 
2 illustrates         
        When you update a data value before the old need to record, roll back when, under the old value update operation. 
            
        undo log records the information required for these rollback, when a transaction fails, the information can benefit undo log in 
        to rewind data to what it was before the modification. 
    * /
         
    3 .mysql of how long to keep?
    / * 
1. innodb using the redo log. , 

        MySQL load data on the disk into memory, modify the data in memory, on disk back in the brush. 
        At this time, downtime, data in memory is lost. 
        
2. How to avoid downtime?        
        Before submitting things to write data to disk. -------- [caused problems. ] "Only modify a page in a byte, it is necessary to brush the entire page into the disk, so a waste of resources 
        
        , after all, a single transaction may involve modification of SQL multiple pages of data, and these data may not be adjacent page , 
        which is part of the random IO. Obviously operate random IO, the speed will be slower. 
        
3. Using redo log? 
        Do when data changes, not only in the village, including the operation, the operation will be recorded in the redo log in,
        When submitting things, will redo log logs in memory, on disk portion of the log portion of the brush plate redo. 
        Restart the database is down, it will redo log content is restored to the database, and then decide according to undo log and binlog content 
        to roll back or to submit data. 
4. Benefits?    
        redo log is small, only a record of that what has changed, small size, fast brush disc. 
        Has to be added at the end, belong to the order io. Efficiency faster than random io. 
    * /
     
    4 how .mysql guarantee of isolation.
/ * 
    Use and mvcc lock mechanism. 
    
    MVCC, i.e., multi-version concurrency control (Multi Version Concurrency Control), 
    a plurality of versions of data rows snapshot data, the snapshot data in the undo log in. 
    
    If the line is doing a transaction reads DELELE or UPDATE operation, 
    the read operation will not wait for the release of the lock on the line, but read the snapshot version of the row. 
    
    When the reading has been submitted to the transaction isolation level (Read Commited), a transaction can read data from another transaction has been submitted, 
    it is not satisfied with the isolation. However, when the transaction isolation level is repeatable read (Repeateable Read), the barrier properties are satisfied. 
* /    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

 

Guess you like

Origin www.cnblogs.com/ZXF6/p/11691969.html