Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLEANUP: Refactored MemcachedConnection.switchoverMemcachedReplGroup() method. #852

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

uhm0311
Copy link
Collaborator

@uhm0311 uhm0311 commented Dec 11, 2024

🔗 Related Issue

⌨️ What I did

  • switchoverMemcachedReplGroup() 메소드의 첫 인자 타입을 MemcachedNode에서 MemcachedReplicaGroup으로 변경합니다.

@uhm0311 uhm0311 requested a review from jhpark816 December 11, 2024 12:24
@jhpark816 jhpark816 requested review from oliviarla and removed request for jhpark816 December 11, 2024 12:42
Copy link
Collaborator

@oliviarla oliviarla left a comment

Choose a reason for hiding this comment

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

리뷰 완료입니다.

src/main/java/net/spy/memcached/MemcachedConnection.java Outdated Show resolved Hide resolved
} else {
getLogger().warn("Delay switchover because invalid group state : " + group);
}
((ArcusReplKetamaNodeLocator) locator).switchoverReplGroup(group);
Copy link
Collaborator

@oliviarla oliviarla Dec 17, 2024

Choose a reason for hiding this comment

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

기존처럼 group.getMasterNode() != null && group.getMasterCandidate() != null 조건이 만족할 때에만 switchover + move operation + old master reconnect 해야 하지 않나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

https://github.com/jam2in/arcus-works/issues/637#issuecomment-2521925920

해당 조건에 맞지 않는데도 이 메소드를 호출하는 경우가 로직적으로는 없어서 조건문을 제거했습니다.
그래도 조건문을 유지하도록 할까요?

Copy link
Collaborator

Choose a reason for hiding this comment

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

private 메서드라서 반드시 유지할 필요는 없어보이지만, 단순 검증 용도로 둔다면 나중에 리팩토링 시에 이 부분을 인지하여 버그 발생 가능성이 줄어들 것 같습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

아래와 같이 조건을 넣어 두시죠.

  • oldMaster는 분명히 존재하는 상황에서 switchover 대상이 될 수 있음.
  • masterCandidate가 null인 경우는 없을 것으로 보이지만,
    masterCandidate가 null인 경우에 locator.switchoverReplGroup(group) 수행은
    오동작(invalid group으로 변환)하게 되므로,
    masterCandidate != null 조건을 넣어두는 것이 괜찮을 것 같습니다.
if (group.getMasterCandidate() != null) {
  ((ArcusReplKetamaNodeLocator) locator).switchoverReplGroup(group);
   . . .
   queueReconnect(oldMaster, ReconnDelay.IMMEDIATE,
        "Discarded all pending reading state operation to move operations.");
} else {
  getLogger().warn("Delay switchover because invalid group state : " + group);
}

oliviarla
oliviarla previously approved these changes Dec 17, 2024
@uhm0311 uhm0311 requested a review from jhpark816 December 17, 2024 06:53
Copy link
Collaborator

@jhpark816 jhpark816 left a comment

Choose a reason for hiding this comment

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

리뷰 완료

@@ -978,6 +976,7 @@ private void handleWrites(MemcachedNode qa)

private void handleReads(MemcachedNode qa)
throws IOException {
MemcachedReplicaGroup group = qa.getReplicaGroup();
Copy link
Collaborator

Choose a reason for hiding this comment

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

복제하지 않는 경우에서 위의 코드는 불필요합니다.

group 변수가 실제로 필요한 곳으로 위의 코드를 옮기면 좋겠습니다.

qa.getReplicaGroup().masterNode == qa) {
delayedSwitchoverGroups.remove(qa.getReplicaGroup());
switchoverMemcachedReplGroup(qa, false);
if (group.isDelayedSwitchover() && group.masterNode == qa) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

group.masterNode 대신에 group.getMasterNode() 호출합시다.

MemcachedNode newMaster = group.getMasterNode();

oldMaster.moveOperations(newMaster, cancelNonIdempotent);
addedQueue.offer(group.getMasterNode());
Copy link
Collaborator

Choose a reason for hiding this comment

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

addedQueue.offer(newMaster); 이면 됩니다.

} else {
getLogger().warn("Delay switchover because invalid group state : " + group);
}
((ArcusReplKetamaNodeLocator) locator).switchoverReplGroup(group);
Copy link
Collaborator

Choose a reason for hiding this comment

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

아래와 같이 조건을 넣어 두시죠.

  • oldMaster는 분명히 존재하는 상황에서 switchover 대상이 될 수 있음.
  • masterCandidate가 null인 경우는 없을 것으로 보이지만,
    masterCandidate가 null인 경우에 locator.switchoverReplGroup(group) 수행은
    오동작(invalid group으로 변환)하게 되므로,
    masterCandidate != null 조건을 넣어두는 것이 괜찮을 것 같습니다.
if (group.getMasterCandidate() != null) {
  ((ArcusReplKetamaNodeLocator) locator).switchoverReplGroup(group);
   . . .
   queueReconnect(oldMaster, ReconnDelay.IMMEDIATE,
        "Discarded all pending reading state operation to move operations.");
} else {
  getLogger().warn("Delay switchover because invalid group state : " + group);
}

@jhpark816 jhpark816 merged commit e35d37a into naver:develop Dec 19, 2024
2 checks passed
@uhm0311 uhm0311 deleted the uhm0311/repl branch December 19, 2024 07:44
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.

3 participants