cleanUrl: /posts/what-is-journal-in-mongo-db

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ea9b680b-d2ee-44fa-90e8-ded03e3f3e12/mongodb-journal-cover.png

wiredTiger engine 의 동작방식을 공부하던 도중 journal 이라는 단어가 나왔는데 정확히 무엇을 의미하는지 모르겠다.

빠르게 읽어 보니 복구에 쓰이고 어디에서 database 가 unexpectly shutdown 되었을 때 그래서 어디서부터 recover 가 필요한지 확인하는데 쓰이는 것 으로 보인다.

정의: To provide durability in the event of a failure, MongoDB uses write ahead logging to on-disk journal files.

WiredTiger engine 은 consistent view 를 제공하기 위해 check point 를 사용한다. MongoDB 는 마지막 check point 를 사용해 recover 를 실행하지만, last check point 와 journal 사이에서 unexpectly shutdown 이 일어난다면, journal 을 이용해 어떻게 복구할지 recover information 을 찾게된다.

check point 란 recover point 로 봐도 무방하다. 출처

MongoDB 4.0 부터 WiredTiger storage engine 을 사용한다면 --nojournal 옵션이나 sotrage.journal.enabled: false 설정을 replica set member 에게 사용할 수 없다.

with journaling, the recover process

  1. data file 들에서 last checkpoint 의 identifier 를 찾아낸다.
  2. journal files 에서 last checkpoint 의 identifier 와 일치하는 record 를 찾는다.
  3. operation 을 journal file 에 적용하는데 last checkpoint 부터 적용된다.

Journaling Process.

client 가 write operation 을 실행하면 wiredTiger engine 은 하나의 journal record 를 만들어 낸다. 이 journal에 포함된 내용은 initial write 으로 부터 발생된 write operation 에 대한 모든 internal write operation 을 포함하고 있다. (예를 들어, document 를 update 하면서 collection 의 index 를 수정하는 작업이 동반되는) wiredTiger 는 update 쿼리와 index 수정이 모두 포함된 단일 record 를 생성합니다.

MongoDB 는 journal record 를 저장하기 위해 in-memory buffering 을 사용하도록 wiredTiger 를 configure 합니다. thread 는 buffer 에 복사하도록 할당한다.

모든 journal records 는 128kb 까지 buffered 된다.

WiredTiger 는 buffered 된 journal record 를 다음 조건에 의해 disk 로 동기화 시킨다.