-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin-cli): support online-migrate table to another cluster usin…
…g table-duplication (#1006)
- Loading branch information
1 parent
6d4d8b6
commit 347f7b9
Showing
11 changed files
with
611 additions
and
81 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,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/apache/incubator-pegasus/admin-cli/executor/toolkits/tablemigrator" | ||
"github.com/apache/incubator-pegasus/admin-cli/shell" | ||
"github.com/desertbit/grumble" | ||
) | ||
|
||
func init() { | ||
shell.AddCommand(&grumble.Command{ | ||
Name: "table-migrator", | ||
Help: "migrate table from current cluster to another via table duplication and metaproxy", | ||
Flags: func(f *grumble.Flags) { | ||
f.String("t", "table", "", "table name") | ||
f.String("n", "node", "", "zk node, addrs:port, default equal with peagsus "+ | ||
"cluster zk addrs, you can use `cluster-info` to show it") | ||
f.String("r", "root", "", "zk root path. the tool will update table addrs in "+ | ||
"the path of meatproxy, if you don't specify it, that is means user need manual-switch the table addrs") | ||
f.String("c", "cluster", "", "target cluster name") | ||
f.String("m", "meta", "", "target meta list") | ||
f.Float64("p", "threshold", 100000, "pending mutation threshold when server will reject all write request") | ||
}, | ||
Run: func(c *grumble.Context) error { | ||
return tablemigrator.MigrateTable(pegasusClient, c.Flags.String("table"), | ||
c.Flags.String("node"), c.Flags.String("root"), | ||
c.Flags.String("cluster"), c.Flags.String("meta"), c.Flags.Float64("threshold")) | ||
}, | ||
}) | ||
} |
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,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/apache/incubator-pegasus/admin-cli/executor" | ||
"github.com/apache/incubator-pegasus/admin-cli/shell" | ||
"github.com/desertbit/grumble" | ||
) | ||
|
||
func init() { | ||
shell.AddCommand(&grumble.Command{ | ||
Name: "data-version", | ||
Help: "query data version", | ||
Run: shell.RequireUseTable(func(c *shell.Context) error { | ||
return executor.QueryTableVersion(pegasusClient, c.UseTable) | ||
}), | ||
}) | ||
} |
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,89 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package executor | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/apache/incubator-pegasus/admin-cli/util" | ||
"github.com/apache/incubator-pegasus/go-client/session" | ||
) | ||
|
||
type TableDataVersion struct { | ||
DataVersion string `json:"data_version"` | ||
} | ||
|
||
func QueryTableVersion(client *Client, table string) error { | ||
version, err := QueryReplicaDataVersion(client, table) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
// formats into JSON | ||
outputBytes, _ := json.MarshalIndent(version, "", " ") | ||
fmt.Fprintln(client, string(outputBytes)) | ||
return nil | ||
} | ||
|
||
func QueryReplicaDataVersion(client *Client, table string) (*TableDataVersion, error) { | ||
nodes := client.Nodes.GetAllNodes(session.NodeTypeReplica) | ||
resp, err := client.Meta.QueryConfig(table) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
args := util.Arguments{ | ||
Name: "app_id", | ||
Value: strconv.Itoa(int(resp.AppID)), | ||
} | ||
results := util.BatchCallHTTP(nodes, getTableDataVersion, args) | ||
|
||
var finalVersion TableDataVersion | ||
versions := make(map[string]TableDataVersion) | ||
for _, result := range results { | ||
if result.Err != nil { | ||
return nil, result.Err | ||
} | ||
err := json.Unmarshal([]byte(result.Resp), &versions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, version := range versions { | ||
if finalVersion.DataVersion == "" { | ||
finalVersion = version | ||
} else { | ||
if version.DataVersion == finalVersion.DataVersion { | ||
continue | ||
} else { | ||
return nil, fmt.Errorf("replica versions are not consistent") | ||
} | ||
} | ||
} | ||
} | ||
return &finalVersion, nil | ||
} | ||
|
||
func getTableDataVersion(addr string, args util.Arguments) (string, error) { | ||
url := fmt.Sprintf("http://%s/replica/data_version?%s=%s", addr, args.Name, args.Value) | ||
return util.CallHTTPGet(url) | ||
} |
Oops, something went wrong.