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

Feature: support managing disk information in database #188

Merged
merged 1 commit into from
Mar 3, 2023

Conversation

legionxiong
Copy link

@legionxiong legionxiong commented Feb 24, 2023

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

[root@curve-1 curvebs]# ./curveadm disks show
global:
  format_percent: 90
  host:
    - curve-1
    - curve-2
    - curve-3
disk:
  - device: /dev/sdb1
    mount: /data/chunkserver0
  - device: /dev/sdc1
    mount: /data/chunkserver1

[root@curve-1 curvebs]# ./curveadm disks ls
Host     Device Path  Device Size  Device URI                                     Disk Format Mount Point  Service ID
----     -----------  -----------  ----------                                     -----------------------  ----------
curve-1  /dev/sdb1    21472739328  fs:uuid//077c677d-144c-4faf-98d5-b1b9f012b5a6  /data/chunkserver0       81793d01ae46
curve-1  /dev/sdc1    21472739328  fs:uuid//fded239b-78bd-4c20-9a53-80c9cdcbcd4c  /data/chunkserver1       3bc6410788cb
curve-2  /dev/sdb1    21472739328  fs:uuid//44198367-0020-4963-9ed4-409eaa2bad68  /data/chunkserver0       15551b243c70
curve-2  /dev/sdc1    21472739328  fs:uuid//286aade7-cb7c-4630-9155-f7935bdc2903  /data/chunkserver1       d24e9354cb01
curve-3  /dev/sdb1    21472739328  fs:uuid//eab438fa-fd11-44b5-93c4-a131a69cfd86  /data/chunkserver0       9cf41f087ef4
curve-3  /dev/sdc1    21472739328  fs:uuid//10e3220b-c598-4cd7-8927-22df166a2a91  /data/chunkserver1       93d4f9eba5fe

cli/cli/cli.go Outdated
clusterPoolData string // cluster pool
hosts string // hosts
disks string // disks
diskRecords []storage.Disk // disk
Copy link
Collaborator

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?

Copy link
Author

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.


// write disk records
for _, hc := range hcs {
for _, dc := range dcs {
Copy link
Collaborator

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.

Copy link
Author

Choose a reason for hiding this comment

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

Good point.

Copy link
Author

Choose a reason for hiding this comment

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

Done

}

// sync disk records
diskRecords := curveadm.DiskRecords()
Copy link
Collaborator

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.

Copy link
Author

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

Copy link
Collaborator

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

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@Wine93
Copy link
Collaborator

Wine93 commented Mar 1, 2023

cc @tsonglew

@@ -216,6 +216,22 @@ func Slice2Map(s []string) map[string]bool {
return m
}

func InterfaceSlice2Map(s []interface{}) map[interface{}]bool {
Copy link
Member

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.

Copy link
Author

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.

Copy link
Author

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.


hostExclude := dc.GetHostExclude()
if len(hostExclude) > 0 {
hosts := []interface{}{}
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

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

Done.

return nil, errno.ERR_PARSE_DISKS_FAILED.E(err)
}

dcs := []*DiskConfig{}
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@tsonglew tsonglew self-requested a review March 2, 2023 00:45
@legionxiong legionxiong force-pushed the new-disk-format branch 3 times, most recently from 968ecba to c5db7e7 Compare March 2, 2023 04:08
@@ -216,6 +222,26 @@ func Slice2Map(s []string) map[string]bool {
return m
}

func GenericSlice2Map[T string | int | any](t []T) booleanMap {
Copy link
Member

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 {
    // ...
}

Copy link
Author

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

Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@legionxiong
Copy link
Author

@tsonglew any other suggestions?

@legionxiong legionxiong requested a review from Wine93 March 2, 2023 07:16
@legionxiong legionxiong force-pushed the new-disk-format branch 2 times, most recently from 0ef0519 to 536425e Compare March 2, 2023 08:35
}

func runCommit(curveadm *cli.CurveAdm, options commitOptions) error {

Copy link
Collaborator

Choose a reason for hiding this comment

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

redundant: blank line.

Copy link
Member

@tsonglew tsonglew Mar 2, 2023

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

Copy link
Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

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 :)

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
Copy link
Collaborator

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.

Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

Copy link
Author

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
       

Copy link
Author

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
Copy link
Collaborator

@Wine93 Wine93 Mar 2, 2023

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.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

)

CONFIG_DISK_HOST_EXCLUDE = itemset.Insert(
common.DISK_HOST_EXCLUDE,
Copy link
Collaborator

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.

Copy link
Author

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?

Copy link
Collaborator

@Wine93 Wine93 Mar 2, 2023

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

Copy link
Author

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?

Copy link
Author

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.

Copy link
Author

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 than exclude

Agree, hosts_exclude is more explicit, but disk configure has nothing to exclude except hosts. @Wine93 How do you think about this?

Copy link
Collaborator

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 than exclude

Agree, hosts_exclude is more explicit, but disk configure has nothing to exclude except hosts. @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.

Copy link
Author

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.

Copy link
Collaborator

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.

Copy link
Author

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 :(

var err error
var diskRecords []storage.Disk
// diskData := curveadm.Disks()
// err = syncDiskRecords(diskData, curveadm, options)
Copy link
Collaborator

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.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@Wine93
Copy link
Collaborator

Wine93 commented Mar 3, 2023

@legionxiong Thank you for your contribution and patience, there are a few small things to do before merge, please:

  • Merge the commits into one.
  • Remove the unrelated commit, b2cbbcb.
  • Modify your commit message: capitalize the first word and let the commit message more clearly and meaningful.

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]>
@legionxiong
Copy link
Author

@legionxiong Thank you for your contribution and patience, there are a few small things to do before merge, please:

  • Merge the commits into one.
  • Remove the unrelated commit, b2cbbcb.
  • Modify your commit message: capitalize the first word and let the commit message more clearly and meaningful.

All done.

@legionxiong legionxiong changed the title add another way to get config for disk formatting Feature: support managing disk information in database Mar 3, 2023
Copy link
Collaborator

@Wine93 Wine93 left a comment

Choose a reason for hiding this comment

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

LGTM!

@legionxiong
Copy link
Author

Shall we merge it?

@tsonglew
Copy link
Member

tsonglew commented Mar 3, 2023

LGTM!

@tsonglew tsonglew merged commit af342de into opencurve:develop Mar 3, 2023
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.

3 participants