-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR add `remove session --component [service] --sessionID [id]` command to clean or force kill session. Signed-off-by: Congqi Xia <[email protected]>
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package remove | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/milvus-io/birdwatcher/framework" | ||
"github.com/milvus-io/birdwatcher/models" | ||
"github.com/milvus-io/birdwatcher/states/etcd/common" | ||
"github.com/samber/lo" | ||
) | ||
|
||
type RemoveSessionParam struct { | ||
framework.ParamBase `use:"remove session" desc:"remove session with specified component type & node id"` | ||
Component string `name:"component" default:"" desc:"component type to remove"` | ||
ID int64 `name:"sessionID" default:"0" desc:"session id to remove"` | ||
Run bool `name:"run" default:"false" desc:"actual remove session, default in dry-run mode"` | ||
} | ||
|
||
func (c *ComponentRemove) RemoveSessionCommand(ctx context.Context, p *RemoveSessionParam) error { | ||
sessions, err := common.ListSessions(c.client, c.basePath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sessions = lo.Filter(sessions, func(s *models.Session, _ int) bool { | ||
return strings.EqualFold(s.ServerName, p.Component) && s.ServerID == p.ID | ||
}) | ||
|
||
if len(sessions) == 0 { | ||
fmt.Printf("Session component type=%s session id=%d not found", p.Component, p.ID) | ||
} | ||
|
||
fmt.Printf("%d session item found:\n", len(sessions)) | ||
for _, session := range sessions { | ||
fmt.Println(session.String()) | ||
fmt.Println(session.GetKey()) | ||
} | ||
|
||
if p.Run { | ||
fmt.Println("Start to remove session") | ||
for _, session := range sessions { | ||
_, err := c.client.Delete(ctx, session.GetKey()) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} else { | ||
fmt.Println("[Dry-mode] skip removing") | ||
} | ||
|
||
return nil | ||
} |