wilfred-s commented on code in PR #1126:
URL: https://github.com/apache/yunikorn-core/pull/1126#discussion_r3780353243


##########
pkg/common/configs/config.go:
##########
@@ -193,18 +221,40 @@ func ParseAndValidateConfig(content []byte) 
(*SchedulerConfig, error) {
        return conf, nil
 }
 
+// GetConfigurationString returns the serialised config content without 
checksum.
+// The checksum is placed at the start or the end of the config and to avoid 
walking a potentially very large
+// config end to end, only the first and the last checksumScanWindow bytes are 
scanned for the checksum key.
 func GetConfigurationString(requestBytes []byte) string {
-       conf := string(requestBytes)
-       checksum := "checksum: "
-       checksumLength := 64 + len(checksum)
-       if strings.Contains(conf, checksum) {
-               checksum += strings.Split(conf, checksum)[1]
-               checksum = strings.TrimRight(checksum, "\n")
-               if len(checksum) > checksumLength {
-                       checksum = checksum[:checksumLength]
+       length := len(requestBytes)
+       if length == 0 {
+               return ""
+       }
+       key := []byte(checksumKey)
+       // look for the checksum in the head of the config first, then in the 
tail
+       head := min(checksumScanWindow, length)
+       checksumIdx := bytes.Index(requestBytes[:head], key)
+       if checksumIdx == -1 {
+               tail := max(length-checksumScanWindow, 0)

Review Comment:
   We want to swap this around: the `SchedulerConfig` object defines `Checksum` 
as the last entry which means that standard automated go yaml serialisation 
will put the checksum last. Only manual updates will have the checksum first.
   Optimise for the default case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to