-
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
Conversation
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 comment
The reason will be displayed to describe this comment to others. Learn more.
the code review:
- The patch adds logic to the runFormat() function to check the chunkserverID and ServiceMountDevice values before formatting a disk.
- The new logic appears to be sound, however it is advisable to include some unit tests to ensure that the new logic works as expected.
- It might be beneficial to add some comments to the code explaining why this new logic is necessary.
- Additionally, if the ServiceMountDevice value is not set to 0 then the code should include some additional checks to ensure that the disk UUID will be written into the correct config file.
- curve-3 | ||
- device: /dev/sde1 | ||
mount: /data/chunkserver3 | ||
host: | ||
host: # override global host config, for the use case tht disk device only exists in some hosts | ||
- 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.
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.
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
with the code review
-
The code patch adds two new constants - DISK_SERVICE_MOUNT_DEVICE and DISK_FORMAT_PERCENT. This should be documented properly to give a better understanding of the purpose of the constants.
-
The DISK_EXCLUDE_HOST constant should also be documented as it is an important parameter that defines which hosts need to be excluded from the disk operations.
-
There should be some checks in place to ensure that the values assigned to the constants are valid. For example, the value of DISK_FORMAT_PERCENT should be checked to ensure it's a valid number between 0 and 100.
-
A unit test should be written to ensure that the code is working as expected. This will help in catching any bugs that might have been missed during the code review.
slice = append(slice, str.(T)) | ||
} | ||
return 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.
.
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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
the code review
- The code looks good and is easy to read.
- The function getBool() was added which is a good thing as it will help in getting a boolean value from the config.
- The function getStrSlice() was also added which is also a good thing as it will help in getting a string slice from the config.
- The function GetServiceMount() was also added which is a good thing as it will help in getting a boolean value from the config.
- There are no obvious bugs in the code, however it would be better to add some comments to the code for better understanding.
- It would be better to do some error handling in case of invalid input.
@@ -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 comment
The 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.
@@ -170,7 +191,7 @@ func NewDiskConfig(sequence int, config map[string]interface{}) *DiskConfig { | |||
} | |||
} | |||
|
|||
func ParseDisks(data string, curveadm *cli.CurveAdm) ([]*DiskConfig, error) { | |||
func ParseDisks(data string) ([]*DiskConfig, error) { | |||
parser := viper.NewWithOptions(viper.KeyDelimiter("::")) | |||
parser.SetConfigType("yaml") | |||
err := parser.ReadConfig(bytes.NewBuffer([]byte(data))) |
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.
with a brief code review.
- The
mergeFinalHost
function is missing error handling, it should return an error value if host to be excluded is not found in the global host list. - A comment can be added to the
GetDiskId
function to explain what kind of disk uri is valid. - The
ParseDisks
function is no longer needed a parametercurveadm *cli.CurveAdm
, this should be removed. - A comment can be added to describe the purpose of the
NewDiskConfig
function. - The
checkDupHost
function can have some more comments on its purpose and also to explain the logic it is using.
MountPoint string | ||
FormtPercent int | ||
FromDiskRecord bool | ||
ServiceMountDevice bool | ||
} | ||
|
||
Format struct { |
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.
by looking at the code patch
The code patch seems to have made some modifications to the struct FormatConfig. The changes include the addition of two variables FromDiskRecord and ServiceMountDevice, as well as changes to existing variables ContainerImage, Host, Device, MountPoint, and FormtPercent. It looks like the intent of these changes is to add more options for configuring the formatting of disks.
It is difficult to say whether or not there are any bugs present in the code without performing a more thorough code review. However, it is important to make sure that the changes made make sense and are properly implemented. It is also important to make sure that any new variables are properly documented and used in the appropriate places.
In terms of improvement suggestions, it would be helpful to make sure that any new variables are properly validated, and that any changes made to existing variables do not break existing code. Additionally, it would be useful to make sure that any changes are tested thoroughly before being released into production.
@@ -32,7 +32,7 @@ const ( | |||
REQUIRE_STRING | |||
REQUIRE_BOOL | |||
REQUIRE_POSITIVE_INTEGER | |||
REQUIRE_SLICE | |||
REQUIRE_STRING_SLICE | |||
|
|||
// default value | |||
DEFAULT_REPORT_USAGE = true |
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.
with the code review
- The code patch looks valid and there are no bugs present.
- Suggestion: use a more descriptive variable name for REQUIRE_STRING_SLICE, such as REQUIRE_STRING_ARRAY.
- Suggestion: use a more descriptive variable name for DEFAULT_REPORT_USAGE, such as DEFAULT_USAGE_REPORT.
@@ -543,7 +544,7 @@ var ( | |||
ERR_START_CRONTAB_IN_CONTAINER_FAILED = EC(690000, "start crontab in container failed") | |||
|
|||
// 800: deploy | |||
ERR_DISK_DEVICE_NOT_FORMATTED = EC(800000, "disk device not formatted") | |||
ERR_DISK_DEVICE_NOT_FORMATTED = EC(800000, "disk device is unformatted") | |||
|
|||
// 900: others | |||
ERR_CANCEL_OPERATION = EC(CODE_CANCEL_OPERATION, "cancel operation") |
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 review
1.The code looks syntactically correct.
2.For better readability, it is advisable to add comments about the purpose of adding these lines.
3.In line 544, "disk device is unformatted" instead of "disk device not formatted" should be used for clarity.
4.It is recommended to add tests to ensure that the code is behaving properly.
5.It is also recommended to add error handling to ensure that any errors are handled properly.
|
||
SET_DISK = `UPDATE disk SET disk_format_mount_point = ?, format_percent = ?, | ||
container_image_location = ?,lastmodified_time = datetime('now','localtime') WHERE id = ?` | ||
container_image = ?, service_mount_device = ?, | ||
lastmodified_time = datetime('now','localtime') WHERE id = ?` | ||
|
||
SET_DISK_URI = `UPDATE disk SET uri = ?, | ||
lastmodified_time = datetime('now','localtime') WHERE host = ? AND device = ?` |
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.
with the code review:
-
The code patch adds a new column 'service_mount_device' to the table 'disk' and also adds this field to the INSERT and UPDATE queries. This is correct and helps in data integrity.
-
The code patch also changes the column name 'container_image_location' to 'container_image'. This could be done for better readability, but it should be tested to make sure there are no bugs due to this change.
-
The code patch also adds the 'service_mount_device' field to the INSERT and UPDATE queries. This is correct and helps in data integrity.
-
The code patch also changes the query for SET_DISK to include the new field. This is again correct and helps in data integrity.
-
The code patch also changes the query for SET_DISK_URI to include the new field. This is again correct and helps in data integrity.
Overall, the code patch looks correct and helps in data integrity. However, it should be tested to make sure there are no bugs due to the changes made.
@@ -413,6 +423,7 @@ func (s *Storage) GetDisk(filter string, args ...interface{}) ([]Disk, error) { | |||
&disk.FormatPercent, | |||
&disk.ContainerImage, | |||
&disk.ChunkServerID, | |||
&disk.ServiceMountDevice, | |||
&disk.LastmodifiedTime) | |||
diskRecords = append(diskRecords, 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.
with the code review:
- The code patch adds a new field, ServiceMountDevice, to Disk struct. This field is used to store the service mount device information.
- In SetDisk function, the new field is added in the INSERT_DISK query and in the SET_DISK query.
- In GetDisk function, the new field is added to the SQL query result.
- In UpdateDiskURI function, no changes are made.
Overall, the code patch looks good and there are no major bugs or risks. However, I suggest adding an additional validation check to the SetDisk function to ensure that the ServiceMountDevice parameter is valid before inserting it into the database.
Add an UT |
} | ||
|
||
// update disk size and uri(diskId) when use disk records commited by disks yaml | ||
if fc.FromDiskRecord { | ||
t.AddStep(&step2UpdateDiskSizeUri{ | ||
host: host, | ||
device: device, |
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.
form the code review.
-
The code looks good, it is well organized and easy to read. It follows standard coding conventions and there are no syntax errors.
-
The code is using if-else conditions correctly which will ensure that the program runs as expected.
-
The code is using comments correctly which helps in understanding the code better.
-
The code could use some improvements, like adding more checks to ensure that the data is valid before processing it. This would help in preventing any unexpected errors in the future.
-
The code could also benefit from using better variable names and a more descriptive naming convention. This would improve readability and make the code easier to maintain.
serviceId: serviceId, | ||
storage: curveadm.Storage(), | ||
execOptions: curveadm.ExecOptions(), | ||
}) | ||
|
||
return t, nil | ||
} |
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 code looks correct, and it seems to add a new step for cleaning disk device of the given service id.
- Since the code only supports one disk device per service, it is better to put a check before the code and make sure there is only one disk device associated with the service id.
- Also, when mounting the disk device back to host, it is necessary to check if the mount point exists and create it if not.
- Besides, please add log message at the beginning and end of the code when the disk device is being cleaned.
Ulimits: []string{"core=-1"}, | ||
Volumes: getMountVolumes(dc), | ||
Volumes: getMountVolumes(dc, serviceMountDevice), | ||
Out: &containerId, | ||
ExecOptions: curveadm.ExecOptions(), | ||
}) |
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.
with the code review
The code patch looks good and does not contain any obvious bugs. However, there are some improvements that can be made.
First of all, it would be better to separate the logic for mounting disks in a separate function, as this is something that could be reused in other parts of the code. Additionally, the parameters to the getMountVolumes() and getRestartPolicy() functions should be updated to include the serviceMountDevice boolean.
Another suggestion would be to use a switch statement instead of if statements for the role. This will make the code more readable and easier to maintain in the future.
Finally, it would be best to add some comments to explain what each block of code is doing, as this will help other developers who may need to work on the code in the future.
Overall, the code looks good and should be safe to use.
ExecOptions: curveadm.ExecOptions(), | ||
}) | ||
} | ||
|
||
t.AddStep(&step.StartContainer{ | ||
ContainerId: &containerId, | ||
ExecOptions: curveadm.ExecOptions(), |
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.
with Code review
- Check indentation, spacing, readability of the code
- Confirm that the functions and variables are named properly
- Confirm that the imported libraries are necessary
- Check for missing return statements
- Check for any potential vulnerabilities (e.g. SQL injection)
- Confirm that the code is performant and efficient
- Confirm that the code is well tested
- Confirm that the code follows security best practices
ExecOptions: curveadm.ExecOptions(), | ||
}) | ||
} | ||
|
||
t.AddStep(&step.StartContainer{ | ||
ContainerId: &containerId, | ||
ExecOptions: curveadm.ExecOptions(), |
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 code review:
- The code looks well organized and easy to read.
- Good practice to add comments in code to explain the purpose of each block of code.
- There is no obvious bug risk in this code.
- Suggestion for improvement: Consider adding validations for all input parameters to ensure their values are within an acceptable range.
ad5f649
to
98fdad2
Compare
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 comment
The reason will be displayed to describe this comment to others. Learn more.
- The code looks clean and well-structured.
- There is a risk that dr.ServiceMountDevice != 0 could cause unexpected behavior if it is not properly handled.
- There is a potential bug with the condition if dr.ChunkServerID != comm.DISK_DEFAULT_NULL_CHUNKSERVER_ID, as the variable should be dr.ChunkServerID instead of dr.ChunkServerID.
- It is advisable to add comments to explain what the code is doing and also add some logging statements to help with debugging.
- 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 comment
The reason will be displayed to describe this comment to others. Learn more.
with code review.
- Code Structure: The code structure looks good and easy to read.
- Comments: The comments provided throughout the code give a good indication of what each section does.
- Variables: The variables are named well and are self-explanatory.
- Security: No security risks were identified in the code.
- Performance: The code looks optimised for performance.
Suggestions:
- Add more comments to explain the usage of certain variables.
- Make sure that the mount points for each disk device is consistent with the "data_dir" field of chunkserver service in topology.
- Check if all hosts have the same version of opencurvedocker/curvebs.
|
||
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 comment
The 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.
slice = append(slice, str.(T)) | ||
} | ||
return 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.
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 convertSlice
instead of REQUIRE_SLICE
?
Apart from that, I think the code is well written and should work without any major issues.
@@ -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 comment
The 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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
with the code review
- The patch adds a new variable CONFIG_GLOBAL_SERVICE_MOUNT_DEVICE with a bool value, this is fine.
- The patch changes the data type of CONFIG_GLOBAL_HOST to comm.REQUIRE_STRING_SLICE, this is also fine.
- The patch changes the data type of CONFIG_DISK_HOST_EXCLUDE to comm.REQUIRE_STRING_SLICE, this is also fine.
Overall, the patch looks good and there are no bugs or risks that can be seen from it. However, you should make sure that all the variables and values used in the code are correct and valid.
@@ -170,7 +191,7 @@ func NewDiskConfig(sequence int, config map[string]interface{}) *DiskConfig { | |||
} | |||
} | |||
|
|||
func ParseDisks(data string, curveadm *cli.CurveAdm) ([]*DiskConfig, error) { | |||
func ParseDisks(data string) ([]*DiskConfig, error) { | |||
parser := viper.NewWithOptions(viper.KeyDelimiter("::")) | |||
parser.SetConfigType("yaml") | |||
err := parser.ReadConfig(bytes.NewBuffer([]byte(data))) |
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 code review:
- The function "mergeFinalHost" should return an error type to indicate whether the exclusion of host is successful or not.
- Check if the host to be excluded is a member of global host list before exclude it.
- The function "returnInvalidDiskUriError" should be declared outside the "GetDiskId" function, this will make the code more readable.
- The function "GetDiskId" should return an error type to indicate whether get disk id is successful or not.
- Add log statement in the function "ParseDisks" to track the process.
MountPoint string | ||
FormtPercent int | ||
FromDiskRecord bool | ||
ServiceMountDevice bool | ||
} | ||
|
||
Format struct { |
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.
with the code review
- The code seems to have a logical flow and is easy to read.
- The use of indentation and spacing is good and consistent.
- There is an additional field "ServiceMountDevice" added to the struct FormatConfig. We need to ensure that this field is used properly and checked for any edge cases.
- The spelling of one field in the struct has been corrected from ContainerIamge to ContainerImage.
- There is an additional boolean field "FromDiskRecord" added to the struct FormatConfig to indicate if the disk record should be used or not. This field should be checked for any errors or edge cases.
- The code is well commented and easy to understand.
@@ -32,7 +32,7 @@ const ( | |||
REQUIRE_STRING | |||
REQUIRE_BOOL | |||
REQUIRE_POSITIVE_INTEGER | |||
REQUIRE_SLICE | |||
REQUIRE_STRING_SLICE | |||
|
|||
// default value | |||
DEFAULT_REPORT_USAGE = true |
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.
with a brief code review
The patch you provided changes the type of a constant from REQUIRE_SLICE to REQUIRE_STRING_SLICE. This indicates that we are now expecting a slice of strings rather than a regular slice. This change should be thoroughly tested to ensure that it doesn't cause any unexpected behavior, and that it still provides the expected results. In addition, any other code that relies on the value of this constant should also be checked to ensure that it is not affected by the change. Finally, it would be beneficial to document this change to ensure that all future developers are aware of it.
@@ -543,7 +544,7 @@ var ( | |||
ERR_START_CRONTAB_IN_CONTAINER_FAILED = EC(690000, "start crontab in container failed") | |||
|
|||
// 800: deploy | |||
ERR_DISK_DEVICE_NOT_FORMATTED = EC(800000, "disk device not formatted") | |||
ERR_DISK_DEVICE_NOT_FORMATTED = EC(800000, "disk device is unformatted") | |||
|
|||
// 900: others | |||
ERR_CANCEL_OPERATION = EC(CODE_CANCEL_OPERATION, "cancel operation") |
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.
with code review
-
The first line of the patch adds a new error code, which is a good practice to ensure that errors are properly tracked and handled.
-
The second line changes the existing error code from "disk device not formatted" to "disk device is unformatted". This change helps to make the message more descriptive and easier to understand for the user.
-
The code looks well-structured and all necessary fields have been included. Additionally, there are no bugs or potential risks in the code.
Overall, the code looks good and is ready for deployment.
|
||
SET_DISK = `UPDATE disk SET disk_format_mount_point = ?, format_percent = ?, | ||
container_image_location = ?,lastmodified_time = datetime('now','localtime') WHERE id = ?` | ||
container_image = ?, service_mount_device = ?, | ||
lastmodified_time = datetime('now','localtime') WHERE id = ?` | ||
|
||
SET_DISK_URI = `UPDATE disk SET uri = ?, | ||
lastmodified_time = datetime('now','localtime') WHERE host = ? AND device = ?` |
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.
with the first patch
The first patch adds a new field service_mount_device
to the disk
table. This is a good addition as it will allow us to track which devices are being used for the service mount. The data type for this field should also be checked to ensure that it is appropriate for the application.
The second patch updates the SET_DISK
query to include the new service_mount_device
field and updates the SET_DISK_URI
query to include the uri
field. This looks good, but it should be tested to make sure that the queries are working correctly and that the data is being updated correctly.
@@ -413,6 +423,7 @@ func (s *Storage) GetDisk(filter string, args ...interface{}) ([]Disk, error) { | |||
&disk.FormatPercent, | |||
&disk.ContainerImage, | |||
&disk.ChunkServerID, | |||
&disk.ServiceMountDevice, | |||
&disk.LastmodifiedTime) | |||
diskRecords = append(diskRecords, 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.
with a code review:
-
The patch adds an additional
ServiceMountDevice
field to theDisk
struct, which should be used to store the device id used by the service for mount the disk. -
The
SetDisk
function has been updated to accept an additional argument forserviceMountDevice
. -
The
UpdateDiskURI
function has been updated to include a check for the existence of theServiceMountDevice
field. -
The
GetDisk
function has been updated to include theServiceMountDevice
field in the query results.
Overall, the patch looks good. There are no obvious bugs or risks. However, it may be worth adding a comment to the SetDisk
and UpdateDiskURI
functions explaining why the ServiceMountDevice
field is being used.
} | ||
|
||
// update disk size and uri(diskId) when use disk records commited by disks yaml | ||
if fc.FromDiskRecord { | ||
t.AddStep(&step2UpdateDiskSizeUri{ | ||
host: host, | ||
device: device, |
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.
with the code review:
- The code looks well organized and easy to read.
- There is a check for the "ServiceMountDevice" flag that determines whether or not to write the disk UUID into /etc/fstab for host mounting.
- The code also checks for the "FromDiskRecord" flag, which is used to update the disk size and uri (diskId) when using disk records committed by disks yaml.
- No bugs were spotted in the code.
- No improvement suggestions were identified.
serviceId: serviceId, | ||
storage: curveadm.Storage(), | ||
execOptions: curveadm.ExecOptions(), | ||
}) | ||
|
||
return t, nil | ||
} |
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.
with the code review
- The code patch has added a step to clean disk service id, which is a good practice.
- An additional step was added to mount the disk device back to the host for data cleaning. This is also a good practice.
- Make sure to add proper checks and validation for all the input parameters.
- To avoid any potential issues, check for potential errors/exceptions when performing operations on the disk.
- Make sure to properly log errors or exceptions.
ExecOptions: curveadm.ExecOptions(), | ||
}) | ||
} | ||
|
||
t.AddStep(&step.StartContainer{ | ||
ContainerId: &containerId, | ||
ExecOptions: curveadm.ExecOptions(), |
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.
with the Code Review.
- The code appears to be importing the necessary packages for the task, and is adding steps to the task. This is good.
- It appears that the code is attempting to unmount a disk device from host, which will then be mounted in service (chunkserver) container. This is also good, as it ensures the disk device is not being used elsewhere.
- However, it is unclear why the device is not being unmounted in the same step as the mount occurs. It may be worthwhile to add a step to unmount the device before the mount step is executed.
- Additionally, there appears to be no error handling for the umount step. It would be worth adding some form of error handling to ensure that the umount step is successful before proceeding with the rest of the task.
- Furthermore, it may be worthwhile to add an additional check to ensure that the disk device is actually found before attempting to unmount it. This could be done by adding a "IgnoreNotFound" flag to the UmountFilesystem step.
Overall, the code looks good, but there are a few areas where improvements can be made to ensure the task is successful.
Disk UUID will be wrote into the config of service(chunkserver) container during curvebs deployment if disks `service_mount_device` was set `true`, then the service could directly mount disk device via `entrypoint.sh` and restart automatically after host power recover. Signed-off-by: Lijin Xiong <[email protected]>
98fdad2
to
2c50545
Compare
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 comment
The reason will be displayed to describe this comment to others. Learn more.
with the code review:
-
The first part of the code snippet checks the error from a given function and returns it if it exists. This is good practice, as it allows for errors to be easily identified and handled by the program.
-
The second part sets the "FromDiskRecord" flag to true. This is necessary to ensure that the disk record is properly read before formatting the disk.
-
The third part checks the "ServiceMountDevice" flag, and if it is set to 1, the "ServiceMountDevice" flag is set to true. This ensures that the disk UUID will be written into the config of the service (chunkserver) container for disk automatic mounting.
-
The fourth part checks if the chunkserverId is not the default null chunkserver id, and if so, skips formatting the disk. This is important to avoid data loss.
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.
- 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review:
-
Global format_percent and service_mount_device:
The global format_percent and service_mount_device variables should be placed at the top of the configuration. This allows for easier debugging and editing. -
Disk device and mount point:
The disk device and mount point should be clearly labeled and the default value for service_mount_device should be clarified in the comments. -
Exclude and host override:
The exclude and host override options should be documented more clearly with examples so that users know how to use them.
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
with the code review
-
The patch adds a new constant
DISK_SERVICE_MOUNT_DEVICE
which seems to be related to disk service mount device. The name is meaningful and consistent with other constants. -
The patch also adds
DISK_FORMAT_PERCENT
which looks like one of the formatting options for disk usage. The name is also meaningful and consistent. -
The indentation of the code is correct and in-line with existing code.
-
There are no bugs or risks associated with the patch, and it should be safe to deploy.
-
There is no room for improvement in this patch.
slice = append(slice, str.(T)) | ||
} | ||
return 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.
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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
with code review:
- The code looks good and the function getBool() is correctly implemented to return false when the value is nil.
- However, there is no check on the type of the value returned in each function. For example, if the return value of getString() is not of type string it will lead to a runtime exception. Therefore, it is suggested to add type checks to each getter function.
- The naming convention for the functions could be improved. For example, getBool could be renamed to something like getBoolValue().
- Also, it would be better to use descriptive variable names instead of single characters like 'v'.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
with code review
- The code patch adds a new configuration item "CONFIG_GLOBAL_SERVICE_MOUNT_DEVICE" with a boolean type, which is missing in the original code. This item should be added to provide more flexibility for users to customize.
- For CONFIG_GLOBAL_HOST, the data type is changed from comm.REQUIRE_SLICE to comm.REQUIRE_STRING_SLICE, which should improve the accuracy of the data.
- For CONFIG_DISK_HOST_EXCLUDE, the data type is changed from comm.REQUIRE_SLICE to comm.REQUIRE_STRING_SLICE, which should improve the accuracy of the data.
In conclusion, this code patch is well structured and should improve the accuracy of the data types. No bug risks have been identified.
@@ -170,7 +191,7 @@ func NewDiskConfig(sequence int, config map[string]interface{}) *DiskConfig { | |||
} | |||
} | |||
|
|||
func ParseDisks(data string, curveadm *cli.CurveAdm) ([]*DiskConfig, error) { | |||
func ParseDisks(data string) ([]*DiskConfig, error) { | |||
parser := viper.NewWithOptions(viper.KeyDelimiter("::")) | |||
parser.SetConfigType("yaml") | |||
err := parser.ReadConfig(bytes.NewBuffer([]byte(data))) |
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.
to do a brief code review of the patch.
Firstly, I noticed that in line 69, the variable type declared for the hostExcludeMap variable is incorrect, it should be a map[string]bool instead of a map[string]string.
Secondly, in line 75, a check should be added to check if the host to be excluded is actually a member of the global host list, otherwise an error should be returned.
Thirdly, in line 97, the GetDiskId function should take the disk as an argument.
Fourthly, in line 110, the return statement for the GetDiskId function should include the diskUriProto and an error.
Lastly, in line 137, the mergeFinalHost function should be called and an error should be checked for.
I hope this helps.
MountPoint string | ||
FormtPercent int | ||
FromDiskRecord bool | ||
ServiceMountDevice bool | ||
} | ||
|
||
Format struct { |
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.
with a brief overview of the patch.
This patch is for a type declaration for the FormatConfig struct in the code. The patch adds a new field, ServiceMountDevice, and modifies the existing fields ContainerImage, Host, Device, MountPoint, FormatPercent, and FromDiskRecord. This appears to be for a configuration for formatting a disk or device.
In terms of code review, I would recommend making sure that all of the changes are necessary and that they are correctly implemented. Additionally, the naming conventions should be checked to ensure that everything is consistent. Any comments or documentation should also be checked to make sure that it accurately reflects the changes and provides enough information for other developers. Finally, if there are any performance or security considerations, those should be taken into account.
@@ -32,7 +32,7 @@ const ( | |||
REQUIRE_STRING | |||
REQUIRE_BOOL | |||
REQUIRE_POSITIVE_INTEGER | |||
REQUIRE_SLICE | |||
REQUIRE_STRING_SLICE | |||
|
|||
// default value | |||
DEFAULT_REPORT_USAGE = true |
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.
with a brief code review
First of all, in this patch, the line at -32 and +32 have been changed from REQUIRE_SLICE to REQUIRE_STRING_SLICE. This change is valid as it ensures that only string values will be accepted in the slice.
However, there may be a risk that changing the type from a generic slice to one that only accepts strings could cause unexpected issues. It would be best to test the code to ensure that the changes don't break existing functionality.
In addition, there is a new constant at line 35, DEFAULT_REPORT_USAGE, which has a default value of true. This could lead to unnecessary overhead when running the code, so it should be tested to make sure that it is necessary and not causing any performance issues.
@@ -543,7 +544,7 @@ var ( | |||
ERR_START_CRONTAB_IN_CONTAINER_FAILED = EC(690000, "start crontab in container failed") | |||
|
|||
// 800: deploy | |||
ERR_DISK_DEVICE_NOT_FORMATTED = EC(800000, "disk device not formatted") | |||
ERR_DISK_DEVICE_NOT_FORMATTED = EC(800000, "disk device is unformatted") | |||
|
|||
// 900: others | |||
ERR_CANCEL_OPERATION = EC(CODE_CANCEL_OPERATION, "cancel operation") |
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 code review:
-
The first snippet of code adds a new error code to the existing list of error codes. This is a valid addition and all the error codes should have a unique code with a descriptive message.
-
The second snippet of code changes the error message for an existing error code. The change is valid as it provides a more descriptive message for the same error.
|
||
SET_DISK = `UPDATE disk SET disk_format_mount_point = ?, format_percent = ?, | ||
container_image_location = ?,lastmodified_time = datetime('now','localtime') WHERE id = ?` | ||
container_image = ?, service_mount_device = ?, | ||
lastmodified_time = datetime('now','localtime') WHERE id = ?` | ||
|
||
SET_DISK_URI = `UPDATE disk SET uri = ?, | ||
lastmodified_time = datetime('now','localtime') WHERE host = ? AND device = ?` |
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.
-
Checking the variable declarations:
The variable SET_DISK has been modified to add an extra variable service_mount_device, which is required to store the value of the device to mount the service. The variable SET_DISK_URI has also been modified to include an extra parameter for the uri. These changes look valid and there should be no issues with these. -
Checking the query syntax:
The syntax of the queries looks valid and there are no issues with it. -
Checking for any potential bugs or security risks:
There are no potential bugs or security risks that I can see in the code patch. -
Suggestions for improvement:
I suggest adding comments to the code to make it more readable and understandable. Additionally, I suggest adding validation checks for all the parameters being passed to the queries. This will help to prevent malicious input from being passed to the database.
diff := utils.Diff(oldDiskRecordsString, newDiskRecordsString) | ||
curveadm.WriteOutln(diff) | ||
} | ||
if len(newDiskRecords) != len(oldDiskRecords) { |
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 of disks
changing.
@@ -32,7 +32,7 @@ const ( | |||
REQUIRE_STRING | |||
REQUIRE_BOOL | |||
REQUIRE_POSITIVE_INTEGER | |||
REQUIRE_SLICE | |||
REQUIRE_STRING_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.
Should const REQUIRE_STRING_SLICE
in dc_item.go
be removed since const REQUIRE_STRING_SLICE
in item_set.go
covers most cases ?
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.
Yeah, it is unnecessary.
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!
LGTM! |
Disk UUID will be passed to container Cmd config during curvebs deployment if disk service_mount_device was enabled, then service(chunkserver) cloud mount disk via entrypoint.sh and restart automatically after host power recover.
to #147 and #165
coordinate with curve pull request opencurve/curve#2285