Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curvefs/tool: delete-fs #1014

Merged
merged 1 commit into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 82 additions & 12 deletions curvefs/src/tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,71 @@ zoneId:1, zoneName:zone1, poolId:1 serverList:{ 1 }
zoneId:2, zoneName:zone2, poolId:1 serverList:{ 2 }
zoneId:3, zoneName:zone3, poolId:1 serverList:{ 3 }
[server]
serverId:1, hostname:metaserver_192.168.1.1_1, internalIp:192.168.1.1, internalPort:16701, externalIp:192.168.1.1, externalPort:16701, zoneId:1, poolId:1 metaserverList:{ 1 }
serverId:2, hostname:metaserver_192.168.1.1_2, internalIp:192.168.1.1, internalPort:26701, externalIp:192.168.1.1, externalPort:26701, zoneId:2, poolId:1 metaserverList:{ 3 }
serverId:3, hostname:metaserver_192.168.1.1_3, internalIp:192.168.1.1, internalPort:36701, externalIp:192.168.1.1, externalPort:36701, zoneId:3, poolId:1 metaserverList:{ 2 }
serverId:1, hostname:192.168.1.1_0_0, internalIp:192.168.1.1, internalPort:16701, externalIp:192.168.1.1, externalPort:16701, zoneId:1, poolId:1 metaserverList:{ 1 }
serverId:2, hostname:192.168.1.1_1_0, internalIp:192.168.1.1, internalPort:26701, externalIp:192.168.1.1, externalPort:26701, zoneId:2, poolId:1 metaserverList:{ 3 }
serverId:3, hostname:192.168.1.1_2_0, internalIp:192.168.1.1, internalPort:36701, externalIp:192.168.1.1, externalPort:36701, zoneId:3, poolId:1 metaserverList:{ 2 }
[metaserver]
metaserverId:1, hostname:pubbeta2-curve20.dg.163.org, hostIp:192.168.1.1, port:16701, externalIp:192.168.1.1, externalPort:16701, onlineState:ONLINE, serverId:1
metaserverId:2, hostname:pubbeta2-curve20.dg.163.org, hostIp:192.168.1.1, port:36701, externalIp:192.168.1.1, externalPort:36701, onlineState:ONLINE, serverId:3
metaserverId:3, hostname:pubbeta2-curve20.dg.163.org, hostIp:192.168.1.1, port:26701, externalIp:192.168.1.1, externalPort:26701, onlineState:ONLINE, serverId:2
```
metaserverId:1, hostname:curvefs-metaserver, hostIp:192.168.1.1, port:16701, externalIp:192.168.1.1, externalPort:16701, onlineState:ONLINE, serverId:1
metaserverId:2, hostname:curvefs-metaserver, hostIp:192.168.1.1, port:36701, externalIp:192.168.1.1, externalPort:36701, onlineState:ONLINE, serverId:3
metaserverId:3, hostname:curvefs-metaserver, hostIp:192.168.1.1, port:26701, externalIp:192.168.1.1, externalPort:26701, onlineState:ONLINE, serverId:2
```

> You can use -jsonType and -jsonPath to output the topology to a json file.
>
> The parameter -jsonType supports build and tree.
>
> build: can be used to create the same topology as the current one;
>
> tree: build a json tree of the current topology.
>
> Usage:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default jsonType is tree?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default jsonType is tree?

build

>
>```shell
> curvefs_tool list-topology -jsonPath=/tmp/test.json -jsonType=build | cat /tmp/test.json | jq .
>```
> Output:
>```
>{
> "pools": [
> {
> "copysetnum": 100,
> "name": "defaultPool",
> "replicasnum": 3,
> "zonenum": 3
> }
> ],
> "servers": [
> {
> "externalip": "192.168.1.1",
> "externalport": 16701,
> "internalip": "192.168.1.1",
> "internalport": 16701,
> "name": "192.168.1.1_0_0",
> "pool": "defaultPool",
> "zone": "zone1"
> },
> {
> "externalip": "192.168.1.1",
> "externalport": 26701,
> "internalip": "192.168.1.1",
> "internalport": 26701,
> "name": "192.168.1.1_1_0",
> "pool": "defaultPool",
> "zone": "zone2"
> },
> {
> "externalip": "192.168.1.1",
> "externalport": 36701,
> "internalip": "192.168.1.1",
> "internalport": 36701,
> "name": "192.168.1.1_2_0",
> "pool": "defaultPool",
> "zone": "zone3"
> }
> ]
>}
>```
>

