From 23659a72d887ef5e268a40aa8fe4964e5ac0b7ef Mon Sep 17 00:00:00 2001 From: jievince <38901892+jievince@users.noreply.github.com> Date: Mon, 2 Aug 2021 10:49:41 +0800 Subject: [PATCH] remove kill query --- go.mod | 2 -- go.sum | 2 ++ main.go | 69 +-------------------------------------------------------- 3 files changed, 3 insertions(+), 70 deletions(-) diff --git a/go.mod b/go.mod index 5a031af..ac7fec6 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 0502ad4..c6d4b27 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/main.go b/main.go index 3061ea8..1ec9167 100644 --- a/main.go +++ b/main.go @@ -11,12 +11,10 @@ import ( "fmt" "log" "os" - "os/signal" "path" "path/filepath" "strconv" "strings" - "syscall" "time" "github.com/vesoft-inc/nebula-console/box" @@ -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) @@ -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 \HOSTS` func loop(c cli.Cli) error { - for loopContinue { + for { line, exit, err := c.ReadLine() if err != nil { return err @@ -302,7 +294,6 @@ func loop(c cli.Cli) error { } g_repeats = 1 } - return fmt.Errorf("loop is stoped") } // Nebula Console version related @@ -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!") @@ -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() @@ -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()) } - }