MCPcopy
hub / github.com/dgraph-io/dgraph / newPool

Function newPool

conn/pool.go:178–209  ·  view source on GitHub ↗

newPool creates a new "pool" with one gRPC connection, refcount 0.

(addr string, tlsClientConf *tls.Config)

Source from the content-addressed store, hash-verified

176
177// newPool creates a new "pool" with one gRPC connection, refcount 0.
178func newPool(addr string, tlsClientConf *tls.Config) (*Pool, error) {
179 conOpts := []grpc.DialOption{
180 grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
181 grpc.WithDefaultCallOptions(
182 grpc.MaxCallRecvMsgSize(x.GrpcMaxSize),
183 grpc.MaxCallSendMsgSize(x.GrpcMaxSize),
184 grpc.UseCompressor((snappyCompressor{}).Name())),
185 grpc.WithBackoffMaxDelay(time.Second),
186 }
187
188 if tlsClientConf != nil {
189 conOpts = append(conOpts, grpc.WithTransportCredentials(credentials.NewTLS(tlsClientConf)))
190 } else {
191 conOpts = append(conOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
192 }
193
194 conn, err := grpc.NewClient(addr, conOpts...)
195 if err != nil {
196 glog.Errorf("unable to connect with %s : %s", addr, err)
197 return nil, err
198 }
199
200 pl := &Pool{
201 conn: conn,
202 Addr: addr,
203 lastEcho: time.Now(),
204 dialOpts: conOpts,
205 closer: z.NewCloser(1),
206 }
207 go pl.MonitorHealth()
208 return pl, nil
209}
210
211// Get returns the connection to use from the pool of connections.
212func (p *Pool) Get() *grpc.ClientConn {

Callers 1

ConnectMethod · 0.85

Calls 3

MonitorHealthMethod · 0.95
NameMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected