Skip to content

Instantly share code, notes, and snippets.

@abiriadev
Last active January 11, 2024 04:46
Show Gist options
  • Save abiriadev/d12aa3e6e412498bad4b4d9f1abf894d to your computer and use it in GitHub Desktop.
Save abiriadev/d12aa3e6e412498bad4b4d9f1abf894d to your computer and use it in GitHub Desktop.

tail -f가 멀쩡하게 작동하는 원리가 뭘까?

새 파일에 데이터가 추가되었음을 어떻게 알 수 있을까? 데이터가 추가되는 게 아니라 데이터가 완전히 바뀌어 버리면 어떻게 될까?

어떻게 newline-delimited라서 읽어보기 전까진 알 수 없는데 데이터를 읽어내는 것일까?

어떻게 새로 추가된 부분을 알 수 있을까? diff를 사용하나?

바이트 오프셋으로 비교하면 알 수 있는가?

How does 'tail -f' work efficiently for large files?

結論

Run strace on it. It will tell you exactly what it is doing.

설마했는데 역시 inotify를 쓴다고 한다. seek backward는 어느정도 예상했었다.


B+Tree가 어떻게 파일로 저장될까?

직렬화를 사용하면 그냥 통채로 파일 하나로 저장될 것이다. 데이터가 조금만 변경되어도 전체 파일을 다시 써버려야 한다.(fuse-json-fs 참고)

하지만 메모리에선 트리 구조가 가장 조회와 수정에 유리하다. 그렇다면 메모리와 persistent layer를 어떻게 동기화 시키는가? WAL의 의미가 여기에서 나오는가?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment