-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
planner, executor: support Change and ChangeExec (#9789)
* support update pump or drainer status
- Loading branch information
1 parent
cca7ec3
commit dd3ca22
Showing
7 changed files
with
91 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package executor | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/pingcap/errors" | ||
"github.com/pingcap/parser/ast" | ||
"github.com/pingcap/tidb-tools/tidb-binlog/node" | ||
"github.com/pingcap/tidb/config" | ||
"github.com/pingcap/tidb/util/chunk" | ||
) | ||
|
||
// ChangeExec represents a change executor. | ||
type ChangeExec struct { | ||
baseExecutor | ||
*ast.ChangeStmt | ||
} | ||
|
||
// Next implements the Executor Next interface. | ||
func (e *ChangeExec) Next(ctx context.Context, req *chunk.RecordBatch) error { | ||
kind := strings.ToLower(e.NodeType) | ||
urls := config.GetGlobalConfig().Path | ||
registry, err := createRegistry(urls) | ||
if err != nil { | ||
return err | ||
} | ||
nodes, _, err := registry.Nodes(ctx, node.NodePrefix[kind]) | ||
if err != nil { | ||
return err | ||
} | ||
state := e.State | ||
nodeID := e.NodeID | ||
for _, n := range nodes { | ||
if n.NodeID != nodeID { | ||
continue | ||
} | ||
switch state { | ||
case node.Online, node.Pausing, node.Paused, node.Closing, node.Offline: | ||
n.State = state | ||
return registry.UpdateNode(ctx, node.NodePrefix[kind], n) | ||
default: | ||
return errors.Errorf("state %s is illegal", state) | ||
} | ||
} | ||
return errors.NotFoundf("node %s, id %s from etcd %s", kind, nodeID, urls) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters