Skip to content

Comments

FEATURE: Add 'memcached start|stop|list' command to manage server znode#17

Merged
namsic merged 1 commit intodevelopfrom
task/memcached2
Sep 23, 2025
Merged

FEATURE: Add 'memcached start|stop|list' command to manage server znode#17
namsic merged 1 commit intodevelopfrom
task/memcached2

Conversation

@singsangssong
Copy link
Contributor

🔗 Related Issue

⌨️ What I did

  • 이전 arcus.sh의 memcached start | stop | list 기능을 arcus-cli에서도 동작하도록 합니다.

  • memcached start <serviceCode> [ip:port..]

    • serviceCode에 등록된 서버를 구동시킵니다.
    • 구동옵션은 /arcus/cache_list/<serviceCode>znode에 저장된, 전역 옵션으로 수행합니다.
    • ip:port를 입력한다면, serviceCode내의 입력한 ip:port 서버만 구동시킵니다.
    • ip:port를 입력하지 않는다면, serviceCode내의 모든 서버를 구동시킵니다.
  • memcached stop <serviceCode> [ip:port...]

    • serviceCode에 등록된 서버를 중지시킵니다.
    • 서버 구동시 -P옵션을 통해 pid를 미리 저장하고, 해당 pid를 통해 프로세스를 종료합니다.
    • ip:port를 입력한다면, serviceCode내의 입력한 ip:port 서버만 중지시킵니다.
    • ip:port를 입력하지 않는다면, serviceCode내의 모든 서버를 중지시킵니다.
  • memcached list <serviceCode>

    • serviceCode의 서버 리스트를 출력합니다.
    • serviceCode의 각 서버 ip:port와 online여부를 보여주고, 마지막에는 총 서버 수와 online, offline의 수를 보여줍니다.
  • memcached listall

    • arcus zk내에 있는 모든 서버 리스트를 출력합니다.
    • 출력은 serviceCode단위로 출력하며, serviceCode 이름, status(서버가 모두 꺼져있으면 DOWN, 아니면 OK), total(총 서버수), online, offline을 출력합니다.

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 32 to 35
if len(serviceCodeServers) == 0 {
fmt.Printf("No servers found for service code '%s'.\n", serviceCode)
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.

acl list와 마찬가지로
아래 Total 보여주고 있으므로 별도로 처리하지 않아도 될 것 같습니다.

Comment on lines 29 to 37
serviceCodes, _, err := zkConn.Children(path.Join(internal.ArcusCacheListPath))
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

var statuses []serviceStatus
for _, sc := range serviceCodes {
serviceCodeServers, _ := getServiceCodeServers(zkConn, sc)
Copy link
Member

Choose a reason for hiding this comment

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

cache_server_mapping은 서비스코드 단위로 디렉토리가 분리되어 있지 않으므로,
어떤 서비스코드를 조회하더라도 /arcus/cache_server_mapping의 모든 children을 탐색하게 됩니다.

현재 구현에서 서비스코드가 많으면 같은 znode를 서비스코드 수만큼 중복 조회하고, ZK에 많은 연산이 보내지게 됩니다.

cache_server_mapping을 탐색하면서 map[string][]string 형태의 서비스코드 + 노드 목록을 만들어 두면,
여러 서비스코드에 대한 정보 조회 시 재사용할 수 있습니다.

Comment on lines +66 to +84
command := fmt.Sprintf(memcachedStartCommandTemplate,
memcachedPath, memcachedPath, memcachedPath, memcachedPath, memcachedPath,
port, string(globalConfig), os.Getenv("ZK_ADDR"))

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
errChan := make(chan error, 1)
go func() {
errChan <- session.Run(command)
}()
select {
case err := <-errChan:
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
case <-ctx.Done():
continue
}
Copy link
Member

Choose a reason for hiding this comment

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

nohup 대신 timeout 사용하기로 하였나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

두 방안 모두 무방하다고 하셔서, 기존 레거시코드 구현을 그대로 유지하고자 timeout으로 구현했습니다.

@singsangssong
Copy link
Contributor Author

singsangssong commented Sep 19, 2025

listlistall의 출력결과입니다.

ZK_ADDR="127.0.0.1:2181" ARCUS_PATH="~/arcus" USER="songseonghun" ./arcus-cli memcached list test              
  - 127.0.0.1:11211       offline
  - 10.0.0.1:11211        offline

Total: 2, Online: 0, Offline: 2


ZK_ADDR="127.0.0.1:2181" ARCUS_PATH="~/arcus" USER="songseonghun" ./arcus-cli memcached listall                
SERVICE CODE              STATUS       TOTAL    ONLINE   OFFLINE 
----------------------------------------------------------------------
test                      DOWN         2        0        2       

Comment on lines 46 to 51
status := "OK"
if len(serviceCodeServers) > 0 {
if onlineCnt == 0 {
status = "DOWN"
}
}
Copy link
Member

Choose a reason for hiding this comment

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

online / offline 정보와 중복이므로, 별도로 제공할 필요 없어 보입니다.

서버가 모두 떨어진 경우에만 DOWN이고 그 외에는 OK 처리하고 있는데,
이러한 구분 기준도 별도 설명 없이는 직관적으로 파악하기 어렵습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

status부분은 제거하겠습니다. listall명령시 아래와 같이 응답하도록 수정했습니다.

SERVICE CODE              TOTAL    ONLINE   OFFLINE 
------------------------------------------------------------
test                      2        0        2       

@singsangssong singsangssong force-pushed the task/memcached2 branch 2 times, most recently from 5f3b94f to 0585acb Compare September 23, 2025 05:14
@singsangssong
Copy link
Contributor Author

singsangssong commented Sep 23, 2025

memcached 출력

기존에 단일 serviceCode의 memcached 서버를 출력하는 list명령과 arcus zk내의 모든 서버 리스트를 출력하는 listall명령을 합칩니다.

  • list [serviceCode] 명령으로 수행하며, 인자가 없을경우에는 기존 listall처럼 동작하고, 인자가 있을 경우에는 단일 serviceCode를 출력하고, 그 아래에 listall 결과를 출력해줍니다.

출력결과의 예시는 아래와 같습니다. 기본적으로 전체 결과에 관해서 출력해주고, serviceCode 명령 인자가 있다면 해당 serviceCode에 대한 결과를 추가로 출력해줍니다.

  • memcached list 출력 결과
$ ZK_ADDR="127.0.0.1:2181" ARCUS_PATH="~/arcus" ./arcus-cli memcached list 
SERVICE CODE              TOTAL    ONLINE   OFFLINE 
------------------------------------------------------------
test                      2        0        2       
  • memcached list [serviceCode] 출력 결과
$ ZK_ADDR="127.0.0.1:2181" ARCUS_PATH="~/arcus" ./arcus-cli memcached list test                     
Servers in service code 'test':
  - 127.0.0.1:11211       offline
  - 10.0.0.1:11211        offline

SERVICE CODE              TOTAL    ONLINE   OFFLINE 
------------------------------------------------------------
test                      2        0        2       

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.

우선 이대로 반영하고, 나중에 일부 구현 리팩토링 해두겠습니다.

@namsic namsic merged commit 9f23d9b into develop Sep 23, 2025
1 check passed
@singsangssong singsangssong deleted the task/memcached2 branch September 23, 2025 05:42
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