-
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 #194
Conversation
if !pass { | ||
curveadm.WriteOut(tuicomm.PromptCancelOpetation("commit disk table")) | ||
return errno.ERR_CANCEL_OPERATION | ||
} | ||
} | ||
|
||
// write new 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.
with the code review:
-
It looks like a variable
serviceMountDevice
was added in line 98, this variable should be initialized to 0 rather than an arbitrary number. -
In the function
writeDiskRecord
the linesif diskRecords, err := curveadm.Storage().GetDisk(common.DISK_FILTER_DEVICE, dr.Host, dr.Device); err != nil {
and} else if len(diskRecords) == 0 {
should be removed as they are redundant. -
In the function
syncDiskRecords
a check should be added to ensure that the number of new disk records is equal to the number of old disk records before confirming if the user wants to continue. -
The variable
keySep
in the functionassambleNewDiskRecords
should be declared as a constant as it has a fixed value. -
The code should be formatted consistently across the patch to improve readability.
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.
- Done.
- Already done.
- Done.
- Already done, the code are formatted consistently by VSCode.
@@ -156,6 +156,9 @@ func runFormat(curveadm *cli.CurveAdm, options formatOptions) error { | |||
return err | |||
} | |||
fc.UseDiskUri = true | |||
if dr.ServiceMountDevice != 0 { | |||
fc.ServiceMountDevice = true | |||
} | |||
chunkserverId := dr.ChunkServerID | |||
if len(chunkserverId) > 1 { | |||
// skip formatting the disk with nonempty chunkserver id |
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 good and there are no obvious bugs. However, it would be better to add some comment in the code to provide a better explanation of why ServiceMountDevice is being set to true. Additionally, it would be helpful to add an error handling block if the ServiceMountDevice field is not valid. This can help to detect any errors at runtime and prevent any unexpected behavior.
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.
@@ -1,6 +1,7 @@ | |||
global: | |||
format_percent: 95 | |||
container_image: opencurvedocker/curvebs:v1.2 | |||
service_mount_device: false # disk device will be mounted by service containers of curvebs if set "true", default "false" | |||
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.
the code review
- The code looks correct and it should work as expected.
- However, it's better to add comments to explain what the new configuration does.
- The value of the service_mount_device parameter can be set to true or false. It is better to add a comment explaining the behaviour when each value is set.
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.
|
||
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 a brief review
Firstly, it looks like the DISK_EXCLUDE_HOST constant is not being used at all. It should be removed to avoid any confusion.
Secondly, DISK_SERVICE_MOUNT_DEVICE has been added which seems to be related to the service and mount constants. This is fine but you should provide more information about why this is needed.
Lastly, DISK_FORMAT_PERCENT has been moved from the end of the list to the middle. This could lead to some confusion in code readability as the constants are ordered in an unusual way. It would be better to put the constants into some logical order.
Overall, the code patch looks good and the changes appear to be valid. However, more information should be provided to explain why the changes were made.
I hope this helps!
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.
DISK_EXCLUDE_HOST
is being used here:
CONFIG_DISK_HOST_EXCLUDE = itemset.Insert(
common.DISK_EXCLUDE_HOST,
comm.REQUIRE_SLICE,
false,
nil,
)
- The comment of
DISK_SERVICE_MOUNT_DEVICE
is in the actual 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) } | |||
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 the code review
The code looks good, but there are a few points to consider.
- Proper naming of variables should be used to improve readability.
- The error handling should be improved to catch any unexpected errors.
- Make sure to use comments to explain the logic of the code.
- Make sure the code is properly tested for any bugs or unexpected behavior.
- Consider using constants for any hardcoded values instead of directly inserting them in the code.
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 variables IS named properly.
- It has value type checking.
- The code logic is simple.
- self-tested.
- Proper constants are used.
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 need some unit tests according to the 4th suggestion
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 need some unit tests according to the 4th suggestion
Agree. Does curveadm
have a unit test framework? We indeed need to add some UT with every change.
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 need some unit tests according to the 4th suggestion
Agree. Does
curveadm
have a unit test framework? We indeed need to add some UT with every change.
We use go built-in unit testing and testify package to testifying our codes, there are a few test code:
We are so much lacking of unit tests and integration tests, it leads the curveadm often unstable. It would be a huge improvement if we had unit tests and integration tests to guarantee curveadm stability. but then again, i think the integration testing is not so easy to implement.
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, I noticed these test files. I thought they were just part of checker.
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.
That's true, integration test is more complicated, especially the automatic one. Some mocking mechanism need to be introduced for curveadm
.
CONFIG_GLOBAL_HOST = itemset.Insert( | ||
common.DISK_FILTER_HOST, | ||
comm.REQUIRE_SLICE, | ||
false, | ||
nil, | ||
) | ||
|
||
CONFIG_DISK_DEVICE = itemset.Insert( | ||
common.DISK_FILTER_DEVICE, | ||
comm.REQUIRE_STRING, |
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 variable CONFIG_GLOBAL_SERVICE_MOUNT looks like it should be a boolean value, however, the code is setting it to false which does not make sense.
- If the variable CONFIG_GLOBAL_HOST is intended as a slice, then it should also require a slice value in the itemset.Insert call.
- The CONFIG_DISK_DEVICE variable should have more descriptive name.
- The code should check if the values inserted into the itemset are valid before proceeding.
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 should be a boolean value, however, the code is setting it to false which does not make sense
, an AI bug?itemset.Insert
acceptsinterface{}
.CONFIG_DISK_DEVICE
is not an ambiguous name.- The value is validated in the logic of
item.Build
.
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 should be a AI bug, since there are no such variable called CONFIG_GLOBAL_SERVICE_MOUNT
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.
} | ||
return "", nil | ||
return "", "", nil | ||
} | ||
|
||
func (dc *DiskConfig) Build() 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.
with the code review:
-
In the GetDiskId() function, it appears that the return type has changed from (string, error) to (string, string, error). Is this intentional? If so, what is the second string value supposed to represent?
-
It appears that the logic for handling different protocols (DISK_URI_PROTO_FS_UUID) has been added to the GetDiskId() function. Is this necessary? Could a more modular approach be used to handle different protocols?
-
It appears that the error handling has been improved in GetDiskId() by returning an error message when an invalid disk URI is encountered. Is this adequate or should additional error checks be added?
-
Are there any other potential bugs or security risks in the code patch that should be addressed?
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.
All Done.
container_image_location = ?,lastmodified_time = datetime('now','localtime') WHERE id = ?` | ||
SET_DISK = `UPDATE disk SET disk_format_mount_point = ?, | ||
format_percent = ?, 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 a code review:
-
The code patch adds a new field 'service_mount_device' to the 'disk' table and updates the 'SET_DISK' query accordingly to include this field. This change appears to be valid and consistent with the database schema.
-
The 'INSERT' query has been updated to include the new field 'service_mount_device'. It is important to consider if this field is required for all 'INSERT' queries as it might make sense to include this field in the 'SET_DISK' query instead.
-
The 'SET_DISK_URI' query has not been updated to include the new field 'service_mount_device'. If this field is necessary for all 'SET_DISK_URI' queries, then it should be included.
-
The code does not appear to contain any bugs. However, it is always best practice to test the code to ensure that it behaves as expected.
Overall, the code appears to be valid and consistent with the database schema. However, it is important to consider if the new field 'service_mount_device' is necessary for all 'INSERT' and 'SET_DISK_URI' queries. If so, then it should be included in the queries. Additionally, it is always best practice to test the code to ensure that it behaves as expected.
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 is guaranteed by the logic of config getting.
- No,
SET_DISK_URI
has nothing to do withservice_mount_device
. - self-tested.
@@ -413,6 +422,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.
the code review
The code seems to be an implementation of a function for setting a disk. It looks like the function is using SQL queries to set the disk parameters. The code looks for an existing disk record in the database and then updates it with the new parameters.
There are a few potential bugs in the code:
- The code does not check for errors when executing the SQL queries which could lead to unexpected behavior.
- The code assumes that the disk record already exists in the database which could lead to errors if the record does not exist.
Suggestions for improvement:
- Add error checking to the SQL queries to make sure they execute successfully.
- Add a check to see if the disk record exists in the database before trying to update it.
- Add logging to the function to track changes to the 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.
- Already done.
- Already done.
- Already done with error message.
curveadm: curveadm, | ||
}) | ||
} | ||
|
||
if fc.UseDiskUri { | ||
t.AddStep(&step2UpdateDiskSizeUri{ | ||
host: host, |
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 valid and seems to be properly indented. It is consistent with formatting best practices.
-
The code adds a step to edit the FSTab only if the ServiceMountDevice flag is not set. This should help to prevent unnecessary steps from being executed.
-
There is no obvious risk of bugs in the code, but it would be helpful to add comments or documentation explaining why this step is necessary or what the code is doing. This will help other developers understand the code better.
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/task/task/bs/format_stop.go
Outdated
curveadm: curveadm, | ||
skipAdd: true, | ||
}) | ||
} | ||
|
||
// 2: list container id and add step to task | ||
t.AddStep(&step.ListContainers{ |
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 above code patch is used to add a step to the task based on a specific condition. The given condition is: "fc.ServiceMountDevice", which checks whether the "ServiceMountDevice" is true or not. If it is true then the step will be added to the task, otherwise it will be skipped.
In the code patch, there are no logical errors or bugs present and the code looks fine. However, there can be some improvement in the code. Firstly, it would be better to define the variable "fc.ServiceMountDevice" outside the if-block so that its scope can be increased and can be used anywhere in the function. Secondly, the variable names used in the code should have more meaningful names. For example, instead of "fc.ServiceMountDevice" we can use "shouldAddStep". This will make the code more readable and understandable.
Apart from this, the code looks good and does not have any critical bugs.
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.
fc.ServiceMountDevice
is a reference not a single variable.
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 agree with that it's unnecessary to add another variable like shouldAddStep
, but should we add some comments about why step2EditFSTab
is called when ServiceMountDevice
is false?
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 agree with that it's unnecessary to add another variable like shouldAddStep
, but should we add some comments about why step2EditFSTab
is called when ServiceMountDevice
is false?
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.
Remove this logic as skipAdd
is true when stop formatting, it actually removes nothing if we use disk config recorded in database.
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.
to review the code
- The aim of this code is to clean the disk service id, which is in the topology DeployConfig.
- The code is trying to mount the disk device back to host for data cleaning. It uses the step.MountFilesystem to do this.
- The code also use step.Scp to copy the recycleScript to the remote path.
- The step2CleanDiskChunkServerId is used to clean the disk service id.
Suggestions:
- Make sure that the step2CleanDiskChunkServerId is correctly implemented and verify it after deployment.
- Make sure that the disk device is correctly mounted to the host before data cleaning.
- Add error handling codes to handle errors during the disk cleaning process.
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 has only one SQL statement.
- Data cleaning will not be executed if mount disk failed.
- It cloud be done by another change, has nothing to do with this change.
AddHost: []string{fmt.Sprintf("%s:127.0.0.1", hostname)}, | ||
Envs: getEnvironments(dc), | ||
Hostname: hostname, | ||
Init: true, | ||
Name: hostname, | ||
Privileged: true, | ||
Restart: getRestartPolicy(dc), | ||
Restart: getRestartPolicy(dc, serviceMountDisk), | ||
Ulimits: []string{"core=-1"}, | ||
Volumes: getMountVolumes(dc), | ||
Out: &containerId, |
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 overall structure of the code looks good and is easy to follow. There are some areas of improvement and potential bug risks that could be addressed.
-
The function getRestartPolicy() has been updated to accept an additional argument - serviceMountDisk. This parameter should be checked for a valid value before using it, or an error should be returned if the value is invalid.
-
The extraParam string variable should be initialized to an empty string in case serviceMountDisk is false.
-
The function getArguments() should have its return type changed to string instead of []string to better reflect its purpose.
-
The variable names in the NewCreateContainerTask() function may be improved for clarity.
-
A comment should be added to explain what the purpose of each step in the tasks is.
These are some ideas that may help improve the quality of the patch.
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.
serviceMountDisk
is a boolean.- Done.
- This patch has no changes with
getArguments
. - This patch has no changes with
NewCreateContainerTask
. - It maybe improved by other change.
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 looks generally well formatted and organized, making it easy to read.
- There are some unused variables that could be removed, such as ‘out’ and ‘success’.
- The code should include more comments for clarity, especially in the 'checkContainerExist' function.
- The code should check for errors when getting the disk records, and handle them accordingly.
- The code should also check if the device is already mounted before attempting to unmount 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.
- It maybe improved by other change.
- It maybe improved by other change.
- Already done.
IgnoreUmounted
is settrue
.
101f5a7
to
23679c1
Compare
if !pass { | ||
curveadm.WriteOut(tuicomm.PromptCancelOpetation("commit disk table")) | ||
return errno.ERR_CANCEL_OPERATION | ||
} | ||
} | ||
|
||
// write new 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.
code review:
1.The constant HOST_DEVICE_SEP is added to replace the string ":" in the code, which is more versatile and easy to maintain;
2.The code in the assambleNewDiskRecords() function adds a variable serviceMountDevice to indicate whether the device is used to mount services;
3.The writeDiskRecord() function has been modified to call curveadm.Storage().SetDisk() directly;
4.Added a comparison of the length of newDiskRecords and oldDiskRecords to determine whether to prompt for confirmation before writing new 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.
Already done.
// into the config of service(chunkserver) container | ||
if dr.ServiceMountDevice != 0 { | ||
fc.ServiceMountDevice = true | ||
} | ||
chunkserverId := dr.ChunkServerID | ||
if len(chunkserverId) > 1 { | ||
// skip formatting the disk with nonempty chunkserver id |
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 well commented. The addition of the comment describing what "ServiceMountDevice" is, is helpful to understand the purpose of the code.
- The logic seems correct and there do not appear to be any risk of bugs.
- To improve the code, it could be broken into smaller, more readable chunks and additional comments could be added to explain the purpose of each block of code. Additionally, if the code is intended for a public repository, it should include additional documentation for other developers who may use the code.
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.
- 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.
the code review:
First of all, it is important to check that the syntax of the code is correct and there are no errors. Additionally, it is important to ensure that the code is understandable, efficient, and secure.
In this code patch, it appears that the formatting of the code is correct and the syntax is valid.
In terms of security, it is important to ensure that all user input is validated and that the code does not contain any vulnerabilities. In the code patch, it appears that all user input is taken into account, and there are no potential security vulnerabilities present.
The code also appears to be efficient, as it is written in a way that allows the program to perform its functions with minimal resource usage.
Finally, it is important to ensure that the code is understandable. In this code patch, the comments provided make the code easy to understand and explain the purpose of each line.
Overall, it appears that the code patch is well written and does not contain any issues.
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.
|
||
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 to the existing list of constants. Its purpose is unclear but it seems to be related to the existing constant DISK_FILTER_MOUNT and DISK_FILTER_SERVICE.
The patch also renames the existing constant DISK_FORMAT_PERCENT to DISK_FORMAT_PERCENT. This ensures that there are no conflicting names in the list of constants.
Finally, the patch also adds two new constants DISK_FORMAT_MOUNT_POINT and DISK_FORMAT_CONTAINER_IMAGE which appear to be related to disk formatting.
Overall, the patch looks to be well thought out and technically sound. No obvious bugs or risks have been identified. There may be opportunities for improvement, such as adding additional documentation to explain the purpose of the new constants.
@@ -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) } | |||
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 didn't have any syntax errors.
- The code implements a function getBool(), which will be used to get boolean values from the config file, so it can provide a better user experience.
- The function getBool() should also have a parameter to specify the variable name, or a reference to the variable to get the value of.
- The code should also include proper error handling code in case the variable is not found or the value is not in the expected format.
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.
Already done.
CONFIG_GLOBAL_HOST = itemset.Insert( | ||
common.DISK_FILTER_HOST, | ||
comm.REQUIRE_SLICE, | ||
false, | ||
nil, | ||
) | ||
|
||
CONFIG_DISK_DEVICE = itemset.Insert( | ||
common.DISK_FILTER_DEVICE, | ||
comm.REQUIRE_STRING, |
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 patch looks good and there are no obvious bugs in the patch.
- There is an extra configuration field called CONFIG_GLOBAL_SERVICE_MOUNT added which is useful for enabling or disabling disk service mount.
- The code is well organized and properly indented.
- The data types of the configuration fields have been appropriately set.
- The code patch is properly commented.
} | ||
return "", nil | ||
} | ||
|
||
func (dc *DiskConfig) Build() 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.
with a brief code review
The code patch looks ok, however there are some potential improvements. Firstly, it would be better to use more descriptive variable names. E.g. instead of "uriSlice" use something like "diskUriComponents". Secondly, consider introducing a separate function for handling the errors and avoid repeating code, e.g.
func returnInvalidUriError(disk storage.Disk) error {
return errno.ERR_INVALID_DISK_URI.
F("The URI[%s] of disk[%s:%s] is invalid", disk.Host, disk.Device, disk.URI)
}
Thirdly, consider adding some comments in the code to describe the purpose of the code and make it easier to read. Finally, it might be worth adding some unit tests to ensure the code is working as expected.
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.
MountPoint string | ||
FormtPercent int | ||
UseDiskUri 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 Code Review:
-
The code patch appears to add an additional field to the FormatConfig struct, named ServiceMountDevice. It looks like this field is intended to be a boolean value, and it has been added with a default value of false.
-
There are no apparent bugs in the code patch, but it might be beneficial to add a comment explaining what the ServiceMountDevice field is used for.
-
The formatting of the code looks good, with consistent spacing and indentation.
@@ -543,7 +543,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.
At first glance, this code appears to be a patch for an error message in the application. The change made is to replace the word "not" with "un" in the error message ERR_DISK_DEVICE_NOT_FORMATTED, from "disk device not formatted" to "disk device is unformatted". This change makes the error message more accurate and easier to understand.
However, it is important to ensure that the existing code is bug-free before making any changes. To do this, you can use a debugging tool to check for any errors or bugs that may exist in the code. Additionally, you should also consider using automated testing tools to test the code before making any changes.
Finally, if the code is being used in a production environment, you should consider doing a thorough code review to make sure that the code is working as expected and to identify any potential security risks.
|
||
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.
code review
-
In line 71, it looks like the variable "container_image_location" was changed to "container_image". Is this intentional? It would be best to add a comment to explain why this change was made.
-
In line 176, an additional parameter "service_mount_device" was added to the VALUES query. Is this value used in any other part of the code? If not, it may not be necessary to include it.
-
In line 181, a comment was added to explain the purpose of the SET_DISK query. This is a good practice, as it helps with readability and understanding of the code.
-
In line 184, an additional parameter "service_mount_device" was added to the SET_DISK query. Is this value used in any other part of the code? If not, it may not be necessary to include it.
Overall, it looks like the code patch is well written and uncomplicated. There are no major risks or bugs detected in this patch. However, it would be best to double-check that all the variables and parameters used are necessary or used elsewhere in the code.
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 is intentional, for the consistent of existed name
container_image
used in other code. - No.
- ditto.
- ditto.
@@ -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.
the code review
The code patch looks good and there does not appear to be any major bugs or risks. A few improvement suggestions for the code are:
- Add comments in the code to explain what the code is doing and why.
- Make sure variable names are descriptive and make sense.
- Ensure that all variables are properly initialized before use.
- Ensure that all parameters are validated and checked for errors before use.
- Check return values from function calls.
- Consider implementing logging or other forms of error tracking.
- Make sure to use proper coding conventions such as indentation, naming conventions, etc.
- Consider refactoring code to make it more readable and maintainable.
- Test the code to ensure it is working as intended.
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.
All Done.
CONFIG_GLOBAL_HOST = itemset.Insert( | ||
common.DISK_FILTER_HOST, | ||
comm.REQUIRE_SLICE, | ||
false, | ||
nil, | ||
) | ||
|
||
CONFIG_DISK_DEVICE = itemset.Insert( | ||
common.DISK_FILTER_DEVICE, | ||
comm.REQUIRE_STRING, |
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:
- There is no error checking for the value of CONFIG_GLOBAL_SERVICE_MOUNT_DEVICE, which could lead to potential errors in the program.
- The variable names should be more descriptive to help understand the purpose of each variable.
- The code can be improved by adding comments to explain the purpose of each variable and what it represents.
- It is recommended to use the constants in place of the literals so that the code is more maintainable.
} | ||
return "", nil | ||
} | ||
|
||
func (dc *DiskConfig) Build() 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.
!
I can see that there is a function GetDiskId() which is intended to get disk id, but it seems that it is not yet implemented.
First of all, the code seems to be missing some validation checks. The function GetDiskId() should have some validation checks to verify if the disk uri is in the correct format.
Also, I think it would be better to split up the logic into separate functions. For example, you could create a separate function to validate the disk URI and another to get the disk ID. This will help improve readability and maintainability of the code.
Lastly, it would be good to add comments to explain what the code is doing and why certain decisions were made. This will help other developers understand the code better.
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.
the code review
-
Variable names should be written in camelCase, for example: containerImage, host, device, mountPoint, formatPercent, fromDiskRecord, serviceMountDevice.
-
Documentation comments should be added to describe the purpose of the struct and the variables.
-
The boolean variable
FromDiskRecord
should be renamed tofromDiskRecord
to match the camelCase convention. -
It is not recommended to use underscores in variable names, as it can lead to confusion. For example,
ContainerIamge
should be changed tocontainerImage
. -
It is good practice to add a comment above each struct definition to explain what it represents.
-
A comment should also be added to explain the purpose of the
FormatConfig
struct.
@@ -543,7 +543,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:
First, the patch looks valid - there is a change of the value string of the ERR_DISK_DEVICE_NOT_FORMATTED constant. The original value is 'disk device not formatted' and the new value is 'disk device is unformatted'.
However, there may be some risks in this change. If this constant is used in the program logic, for example in an if-else statement, then the logic may be affected if the value does not accurately reflect the expected result of the condition set by the if-else statement. Therefore, it is important to review how this constant is used and to ensure that the new value is appropriate for the condition set by the if-else statement.
In addition, it is recommended to add more descriptive comments to the code to explain the purpose of the changes. This will help other developers who may review or work on the code in the future.
|
||
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 added line of code looks correct, as it is adding a new variable to the database table that can store the service mount device.
-
The changes in the code also seem correct, as the code is adding the new variable to the SELECT and SET statements.
-
It also appears that the lastmodified_time field is being updated whenever the disk information is changed, which is a good practice.
-
There is a risk of SQL injection, as user input is being used when inserting data into the database. To mitigate this risk, it would be best to use prepared statements or parameterized queries.
Overall, the code patch looks correct and there are no major bugs or issues. However, it would be best to use prepared statements or parameterized queries to prevent any potential SQL injection attacks.
@@ -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 first thing to notice is that the code in the patch adds the ServiceMountDevice variable to the Disk struct, which is a good addition. This means that the SetDisk() function has been modified to accept an additional parameter: the serviceMountDevice int. The new parameter is handled correctly, and the return statement has been updated to also include it.
The next thing to review is the GetDisk() function. This function has been updated to also retrieve the ServiceMountDevice variable. This is a good addition since it allows for more information to be retrieved about the disk.
Finally, the UpdateDiskURI() function has been modified to update the LastmodifiedTime field when the URI is updated. This is a sensible addition since it allows the user to keep track of when changes are made.
Overall, the code looks good and there don't seem to be any major issues or risks. One suggestion for improvement would be to add comments to the code to help explain the purpose of the changes.
} | ||
|
||
// 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.
the review.
First, it appears that there is a conditional statement that checks to see if the variable "fc.ServiceMountDevice" is false before continuing with the code patch. This is a good practice, as it prevents errors from occuring due to unexpected input.
The code also adds a comment explaining what "ServiceMountDevice" is and when it should be set. This helps to clarify the code and make it more understandable, which is important for future maintenance.
Finally, the code adds a step to update the disk size and URI when the disk records are committed by disks yaml. This is also a good practice, as it ensures that any changes made to the disk records are properly reflected in the code.
Overall, this code looks good and should not have any major bugs.
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 a brief Code review.
The code patch above looks good but there are a few improvements that can be made to ensure better performance and reliability.
First, the getMountVolumes() function has been modified to take an additional parameter (serviceMountDevice) to indicate if the service should mount the disk device directly in the container. This allows the code to handle different scenarios where the disk device is either mounted directly or via a volume bind.
Second, the getRestartPolicy() function has been modified to take the additional parameter. This is so that the policy can be adjusted depending on whether the disk device is mounted directly or via a volume bind.
Finally, the CreateContainer step has also been modified to pass the extra parameters and to use the updated restart policy.
Overall, the code looks good and should not have any major bugs or risks. However, it is always recommended to test the code thoroughly before deployment.
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 cloud mount disk via `entrypoint.sh` and restart automatically after host power recover. Signed-off-by: Lijin Xiong <[email protected]>
2ad43c8
to
7058a7b
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 code review of the above code.
- The code is written in a readable manner and is well commented which makes it fairly easy to understand.
- The code is checking for ServiceMountDevice value and if it is not 0, then it is setting the ServiceMountDevice flag to true. This could be improved by using an enum or constant for the ServiceMountDevice value instead of using a hard coded integer value.
- There is a check for the ChunkServerID and if it is not equal to the default null value, it skips formatting the disk. This check could be improved by adding a comment or description explaining why it's necessary to skip formatting the disk with a nonempty chunkserver id.
- There is a potential bug risk in that the code is not checking for errors when attempting to get the disk info. This should be added to ensure that any errors are properly handled.
In summary, the code looks good but could be improved by adding better comments and checks for errors.
- 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.
.
The code patch looks good, and there are no obvious bugs or issues. The new service_mount_device flag looks useful and is consistent with the rest of the configuration. The new exclude flag looks useful too, allowing users to exclude hosts from configuration.
There are some minor improvements that could be made. Firstly, it would be helpful to include a brief comment explaining what each field of the configuration does. Secondly, the formatting of the code could be improved by making sure all lines are indented correctly and using spaces instead of tabs.
Overall the code looks good and should be safe to use.
|
||
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.
:
- The variable names are descriptive, which is good.
- The code looks well-formatted and easy to read, that's great.
- The code adds two new constants, DISK_SERVICE_MOUNT_DEVICE, DISK_FORMAT_PERCENT, which is good.
- There is no bug risk identified in this patch.
- No improvement suggestion for 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 code contains a bug, in the
convertSlice[T int | string | any](key, value any) ([]T, error)
function, the switch statement should useT
instead ofanySlice[0].(type)
. - Another improvement recommendation is to add comments to explain the purpose of the
convertSlice
function.
@@ -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 patch is relatively clean and easy to understand. It is adding a new function which returns a boolean value to the existing DiskConfig class. The name of the new function is getBool, which is appropriate for what it is doing. The code is properly indented and the logic is easy to follow.
There are no obvious bugs in the code. However, it would be better to add some checks to make sure that the value being returned is actually a boolean type before returning it. This could be done by using an assertion or by using type switches.
Overall, the code is well written and should not have any major issues.
@@ -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:
- We can see that the code is trying to set up global variables for the application, and it looks like the variables are being set up correctly according to their specified data types.
- It looks like the code is using "itemset.Insert" to set up the variables. This is a good practice as it ensures that the variables are properly initialized and stored in a safe and secure way.
- It looks like the code is using the correct data types for each of the variables, such as using "comm.REQUIRE_BOOL" for the CONFIG_GLOBAL_SERVICE_MOUNT_DEVICE variable.
- The code also uses a "comm.REQUIRE_STRING_SLICE" for the CONFIG_GLOBAL_HOST and CONFIG_DISK_HOST_EXCLUDE variables. This is good practice, as it ensures that the host and exclude list will contain only strings.
- Overall, the code looks good and there does not appear to be any major bugs or risks present. If any improvements are desired, it might be beneficial to add additional comments to explain what each variable is used for. Additionally, it might be beneficial to add more documentation to the code to make it easier to read and understand.
@@ -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.
code review.
The code looks good and there are no major bugs risk. The code seems to be properly indented and well structured.
However, some improvement suggestions are as follows:
- Add loggers or error messages to the code.
- Use comments for complex logic if any.
- Add more test cases for better code coverage.
- In the mergeFinalHost function, use a for loop to check if the host to be excluded is the member of global hosts list.
- In the GetDiskId function, add support for other disk URIs.
- Add constants for variables like DISK_URI_SEP.
- In the ParseDisks function, use dependency injection to inject CurveAdm object.
- Handle invalid input data in the ParseDisks function.
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 of this patch.
First, we can see that the patch adds an additional field to the FormatConfig struct, namely "FromDiskRecord" and "ServiceMountDevice". We should check if these fields are used in other parts of the code, and if so, if they are being used correctly. Additionally, we should make sure that the values being set in the new fields are valid and appropriate for the function they serve.
Next, we should check if there are any security risks associated with the new fields. These risks could include potential SQL injection attacks or buffer overflows. We should also look for any potential bugs that could be caused by the new fields, such as typos or incorrect data types.
Finally, we should consider whether any improvements could be made to the code. This could include refactoring existing code to make it more efficient or reducing redundant code. We should also consider any potential performance issues that could be caused by the new fields, and if necessary, suggest ways to improve performance.
@@ -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.
the code review
First, it looks like you are changing the constant type from REQUIRE_SLICE to REQUIRE_STRING_SLICE. If that is indeed the case, you should make sure that this change does not break any existing code or cause any unexpected behavior in your application. Also, make sure that the constant name is appropriate and descriptive for what it is intended for.
Second, you should verify that the value of DEFAULT_REPORT_USAGE is correctly set to true. It is also important to make sure that this value is consistent throughout the codebase.
Finally, make sure that the syntax and formatting of the code is correct and adhere to the coding conventions of your project.
I hope this helps. Please let me know if you have any further questions.
@@ -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 the code review.
-
The first part of the code patch adds a new error code: ERR_CONFIGURE_VALUE_REQUIRES_NONEMPTY_SLICE. This will help in checking if the configure value requires an nonempty array.
-
The second part changes the error code ERR_DISK_DEVICE_NOT_FORMATTED to be more descriptive, now it reads "disk device is unformatted". This makes it easier for the user to understand what the issue is.
Overall, the code patch looks good. There are no clear bugs or risks, and the changes make the code more descriptive and easier to understand.
|
||
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.
code review:
-
The patch adds a new column to the table, service_mount_device, which should be of type INTEGER and have a default value of 0. This is good practice to ensure that the table has a consistent structure.
-
The patch also updates the INSERT and UPDATE SQL queries to include the new column. It is good practice to make sure that all fields are included in the query, as this will ensure that the data is stored correctly.
-
In addition, the patch adds an additional parameter to the INSERT query, which is good practice as it ensures that all values are correctly specified.
-
Finally, the patch updates the SET_DISK_URI query to include the new uri field. This is good practice as it ensures that the data is stored 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.
a brief code review:
-
The variable names used in the code are all meaningful, which is easy to understand, so it's ok.
-
In the SetDisk function, the serviceMountDevice variable is not properly initialized when the diskRecords length is 0, it can be initialized to 0.
-
In the GetDisk function, the ServiceMountDevice variable is not included in the query result and should be added.
-
The UpdateDiskURI function does not have the ServiceMountDevice variable, but the serviceMountDevice variable is included in the SetDisk function, so when updating the disk, the ServiceMountDevice variable should also be updated.
} | ||
|
||
// 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.
!
The code patch looks ok. There are two if statements with different conditions. The first if statement is used to check if "ServiceMountDevice" is set to false, which means that the disk UUID should be written into /etc/fstab for host mounting. The second if statement is used to update the disk size and uri(diskId) when "FromDiskRecord" is set to true.
I think the code patch looks ok, but there are a few things that can be improved:
-
It would be better to add more comments to explain the purpose of the two if statements.
-
The variable names should be more descriptive and consistent. For example, "FromDiskRecord" could be changed to "fromDiskRecord" or "from_disk_record".
-
The logic of the code can be simplified by using a switch statement instead of two if statements.
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 patch adds a new step to mount the disk devices back to host for data cleaning. This ensures that data will be cleaned even if the disk device is mounted.
- The code also adds a step to clean the service id from disks. This makes sure that the service id is removed from all disks.
- There is no bug risk in this code patch, since it ensures data cleaning and removes service id from all disks.
- No improvement suggestion as such, but one suggestion could be to add more validations to check if the disk is mounted or not before mounting it back.
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.
the code review:
Analysis:
1.The code patch is adding the "github.com/opencurve/curveadm/internal/configure/disks" package, and also adding a parameter for the step.CreateContainer to support serviceMountDevice
2.In getMountVolumes function, it adds a new parameter serviceMountDevice and check it when adding volume binds if not directly mount disk device in container.
3.In getRestartPolicy function, it checks the topology role and add an extra condition to check serviceMountDevice
Suggestion:
1.It is better to add more comments to explain the logic in the code patch.
2.In getMountVolumes function, it is better to add one more parameter for the role to make sure it can get the correct role for different services.
3.If there are more roles to be added, it is better to use switch-case statement instead of if-else statement.
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 a brief code review of this patch.
-
The first thing we notice is that the code has been properly indented for readability and there are comments explaining the purpose of each step. This is a good sign as it makes it easier to review and understand the code.
-
There is a new import statement for "github.com/opencurve/curveadm/internal/common" which suggests that the code is using some common methods and data structures shared by other parts of the program.
-
A new check has been added to verify if there are any disks associated with the service and, if so, to get the device name. This looks like a good addition as it ensures that the disk is unmounted before starting the container.
-
The code has added a new step to unmount the device before starting the container, which prevents any potential conflicts or errors.
Overall, the code looks good and seems to be free of any bugs. The only improvement suggestion I have is to add more comments to explain what each step does in more detail. This will make it easier to read and understand the code in the future.
Disk UUID will be passed to container
Cmd
config during curvebs deployment if diskservice_mount_device
was enabled, then service(chunkserver) cloud mount disk viaentrypoint.sh
and restart automatically after host power recover.to #147 and #165
coordinate with
curve
pull request opencurve/curve#2285