bitflicker64 commented on code in PR #366:
URL: 
https://github.com/apache/hugegraph-computer/pull/366#discussion_r4356734659


##########
vermeer/apps/common/pd_peers.go:
##########
@@ -0,0 +1,70 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with this
+work for additional information regarding copyright ownership. The ASF
+licenses this file to You under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package common
+
+import (
+       "encoding/json"
+       "errors"
+       "net"
+       "os"
+       "slices"
+       "strconv"
+)
+
+func deploymentConfig(environment, key string) string {
+       if value := os.Getenv(environment); value != "" {
+               return value
+       }
+       value, _ := GetConfigDefault(key, "").(string)
+       return value
+}
+
+// Deployment discovery takes precedence over task parameters on both Master 
and Worker.
+func resolvePDPeers(taskPeers []string) ([]string, error) {
+       configured := deploymentConfig("VERMEER_PD_PEERS", "pd_peers")
+       if configured == "" {
+               if deploymentConfig("VERMEER_PD_PASSWORD_FILE", 
"pd_password_file") != "" ||
+                       deploymentConfig("VERMEER_HUGEGRAPH_CREDENTIALS_FILE", 
"hugegraph_credentials_file") != "" {
+                       return nil, errors.New("configure pd_peers when using 
deployment credentials")
+               }
+               return taskPeers, nil
+       }
+       var peers []string
+       if json.Unmarshal([]byte(configured), &peers) != nil || len(peers) == 0 
{
+               return nil, errors.New("pd_peers must be a nonempty JSON array 
of host:port addresses")
+       }
+       for _, peer := range peers {
+               host, port, err := net.SplitHostPort(peer)
+               number, portErr := strconv.Atoi(port)
+               if err != nil || host == "" || portErr != nil || number < 1 || 
number > 65535 {
+                       return nil, errors.New("pd_peers must contain valid 
host:port addresses")
+               }
+       }
+       return peers, nil

Review Comment:
   Minor: When `pd_peers` is set, task peers from `load.hg_pd_peers` and 
`output.hg_pd_peers` are dropped here without a log line or error. The stored 
task parameters still show a PD that was never contacted, so a setup that used 
per-task peers for several clusters would quietly load a same-named graph from 
the deployment cluster instead.
   
   The smallest fix is a `logrus.Warnf` here when a task peer is not in `peers` 
(`logrus` needs importing). Checking membership rather than equality keeps 
`requireTrustedPD` quiet, since it always passes a configured peer. Rejecting 
such tasks would be stricter, but would also fail tasks that spell the same PD 
differently.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to