From eb28817afeabc455ef85dfedd4df10e3ae606944 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Mon, 5 Oct 2015 16:55:10 -0700 Subject: [PATCH] Don't panic when DROPing non-existent nodes --- meta/statement_executor.go | 10 +++++++--- meta/statement_executor_test.go | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/meta/statement_executor.go b/meta/statement_executor.go index fadbd1e21c..af4432006c 100644 --- a/meta/statement_executor.go +++ b/meta/statement_executor.go @@ -157,12 +157,16 @@ func (e *StatementExecutor) executeShowServersStatement(q *influxql.ShowServersS } func (e *StatementExecutor) executeDropServerStatement(q *influxql.DropServerStatement) *influxql.Result { - // Dropping only non-Raft nodes supported. - peers, err := e.Store.Peers() + ni, err := e.Store.Node(q.NodeID) if err != nil { return &influxql.Result{Err: err} } - ni, err := e.Store.Node(q.NodeID) + if ni == nil { + return &influxql.Result{Err: ErrNodeNotFound} + } + + // Dropping only non-Raft nodes supported. + peers, err := e.Store.Peers() if err != nil { return &influxql.Result{Err: err} } diff --git a/meta/statement_executor_test.go b/meta/statement_executor_test.go index 6e76b12655..9aef1618a8 100644 --- a/meta/statement_executor_test.go +++ b/meta/statement_executor_test.go @@ -147,6 +147,19 @@ func TestStatementExecutor_ExecuteStatement_ShowServers(t *testing.T) { // Ensure a DROP SERVER statement can be executed. func TestStatementExecutor_ExecuteStatement_DropServer(t *testing.T) { e := NewStatementExecutor() + e.Store.PeersFn = func() ([]string, error) { + return []string{"node1"}, nil + } + + // Ensure non-existent nodes do not cause a problem. + e.Store.NodeFn = func(id uint64) (*meta.NodeInfo, error) { + return nil, nil + } + if res := e.ExecuteStatement(influxql.MustParseStatement(`DROP SERVER 666`)); res.Err != meta.ErrNodeNotFound { + t.Fatalf("unexpected error: %s", res.Err) + } + + // Make a node exist. e.Store.NodeFn = func(id uint64) (*meta.NodeInfo, error) { return &meta.NodeInfo{ ID: 1, Host: "node1", @@ -154,9 +167,6 @@ func TestStatementExecutor_ExecuteStatement_DropServer(t *testing.T) { } // Ensure Raft nodes cannot be dropped. - e.Store.PeersFn = func() ([]string, error) { - return []string{"node1"}, nil - } if res := e.ExecuteStatement(influxql.MustParseStatement(`DROP SERVER 1`)); res.Err != meta.ErrNodeRaft { t.Fatalf("unexpected error: %s", res.Err) }