Computer-Science

λͺ©μ°¨

Transaction Processing

νŠΈλžœμž­μ…˜μ˜ μ •μ˜

νŠΈλžœμž­μ…˜μ˜ μ£Όμš” μ„±μ§ˆ: ACID

μ›μžμ„±μ„ μœ„ν•œ μ—°μ‚°

MySQL의 autocommit, commit, rollback

mysql> SHOW VARIABLES LIKE "%commit%";
+-----------------------------------------+-------------------+
| Variable_name                           | Value             |
+-----------------------------------------+-------------------+
| autocommit                              | ON                |
| binlog_group_commit_sync_delay          | 0                 |
| binlog_group_commit_sync_no_delay_count | 0                 |
| binlog_order_commits                    | ON                |
| innodb_api_bk_commiTinterval           | 5                 |
| innodb_commit_concurrency               | 0                 |
| innodb_flush_log_at_trx_commit          | 1                 |
| original_commit_timestamp               | 36028797018963968 |
| replica_preserve_commit_order           | ON                |
| replication_sender_observe_commit_only  | OFF               |
| slave_preserve_commit_order             | ON                |
+-----------------------------------------+-------------------+
11 rows in set (0.06 sec)

mysql> SET autocommit = 0;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE "%commit%";
+-----------------------------------------+-------------------+
| Variable_name                           | Value             |
+-----------------------------------------+-------------------+
| autocommit                              | OFF               |
| binlog_group_commit_sync_delay          | 0                 |
| binlog_group_commit_sync_no_delay_count | 0                 |
| binlog_order_commits                    | ON                |
| innodb_api_bk_commiTinterval           | 5                 |
| innodb_commit_concurrency               | 0                 |
| innodb_flush_log_at_trx_commit          | 1                 |
| original_commit_timestamp               | 36028797018963968 |
| replica_preserve_commit_order           | ON                |
| replication_sender_observe_commit_only  | OFF               |
| slave_preserve_commit_order             | ON                |
+-----------------------------------------+-------------------+
11 rows in set (0.00 sec)
mysql> CREATE TABLE customer (a INT, b CHAR (20), INDEX (a));
Query OK, 0 rows affected (0.00 sec)

mysql> -- Do a transaction with autocommit turned on.
mysql> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO customer VALUES (10, 'Heikki');
Query OK, 1 row affected (0.00 sec)

mysql> COMMIT;
Query OK, 0 rows affected (0.00 sec)

mysql> -- Do another transaction with autocommit turned off.
mysql> SET autocommit=0;
Query OK, 0 rows affected (0.00 sec)

mysq1> INSERT INTO customer VALUES (15, 'John');
Query OK, 1 row affected (0.00 sec)

mysq1> INSERT INTO customer VALUES (20, 'Paul');
Query OK, 1 row affected (0.00 sec)

mysql> DELETE FROM customer WHERE b = 'Heikki';
Query OK, 1 row affected (0.00 sec)

mysql> -- Now we undo those last 2 inserts and the delete.
mysql> ROLLBACK;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT * FROM customer;
+------+---------+
| a    | b       |
+------+---------+
|   10 | Heikki  |
+------+---------+
1 row in set (0.00 sec)

νŠΈλžœμž­μ…˜ μƒνƒœ

Transaction_status

νŠΈλžœμž­μ…˜μ˜ 예

μ‹€νŒ¨ μƒνƒœμ— μžˆλŠ” νŠΈλžœμž­μ…˜

μž₯μ• 

μ €μž₯μž₯μΉ˜μ™€ μž₯μ• 

회볡 (recovery)

νšŒλ³΅μ„ μœ„ν•œ μ—°μ‚°

λ°μ΄ν„°λ² μ΄μŠ€ 둜그 : 둜그 μ••μΆ•

λ‹€μ–‘ν•œ 회볡 기법

(1-1) μ¦‰μ‹œ κ°±μ‹  회볡 기법

νŠΈλžœμž­μ…˜ μˆ˜ν–‰ 도쀑 데이터λ₯Ό λ³€κ²½ν•˜λ©΄ λ³€κ²½ 정보λ₯Ό 둜그 νŒŒμΌμ— μ €μž₯ν•˜κ³ , νŠΈλžœμž­μ…˜μ΄ λΆ€λΆ„ μ™„λ£Œλ˜κΈ° 전이라도 λͺ¨λ“  λ³€κ²½ λ‚΄μš©μ„ μ¦‰μ‹œ λ°μ΄ν„°λ² μ΄μŠ€μ— λ°˜μ˜ν•˜λŠ” 기법

