Skip to content

Commit

Permalink
remove kill query
Browse files Browse the repository at this point in the history
  • Loading branch information
jievince committed Aug 2, 2021
1 parent 2c71fa3 commit 600a7b0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 58 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ require (
)

replace github.com/vesoft-inc/nebula-go/v2 => /home/jie.wang/nebula-go

replace github.com/jievince/liner => /home/jie.wang/liner
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ github.com/facebook/fbthrift v0.31.1-0.20210223140454-614a73a42488 h1:A4KCT0mvTB
github.com/facebook/fbthrift v0.31.1-0.20210223140454-614a73a42488/go.mod h1:2tncLx5rmw69e5kMBv/yJneERbzrr1yr5fdlnTbu8lU=
github.com/jedib0t/go-pretty/v6 v6.0.5 h1:oOo0/jSb3NEYKT6l1hhFXoX2UZnkanMuCE2DVT1mqnE=
github.com/jedib0t/go-pretty/v6 v6.0.5/go.mod h1:MTr6FgcfNdnN5wPVBzJ6mhJeDyiF0yBvS2TMXEV/XSU=
github.com/jievince/liner v1.2.3 h1:hpMEqBKkIg/RHzHCHZqbs19MDq8bT8b5o85D3o/Yggk=
github.com/jievince/liner v1.2.3/go.mod h1:6szfFB+ea00sIHdOn/4gDFoD6sa2UaUHR28Ca8QGj9U=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
Expand Down
57 changes: 1 addition & 56 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ import (
"fmt"
"log"
"os"
"os/signal"
"path"
"path/filepath"
"strconv"
"strings"
"syscall"
"time"

"github.com/vesoft-inc/nebula-console/box"
Expand Down Expand Up @@ -86,11 +84,6 @@ func playData(data string) (string, error) {
}

c.PlayingData(true)
playingData = true
defer func() {
playingData = false
loopContinue = true
}()

defer c.PlayingData(false)
fmt.Printf("Start loading dataset %s...\n", data)
Expand Down Expand Up @@ -245,7 +238,7 @@ func printResultSet(res *nebula.ResultSet, startTime time.Time) (duration time.D
// We treat one line as one query
// Add line break yourself as `SHOW \<CR>HOSTS`
func loop(c cli.Cli) error {
for loopContinue {
for {
line, exit, err := c.ReadLine()
if err != nil {
return err
Expand Down Expand Up @@ -302,7 +295,6 @@ func loop(c cli.Cli) error {
}
g_repeats = 1
}
return fmt.Errorf("loop is stoped")
}

// Nebula Console version related
Expand Down Expand Up @@ -354,54 +346,10 @@ func validateFlags() {
}
}

// RegisterSignalHandler creates a 'listener' on a new goroutine which will notify the
// program if it receives an interrupt from the OS. We then handle this by calling
// our clean up procedure and exiting the program.
func RegisterSignalHandler(cli cli.Cli, toBeKilledSessionID int64) {
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM) // ctrlC

go func() {
helperSession, err := pool.GetSession(*username, *password)
if err != nil {
log.Panicf("Fail to create a new session from connection pool, %s", err.Error())
}

for {
<-c
fmt.Println("^C")
if playingData {
loopContinue = false
} else {
killQueryStmt := fmt.Sprintf("SHOW ALL QUERIES | YIELD $-.SessionID AS sid, "+
"$-.ExecutionPlanID AS eid, $-.StartTime AS st "+
"WHERE $-.SessionID == %v | ORDER BY $-.st DESC | LIMIT 1 | "+
"KILL QUERY(session=$-.sid, plan=$-.eid)", toBeKilledSessionID)
res, err := helperSession.Execute(killQueryStmt)
if err != nil {
fmt.Println(err)
helperSession.Release()
// if call os.Exit, the defer stack of main() will not be executed.
// But I have no idea to execute the defer stack manually here, so direcyly call os.Exit.
os.Exit(1)
}
if !res.IsSucceed() {
fmt.Printf("[ERROR (%d)]: %s", res.GetErrorCode(), res.GetErrorMsg())
}
}

}
}()
}

var pool *nebula.ConnectionPool

var session *nebula.Session

var loopContinue bool

var playingData bool

func main() {
flag.Parse()

Expand Down Expand Up @@ -469,9 +417,6 @@ func main() {

defer c.Close()

RegisterSignalHandler(c, session.GetSessionID())

loopContinue = true
err = loop(c)

if err != nil {
Expand Down

0 comments on commit 600a7b0

Please sign in to comment.