[#5] Add container zone names support #6

Merged
alexvanin merged 2 commits from KurlesHS/rclone:feature/add-container-zones-support into tcl/master 2025-01-29 13:09:46 +00:00
Member

Added the ability to explicitly specify the container zone in its name. For this, the syntax "<cnr-name>.<zone-name>" is used, where <cnr-name> is the name of a container and <zone-name> is the name of the zone. If no zone is explicitly specified, the default zone will be used.

A new parameter has been added for the frostfs backend: "default_container_zone", which is responsible for the zone where new containers are created and existing containers are resolved if no zone is specified in the container's name.

close #5

Added the ability to explicitly specify the container zone in its name. For this, the syntax "`<cnr-name>.<zone-name>`" is used, where `<cnr-name>` is the name of a container and `<zone-name>` is the name of the zone. If no zone is explicitly specified, the default zone will be used. A new parameter has been added for the frostfs backend: "`default_container_zone`", which is responsible for the zone where new containers are created and existing containers are resolved if no zone is specified in the container's name. close #5
KurlesHS added 2 commits 2025-01-22 16:38:12 +00:00
Signed-off-by: Aleksey Kravchenko <al.kravchenko@yadro.com>
[#5] Update frostfs backend docs
All checks were successful
/ DCO (pull_request) Successful in 43s
/ Builds (pull_request) Successful in 2m0s
/ Lint (pull_request) Successful in 4m20s
/ Test (pull_request) Successful in 3m0s
787f164997
Signed-off-by: Aleksey Kravchenko <al.kravchenko@yadro.com>
Member

It's possible that I'm wrong, but I've seen/heard in demos the opposite naming convention: <cnr-name>.<zone-name>. I think we should stick to one approach everywhere.

It's possible that I'm wrong, but I've seen/heard in demos the opposite naming convention: `<cnr-name>.<zone-name>`. I think we should stick to one approach everywhere.
KurlesHS was assigned by dkirillov 2025-01-23 08:04:51 +00:00
requested reviews from storage-services-committers, storage-services-developers 2025-01-23 08:05:04 +00:00
KurlesHS force-pushed feature/add-container-zones-support from 787f164997 to 0889e3075f 2025-01-23 08:35:08 +00:00 Compare
Author
Member

It's possible that I'm wrong, but I've seen/heard in demos the opposite naming convention: <cnr-name>.<zone-name>. I think we should stick to one approach everywhere.

Yes, you're not the only one who noticed this. I changed the format of the zone assignment to the expected one.

> It's possible that I'm wrong, but I've seen/heard in demos the opposite naming convention: `<cnr-name>.<zone-name>`. I think we should stick to one approach everywhere. Yes, you're not the only one who noticed this. I changed the format of the zone assignment to the expected one.
dkirillov reviewed 2025-01-23 09:18:30 +00:00
@ -818,3 +828,3 @@
container.SetCreationTime(&cnr, time.Now())
container.SetName(&cnr, containerName)
container.SetName(&cnr, containerStr)
Member

Probably we can set to this just name rather than name+zone

Probably we can set to this just name rather than name+zone
Author
Member

For the internal logic of the application, it does not matter what value is in this property. But if we suddenly have to look at containers not using rclone, but using frostfs-cli, it seems to me that it is better to store in this property the value that the user explicitly entered when specifying the name of the root directory. Besides, in most cases there will be a name without a zone anyway.

For the internal logic of the application, it does not matter what value is in this property. But if we suddenly have to look at containers not using `rclone`, but using `frostfs-cli`, it seems to me that it is better to store in this property the value that the user explicitly entered when specifying the name of the root directory. Besides, in most cases there will be a name without a zone anyway.
dkirillov marked this conversation as resolved
@ -946,3 +958,2 @@
func getContainerIDByName(dirEntry fs.DirEntry, containerName string) (ok bool, cnrID cid.ID, err error) {
if dirEntry.Remote() != containerName {
func getContainerIDByZoneAndName(dirEntry fs.DirEntry, cnrZone, cnrName, defaultZone string) (ok bool, cnrID cid.ID, err error) {
Member

Maybe it's matter of taste, but It's more common to see ok bool after value (cnrID cid.ID)

Maybe it's matter of taste, but It's more common to see `ok bool` after value (`cnrID cid.ID`)
dkirillov marked this conversation as resolved
@ -957,3 +970,3 @@
}
func resolveContainerIDWithNNS(resolver *resolver.NNS, containerName string) (cid.ID, error) {
func resolveContainerIDWithNNS(resolver *resolver.NNS, cnrZone, cnrName, containerStr string) (cid.ID, error) {
Member

I'm not sure if we need containerStr string parameter here

I'm not sure if we need `containerStr string` parameter here
dkirillov marked this conversation as resolved
@ -968,2 +982,2 @@
func (f *Fs) resolveContainerIDHelper(ctx context.Context, containerName string) (cid.ID, error) {
cnrIDStr, ok := f.containerIDCache[containerName]
func (f *Fs) resolveContainerIDHelper(ctx context.Context, containerStr string) (cid.ID, error) {
cnrIDStr, ok := f.containerIDCache[containerStr]
Member

Shouldn't we protect f.containerIDCache more granular? Now we hold lock when create/delete container. I'm not sure if it's necessary

Shouldn't we protect `f.containerIDCache` more granular? Now we hold lock when create/delete container. I'm not sure if it's necessary
Author
Member

Due to the fact that PUT operations are performed in parallel in separate goroutines, if a requested container is missing, and we do not use a global lock, all these goroutines will attempt to create their own containers, which could lead to conflicts.

Due to the fact that `PUT` operations are performed in parallel in separate goroutines, if a requested container is missing, and we do not use a global lock, all these goroutines will attempt to create their own containers, which could lead to conflicts.
Member

Well, let's add comment about this then.

By the way I'm a little confused by not seeing using mutex in function where we work with resource that should be protected by it (f.containerIDCache). Maybe we should not extract resolveContainerIDHelper into separate function but make a little duplication in resolveContaienrID and resolveOrCreateContainer?

@alexvanin

Well, let's add comment about this then. By the way I'm a little confused by not seeing using mutex in function where we work with resource that should be protected by it (`f.containerIDCache`). Maybe we should not extract `resolveContainerIDHelper` into separate function but make a little duplication in `resolveContaienrID` and `resolveOrCreateContainer`? @alexvanin
Owner

#9

https://git.frostfs.info/TrueCloudLab/rclone/issues/9
@ -976,2 +994,2 @@
if cnrID, err = resolveContainerIDWithNNS(f.resolver, containerName); err == nil {
f.containerIDCache[containerName] = cnrID.String()
if cnrID, err = resolveContainerIDWithNNS(f.resolver, cnrZone, cnrName, containerStr); err == nil {
f.containerIDCache[containerStr] = cnrID.String()
Member

Why don't we update cache inside resolveContainerIDWithNNS?
Then we can simplify code here to

if f.resolver != nil {
    return resolveContainerIDWithNNS(f.resolver, cnrZone, cnrName, containerStr)
}
Why don't we update cache inside `resolveContainerIDWithNNS`? Then we can simplify code here to ```golang if f.resolver != nil { return resolveContainerIDWithNNS(f.resolver, cnrZone, cnrName, containerStr) } ```
Member

Or we can rewrite resolveContainerIDHelper so it looks like:

cnrIDStr, ok := f.containerIDCache[containerStr]
if ok {
	return parseContainerID(cnrIDStr)
}

cnrID, err := funcToResolveCID()
if err !=nil {
    return cid.ID{}, err 
}

f.containerIDCache[containerStr] = cnrID.String()
return cnrID, nil
Or we can rewrite `resolveContainerIDHelper` so it looks like: ```golang cnrIDStr, ok := f.containerIDCache[containerStr] if ok { return parseContainerID(cnrIDStr) } cnrID, err := funcToResolveCID() if err !=nil { return cid.ID{}, err } f.containerIDCache[containerStr] = cnrID.String() return cnrID, nil ```
dkirillov marked this conversation as resolved
@ -302,3 +302,3 @@
if domain := container.ReadDomain(cnr); domain.Name() != "" {
remote = domain.Name()
if defaultZone != domain.Zone() {
Member

Why do we need such difference?

Why do we need such difference?
Author
Member

Why do we need such difference?

Without this, the root directories in the default zone will be resolved as "<cnr-name>.<default-zone>", and many integration tests will fail. If we leave only the container name as "Remote", then when listing all container files, the root directories "root-dir.z1" and "root-dir.z2" will have the same name "root-dir", which will lead to ambiguity.

> Why do we need such difference? Without this, the root directories in the default zone will be resolved as `"<cnr-name>.<default-zone>"`, and many integration tests will fail. If we leave only the container name as "Remote", then when listing all container files, the root directories "root-dir.z1" and "root-dir.z2" will have the same name "root-dir", which will lead to ambiguity.
dkirillov marked this conversation as resolved
@ -310,2 +314,4 @@
return dir
}
func getZoneAndContainerNames(containerStr, defaultZone string) (cnrZone string, cnrName string) {
Member

Can we return values in opposite order (name, zone)?

Can we return values in opposite order (name, zone)?
dkirillov marked this conversation as resolved
@ -312,0 +317,4 @@
func getZoneAndContainerNames(containerStr, defaultZone string) (cnrZone string, cnrName string) {
defer func() {
if len(cnrZone) == 0 {
cnrZone = "container"
Member

I woudn't allow empty cnrZone. By the way why we use here "container" rather than defaultZone?

I woudn't allow empty `cnrZone`. By the way why we use here `"container"` rather than `defaultZone`?
Author
Member

Here I mean the following logic: if the user enters the name of the root directory as "<cnr-name>", the zone name will be resolved to the one specified in the restic configuration in the "default_container_zone" parameter. And if the name of root directory is specified in "<cnr-name>." format (with a dot at the end), then zone will resolve to standard one for FrostFS, which is "container".

Here I mean the following logic: if the user enters the name of the root directory as `"<cnr-name>"`, the zone name will be resolved to the one specified in the restic configuration in the "`default_container_zone`" parameter. And if the name of root directory is specified in `"<cnr-name>."` format (with a dot at the end), then zone will resolve to standard one for FrostFS, which is "`container`".
Member

Maybe it's better, if user want to enter name of root directory that isn't in default zone make he enter full name (with zone) even if it's container?

Maybe it's better, if user want to enter name of root directory that isn't in default zone make he enter full name (with zone) even if it's `container`?
KurlesHS force-pushed feature/add-container-zones-support from 0889e3075f to 5ad64af106 2025-01-23 12:22:19 +00:00 Compare
dkirillov reviewed 2025-01-27 09:36:29 +00:00
@ -997,0 +1005,4 @@
return parseContainerID(cnrIDStr)
}
cnrID, err := f.resolveCIDByRootDirName(ctx, rootDirName)
if err == nil {
Member

Can we use opposite condition if err != nil ? It's more common

Can we use opposite condition ` if err != nil` ? It's more common
@ -997,0 +1008,4 @@
if err == nil {
f.containerIDCache[rootDirName] = cnrID.String()
}
return cnrID, err
Member

If we know that value doesn't matter because of err != nil, let's write

return cid.ID{}, err

to highlight the fact that we aren't interested in value

If we know that value doesn't matter because of `err != nil`, let's write ```golang return cid.ID{}, err ``` to highlight the fact that we aren't interested in value
@ -1005,2 +1021,4 @@
func (f *Fs) parseContainer(ctx context.Context, rootDirName string) (cid.ID, error) {
cnrID, err := parseContainerID(rootDirName)
if err == nil {
return cnrID, err
Member

Matter of taste but can we write return <val>, nil in such cases rather than return <val>, err?

Matter of taste but can we write `return <val>, nil` in such cases rather than `return <val>, err`?
KurlesHS force-pushed feature/add-container-zones-support from 5ad64af106 to 12b572e62a 2025-01-27 13:34:13 +00:00 Compare
alexvanin approved these changes 2025-01-29 12:56:10 +00:00
alexvanin left a comment
Owner

Looks good to me

Looks good to me
alexvanin merged commit 12b572e62a into tcl/master 2025-01-29 13:09:46 +00:00
alexvanin deleted branch feature/add-container-zones-support 2025-01-29 13:09:49 +00:00
Sign in to join this conversation.
No description provided.