Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/2-cluster-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ arcusctl cluster list
ํ˜„์žฌ ์šด์˜ ์žฅ๋น„์— ์ €์žฅ๋œ ๋ฐฐํฌ ์ •๋ณด๋ฅผ ๊ธฐ์ค€์œผ๋กœ Arcus ํด๋Ÿฌ์Šคํ„ฐ ๋ชฉ๋ก์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

```text
SERVICECODE VERSION EDITION NODES DEPLOYED_AT
my-cluster 1.16.1 community 3 2026-08-01 12:30:02
my-repl-cluster 0.12.1-E enterprise 4 2026-09-01 01:00:13
SERVICECODE VERSION EDITION NODES GROUPS DEPLOYED_AT
my-cluster 1.16.1 community 3 - 2026-08-01 12:30:02
my-repl-cluster 0.12.1-E enterprise 4 2 2026-09-01 01:00:13
```

๋‹ค์Œ ์ •๋ณด๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.
Expand All @@ -373,6 +373,7 @@ my-repl-cluster 0.12.1-E enterprise 4 2026-09-01 01:00:13
- Arcus ๋ฒ„์ „
- Edition
- ์บ์‹œ ์„œ๋ฒ„ ์ˆ˜
- replication group ์ˆ˜
- ๋ฐฐํฌ ์‹œ๊ฐ„

`list`๋Š” ์‹คํ–‰ ์ค‘์ธ ์บ์‹œ ์„œ๋ฒ„๋ฅผ ์ž๋™์œผ๋กœ ํƒ์ƒ‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
Expand Down
14 changes: 10 additions & 4 deletions internal/cluster/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package cluster
import (
"fmt"
"os"
"strconv"
"text/tabwriter"

"github.com/jam2in/arcusctl/internal/store"
"github.com/jam2in/arcusctl/internal/topology"
)

func List() error {
Expand All @@ -20,26 +22,30 @@ func List() error {
}

w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "SERVICECODE\tVERSION\tEDITION\tNODES\tDEPLOYED_AT")
fmt.Fprintln(w, "SERVICECODE\tVERSION\tEDITION\tNODES\tGROUPS\tDEPLOYED_AT")

for _, serviceCode := range serviceCodes {
meta, err := store.LoadClusterMeta(serviceCode)
if err != nil {
fmt.Fprintf(w, "%s\t<error>\t\t\t%v\n", serviceCode, err)
fmt.Fprintf(w, "%s\t<error>\t\t\t\t%v\n", serviceCode, err)
continue
}

edition := "<unknown>"
servers := 0
groups := "-"
if topo, err := store.LoadClusterTopology(serviceCode); err == nil {
servers = len(topo.Servers)
if e, err := topo.Edition(); err == nil {
edition = string(e)
if e == topology.EnterpriseEdition {
groups = strconv.Itoa(topo.GroupCount())
}
}
}

fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\n",
serviceCode, meta.Version, edition, servers,
fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\t%s\n",
serviceCode, meta.Version, edition, servers, groups,
meta.DeployedAt.Format("2006-01-02 15:04:05"),
)
}
Expand Down
11 changes: 11 additions & 0 deletions internal/topology/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,14 @@ func (s *CacheServer) IsMaster() bool {
func (s *CacheServer) Host() string {
return strings.SplitN(s.Address, ":", 2)[0]
}

func (topo *ClusterTopology) GroupCount() int {
names := make(map[string]struct{}, len(topo.Servers))
for _, server := range topo.Servers {
if server.Group != nil {
names[server.Group.Name] = struct{}{}
}
}

return len(names)
Comment thread
f1v3-dev marked this conversation as resolved.
}
57 changes: 57 additions & 0 deletions internal/topology/cluster_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package topology

import "testing"

func TestClusterTopology_GroupCount(t *testing.T) {
tests := []struct {
name string
servers []CacheServer
want int
}{
{
name: "no groups",
servers: []CacheServer{
{Address: "10.0.0.1:11211"},
{Address: "10.0.0.2:11211"},
},
want: 0,
},
{
name: "duplicate group names are counted once",
servers: []CacheServer{
{Address: "10.0.0.1:11211", Group: &GroupInfo{Name: "g1", Role: "master", Port: 22322}},
{Address: "10.0.0.2:11211", Group: &GroupInfo{Name: "g1", Role: "slave", Port: 22322}},
},
want: 1,
},
{
name: "multiple groups",
servers: []CacheServer{
{Address: "10.0.0.1:11211", Group: &GroupInfo{Name: "g1", Role: "master"}},
{Address: "10.0.0.2:11211", Group: &GroupInfo{Name: "g1", Role: "slave"}},
{Address: "10.0.0.3:11211", Group: &GroupInfo{Name: "g2", Role: "master"}},
{Address: "10.0.0.4:11211", Group: &GroupInfo{Name: "g2", Role: "slave"}},
},
want: 2,
},
{
name: "multiple groups only masters",
servers: []CacheServer{
{Address: "10.0.0.1:11211", Group: &GroupInfo{Name: "g1", Role: "master"}},
{Address: "10.0.0.2:11211", Group: &GroupInfo{Name: "g2", Role: "master"}},
{Address: "10.0.0.3:11211", Group: &GroupInfo{Name: "g3", Role: "master"}},
},
want: 3,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
topo := &ClusterTopology{Servers: test.servers}

if got := topo.GroupCount(); got != test.want {
t.Errorf("GroupCount() = %d, want %d", got, test.want)
}
})
}
}
Loading