-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support migarte etcd mds and snapshot
Signed-off-by: caoxianfei1 <[email protected]>
- Loading branch information
1 parent
b1a3a4e
commit 7317d1a
Showing
17 changed files
with
627 additions
and
11 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,16 @@ | ||
kind: curvefs | ||
s3.ak: curve | ||
s3.sk: Netease@2023 | ||
s3.endpoint: 10.182.26.46:19005 | ||
s3.bucket_name: curvefs | ||
container_image: quay.io/opencurve/curve/curvefs:v2.7.0-rc1_d8a1137 | ||
mdsOpt.rpcRetryOpt.addrs: 10.182.26.46:6700,10.182.26.35:6700,10.182.26.36:6700 | ||
log_dir: /home/caoxianfei/client/logs | ||
data_dir: /mnt/v27cache | ||
diskCache.fullRatio: 90 | ||
diskCache.safeRatio: 70 | ||
diskCache.trimRatio: 50 | ||
diskCache.maxUsableSpaceBytes: 10737418240 | ||
diskCache.maxFileNums: 1000000 | ||
diskCache.trimCheckIntervalSec: 5 | ||
client.loglevel: 9 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Usage: | ||
# Example: | ||
# Created Date: 2023-12-15 | ||
# Author: Caoxianfei | ||
|
||
etcdctl=$1 | ||
endpoints=$2 | ||
old_name=$3 | ||
new_name=$4 | ||
new_peer_url=$5 | ||
|
||
${etcdctl} --endpoints=${endpoints} member add ${new_name} --peer-urls ${new_peer_url} > add_etcd.log 2>&1 | ||
if [ $? -ne 0 ]; then | ||
if cat add_etcd.log | grep -q "Peer URLs already exists"; then | ||
exit 0 | ||
else | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# output=$(${etcdctl} --endpoints=${endpoints} member list) | ||
# if [ $? -ne 0 ]; then | ||
# echo "failed to list all etcd members" | ||
# exit 1 | ||
# fi | ||
|
||
# id=$(echo "$output" | awk -v name="$old_name" -F ', ' '$3 == name {print $1}') | ||
# if [ -z "${id}" ]; then | ||
# echo "failed to get id of member ${old_name}" | ||
# exit 1 | ||
# fi | ||
|
||
# ${etcdctl} --endpoints=${endpoints} member remove ${id} | ||
# if [ $? -ne 0 ]; then | ||
# echo "failed to remove member ${old_name}" | ||
# exit 1 | ||
# fi | ||
|
||
|
||
|
||
|
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,32 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Usage: | ||
# Example: | ||
# Created Date: 2023-12-15 | ||
# Author: Caoxianfei | ||
|
||
etcdctl=$1 | ||
endpoints=$2 | ||
old_name=$3 | ||
|
||
output=$(${etcdctl} --endpoints=${endpoints} member list) | ||
if [ $? -ne 0 ]; then | ||
echo "failed to list all etcd members" | ||
exit 1 | ||
fi | ||
|
||
id=$(echo "$output" | awk -v name="$old_name" -F ', ' '$3 == name {print $1}') | ||
if [ -z "${id}" ]; then | ||
echo "failed to get id of member ${old_name}" | ||
exit 1 | ||
fi | ||
|
||
${etcdctl} --endpoints=${endpoints} member remove ${id} | ||
if [ $? -ne 0 ]; then | ||
echo "failed to remove member ${old_name}" | ||
exit 1 | ||
fi | ||
|
||
|
||
|
||
|
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,116 @@ | ||
/* | ||
* Copyright (c) 2023 NetEase 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, | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* Project: CurveAdm | ||
* Created Date: 2023-12-20 | ||
* Author: Caoxianfei | ||
*/ | ||
|
||
package common | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/opencurve/curveadm/cli/cli" | ||
comm "github.com/opencurve/curveadm/internal/common" | ||
"github.com/opencurve/curveadm/internal/configure" | ||
"github.com/opencurve/curveadm/internal/configure/topology" | ||
"github.com/opencurve/curveadm/internal/errno" | ||
"github.com/opencurve/curveadm/internal/task/context" | ||
"github.com/opencurve/curveadm/internal/task/scripts" | ||
"github.com/opencurve/curveadm/internal/task/step" | ||
"github.com/opencurve/curveadm/internal/task/task" | ||
tui "github.com/opencurve/curveadm/internal/tui/common" | ||
) | ||
|
||
func checkAddEtcdMemberStatus(success *bool, out *string) step.LambdaType { | ||
return func(ctx *context.Context) error { | ||
if !*success { | ||
return errno.ERR_ADD_ETCD_MEMEBER.S(*out) | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func NewAddEtcdMemberTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*task.Task, error) { | ||
serviceId := curveadm.GetServiceId(dc.GetId()) | ||
containerId, err := curveadm.GetContainerId(serviceId) | ||
if curveadm.IsSkip(dc) { | ||
return nil, nil | ||
} else if err != nil { | ||
return nil, err | ||
} | ||
hc, err := curveadm.GetHost(dc.GetHost()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
subname := fmt.Sprintf("host=%s role=%s containerId=%s", | ||
dc.GetHost(), dc.GetRole(), tui.TrimContainerId(containerId)) | ||
t := task.NewTask("Backup Etcd Data", subname, hc.GetSSHConfig()) | ||
|
||
host, role := dc.GetHost(), dc.GetRole() | ||
script := scripts.ADD_ETCD | ||
layout := dc.GetProjectLayout() | ||
scriptPath := fmt.Sprintf("%s/add_etcd.sh", layout.ServiceBinDir) | ||
etcdctlPath := layout.ServiceBinDir + "/etcdctl" | ||
endpoints, err := dc.GetVariables().Get("cluster_etcd_addr") | ||
if err != nil { | ||
return nil, errno.ERR_GET_CLUSTER_ETCD_ADDR | ||
} | ||
oldName := fmt.Sprint("etcd", strconv.Itoa(dc.GetHostSequence()), strconv.Itoa(dc.GetInstancesSequence())) | ||
newName := fmt.Sprint("etcd", strconv.Itoa(dc.GetHostSequence()+3), strconv.Itoa(dc.GetInstancesSequence())) | ||
migrates := []*configure.MigrateServer{} | ||
if curveadm.MemStorage().Get(comm.KEY_MIGRATE_SERVERS) != nil { | ||
migrates = curveadm.MemStorage().Get(comm.KEY_MIGRATE_SERVERS).([]*configure.MigrateServer) | ||
} | ||
toService := migrates[0].To | ||
peerUrl := fmt.Sprint("http://", toService.GetListenIp(), ":", strconv.Itoa(toService.GetListenPort())) | ||
addEtcdCmd := fmt.Sprintf("/bin/bash %s %s %s %s %s %s", scriptPath, etcdctlPath, endpoints, oldName, newName, peerUrl) | ||
|
||
var success bool | ||
var out string | ||
t.AddStep(&step.ListContainers{ | ||
ShowAll: true, | ||
Format: `"{{.ID}}"`, | ||
Filter: fmt.Sprintf("id=%s", containerId), | ||
Out: &out, | ||
ExecOptions: curveadm.ExecOptions(), | ||
}) | ||
t.AddStep(&step.Lambda{ | ||
Lambda: CheckContainerExist(host, role, containerId, &out), | ||
}) | ||
t.AddStep(&step.InstallFile{ | ||
ContainerId: &containerId, | ||
ContainerDestPath: scriptPath, | ||
Content: &script, | ||
ExecOptions: curveadm.ExecOptions(), | ||
}) | ||
t.AddStep(&step.ContainerExec{ | ||
ContainerId: &containerId, | ||
Success: &success, | ||
Out: &out, | ||
Command: addEtcdCmd, | ||
ExecOptions: curveadm.ExecOptions(), | ||
}) | ||
t.AddStep(&step.Lambda{ | ||
Lambda: checkAddEtcdMemberStatus(&success, &out), | ||
}) | ||
|
||
return t, nil | ||
} |
Oops, something went wrong.