@@ -316,10 +316,8 @@ func (s *Server) ServingTablet(tablet string) *pb.Tablet {
316
316
defer s .RUnlock ()
317
317
318
318
for _ , group := range s .state .Groups {
319
- for key , tab := range group .Tablets {
320
- if key == tablet {
321
- return tab
322
- }
319
+ if tab , ok := group .Tablets [tablet ]; ok {
320
+ return tab
323
321
}
324
322
}
325
323
return nil
@@ -341,10 +339,8 @@ func (s *Server) servingTablet(tablet string) *pb.Tablet {
341
339
s .AssertRLock ()
342
340
343
341
for _ , group := range s .state .Groups {
344
- for key , tab := range group .Tablets {
345
- if key == tablet {
346
- return tab
347
- }
342
+ if tab , ok := group .Tablets [tablet ]; ok {
343
+ return tab
348
344
}
349
345
}
350
346
return nil
@@ -386,6 +382,8 @@ func (s *Server) createProposals(dst *pb.Group) ([]*pb.ZeroProposal, error) {
386
382
})
387
383
}
388
384
}
385
+
386
+ var tablets []* pb.Tablet
389
387
for key , dstTablet := range dst .Tablets {
390
388
group , has := s .state .Groups [dstTablet .GroupId ]
391
389
if ! has {
@@ -401,15 +399,81 @@ func (s *Server) createProposals(dst *pb.Group) ([]*pb.ZeroProposal, error) {
401
399
d := float64 (dstTablet .OnDiskBytes )
402
400
if dstTablet .Remove || (s == 0 && d > 0 ) || (s > 0 && math .Abs (d / s - 1 ) > 0.1 ) {
403
401
dstTablet .Force = false
404
- proposal := & pb.ZeroProposal {
405
- Tablet : dstTablet ,
406
- }
407
- res = append (res , proposal )
402
+ tablets = append (tablets , dstTablet )
408
403
}
409
404
}
405
+
406
+ if len (tablets ) > 0 {
407
+ res = append (res , & pb.ZeroProposal {Tablets : tablets })
408
+ }
410
409
return res , nil
411
410
}
412
411
412
+ func (s * Server ) Inform (ctx context.Context , req * pb.TabletRequest ) (* pb.TabletResponse , error ) {
413
+ ctx , span := otrace .StartSpan (ctx , "Zero.Inform" )
414
+ defer span .End ()
415
+ if req == nil || len (req .Tablets ) == 0 {
416
+ return nil , errors .Errorf ("Tablets are empty in %+v" , req )
417
+ }
418
+
419
+ if req .GroupId == 0 {
420
+ return nil , errors .Errorf ("Group ID is Zero in %+v" , req )
421
+ }
422
+
423
+ tablets := make ([]* pb.Tablet , 0 )
424
+ unknownTablets := make ([]* pb.Tablet , 0 )
425
+ for _ , t := range req .Tablets {
426
+ tab := s .ServingTablet (t .Predicate )
427
+ span .Annotatef (nil , "Tablet for %s: %+v" , t .Predicate , tab )
428
+ switch {
429
+ case tab != nil && ! t .Force :
430
+ tablets = append (tablets , t )
431
+ case t .ReadOnly :
432
+ tablets = append (tablets , & pb.Tablet {})
433
+ default :
434
+ unknownTablets = append (unknownTablets , t )
435
+ }
436
+ }
437
+
438
+ if len (unknownTablets ) == 0 {
439
+ return & pb.TabletResponse {
440
+ Tablets : tablets ,
441
+ }, nil
442
+ }
443
+
444
+ // Set the tablet to be served by this server's group.
445
+ var proposal pb.ZeroProposal
446
+ proposal .Tablets = make ([]* pb.Tablet , 0 )
447
+ for _ , t := range unknownTablets {
448
+ if x .IsReservedPredicate (t .Predicate ) {
449
+ // Force all the reserved predicates to be allocated to group 1.
450
+ // This is to make it easier to stream ACL updates to all alpha servers
451
+ // since they only need to open one pipeline to receive updates for all
452
+ // ACL predicates.
453
+ // This will also make it easier to restore the reserved predicates after
454
+ // a DropAll operation.
455
+ t .GroupId = 1
456
+ }
457
+ proposal .Tablets = append (proposal .Tablets , t )
458
+ }
459
+
460
+ if err := s .Node .proposeAndWait (ctx , & proposal ); err != nil && err != errTabletAlreadyServed {
461
+ span .Annotatef (nil , "While proposing tablet: %v" , err )
462
+ return nil , err
463
+ }
464
+
465
+ for _ , t := range unknownTablets {
466
+ tab := s .ServingTablet (t .Predicate )
467
+ x .AssertTrue (tab != nil )
468
+ span .Annotatef (nil , "Now serving tablet for %s: %+v" , t .Predicate , tab )
469
+ tablets = append (tablets , tab )
470
+ }
471
+
472
+ return & pb.TabletResponse {
473
+ Tablets : tablets ,
474
+ }, nil
475
+ }
476
+
413
477
// RemoveNode removes the given node from the given group.
414
478
// It's the user's responsibility to ensure that node doesn't come back again
415
479
// before calling the api.
0 commit comments