Skip to content

Comments

FIX: Handling abnormal swithover from zk.#867

Merged
jhpark816 merged 1 commit intonaver:developfrom
brido4125:fix/abnormalSwithcover
Feb 3, 2025
Merged

FIX: Handling abnormal swithover from zk.#867
jhpark816 merged 1 commit intonaver:developfrom
brido4125:fix/abnormalSwithcover

Conversation

@brido4125
Copy link
Contributor

@brido4125 brido4125 commented Jan 8, 2025

🔗 Related Issue

캐시 서버로부터의 응답을 통해 master candidate를 설정하고 난 뒤,
zk로부터 비정상적인 switchover를 감지하는 경우에 대한 처리이다.

이중화

상태 ROLE1 ROLE2 처리로직
초기상태 M S
SwitchOver 응답 후 상태 M S(masterCandidate)
정상 상태 (1st ZK 변경) S S Invalid Group 처리
정상 상태 (2nd ZK 변경) S M switch-over 로직이 처리
비정상1 X M Fail-Over 로직이 처리
비정상2 M X 처리필요
비정상3 X X 그룹 제거(기존 로직이 처리)

삼중화

상태 ROLE1 ROLE2 ROLE3 처리로직
초기상태 M S1 S2
SwitchOver 응답 후 상태 M S1(masterCandidate) S2
정상 상태 (1st ZK 변경) S3 S1 S2 Invalid Group 처리
정상 상태 (2nd ZK 변경) S3 M S2 switch-over 로직이 처리
비정상1 S3 M X Switch-Over 로직이 처리
비정상2 X M S2 Fail-Over 로직이 처리
비정상3 S3 X M 처리필요
비정상4 X M X Fail-Over 로직이 처리
비정상5 X X M Fail-Over 로직이 처리
비정상6 M X X 처리필요
비정상7 X X X 그룹 제거(기존 로직이 처리)

참고로 아래와 같은 케이스들은 zk 시퀀스 넘버에 의한
Repl Role 선정 방식에 의해 발생되지 않습니다.

ROLE1 ROLE2 ROLE3
M X S

위 표를 참고하여 발생 가능한 비정상 경우들은 아래와 같다.

이중화

  • M S : 초기 상태
  • M S(master-candidate) : 서버로부터 응답을 받은 후 상태
  • M X : new Master가 될 노드가 떨어지고 old Master가 newMaster인 상태 - 비정상
  • S M : 정상적인 경우

삼중화

아래 케이스와 함께 이중화의 비정상 케이스처럼
old Master가 newMaster이고 slave가 모두 떨어진 케이스

  • M S1 S2: 초기 상태
  • M S1(master-candidate) S2: 서버로부터 응답을 받은 후 상태
  • S X M : new Master가 될 노드가 떨어지고 2번 Slave가 새로운 New master가 된 상태 - 비정상
  • S M S : 정상적인 경우

⌨️ What I did

비정상 이중화인 경우는 oldMaster와 newMaster가 동일하기 때문에 아래 로직을 따른다.

