-
Notifications
You must be signed in to change notification settings - Fork 72
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
Feature: support managing disk information in database #188
Conversation
4379c61
to
6798511
Compare
cli/cli/cli.go
Outdated
clusterPoolData string // cluster pool | ||
hosts string // hosts | ||
disks string // disks | ||
diskRecords []storage.Disk // disk |
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.
How about diskTable
, like fstab
?
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.
diskTable
refers to a database table that holding records, diskRecords
refers to the disk records queried from database.
cli/command/disks/commit.go
Outdated
|
||
// write disk records | ||
for _, hc := range hcs { | ||
for _, dc := range dcs { |
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 wrap the below logic into one function.
BTW: i think you can make the function ParseDisk
more powerful, and let it return the final disk config which already handle hosts_exclude
and hosts_exclude
, and then insert the records into database.
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.
Good point.
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.
Done
cli/command/disks/commit.go
Outdated
} | ||
|
||
// sync disk records | ||
diskRecords := curveadm.DiskRecords() |
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.
I think the below logic is a bit complex, you can provide a function to get the difference bettwen new records and old records, then to handle the difference, like receive the commit or denied.
Maybe you can refer checkScaleOutTopology, and if you refuse the commit, you can provide some more meaningful error codes, like ERR_DELETE_BINDING_DISK_IS_DENIED
.
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.
Done.
@@ -0,0 +1,18 @@ | |||
global: | |||
format_percent: 90 | |||
|
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.
I think maybe we should provide the globalhosts
section to let user specify the all host which will to formatted, otherwise user needs to setting many hosts_exclude
or hosts_only
if there are many hosts. if using hosts
, user can focus on a part hosts quicky, and then using hosts_exclude
and hosts_only
to achieve its aim.
global:
format_percent: 95
hosts:
- curve1
- curve2
- curve3
disks:
...
BTW, how do you think about the below configure design? I think:
- It might be more easier to understand.
- The level design
SAME AS
our other configures, like topology. - The logic of parse disks configure file is more simpler.
global:
format_percent: 95
hosts:
- curve-1
- curve-2
- curve-3
disks:
- device: /dev/sdb1
mount: /data/chunkserver0
- device: /dev/sdc1
mount: /data/chunkserver1
format_percent: 90
- device: /dev/sdd1
mount: /data/chunkserver2
hosts:
- curve-1
- curve-2
- device: /dev/sde1
mount: /data/chunkserver3
hosts:
- curve1
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.
Done.
cc @tsonglew |
internal/utils/common.go
Outdated
@@ -216,6 +216,22 @@ func Slice2Map(s []string) map[string]bool { | |||
return m | |||
} | |||
|
|||
func InterfaceSlice2Map(s []interface{}) map[interface{}]bool { |
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's better to implement a generic function to replace Slice2Map
and InterfaceSlice2Map
in my opinion, since Go 1.18 is used on develop branch.
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.
Sure, so glad to use Go 1.18.
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.
Add GenericSlice2Map
and keep Slice2Map
for old references.
internal/configure/disks/disks.go
Outdated
|
||
hostExclude := dc.GetHostExclude() | ||
if len(hostExclude) > 0 { | ||
hosts := []interface{}{} |
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.
the variable name hosts
collides with "github.com/opencurve/curveadm/internal/configure/hosts", should we consider another name for it?
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.
Done.
internal/configure/disks/disks.go
Outdated
return nil, errno.ERR_PARSE_DISKS_FAILED.E(err) | ||
} | ||
|
||
dcs := []*DiskConfig{} |
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.
should we use var dcs []*DiskConfig
to declare the empty slice, as mentioned in go/wiki/CodeReviewComment
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.
Done.
968ecba
to
c5db7e7
Compare
internal/utils/common.go
Outdated
@@ -216,6 +222,26 @@ func Slice2Map(s []string) map[string]bool { | |||
return m | |||
} | |||
|
|||
func GenericSlice2Map[T string | int | any](t []T) booleanMap { |
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.
how about turning Slice2Map
into
func Slice2Map[T comparable](t []T) map[T]bool {
m := map[T]bool{}
for _, item := range t {
m[item] = true
}
return m
}
and calling it from internal/configure/disks/disks.go
in this way ?
hostExcludeMap := utils.Slice2Map(hostExclude)
// ...
if _, ok := hostExcludeMap[h]; !ok {
// ...
}
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.
but interface is not comparable
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.
My bad, Go1.20 is required to do so.
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.
Done.
c5db7e7
to
9e1956a
Compare
@tsonglew any other suggestions? |
0ef0519
to
536425e
Compare
cli/command/disks/commit.go
Outdated
} | ||
|
||
func runCommit(curveadm *cli.CurveAdm, options commitOptions) 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.
redundant: blank line.
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.
Probably we need an action for style check. I'd like to put it into practice with another pr
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.
Done.
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.
Probably we need an action for style check. I'd like to put it into practice with another pr
That's great :)
configs/bs/cluster/disks.yaml
Outdated
mount: /data/chunkserver1 | ||
- device: /dev/sdd1 | ||
mount: /data/chunkserver2 | ||
host_exclude: # for the use case that all hosts have this disk device except some hosts |
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.
We should keep the config template and the implemetion consistent.
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.
disks.yaml
template and the implementation is consistent with double check. It would be helpful with more specific comments.
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.
Done.
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.
We should keep the config template and the implemetion consistent.
Note, disks configure item names disk
and host
are used in implementation, not disks
and hosts
.
global:
format_percent: 95
host:
- curve-1
- curve-2
- curve-3
disk:
- device: /dev/sdb1
mount: /data/chunkserver0
- device: /dev/sdc1
mount: /data/chunkserver1
format_percent: 90
- device: /dev/sdd1
mount: /data/chunkserver2
exclude:
- curve-1
- device: /dev/sde1
mount: /data/chunkserver3
host:
- curve-1
- curve-2
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.
Disks struct {
Global map[string]interface{} `mapstructure:"global"`
Disk []map[string]interface{} `mapstructure:"disk"`
}
@@ -35,6 +35,7 @@ const ( | |||
REQUIRE_BOOL | |||
REQUIRE_INT | |||
REQUIRE_POSITIVE_INTEGER | |||
REQUIRE_SLICE |
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.
Now we add the type REQUIRE_SLICE
, but there is no corresponding checker implementation for it.
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.
Done.
internal/configure/disks/dc_item.go
Outdated
) | ||
|
||
CONFIG_DISK_HOST_EXCLUDE = itemset.Insert( | ||
common.DISK_HOST_EXCLUDE, |
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.
Maybe we can remove the host_exclude
and host_only
configure item.
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.
Are there any good solutions to support different disk number among hosts?
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.
What about the use case that disk number is different among hosts?
Hi, guys, for solving the problem that the disk list in each hosts is different while formatting, we have provide two designs which show as below:
Design 1: using host_only
and host_exclude
global:
format_percent: 95
host:
- curve-1
- curve-2
- curve-3
disk:
- device: /dev/sdb1
mount: /data/chunkserver0
- device: /dev/sdc1
mount: /data/chunkserver1
- device: /dev/sdd1
mount: /data/chunkserver2
host_exclude: # for the use case that all hosts have this disk device except some hosts
- curve-3
- device: /dev/sde1
mount: /data/chunkserver3
host_only: # for the use case that only some hosts have this disk device
- curve-1
- curve-2
from @legionxiong
Design 2: using level design
global:
format_percent: 95
hosts:
- curve-1
- curve-2
- curve-3
disks:
- device: /dev/sdb1
mount: /data/chunkserver0
- device: /dev/sdc1
mount: /data/chunkserver1
format_percent: 90
- device: /dev/sdd1
mount: /data/chunkserver2
hosts:
- curve-1
- curve-2
- device: /dev/sde1
mount: /data/chunkserver3
hosts:
- curve1
- curve2
pros:
- It might be more easier to understand.
- The level design
SAME AS
our other configures, like topology.
what's your opinion? cc @aspirer @Cyber-SiKu @tsonglew
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.
Or different disk number among hosts is not expected for curvebs, but what about the different disk device path?
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.
Design 2
is much easier than host_only
use case 👍 , but for host_exclude
use case it may be a bit painful. And disk devices among hosts may be changed from time to 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.
I would prefer the 2nd and the 3rd among designs above. And it seems
hosts_exclude
is a more explicit name thanexclude
Agree, hosts_exclude
is more explicit, but disk configure has nothing to exclude
except hosts
. @Wine93 How do you think about this?
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.
I would prefer the 2nd and the 3rd among designs above. And it seems
hosts_exclude
is a more explicit name thanexclude
Agree,
hosts_exclude
is more explicit, but disk configure has nothing toexclude
excepthosts
. @Wine93 How do you think about this?
As you said, it is still easy to understand if we clearly describe what exclude does in our WIKI, like hosts. I agree the design 3 shown above.
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.
OK, how to add / update curveadm WiKi? We need add a disks
page.
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.
OK, how to add / update curveadm WiKi? We need add a
disks
page.
You can refer to how-can-i-make-a-pull-request-for-a-wiki-page-on-github, and our wiki git address is https://github.com/opencurve/curveadm.wiki.git.
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.
OK, how to add / update curveadm WiKi? We need add a
disks
page.You can refer to how-can-i-make-a-pull-request-for-a-wiki-page-on-github, and our wiki git address is https://github.com/opencurve/curveadm.wiki.git.
It seems I have no privilege to view curveadm wilki repo, got 404
:(
cli/command/disks/list.go
Outdated
var err error | ||
var diskRecords []storage.Disk | ||
// diskData := curveadm.Disks() | ||
// err = syncDiskRecords(diskData, curveadm, options) |
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 should fix it, it not works.
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.
Done.
66c8819
to
5f6dd63
Compare
@legionxiong Thank you for your contribution and patience, there are a few small things to do before merge, please:
|
5f6dd63
to
3842a59
Compare
With database disk records commited by `disks.yaml`, disk formatting cloud be performed without `format.yaml`. And it will get and wirte disk `size` and `URI` during disk formatting, thus record the ID of service(chunkserver) with associated disk when deploy curvebs cluster. Use `curveadm disks ls` to view all disk information. Usage: curveadm disks commit /path/to/disks.yaml curveadm disks ls curveadm format Signed-off-by: Lijin Xiong <[email protected]>
3842a59
to
de36749
Compare
All done. |
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.
LGTM!
Shall we merge it? |
LGTM! |
With database disk records commited by
disks.yaml
,disk formatting cloud be performed without
format.yaml
.And it will get and wirte disk
size
andURI
duringdisk formatting, thus record the ID of service(chunkserver)
with associated disk when deploy curvebs cluster. Use
curveadm disks ls
to view all disk information.