Skip to content

Comments

FEATURE: Add 'zookeeper start|stop|stat' command to manage zk ensemble#19

Closed
singsangssong wants to merge 1 commit intodevelopfrom
task/zk
Closed

FEATURE: Add 'zookeeper start|stop|stat' command to manage zk ensemble#19
singsangssong wants to merge 1 commit intodevelopfrom
task/zk

Conversation

@singsangssong
Copy link
Contributor

🔗 Related Issue

⌨️ What I did

이전 arcus.shzookeeper a | stop | stat 기능을 arcus-cli에서도 동작하도록 합니다.
3가지 명령 모두 환경변수(ZK_PATH)를 통해 zookeeper의 경로를 결정하도록 합니다.

  • zookeeper start
    • 환경변수로 받은 zookeeper주소(ZK_ADDR)의 zookeeper 서버를 구동합니다.
    • ssh를 통해 연결을 맺고, zkServer.sh start명령을 수행합니다.
  • zookeeper stop
    • 환경변수로 받은 zookeeper주소(ZK_ADDR)의 zookeeper 서버를 중지합니다.
    • ssh를 통해 연결을 맺고, zkServer.sh stop명령을 수행합니다.
  • zookeeper stat
    • 환경변수로 받은 zookeeper주소(ZK_ADDR)의 zookeeper 상태를 조회합니다.
    • ssh를 통해 연결을 맺고, echo stat | nc localhost <port>명령을 수행합니다.

@singsangssong
Copy link
Contributor Author

추가적인 코멘트이자 질문으로, 현재 구현으로는 원격 서버에서 zkServer.sh start를 실행할때 standalone모드로 설정될때만 성공적인 동작을 수행합니다.

해당 원인을 살펴본 결과, 클러스터로 설정된 환경에서는 myid 파일 부재나 zoo.cfg 내 서버 목록 미정의 등의 문제로 시작에 실패할 수 있습니다. 이전 arcus.sh는 zookeeper init 과정에서 각 서버의 zoo.cfg와 myid 파일을 동적으로 생성하여 이 문제를 해결했던 것으로 파악됩니다.

이에 zookeeper init 구현에서 zoo.cfg를 수정하는 것을 추가하는 것이 어떨지 궁금합니다. 현재zookeeper init에서는 arcus zk에 필요한 znode생성까지만 수행하고 있습니다.
(이를 수행한다면 새로 이슈를 파고, 브랜치를 따로 파서 진행하겠습니다.)

@namsic
Copy link
Member

namsic commented Sep 23, 2025

이에 zookeeper init 구현에서 zoo.cfg를 수정하는 것을 추가하는 것이 어떨지 궁금합니다. 현재 zookeeper init에서는 arcus zk에 필요한 znode 생성까지만 수행하고 있습니다.

zookeeper init에서 아래 작업만 수행하면 될 것 같습니다.

  • config file 수정
  • myid 파일 생성

기존에 arcus.sh에서 zookeeper init 수행 시 znode 생성을 위해
(1) 서버를 구동하고 (2) znode 생성하고 (3) 다시 서버 종료하는 방식으로 동작했던 것으로 알고 있는데,
이 때 서버가 이미 구동되어 있거나, 도중에 에러 발생하여 서버 종료하지 않고 중지되는 경우 등의 상황에서
유연하게 동작하기 어려워 아래와 같이 항상 stop 후 실행해야 하는 문제가 있었습니다.

만약 zookeeper init/ start부분에서 에러날 경우 zookeeper server가 켜져있는지 확인 후 모두 stop 시킨 후 재구동 하기

이전에 memcached add PR에서 잠깐 논의했던 것처럼, znode 생성 부분은 다른 방식으로 제공하는 것을 고민해 보면 좋겠습니다.

Copy link
Member

@namsic namsic left a comment

Choose a reason for hiding this comment

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

환경변수 관련 동작을 먼저 정리하고 그 기준에 맞춰 나머지 PR을 다시 보는 것이 좋겠습니다.

Comment on lines 16 to 17
zkAddress := os.Getenv("ZK_ADDR")
ip := strings.Split(zkAddress, ":")[0]
Copy link
Member

Choose a reason for hiding this comment

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

ZK_ADDR이 한 개 서버에 대한 주소만 갖는다는 것을 명확히 드러내야 합니다.

ZK_ADDR 이면 캐시 서버에 -z 인자로 전달하는 주소를 의미하는 것으로 받아들여질 수 있고,
이 값은 ,로 연결된 서버 목록이거나, 여러 서버들을 묶은 도메인(zkservers.example.com:2181)일 수 있습니다.

Comment on lines 19 to 28
client, err := internal.NewSSHClient(ip)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
session, err := client.NewSession()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
Copy link
Member

Choose a reason for hiding this comment

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

SSHClient 생성하고 Session 없이 사용하는 경우가 있나요?
없다면 세션 생성까지 internal에서 처리하는 것이 낫겠습니다.

추가로, 생성한 client나 session은 close하지 않아도 되나요?

Comment on lines 18 to 34
command := fmt.Sprintf(zookeeperStatCommandTemplate, port)
client, err := internal.NewSSHClient(ip)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
session, err := client.NewSession()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
output, err := session.Output(command)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println(string(output))
Copy link
Member

Choose a reason for hiding this comment

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

  • ssh로 연결하여 localhost로 다시 요청을 보내는 것이 아니라,
    ip:port로 바로 stat 명령을 보내면 됩니다.
  • 캐시 장비에 nc가 설치되어 있지 않은 경우가 다수 있습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

각 zk서버 주소와 tcp 연결을 맺고, stat명령을 요청하겠습니다.

@singsangssong singsangssong mentioned this pull request Sep 25, 2025
@singsangssong
Copy link
Contributor Author

현재 memcached와 zookeeper(zookeeper init 리팩토링한 것까지)명령에 대한 코드를 살펴본 결과, zookeeper stat | start | stop을 구현하면서 ZK_ADDR 환경변수를 모호하게 사용한 경우가 많아보입니다.

수정된 코드에서는 ZK_ADDR이라는 환경변수명은 유지한채로, zookeeper 주소 리스트가 담겨있다는 전제로 코드를 구현했습니다. 향후 환경변수에 관한 PR에서 ZK_LIST로 변수명을 수정하겠습니다.

@singsangssong
Copy link
Contributor Author

singsangssong commented Oct 2, 2025

위 이슈에서 선언형 인터페이스로 설계가 변경되었습니다. 이에 명령형 인터페이스에 관한 PR이므로 해당 PR을 닫겠습니다.

@singsangssong singsangssong deleted the task/zk branch October 10, 2025 08:09
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