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

[feat] tools-v2: add bs status volume snapshot command #2745

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

saicaca
Copy link
Contributor

@saicaca saicaca commented Sep 12, 2023

What problem does this PR solve?

Issue Number: #2583

Problem Summary: Add bs status volume snapshot command

What is changed and how it works?

What's Changed: Implement the bs status volume snapshot command ,which is equivalent to the snapshot-status command in snaptool.py.

How it Works: It acquires snapshot status data through HTTP requests, mirroring the behavior in the Python version.

Side effects(Breaking backward compatibility? Performance regression?):

Check List

  • Relevant documentation/comments is changed or added
  • I acknowledge that all my contributions will be made under the project's license

@saicaca saicaca force-pushed the dev branch 2 times, most recently from 3514dcb to deb32ef Compare September 18, 2023 05:09
Copy link
Contributor

@Cyber-SiKu Cyber-SiKu left a comment

Choose a reason for hiding this comment

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

This pr is encapsulated, and you can add your calls on this basis.

sCmd.health = cobrautil.HEALTH_WARN
}

count := []int{0, 0, 0, 0, 0, 0}
Copy link
Contributor

Choose a reason for hiding this comment

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

map is better ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the latest commit.

@saicaca
Copy link
Contributor Author

saicaca commented Sep 24, 2023

This pr is encapsulated, and you can add your calls on this basis.

I have rewritten this using the new snapshot utils.

cobrautil.QueryAction: cobrautil.ActionGetFileSnapshotList,
cobrautil.QueryUser: sCmd.user,
cobrautil.QueryFile: sCmd.filename,
cobrautil.QueryLimit: 100,
Copy link
Contributor

Choose a reason for hiding this comment

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

defined as constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

cobrautil.QueryUser: sCmd.user,
cobrautil.QueryFile: sCmd.filename,
cobrautil.QueryLimit: 100,
cobrautil.QueryOffset: 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines 149 to 151
for _, s := range statusList {
count[s] = 0
}
Copy link
Contributor

Choose a reason for hiding this comment

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

no need

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

