Skip to content

Commit

Permalink
Merge pull request influxdata#6809 from influxdata/js-kill-query-on-s…
Browse files Browse the repository at this point in the history
…pecific-host

Add option to KILL QUERY to kill on a specific host
  • Loading branch information
jsternberg authored Jun 10, 2016
2 parents c8e90fa + 2fa6d30 commit 48692a1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
12 changes: 11 additions & 1 deletion influxql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,10 +685,20 @@ func (s *GrantAdminStatement) RequiredPrivileges() (ExecutionPrivileges, error)
type KillQueryStatement struct {
// The query to kill.
QueryID uint64

// The host to delegate the kill to.
Host string
}

func (s *KillQueryStatement) String() string {
return fmt.Sprintf("KILL QUERY %d", s.QueryID)
var buf bytes.Buffer
_, _ = buf.WriteString("KILL QUERY ")
_, _ = buf.WriteString(strconv.FormatUint(s.QueryID, 10))
if s.Host != "" {
_, _ = buf.WriteString(" ON ")
_, _ = buf.WriteString(QuoteIdent(s.Host))
}
return buf.String()
}

func (s *KillQueryStatement) RequiredPrivileges() (ExecutionPrivileges, error) {
Expand Down
12 changes: 11 additions & 1 deletion influxql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,17 @@ func (p *Parser) parseKillQueryStatement() (*KillQueryStatement, error) {
if err != nil {
return nil, err
}
return &KillQueryStatement{QueryID: qid}, nil

var host string
if tok, _, _ := p.scanIgnoreWhitespace(); tok == ON {
host, err = p.parseIdent()
if err != nil {
return nil, err
}
} else {
p.unscan()
}
return &KillQueryStatement{QueryID: qid, Host: host}, nil
}

// parseCreateSubscriptionStatement parses a string and returns a CreatesubScriptionStatement.
Expand Down
10 changes: 10 additions & 0 deletions influxql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,15 @@ func TestParser_ParseStatement(t *testing.T) {
},
},

// KILL QUERY 4 ON localhost
{
s: `KILL QUERY 4 ON localhost`,
stmt: &influxql.KillQueryStatement{
QueryID: 4,
Host: "localhost",
},
},

// SHOW RETENTION POLICIES
{
s: `SHOW RETENTION POLICIES ON mydb`,
Expand Down Expand Up @@ -2312,6 +2321,7 @@ func TestParser_ParseStatement(t *testing.T) {
{s: `GRANT ALL PRIVILEGES TO`, err: `found EOF, expected identifier at line 1, char 25`},
{s: `KILL`, err: `found EOF, expected QUERY at line 1, char 6`},
{s: `KILL QUERY 10s`, err: `found 10s, expected integer at line 1, char 12`},
{s: `KILL QUERY 4 ON 'host'`, err: `found host, expected identifier at line 1, char 16`},
{s: `REVOKE`, err: `found EOF, expected READ, WRITE, ALL [PRIVILEGES] at line 1, char 8`},
{s: `REVOKE BOGUS`, err: `found BOGUS, expected READ, WRITE, ALL [PRIVILEGES] at line 1, char 8`},
{s: `REVOKE READ`, err: `found EOF, expected ON at line 1, char 13`},
Expand Down

0 comments on commit 48692a1

Please sign in to comment.