Skip to content

FEATURE: Add Ketama node locator - #3

Merged
f1v3-dev merged 1 commit into
developfrom
feature/apl-168
Oct 22, 2026
Merged

f1v3-dev merged 1 commit into
developfrom
feature/apl-168

Conversation

@f1v3-dev

Copy link
Copy Markdown
Collaborator

🔗 Related Issue

⌨️ What I did

  • Ketama 해시 기반으로 키의 대상 캐시 노드를 선택하는 ArcusLocator를 구현했습니다.
  • 기존 Python, Java 클라이언트와 동일한 해시 포인트 선택 및 충돌 시 노드 선택 기준을 적용하였습니다.
  • 노드 추가 및 제거에 따라 해시 링을 갱신하고, 노드 내부 및 노드 간 중복 포인트를 처리합니다.

@f1v3-dev
f1v3-dev requested a review from ing-eoking October 21, 2026 09:28
@f1v3-dev f1v3-dev self-assigned this Oct 21, 2026
@linear-code

linear-code Bot commented Oct 21, 2026

Copy link
Copy Markdown

APL-168

Comment thread src/arcus/_cluster/locator.py Outdated
def _remove_hash(self, address: str) -> None:
for point in set(node_points(address)):
nodes = self._ring[point]
nodes.remove(address)

@ing-eoking ing-eoking Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

동일한 노드에 대해 중복으로 삭제 요청이 들어올 경우 문제가 발생할 수 있으므로, remove 대신 해당 항목이 없어도 예외가 발생하지 않는 discard를 사용하는 편이 좋을 것 같습니다.

또한, _ring[point]에 해당하는 항목이 없을 수도 있으므로, _ring.get(point)로 조회한 뒤 None 여부를 확인하여 처리하는 것이 좋을 것 같습니다.

아래 형태로 변경해주시면 될 것 같습니다.

def _remove_hash(self, address: str) -> None:
  for point in node_points(address):
    nodes = self._ring.get(point)
    if nodes is not None:
      nodes.discard(address)
      if not nodes:
        del self._ring[point]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가, 삭제 대상은 호출부에서 현재 등록된 노드와 새로 발견한 노드를 각각 set으로 변환한 뒤, 아래와 같이 차집합으로 계산하도록 구현하고자 합니다.

  • to_attach = discovered - registered
  • to_delete = registered - discovered

이렇게 계산하면 각 집합 내부의 중복뿐 아니라 두 집합 간의 중복도 발생하지 않으며, to_delete에는 현재 등록된 노드만 포함됩니다. 노드 변경은 순서대로 반영하고, 처리 완료 후 등록 목록을 갱신하여 다음 차집합 계산에 사용하도록 하겠습니다.

이 호출 계약을 전제로 하면 미등록 노드나 이미 삭제된 노드를 다시 삭제하는 요청은 발생하지 않으므로, _ring.get()과 discard()로 없는 항목을 무시하는 처리는 추가하지 않아도 될 것으로 봅니다.

또한, Java에서 다룬 한 노드 내부의 중복 해시 포인트 문제는 node_points()가 set을 반환하여 이미 처리하고 있습니다.

Comment thread src/arcus/_cluster/locator.py Outdated
self._points: list[int] = []
self.update(addresses, [])

def update(self, to_attach: list[str], to_delete: list[str]) -> None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_attach와 to_delete에서 노드가 겹칠 수도 있나요?

@f1v3-dev f1v3-dev Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위 코멘트를 참고해주시면 될 것 같습니다

@f1v3-dev
f1v3-dev merged commit a2afb04 into develop Oct 22, 2026
3 checks passed
@f1v3-dev
f1v3-dev deleted the feature/apl-168 branch October 22, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants