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

Method Inform

dgraph/cmd/zero/zero.go:407–470  ·  view source on GitHub ↗
(ctx context.Context, req *pb.TabletRequest)

Source from the content-addressed store, hash-verified

405}
406
407func (s *Server) Inform(ctx context.Context, req *pb.TabletRequest) (*pb.TabletResponse, error) {
408 ctx, span := otel.Tracer("").Start(ctx, "Zero.Inform")
409 defer span.End()
410 if req == nil || len(req.Tablets) == 0 {
411 return nil, errors.Errorf("Tablets are empty in %+v", req)
412 }
413
414 if req.GroupId == 0 {
415 return nil, errors.Errorf("Group ID is Zero in %+v", req)
416 }
417
418 tablets := make([]*pb.Tablet, 0)
419 unknownTablets := make([]*pb.Tablet, 0)
420 for _, t := range req.Tablets {
421 tab := s.ServingTablet(t.Predicate)
422 span.SetAttributes(attribute.String("tablet_predicate", t.Predicate))
423 switch {
424 case tab != nil && !t.Force:
425 tablets = append(tablets, t)
426 case t.ReadOnly:
427 tablets = append(tablets, &pb.Tablet{})
428 default:
429 unknownTablets = append(unknownTablets, t)
430 }
431 }
432
433 if len(unknownTablets) == 0 {
434 return &pb.TabletResponse{
435 Tablets: tablets,
436 }, nil
437 }
438
439 // Set the tablet to be served by this server's group.
440 var proposal pb.ZeroProposal
441 proposal.Tablets = make([]*pb.Tablet, 0)
442 for _, t := range unknownTablets {
443 if x.IsReservedPredicate(t.Predicate) {
444 // Force all the reserved predicates to be allocated to group 1.
445 // This is to make it easier to stream ACL updates to all alpha servers
446 // since they only need to open one pipeline to receive updates for all
447 // ACL predicates.
448 // This will also make it easier to restore the reserved predicates after
449 // a DropAll operation.
450 t.GroupId = 1
451 }
452 proposal.Tablets = append(proposal.Tablets, t)
453 }
454
455 if err := s.Node.proposeAndWait(ctx, &proposal); err != nil && err != errTabletAlreadyServed {
456 span.AddEvent(fmt.Sprintf("Error proposing tablet: %+v. Error: %v", &proposal, err))
457 return nil, err
458 }
459
460 for _, t := range unknownTablets {
461 tab := s.ServingTablet(t.Predicate)
462 x.AssertTrue(tab != nil)
463 span.AddEvent(fmt.Sprintf("Tablet served: %+v", tab))
464 tablets = append(tablets, tab)

Callers

nothing calls this directly

Calls 7

ServingTabletMethod · 0.95
IsReservedPredicateFunction · 0.92
AssertTrueFunction · 0.92
StartMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45
proposeAndWaitMethod · 0.45

Tested by

no test coverage detected