if (oldMasterAddr.isSameAddress(newMasterAddr)) {

비정상 삼중화인 경우는 oldSlaves 내에 newMaster가 있고
newSlaves 내에 oldMaster가 존재하기에 기존의 Switchover 로직을 따른다.

} else if (oldSlaveAddrs.contains(newMasterAddr)) {
if (newSlaveAddrs.contains(oldMasterAddr)) {

두 경우 모두 cache server 응답에 의해 설정된
master candidate에 쌓인 ops 객체들을 oldmaster로 옮겨줘야한다.

이중화의 경우 master candidate를 null로 설정해서 master로 op가 처리되도록 한다.

삼중화는 zk로부터 받은 master를 설정하여
최신 master에 op가 처리되도록 한다.

@brido4125 brido4125 force-pushed the fix/abnormalSwithcover branch from 1286a78 to 0e988d2 Compare January 8, 2025 08:14
@jhpark816
Copy link
Collaborator

@brido4125
리뷰어가 PR 설명을 이해할 수 있는 지를 확인하고
이해가 어렵다면, 먼저 설명하고 리뷰하는 것이 좋겠습니다.

@jhpark816 jhpark816 requested review from oliviarla and uhm0311 January 8, 2025 08:49
@brido4125
Copy link
Contributor Author

@uhm0311 @oliviarla

혹시 오프라인 설명이 필요하다면 편하게 말해주세요

@uhm0311
Copy link
Collaborator

uhm0311 commented Jan 9, 2025

설명 한 번 해주세요.
내일 해도 됩니다.

@brido4125 brido4125 marked this pull request as draft January 16, 2025 05:46
@brido4125 brido4125 self-assigned this Jan 16, 2025
@brido4125 brido4125 marked this pull request as ready for review January 16, 2025 07:52
@brido4125
Copy link
Contributor Author

@uhm0311 @oliviarla

PR 코멘트 업데이트 했습니다.

@brido4125 brido4125 marked this pull request as draft January 17, 2025 01:28
@brido4125 brido4125 force-pushed the fix/abnormalSwithcover branch from 0e988d2 to 4657886 Compare January 17, 2025 02:02
@brido4125 brido4125 marked this pull request as ready for review January 17, 2025 02:16
@brido4125 brido4125 force-pushed the fix/abnormalSwithcover branch from 4657886 to ce2f9fc Compare January 17, 2025 02:18
uhm0311
uhm0311 previously approved these changes Jan 17, 2025
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.

리뷰 완료

다른 경우도 확인하여 안전한 방식으로 구현합시다.

@brido4125 brido4125 force-pushed the fix/abnormalSwithcover branch from ce2f9fc to 542c8c4 Compare January 20, 2025 05:39
@brido4125 brido4125 marked this pull request as draft January 20, 2025 05:45
@brido4125 brido4125 marked this pull request as ready for review January 20, 2025 05:46
@jhpark816
Copy link
Collaborator

@brido4125

다른 경우도 확인하여 안전한 방식으로 구현합시다.

위의 코멘트에 대해서도 검토가 되었나요?

@brido4125 brido4125 force-pushed the fix/abnormalSwithcover branch from 542c8c4 to 3cad10c Compare January 21, 2025 06:53
@brido4125 brido4125 requested a review from jhpark816 January 21, 2025 07:01
@jhpark816
Copy link
Collaborator

@uhm0311 @oliviarla
리뷰 다시 진행해 주면 됩니다.

oliviarla
oliviarla previously approved these changes Jan 22, 2025
@jhpark816
Copy link
Collaborator

@uhm0311 빠른 리뷰 바랍니다.

@uhm0311
Copy link
Collaborator

uhm0311 commented Jan 23, 2025

코드가 많이 간략화되었는데, 각 경우를 어떤 원리로 커버할 수 있는지 설명해주었으면 합니다.

uhm0311
uhm0311 previously approved these changes Jan 24, 2025
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.

일부 리뷰

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.

리뷰 완료

@brido4125 brido4125 dismissed stale reviews from uhm0311 and oliviarla via 2021488 February 3, 2025 04:47
@brido4125 brido4125 force-pushed the fix/abnormalSwithcover branch from 3cad10c to 2021488 Compare February 3, 2025 04:47
// Old master has gone away. And, new group has appeared.
if (oldGroup.getMasterCandidate() != null) {
oldGroup.clearMasterCandidate();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

slave 제거할 시에 masterCandidate clear하는 것이 좋겠습니다.

        for (MemcachedNode oldSlaveNode : oldSlaveNodes) {
          removeNodes.add(oldSlaveNode);
          // move operation slave -> master.
          taskList.add(new MoveOperationTask(
              oldSlaveNode, newMasterNode, false));
          // clear the masterCandidate if the removed slave is the masterCandidate.
          if (oldGroup.getMasterCandidate() == oldSlaveNode) {
            oldGroup.clearMasterCandidate();
          }
        }

@brido4125 brido4125 force-pushed the fix/abnormalSwithcover branch from 2021488 to 7e9941c Compare February 3, 2025 05:10
@jhpark816 jhpark816 merged commit b3c0fbd into naver:develop Feb 3, 2025
2 checks passed
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.

기존 merged PR에 문제가 있어 코멘트 남깁니다.
확인하고, 문제가 있다면 이를 해결하는 PR을 다시 보내주세요.

@oliviarla
Copy link
Collaborator

@brido4125 본 PR 코멘트는 다 반영된 상태인거죠?
어떤 PR에서 해결되었는지 코멘트 달아두면 좋겠습니다.

@brido4125
Copy link
Contributor Author

brido4125 commented May 12, 2025

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.

4 participants