if err := json.Unmarshal([]byte(result), &resp); err != nil {
return err
}
if resp.Code != "0" {
Copy link
Contributor

Choose a reason for hiding this comment

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

defined as constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

if resp.Code != "0" {
return fmt.Errorf("get clone list fail, error code: %s", resp.Code)
}
if len(resp.Snapshots) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

defined as constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@Cyber-SiKu Cyber-SiKu mentioned this pull request Oct 10, 2023
2 tasks
@Cyber-SiKu
Copy link
Contributor

Please resolve the conflict and rebase your commit into one.

@saicaca
Copy link
Contributor Author

saicaca commented Oct 10, 2023

Please resolve the conflict and rebase your commit into one.

Conflicts have been addressed and I've squashed the commits. Please have a look.

@Cyber-SiKu
Copy link
Contributor

cicheck

1 similar comment
@Cyber-SiKu
Copy link
Contributor

cicheck

@caoxianfei1
Copy link
Contributor

@saicaca
image

@saicaca
Copy link
Contributor Author

saicaca commented Oct 12, 2023

@caoxianfei1
I think this is because NewSnapshotQuerySubUri in tools-v2/internal/utils/snapshot.go incorrectly uses %s instead of %v for params of any type. This causes non-string parameters to be converted into strings like %!s(int=100). The % in the string results in the appearance of (MISSING) in the final URL because of this. The same issue should also occur in other commands where NewSnapshotQuerySubUri is used.

I noticed that #2793 will address this issue so maybe we don't have to fix it in this PR?

@caoxianfei1
Copy link
Contributor

@caoxianfei1 I think this is because NewSnapshotQuerySubUri in tools-v2/internal/utils/snapshot.go incorrectly uses %s instead of %v for params of any type. This causes non-string parameters to be converted into strings like %!s(int=100). The % in the string results in the appearance of (MISSING) in the final URL because of this. The same issue should also occur in other commands where NewSnapshotQuerySubUri is used.

I noticed that #2793 will address this issue so maybe we don't have to fix it in this PR?

I think we need to modify this issue to ensure that every pull request is correct and not rely on a code that has not yet been merged.

@caoxianfei1
Copy link
Contributor

@saicaca it works after modify the function. And it's better that you fix it.

@saicaca
Copy link
Contributor Author

saicaca commented Oct 13, 2023

@saicaca it works after modify the function. And it's better that you fix it.

I will do it this noon.

@saicaca
Copy link
Contributor Author

saicaca commented Oct 13, 2023

@caoxianfei1 NewSnapshotQuerySubUri is fixed in the latest commit.

@saicaca
Copy link
Contributor Author

saicaca commented Oct 13, 2023

cicheck

2 similar comments
@saicaca
Copy link
Contributor Author

saicaca commented Oct 13, 2023

cicheck

@Cyber-SiKu
Copy link
Contributor

cicheck

snapshotAddrs []string
timeout time.Duration
user string
filename string
Copy link
Contributor

@caoxianfei1 caoxianfei1 Oct 24, 2023

Choose a reason for hiding this comment

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

It means that we can query one volume snapshot status? can you give an exmaple in README.md.

And i think it may be error.

Copy link
Contributor Author

@saicaca saicaca Oct 24, 2023

Choose a reason for hiding this comment

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

This argument also exists in the old version tools.

def snapshot_status(args):
totalCount, records = curltool.get_snapshot_list_all(args.user, args.filename)

According to the implementation of the backend service, only the snapshots with the matching filename will be queried. It seems that the filename doesn't need to be unique so it can return multiple snapshots.

int SnapshotCloneMetaStoreEtcd::GetSnapshotList(const std::string &filename,
std::vector<SnapshotInfo> *v) {
ReadLockGuard guard(snapInfos_mutex);
for (auto it = snapInfos_.begin();
it != snapInfos_.end();
it++) {
if (filename == it->second.GetFileName()) {
v->push_back(it->second);
}
}
if (v->size() != 0) {
return 0;
}
return -1;
}

The filename is set when creating the snapshot. (#2772) (It is the same in the old version tools)

curve bs create volume snapshot --user root --filename test --snapshotname snap-test

So, I think this argument can be used like

curve bs status volume snapshot --filename test --snapshotaddr 127.0.0.1:5550,127.0.0.1:5551,127.0.0.1:5552

I will add it to the README.

@saicaca
Copy link
Contributor Author

saicaca commented Oct 25, 2023

cicheck

@caoxianfei1
Copy link
Contributor

need to rebase and fix the conflict.

@saicaca saicaca force-pushed the dev branch 2 times, most recently from e5fa7e4 to 7cadf7a Compare October 27, 2023 07:44
@saicaca
Copy link
Contributor Author

saicaca commented Oct 27, 2023

cicheck

@saicaca
Copy link
Contributor Author

saicaca commented Oct 27, 2023

need to rebase and fix the conflict.

@caoxianfei1 I think it's ready to merge.

Copy link
Member

@baytan0720 baytan0720 left a comment

Choose a reason for hiding this comment

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

#2793 is merged, it fix NewSnapshotQuerySubUri did not work properly. you can rebase and fix conflict.

"github.com/spf13/cobra"
"strconv"
"time"
)
Copy link
Member

Choose a reason for hiding this comment

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

sort import libs as

import (
standard lib ...

external lib ...
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the latest commit.

STATUS_ERROR_DELETING: "errorDeleting",
STATUS_CANCELING: "canceling",
STATUS_ERROR: "error",
}
Copy link
Member

Choose a reason for hiding this comment

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

these structs and variables were defined in snapshotutil, you can use it directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the latest commit.

return err.ToError()
}

var resp QueryResponse
Copy link
Member

@baytan0720 baytan0720 Nov 1, 2023

Choose a reason for hiding this comment

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

you can declare a variable

var resp struct {
			snapshotutil.Response
			SnapshotInfos snapshotutil.SnapshotInfos `json:"SnapshotInfos"`
		}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the latest commit.

@Cyber-SiKu
Copy link
Contributor

pls fix conflicts

@saicaca saicaca force-pushed the dev branch 4 times, most recently from 020541c to 7b58dc5 Compare November 3, 2023 15:26
@saicaca
Copy link
Contributor Author

saicaca commented Nov 3, 2023

pls fix conflicts

Conflicts fixed.

@saicaca saicaca requested a review from baytan0720 November 3, 2023 15:33
@saicaca
Copy link
Contributor Author

saicaca commented Nov 3, 2023

cicheck

1 similar comment
@Cyber-SiKu
Copy link
Contributor

cicheck

@caoxianfei1
Copy link
Contributor

cicheck

@montaguelhz
Copy link
Contributor

Are you free to move on, fix the conflict and complete it.

@saicaca
Copy link
Contributor Author

saicaca commented Jan 6, 2024

Are you free to move on, fix the conflict and complete it.

Yes, I have fixed the conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants