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 23659a7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 70 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ require (
github.com/vesoft-inc/nebula-go/v2 v2.0.0-20210701060243-a0577f67f375
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
)

replace github.com/vesoft-inc/nebula-go/v2 => /home/jie.wang/nebula-go
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/vesoft-inc/nebula-go/v2 v2.0.0-20210701060243-a0577f67f375 h1:7us19i0qiJffpnKeWMQTPxAjaYItR8xTVohSa3JZVqk=
github.com/vesoft-inc/nebula-go/v2 v2.0.0-20210701060243-a0577f67f375/go.mod h1:B7nR6+nOSo0umq/HkCmUfyRtYrJVOsNiPS9u4djDbSc=
golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
69 changes: 1 addition & 68 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,12 +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)
err := loop(c)
Expand Down Expand Up @@ -245,7 +237,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 +294,6 @@ func loop(c cli.Cli) error {
}
g_repeats = 1
}
return fmt.Errorf("loop is stoped")
}

// Nebula Console version related
Expand Down Expand Up @@ -332,16 +323,6 @@ func init() {
flag.StringVar(file, "file", "", "The nGQL script file name")
}

// func isFlagPassed(name string) bool {
// found := false
// flag.Visit(func(f *flag.Flag) {
// if f.Name == name {
// found = true
// }
// })
// return found
// }

func validateFlags() {
if *port == -1 {
log.Panicf("Error: argument port is missed!")
Expand All @@ -354,54 +335,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,13 +406,9 @@ func main() {

defer c.Close()

RegisterSignalHandler(c, session.GetSessionID())

loopContinue = true
err = loop(c)

if err != nil {
log.Panicf("Loop error, %s", err.Error())
}

}

0 comments on commit 23659a7

Please sign in to comment.