GURP-2018S / acid

0 stars 0 forks source link

Recovery Scheme 공부 #2

Open sean-ahn opened 6 years ago

sean-ahn commented 6 years ago

목적: 테스트가 끝난 뒤 DB를 테스트 이전 상태로 돌아가게 함

질문: Recovery scheme을 공부해서 system에 undo. Redo 메세지를 보내서 예전 상태로 돌릴 수 있는가? (transaction이 commit되면 변경할 수 없음)

세부 목적: MySQL DB logging 에 대해 알아봄 Checkpoint signal 에 대해 알아봄 compensation operation 의 구현 방법을 알아봄

예시: DBMS가 가동되다가 중간에 죽는다면, 일반적으로 operation을 기록함 commit 하면 데이터를 못 바꾸게 되어 있음 (다른 transaction에 변경되면 안됨) operation 실행 전에 logging을 함 (undo 할 때 log를 가지고 돌아감)

parkchansoo commented 6 years ago

현재 mySQL DB에서 지원해주고 있는 undo log에 대해서

  1. undo logs는 a single transction에 대해서 모든 변동사항을 카피애서 기록한다. https://dev.mysql.com/doc/refman/5.7/en/innodb-undo-logs.html roll back pointer는 가장 최근에 일어난 db event에 대한 undo log를 가르키고 있고, 각각의 undo log는 자신의 이전 undo log를 가르키고 있다.

  2. undo table이 존재. 기본적으로 undo log는 기존의 data base의 구조와 거의 동일한 형태로, sql서버에 같이 저장된다. 이를 분리된 위치에서도 관리 가능하며 그 크기에는 제한이 없다. 지금은 휘발적인 데이터로 취급. commit하면 undo log를 정리한다.

+. read view. read view는 어떤 버전의 기록을 보여줄 것이냐에 대한 설정이다. READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ 크게 세가지로 나뉘며, 보통은 세번째 것이 default로 지정되어있다.

  1. 데이터베이스를 관리하는데 소요되는 시간 복잡도는 아래와 같다. O(n_sample * (n_cols_in_uniq_i + n_cols_in_non_uniq_i + n_cols_in_pk (1 +n_non_uniq_i)) \ n_part)

n_sample is the number of pages sampled (defined by innodb_stats_persistent_sample_pages) n_cols_in_uniq_i is total number of all columns in all unique indexes (not counting the primary key columns) n_cols_in_non_uniq_i is the total number of all columns in all nonunique indexes n_cols_in_pk is the number of columns in the primary key (if a primary key is not defined, InnoDB creates a single column primary key internally) n_non_uniq_i is the number of nonunique indexes in the table n_part is the number of partitions. If no partitions are defined, the table is considered to be a single partition.

  1. 위의 사실을 바탕으로 보면, undo log를 따로 묶어서 정리해서 쓰는 방법을 생각해볼 수 있을것 같다. 이때 고려할 점은 a. 이전의 transaction간의 log를 어떻게 한번에 관리 할 수 있을까 b. 데이터를 보존했다가 다시 넣는것과, undo log를 이용한 복구의 효율성 비교가 필요할 것 같다. c. undo log의 데이터가 굉장히 커질 것으로 보인다.

references https://blog.jcole.us/2014/04/16/the-basics-of-the-innodb-undo-logging-and-history-system/ http://dolphhong.blogspot.kr/2015/02/mysql-56-undo-tablespace.html http://intomysql.blogspot.kr/2010/12/innodb-redoundo.html https://dev.mysql.com/doc/refman/5.7/en/innodb-undo-logs.html https://dev.mysql.com/doc/refman/5.7/en/innodb-analyze-table-complexity.html

sean-ahn commented 6 years ago

MySQL의 Binary Log 에 대하여

Binary Log 로 쉽게 Point-in-Time Recovery를 수행할 수 있음


Binary Log 설명 (MySQL 5.7)