-
Notifications
You must be signed in to change notification settings - Fork 526
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
base: master
Are you sure you want to change the base?
Conversation
3514dcb
to
deb32ef
Compare
There was a problem hiding this 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} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map is better ?
There was a problem hiding this comment.
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.
I have rewritten this using the new snapshot utils. |
cobrautil.QueryAction: cobrautil.ActionGetFileSnapshotList, | ||
cobrautil.QueryUser: sCmd.user, | ||
cobrautil.QueryFile: sCmd.filename, | ||
cobrautil.QueryLimit: 100, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defined as constant
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
for _, s := range statusList { | ||
count[s] = 0 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need
There was a problem hiding this comment.
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" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defined as constant
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defined as constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Please resolve the conflict and rebase your commit into one. |
Conflicts have been addressed and I've squashed the commits. Please have a look. |
cicheck |
1 similar comment
cicheck |
@caoxianfei1 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. |
@saicaca it works after modify the function. And it's better that you fix it. |
I will do it this noon. |
@caoxianfei1 |
cicheck |
2 similar comments
cicheck |
cicheck |
snapshotAddrs []string | ||
timeout time.Duration | ||
user string | ||
filename string |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
curve/tools/snaptool/querysnap.py
Lines 32 to 33 in ba010be
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.
curve/src/snapshotcloneserver/common/snapshotclone_meta_store_etcd.cpp
Lines 149 to 163 in ba010be
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.
cicheck |
need to rebase and fix the conflict. |
e5fa7e4
to
7cadf7a
Compare
cicheck |
@caoxianfei1 I think it's ready to merge. |
There was a problem hiding this 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" | ||
) |
There was a problem hiding this comment.
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 ...
)
There was a problem hiding this comment.
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", | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"`
}
There was a problem hiding this comment.
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.
pls fix conflicts |
020541c
to
7b58dc5
Compare
Conflicts fixed. |
cicheck |
1 similar comment
cicheck |
cicheck |
Are you free to move on, fix the conflict and complete it. |
Signed-off-by: saicaca <[email protected]>
Yes, I have fixed the conflict. |
What problem does this PR solve?
Issue Number: #2583
Problem Summary: Add
bs status volume snapshot
commandWhat is changed and how it works?
What's Changed: Implement the
bs status volume snapshot
command ,which is equivalent to thesnapshot-status
command insnaptool.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