ZooKeeper가 제공하는 네임스페이스는 표준 파일 시스템의 형식과 비슷하다. 이름은 슬래시(/)로 구분된 경로로 표현한다. ZooKeeper 네임스페이스의 모든 znode(데이터)는 경로로 식별된다.
ZooKeeper's Hierarchical Namespace
image source : https://rohitbankar.medium.com/zookeeper-what-is-it-df7e9bcba9f1
표준 파일 시스템과 Zookeeper Namespace 가 다른 점은 ZooKeeper 네임스페이스의 각 노드(znode)는 하위 노드뿐만 아니라 해당 노드와 연결된 데이터를 가질 수 있다. 파일 자신이 디렉터리가 될 수 있는 파일 시스템을 갖는 다고 이해하면 쉽다.
Q. 다음 사례 중 Zookeeper 를 잘못 사용하는 경우는?
1. 분산 시스템에서 runtime에 변경 가능한 설정 정보
2. 분산시스템을 구성하는 노드의 IP, port 번호
3. 분산시스템에 연결된 클라이언트의 상태 정보 e.g. latest commit id
4. 분산 데이터베이스에 저장된 user 테이블의 PK리스트 e.g. user_id in user table
분산 시스템에서 runtime에 변경 가능한 설정 정보
→ 적절함
분산시스템을 구성하는 노드의 IP, port 번호
→ 적절함
분산시스템에 연결된 클라이언트의 상태 정보 (e.g. latest commit id)
→ 적절함
분산 데이터베이스에 저장된 user 테이블의 PK 리스트 (예: user_id in user table)
→ 부적절 — 정답
Znode는 캐시 유효성 검사 및 동기화된(coordinated) 업데이트를 위해 버전 번호(version number)를 가지고 있다.
이 버전 번호는 다음과 같은 변경이 발생할 때마다 증가한다:
클라이언트가 Znode의 데이터를 조회할 때는 해당 버전 번호도 함께 전달된다.
이를 통해 클라이언트는 데이터가 중간에 변경되었는지 확인하거나,
조건부 갱신(예: "내가 본 이후로 바뀌지 않았다면 업데이트")을 안전하게 수행할 수 있다.
ZooKeeper의 네임스페이스를 구성하는 각 znode는 atomic한(read/write) 데이터 접근을 지원한다.
Read 연산은 해당 znode에 연결된 전체 데이터를 한 번에 가져오고,
Write 연산은 기존 데이터를 통째로 덮어쓴다.
(부분 수정은 불가능하며, 항상 전체 단위로 처리됨)
또한, 각 znode에는 접근 권한을 제한하는 ACL(Access Control List)이 설정되어 있으며,
이를 통해 누가 어떤 작업(읽기, 쓰기, 삭제 등)을 수행할 수 있는지 제어할 수 있다.
ZooKeeper는 일시적인 노드의 개념을 가지고 있다. 이 Ephemeral znode는 znode를 생성한 세션이 활성화되어 있는 동안만 존재한다. 세션이 종료되면 znode가 삭제된다.
클라이언트가 특정 znode에 watch를 설정하면, 해당 znode 또는 자식 노드에 변경(update)이 발생할 때 watch 이벤트가 발생(trigger)한다.
이때, 기본 동작에서는 watch가 한 번만 동작하고 자동으로 해제된다.
클라이언트는 ZooKeeper API를 통해 watch에 대한 콜백 함수(callback function)를 등록할 수 있으며,
이를 통해 변경 감지 시 원하는 작업을 수행할 수 있다.
단, ZooKeeper 3.6.0 버전부터는
watch가 트리거된 이후에도 계속 유지(persistent)될 수 있도록 설정할 수 있는 기능이 추가되었다.
Sequential Consistency
: Updates from a client will be applied in the order that they were sent.Atomicity
: Updates either succeed or fail. No partial results.Single System Image
: A client will see the same view of the service regardless of the server that it connects to. i.e., a client will never see an older view of the system even if the client fails over to a different server with the same session.Reliability
: Once an update has been applied, it will persist from that time forward until a client overwrites the update.Timeliness
: The clients view of the system is guaranteed to be up-to-date within a certain time bound.Zookeeper 는 다음 API를 제공한다.
create
: creates a node at a location in the treedelete
: deletes a nodeexists
: tests if a node exists at a locationget data
: reads the data from a nodeset data
: writes data to a nodeget children
: retrieves a list of children of a nodesync
: waits for data to be propagated