-
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 direct disk mounting for service container #201
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,9 +155,17 @@ func runFormat(curveadm *cli.CurveAdm, options formatOptions) error { | |
if err != nil { | ||
return err | ||
} | ||
fc.UseDiskUri = true | ||
chunkserverId := dr.ChunkServerID | ||
if len(chunkserverId) > 1 { | ||
|
||
fc.FromDiskRecord = true | ||
|
||
// "ServiceMountDevice=0" means write disk UUID into /etc/fstab for host mounting. | ||
// "ServiceMountDevice=1" means not to update /etc/fstab, the disk UUID will be wrote | ||
// into the config of service(chunkserver) container for disk automatic mounting. | ||
if dr.ServiceMountDevice != 0 { | ||
fc.ServiceMountDevice = true | ||
} | ||
|
||
if dr.ChunkServerID != comm.DISK_DEFAULT_NULL_CHUNKSERVER_ID { | ||
// skip formatting the disk with nonempty chunkserver id | ||
continue | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code review:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with the code review:
Overall, the code looks correct and is well written. There doesn't seem to be any bugs or risks present, and no improvements are necessary. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
global: | ||
format_percent: 95 | ||
container_image: opencurvedocker/curvebs:v1.2 | ||
service_mount_device: false # disk device will be mounted by service(chunkserver) directly if set "true", default "false" | ||
host: | ||
- curve-1 | ||
- curve-2 | ||
- curve-3 | ||
|
||
disk: | ||
- device: /dev/sdb1 | ||
mount: /data/chunkserver0 | ||
- device: /dev/sdb1 # disk device path | ||
mount: /data/chunkserver0 # mount point for disk formatting, consistent with the "data_dir" field of chunkserver service in topology | ||
- device: /dev/sdc1 | ||
mount: /data/chunkserver1 | ||
format_percent: 90 | ||
format_percent: 90 # use a different value for disk format percent | ||
- device: /dev/sdd1 | ||
mount: /data/chunkserver2 | ||
exclude: # for the use case that some hosts have not certain disk device | ||
exclude: # for the use case that disk device does not exist in some hosts | ||
- curve-3 | ||
- device: /dev/sde1 | ||
mount: /data/chunkserver3 | ||
host: | ||
host: # override global host config, for the use case that disk device only exists in some hosts | ||
- curve-1 | ||
- curve-2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with a brief code review: The code patch looks good. The addition of the "service_mount_device" field to the global block is a welcome change and it provides more flexibility in how disk devices are mounted. The inclusion of the "exclude" field in the disk block is also useful, as it allows disk devices to be excluded from certain hosts. Finally, the "host" field in the disk block allows for overriding the global host config for specific disk devices, which is helpful for cases where a disk device only exists on certain hosts. Overall, the code patch looks well-constructed and should not have any major risks or bugs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with code review.
Suggestions:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code Review:
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,8 +57,8 @@ const ( | |
DISK_FILTER_MOUNT = "mount" | ||
DISK_FILTER_SERVICE = "service" | ||
DISK_EXCLUDE_HOST = "exclude" | ||
|
||
DISK_FORMAT_PERCENT = "format_percent" | ||
DISK_SERVICE_MOUNT_DEVICE = "service_mount_device" | ||
DISK_FORMAT_PERCENT = "format_percent" | ||
|
||
DISK_FORMAT_MOUNT_POINT = "mount" | ||
DISK_FORMAT_CONTAINER_IMAGE = "container_image" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with the code review
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from the code patch. The code looks correct and does not have any bug risks. The only suggestion for improvement is to add comments for each of the constants in order to make the code easier to read and understand. This will help other developers understand the purpose and usage of each constant more easily. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with the code review
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ const ( | |
REQUIRE_BOOL | ||
REQUIRE_INT | ||
REQUIRE_POSITIVE_INTEGER | ||
REQUIRE_SLICE | ||
REQUIRE_STRING_SLICE | ||
) | ||
|
||
type ( | ||
|
@@ -82,6 +82,25 @@ func (itemset *ItemSet) GetAll() []*Item { | |
return itemset.items | ||
} | ||
|
||
func convertSlice[T int | string | any](key, value any) ([]T, error) { | ||
var slice []T | ||
if !utils.IsAnySlice(value) || len(value.([]any)) == 0 { | ||
return slice, errno.ERR_CONFIGURE_VALUE_REQUIRES_NONEMPTY_SLICE | ||
} | ||
anySlice := value.([]any) | ||
switch anySlice[0].(type) { | ||
case T: | ||
for _, str := range anySlice { | ||
slice = append(slice, str.(T)) | ||
} | ||
default: | ||
return slice, errno.ERR_UNSUPPORT_CONFIGURE_VALUE_TYPE. | ||
F("%s: %v", key, value) | ||
} | ||
|
||
return slice, nil | ||
} | ||
|
||
func (itemset *ItemSet) Build(key string, value interface{}) (interface{}, error) { | ||
item := itemset.Get(key) | ||
if item == nil { | ||
|
@@ -135,34 +154,12 @@ func (itemset *ItemSet) Build(key string, value interface{}) (interface{}, error | |
return v, nil | ||
} | ||
|
||
case REQUIRE_SLICE: | ||
anySlice := value.([]any) | ||
if len(anySlice) > 0 { | ||
switch anySlice[0].(type) { | ||
case string: | ||
return convertSlice[string](value), nil | ||
case int: | ||
return convertSlice[int](value), nil | ||
case bool: | ||
return convertSlice[bool](value), nil | ||
default: | ||
return []any{}, errno.ERR_UNSUPPORT_CONFIGURE_VALUE_TYPE. | ||
F("%s: %v", key, value) | ||
} | ||
} | ||
return []any{}, nil | ||
case REQUIRE_STRING_SLICE: | ||
return convertSlice[string](key, value) | ||
|
||
default: | ||
// do nothing | ||
} | ||
|
||
return value, nil | ||
} | ||
|
||
func convertSlice[T int | string | any](value any) []T { | ||
var slice []T | ||
for _, str := range value.([]any) { | ||
slice = append(slice, str.(T)) | ||
} | ||
return slice | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. . The code patch adds a new function convertSlice[T int | string | any](key, value any) ([]T, error). It looks like it is used to convert any type of slice. The main purpose of this patch is to add support for REQUIRE_STRING_SLICE type in the Build() function. However, it is possible that the convertSlice() function can be used in other parts of the code. The code looks correct and there are no potential bugs. However, it may be improved by adding more documentation and comments to better explain the purpose of the function. Additionally, it may be useful to add unit tests for the added code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. our code review The patch looks ok. The only thing I would suggest is to add more comments to explain the logic behind the new code. Additionally, it would be better if you could provide more context about the changes and why it was done. For example, why did you decide to use Apart from that, I think the code is well written and should work without any major issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the review: The patch looks okay, but there are some improvements that can be made. First, the type of value passed to convertSlice should be checked to make sure it is an array before attempting to cast it. Second, the return type of convertSlice should also be checked to ensure that it is of the correct type (int, string, or any). Finally, the error codes for errno should be updated to match the new function name. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,14 @@ func (dc *DiskConfig) getInt(i *comm.Item) int { | |
return v.(int) | ||
} | ||
|
||
func (hc *DiskConfig) getBool(i *comm.Item) bool { | ||
v := hc.get(i) | ||
if v == nil { | ||
return false | ||
} | ||
return v.(bool) | ||
} | ||
|
||
func (dc *DiskConfig) getStrSlice(i *comm.Item) []string { | ||
v := dc.get(i) | ||
if v == nil { | ||
|
@@ -65,6 +73,7 @@ func (dc *DiskConfig) getStrSlice(i *comm.Item) []string { | |
|
||
func (dc *DiskConfig) GetContainerImage() string { return dc.getString(CONFIG_GLOBAL_CONTAINER_IMAGE) } | ||
func (dc *DiskConfig) GetFormatPercent() int { return dc.getInt(CONFIG_GLOBAL_FORMAT_PERCENT) } | ||
func (dc *DiskConfig) GetServiceMount() bool { return dc.getBool(CONFIG_GLOBAL_SERVICE_MOUNT_DEVICE) } | ||
func (dc *DiskConfig) GetHost() []string { return dc.getStrSlice(CONFIG_GLOBAL_HOST) } | ||
func (dc *DiskConfig) GetDevice() string { return dc.getString(CONFIG_DISK_DEVICE) } | ||
func (dc *DiskConfig) GetMountPoint() string { return dc.getString(CONFIG_DISK_MOUNT_POINT) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code review
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code patch appears to be valid and should not contain any bugs. However, there is a lack of documentation on the purpose of the new getBool method which makes it difficult to understand how it contributes to the overall functionality. Adding more comments to explain the intent of the method will be helpful. It would also be beneficial to add some tests to ensure that the new code works correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with code review:
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,12 +48,20 @@ var ( | |
DEFAULT_FORMAT_PERCENT, | ||
) | ||
|
||
CONFIG_GLOBAL_SERVICE_MOUNT_DEVICE = itemset.Insert( | ||
common.DISK_SERVICE_MOUNT_DEVICE, | ||
comm.REQUIRE_BOOL, | ||
false, | ||
false, | ||
) | ||
|
||
CONFIG_GLOBAL_HOST = itemset.Insert( | ||
common.DISK_FILTER_HOST, | ||
comm.REQUIRE_SLICE, | ||
comm.REQUIRE_STRING_SLICE, | ||
false, | ||
nil, | ||
) | ||
|
||
CONFIG_DISK_DEVICE = itemset.Insert( | ||
common.DISK_FILTER_DEVICE, | ||
comm.REQUIRE_STRING, | ||
|
@@ -70,7 +78,7 @@ var ( | |
|
||
CONFIG_DISK_HOST_EXCLUDE = itemset.Insert( | ||
common.DISK_EXCLUDE_HOST, | ||
comm.REQUIRE_SLICE, | ||
comm.REQUIRE_STRING_SLICE, | ||
false, | ||
nil, | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code review. Firstly, I would suggest to check the type of the variables declared in the code patch. For example, the variable CONFIG_GLOBAL_SERVICE_MOUNT_DEVICE should be set as a boolean value, while the variables CONFIG_GLOBAL_HOST and CONFIG_DISK_HOST_EXCLUDE should be set as string slices. Secondly, I would suggest to check the order of the variables declared in the code patch. It is better to have all the variables of the same type grouped together. Thirdly, I would suggest to check if there are any unnecessary lines of code in the code patch. If yes, then remove them to reduce the complexity of the code. Finally, I would suggest to check for any potential bugs that could arise due to the changes made in the code patch. For example, if the changes made in the code patch could lead to an unexpected result or an error, then appropriate measures should be taken to fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with the code review
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with code review
In conclusion, this code patch is well structured and should improve the accuracy of the data types. No bug risks have been identified. |
||
|
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 looks like the confirmation is required only if the length of disk records were changed. Is the confirmation necessary when there are any modification on any property(device, mount path, etc) of disk records ?
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 confirmation of
disk
number changing(add or delete) is a double confirmation to show user that what disk records will be added or deleted. The modification of other properties will be shown in the first confirmation which is the confirmation ofdisks
changing.