foreverneverer commented on code in PR #1006: URL: https://github.com/apache/incubator-pegasus/pull/1006#discussion_r902369624
########## admin-cli/executor/toolkits/tablemigrator/migrator.go: ########## @@ -0,0 +1,146 @@ +/* + * 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 tablemigrator + +import ( + "fmt" + "time" + + "github.com/apache/incubator-pegasus/admin-cli/executor" + "github.com/apache/incubator-pegasus/admin-cli/executor/toolkits" + "github.com/apache/incubator-pegasus/admin-cli/util" + "github.com/apache/incubator-pegasus/go-client/session" + "github.com/pegasus-kv/collector/aggregate" +) + +var pendingMutationThreshold = 100000.0 + +func MigrateTable(client *executor.Client, table string, metaProxyZkAddrs string, metaProxyZkRoot string, targetCluster string, targetAddrs string, threshold float64) error { + pendingMutationThreshold = threshold + toolkits.LogInfo(fmt.Sprintf("set pendingMutationThreshold = %d means that server will reject all write "+ + "and ready to switch cluster if the pending less the value", int64(pendingMutationThreshold))) + //1. check data version + toolkits.LogInfo("check the table data version") + version, err := executor.QueryReplicaDataVersion(client, table) + if err != nil { + return err + } + if version.DataVersion != "1" { + return fmt.Errorf("not support migrate table with data_version = %s by duplication", version.DataVersion) + } + + //2. create table duplication + toolkits.LogInfo(fmt.Sprintf("create the table duplication to %s", targetCluster)) + err = executor.AddDuplication(client, table, targetCluster, true) + if err != nil { + return err + } + + //3. check pending mutation count if less `pendingMutationThreshold` + toolkits.LogInfo(fmt.Sprintf("check pending mutation count if less %d", int64(pendingMutationThreshold))) + nodes := client.Nodes.GetAllNodes(session.NodeTypeReplica) + perfSessions := make(map[string]*aggregate.PerfSession) + for _, n := range nodes { + perf := client.Nodes.GetPerfSession(n.TCPAddr(), session.NodeTypeReplica) + perfSessions[n.CombinedAddr()] = perf + } + err = checkPendingMutationCount(perfSessions) + if err != nil { + return err + } + //4. set env config deny write request + toolkits.LogInfo("set env config deny write request") + var envs = map[string]string{ + "replica.deny_client_request": "timeout*write", + } + err = client.Meta.UpdateAppEnvs(table, envs) Review Comment: Yeah, origin table `write request`will be prohibited and no need revert -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
