Skip to content

Commit c37f937

Browse files
committed
implement Close() to gracefully stop all servers
1 parent c2bc412 commit c37f937

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

http/service.go

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Cluster interface {
2525
Delete(key string) error
2626
AddNode()
2727
RemoveNode(addr string)
28+
Close()
2829
}
2930

3031
type Service struct {

store/cluster.go

+7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ func (c *Cluster) Open() {
114114
}
115115
}
116116

117+
func (c *Cluster) Close() {
118+
fmt.Println("Closing entire cluster..")
119+
for _, node := range c.nodes {
120+
node.server.GracefulStop()
121+
}
122+
}
123+
117124
func (c *Cluster) Put(key, value string) error {
118125
nodeAddr, _ := c.hashRing.GetNode(key) // get which node this key should be on
119126
fmt.Printf("key = %s\t", key)

0 commit comments

Comments
 (0)