(1-2) 지연 κ°±μ‹  회볡 기법

νŠΈλžœμž­μ…˜μ΄ μˆ˜ν–‰λ˜λŠ” λ™μ•ˆμ—λŠ” 데이터 λ³€κ²½ μ—°μ‚°μ˜ κ²°κ³Όλ₯Ό λ°μ΄ν„°λ² μ΄μŠ€μ— μ¦‰μ‹œλ°˜μ˜ν•˜μ§€ μ•Šκ³  둜그 νŒŒμΌμ—λ§Œ κΈ°λ‘ν•΄λ‘μ—ˆλ‹€κ°€, νŠΈλžœμž­μ…˜μ΄ μ™„λ£Œλœ 후에 λ‘œκ·Έμ— 기둝된 λ‚΄μš©μ„ μ΄μš©ν•΄ λ°μ΄ν„°λ² μ΄μŠ€μ— ν•œ λ²ˆμ— 반영

μ–΄λ–€ νŠΈλžœμž­μ…˜μ΄ Redo λ˜μ–΄μ•Ό ν•˜λŠ”κ°€?

(2) κ²€μ‚¬μ‹œμ  회볡

λ°μ΄ν„°λ² μ΄μŠ€ νŠΈλžœμž­μ…˜ λ™μž‘ 과정에 주기적으둜 검사점을 κΈ°λ‘ν•˜μ—¬ λ°μ΄ν„°λ² μ΄μŠ€ μž₯μ• μ‹œ 둜그λ₯Ό 기반으둜 νšŒλ³΅ν•˜λŠ” 기법

κ²€μ‚¬μ‹œμ (checkpoint) 회볡이 ν•„μš”ν•œ 이유

μΌμ •ν•œ κ°„κ²©μœΌλ‘œ μƒμ„±λœ κ²€μ‚¬μ‹œμ μ€ μž₯μ• κ°€ λ°œμƒν–ˆμ„ λ•Œ, λΆˆν•„μš”ν•œ λΆ€ν•˜λ₯Ό μ€„μ΄κ²Œ 됨으둜써 회볡 처리 절차의 μ‹œκ°„μ„ μ ˆμ•½ν•΄ μ€€λ‹€.
μ‹œμŠ€ν…œ μ—λŸ¬κ°€ 났을 λ•Œ νšŒλ³΅κ΄€λ¦¬μžκ°€ 이λ₯Ό ν•΄κ²°ν•˜κΈ° μœ„ν•΄ 둜그 전체λ₯Ό 뢄석해야 λ˜λŠ”λ° μ‹œκ°„μ΄ 많이 μ†Œμš”λ˜κ³  λΆˆν•„μš”ν•œ REDO 연산을 λ°˜λ³΅ν•˜λŠ” λ¬Έμ œκ°€ λ°œμƒν•˜λ―€λ‘œ κ²€μ‚¬μ‹œμ  회볡이 ν•„μš”ν•˜λ‹€.

(3) λ―Έλ””μ–΄ 회볡 기법


References

  1. Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe.
  2. https://overcome-the-limits.tistory.com/528
  3. https://itwiki.kr/w/%EB%A1%9C%EA%B7%B8%EA%B8%B0%EB%B0%98%ED%9A%8C%EB%B3%B5_%EA%B8%B0%EB%B2%95
  4. https://m.blog.naver.com/wook2124/222108776229
  5. https://itwiki.kr/w/%EA%B2%80%EC%82%AC%EC%A0%90%ED%9A%8C%EB%B3%B5%EA%B8%B0%EB%B2%95
  6. https://www.studocu.com/ko/document/dankook-university/%EB%8D%B0%EC%9D%B4%ED%84%B0%EB%B2%A0%EC%9D%B4%EC%8A%A4-%EA%B4%80%EB%A6%AC/%EA%B2%BD%EC%98%81%ED%95%99%EA%B3%BC-%EB%8D%B0%EC%9D%B4%ED%84%B0%EB%B2%A0%EC%9D%B4%EC%8A%A4-%EA%B0%9C%EB%A1%A0-%EA%B8%B0%EB%A7%90%EA%B3%A0%EC%82%AC-%EB%8C%80%EB%B9%84-%EC%9E%90%EB%A3%8C-%EA%B5%90%EC%9E%AC-%EB%B0%8F-%EC%88%98%EC%97%85-%EB%82%B4%EC%9A%A9-%ED%95%84%EA%B8%B0-%EB%85%B8%ED%8A%B8/17316211
  7. https://m.blog.naver.com/paradice29/50184565199