hhtlxhhxy
(Haitao)
January 7, 2019, 10:31am
1
Hi,
when I use the go client to query and mutate , I have a question about the high availability, the code for example as below:
func NewGrapher(cfg *GrapherConfig) (*BTCGrapher, error) {
p := new(BTCGrapher)
p.cfg = cfg
conn, err := grpc.Dial(p.cfg.Address+":"+p.cfg.Port, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(4<<30),
grpc.MaxCallSendMsgSize(4<<30)), grpc.WithInsecure())
if err != nil {
log.Error("While trying to dial gRPC", err)
log.DetailError(err)
return nil, err
}
p.grapherClientConn = conn
ctx := context.Background()
mu := &api.Mutation{
CommitNow: true,
DeleteJson: pb,
}
_, err = dgo.NewDgraphClient(api.NewDgraphClient(p.grapherClientConn)).NewTxn().Mutate(ctx, mu)
if err != nil {
log.DetailError(err)
}
return p, nil
}
I have three alpha nodes and I have a domain like “test.dgraph.xx.com ” point to the three alpha port 9080, I do not clear how can I write codes to relize the high availability like the method GET or POST in HTTP.
Thank You Very Much!
hhtlxhhxy
(Haitao)
January 7, 2019, 10:38am
2
like that ?
func NewGrapher(cfg *GrapherConfig) (*BTCGrapher, error) {
conn1, err := grpc.Dial(p.cfg.Address1+":"+p.cfg.Port1, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(4<<30),
grpc.MaxCallSendMsgSize(4<<30)), grpc.WithInsecure())
conn2, err := grpc.Dial(p.cfg.Address2+":"+p.cfg.Port2, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(4<<30),
grpc.MaxCallSendMsgSize(4<<30)), grpc.WithInsecure())
conn3, err := grpc.Dial(p.cfg.Address3+":"+p.cfg.Port3, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(4<<30),
grpc.MaxCallSendMsgSize(4<<30)), grpc.WithInsecure())
ctx := context.Background()
mu := &api.Mutation{
CommitNow: true,
DeleteJson: pb,
}
_, err = dgo.NewDgraphClient(api.NewDgraphClient(conn1), api.NewDgraphClient(conn2), api.NewDgraphClient(conn3)).NewTxn().Mutate(ctx, mu)
if err != nil {
log.DetailError(err)
}
return p, nil
}
but, how can I know which alpha node is alive? If I kill one alpha node , how can I know it?
javier
(Javier Alvarado)
January 7, 2019, 8:03pm
3
The recommended way to ensure high availability is to run Dgraph behind a load balancer which would be responsible for keeping track of which nodes are alive.
The sample code
_, err = dgo.NewDgraphClient(api.NewDgraphClient(conn1), api.NewDgraphClient(conn2), api.NewDgraphClient(conn3)).NewTxn().Mutate(ctx, mu)
if err != nil {
log.DetailError(err)
}
will not work as you intend. When a DgraphClient is initialized with multiple connections, each operation uses only one of them at random. You have to check the error and retry if it the node is down.
Thanks for your reply, I understand your mean, I know I need a load balancer, but I do not know how to client an domain in grpc,can you show me an example code? like that?
conn, err := grpc.Dial("dns:///"+ p.cfg.Domain+":"+p.cfg.Port, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(4<<30),
grpc.MaxCallSendMsgSize(4<<30)), grpc.WithInsecure())
Thank you!
dmai
(Daniel Mai)
January 8, 2019, 1:10am
5
The grpc.Dial address can be a DNS name.
Hi dmai, thanks for your reply, do you have time to look at my another question?
Dgraph cluster:
zero:1
alpha:3
Server information:
CPU:64
Memory:256G
Disk: 7T SSD
Data:
RDF:8billion
Edges:18billion
[WechatIMG8]
Question One:
I use the dgraph bulk loader gengrate the dir p/ ,and copy the dir p/ to three alpha nodes, the p/ dir includes nearly 2W+ files, when I start up the alpha node, it take up nearly 45 minutes, why it is so slow?
[WechatIMG9]
Queation Two:
After the alpha node start, it have pending proposals , and I can not query anything! Why?And,it happ…
Thanks very much! I have solved the problem, the load balancer I did before is L7 load balancer, now I relize the load balancer in L4. Now it can work well with domain test.dgraph.xx.com in grpc.
system
(system)
Closed
February 7, 2019, 3:28am
8
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.