MCPcopy Create free account
hub / github.com/ContentSquare/chproxy / newReplicas

Function newReplicas

scope.go:710–740  ·  view source on GitHub ↗
(replicasCfg []config.Replica, nodes []string, scheme string, c *cluster)

Source from the content-addressed store, hash-verified

708}
709
710func newReplicas(replicasCfg []config.Replica, nodes []string, scheme string, c *cluster) ([]*replica, error) {
711 if len(nodes) > 0 {
712 // No replicas, just flat nodes. Create default replica
713 // containing all the nodes.
714 r := &replica{
715 cluster: c,
716 name: "default",
717 }
718 hosts, err := newNodes(nodes, scheme, r)
719 if err != nil {
720 return nil, err
721 }
722 r.hosts = hosts
723 return []*replica{r}, nil
724 }
725
726 replicas := make([]*replica, len(replicasCfg))
727 for i, rCfg := range replicasCfg {
728 r := &replica{
729 cluster: c,
730 name: rCfg.Name,
731 }
732 hosts, err := newNodes(rCfg.Nodes, scheme, r)
733 if err != nil {
734 return nil, fmt.Errorf("cannot initialize replica %q: %w", rCfg.Name, err)
735 }
736 r.hosts = hosts
737 replicas[i] = r
738 }
739 return replicas, nil
740}
741
742func newNodes(nodes []string, scheme string, r *replica) ([]*topology.Node, error) {
743 hosts := make([]*topology.Node, len(nodes))

Callers 1

newClusterFunction · 0.85

Calls 1

newNodesFunction · 0.85

Tested by

no test coverage detected