[TOC](#table-of-contents)

Expand Down Expand Up @@ -400,16 +457,29 @@ delete fs by fsName
Usage:

```shell
curvefs_tool delete-fs -fsName=/test -confirm
curvefs_tool delete-fs -fsName=/test
```

Output:

```shell
This command will delete fs (test) and is not recoverable!!!
Do you really want to delete this fs? [Yes, delete!]: Yes, delete!
delete fs (test) success.
```

[**WARNING**] If you enter -noconfirm, fs will be deleted directly without checking, please use with caution!

Usage:

```shell
curvefs_tool delete-fs -fsName=/test -noconfirm
```

Output:

```shell
1. do you really want to delete fs (/test) :[Ny]y
2. do you really want to delete fs (/test) :[Ny]y
3. do you really want to delete fs (/test) :[Ny]y
delete fs /test success.
delete fs (test) success.
```

[TOC](#table-of-contents)
Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/tools/curvefs_tool_define.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ DEFINE_string(poolId, "1,2,3", "pools id");
DEFINE_bool(detail, false, "show more infomation");
DEFINE_string(partitionId, "1,2,3", "partition id");
DEFINE_string(metaserverId, "1,2,3", "metaserver id");
DEFINE_bool(confirm, false, "confirm execution");
DEFINE_bool(noconfirm, false, "execute command without confirmation");
DEFINE_uint64(blockSize, 1048576, "block size");
DEFINE_string(fsType, "s3", "fs type: s3 or volume");
DEFINE_uint64(volumeSize, 1048576, "block size");
Expand Down
35 changes: 14 additions & 21 deletions curvefs/src/tools/delete/curvefs_delete_fs_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@

DECLARE_string(fsName);
DECLARE_string(mdsAddr);
DECLARE_bool(confirm);
DECLARE_bool(noconfirm);

namespace curvefs {
namespace tools {
namespace delete_ {

void DeleteFsTool::PrintHelp() {
CurvefsToolRpc::PrintHelp();
std::cout << " -fsName=" << FLAGS_fsName << " -confirm=" << FLAGS_confirm
<< " [-mdsAddr=" << FLAGS_mdsAddr << "]";
std::cout << " -fsName=" << FLAGS_fsName
<< " [-noconfirm=" << FLAGS_noconfirm
<< "] [-mdsAddr=" << FLAGS_mdsAddr << "]";
std::cout << std::endl;
}

Expand All @@ -59,27 +60,19 @@ void DeleteFsTool::AddUpdateFlags() {
}

int DeleteFsTool::RunCommand() {
if (!FLAGS_confirm) {
std::cerr << "please input \"-confirm\" or \"-confirm=true\""
<< std::endl;
return -1;
}

// confirm input
for (size_t i = 0; i < checkTimes_; i++) {
std::cout << i + 1 << ". do you really want to delete fs ("
<< FLAGS_fsName << ") :[Ny]";
char confirm = 'N';
std::cin >> confirm;
// clean up redundant output
std::cin.clear();
std::cin.ignore(INT_MAX, '\n');
if (!(confirm == 'Y' || confirm == 'y')) {
if (!FLAGS_noconfirm) {
// confirm input
std::cout << "This command will delete fs (" << FLAGS_fsName
<< ") and is not recoverable!!!\n"
<< "Do you really want to delete this fs? [Yes, delete!]: ";
std::string confirm = "no";
std::getline(std::cin, confirm);
if (confirm != "Yes, delete!") {
// input is not 'Y' or 'y'
std::cout << "delete canceled!" << std::endl;
return -1;
}
}

return CurvefsToolRpc::RunCommand();
}

Expand All @@ -93,7 +86,7 @@ bool DeleteFsTool::AfterSendRequestToHost(const std::string& host) {
curvefs::mds::FSStatusCode::NOT_FOUND) {
std::cerr << "delete fs failed, fs not found!" << std::endl;
} else if (response_->statuscode() == curvefs::mds::FSStatusCode::OK) {
std::cout << "delete fs " << FLAGS_fsName << " success." << std::endl;
std::cout << "delete fs (" << FLAGS_fsName << ") success." << std::endl;
ret = true;
} else {
std::cerr << "delete fs from mds: " << host
Expand Down
1 change: 0 additions & 1 deletion curvefs/src/tools/delete/curvefs_delete_fs_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class DeleteFsTool : public CurvefsToolRpc<curvefs::mds::DeleteFsRequest,
bool CheckRequiredFlagDefault() override;

protected:
uint32_t checkTimes_ = 3;
};

} // namespace delete_
Expand Down