Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions dgraph/cmd/zero/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ instances to achieve high-availability.
" The count includes the original shard.")
flag.String("peer", "", "Address of another dgraphzero server.")
flag.StringP("wal", "w", "zw", "Directory storing WAL.")
flag.Duration("rebalance_interval", 8*time.Minute, "Interval for trying a predicate move.")
flag.Duration("rebalance_interval", 8*time.Minute, "Interval for trying a predicate move. "+
"Set to 0 to disable automatic tablet rebalancing.")
flag.String("enterprise_license", "", "(deprecated) Path to the enterprise license file.")
flag.String("cid", "", "Cluster ID")

Expand Down Expand Up @@ -282,9 +283,9 @@ func run() {
"WAL directory and Audit output cannot be the same ('%s').", opts.audit.Output)
}

if opts.rebalanceInterval <= 0 {
log.Fatalf("ERROR: Rebalance interval must be greater than zero. Found: %d",
opts.rebalanceInterval)
if opts.rebalanceInterval < 0 {
log.Fatalf("ERROR: Rebalance interval must be zero (to disable automatic tablet "+
"rebalancing) or positive. Found: %d", opts.rebalanceInterval)
}

addr := "localhost"
Expand Down
10 changes: 8 additions & 2 deletions dgraph/cmd/zero/tablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ This would trigger G1 to get latest state. Wait for it.
*/

// TODO: Have a event log for everything.
func (s *Server) rebalanceTablets() {
ticker := time.Tick(opts.rebalanceInterval)
func (s *Server) rebalanceTablets(interval time.Duration) {
// A zero interval disables automatic rebalancing; it must not reach time.Tick,
// which panics on non-positive durations.
if interval <= 0 {
glog.Infof("Automatic tablet rebalancing is disabled (rebalance_interval=%v).", interval)
return
}
ticker := time.Tick(interval)
for range ticker {
predicate, srcGroup, dstGroup := s.chooseTablet()
if len(predicate) == 0 {
Expand Down
17 changes: 17 additions & 0 deletions dgraph/cmd/zero/tablet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,20 @@ func TestMoveBackoff(t *testing.T) {
s.recordMoveResult(pred, time.Minute, nil)
require.False(t, s.skipMove(pred))
}

func TestRebalanceTabletsDisabled(t *testing.T) {
// A non-positive interval disables automatic rebalancing: the loop must return
// immediately instead of ticking (time.Tick would panic on these values).
for _, interval := range []time.Duration{0, -time.Minute} {
done := make(chan struct{})
go func() {
(&Server{}).rebalanceTablets(interval)
close(done)
}()
select {
case <-done:
case <-time.After(5 * time.Second):
t.Fatalf("rebalanceTablets(%v) did not return; rebalancing not disabled", interval)
}
}
}
2 changes: 1 addition & 1 deletion dgraph/cmd/zero/zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s *Server) Init() {
opts.limiterConfig.RefillAfter, s.closer)
}

go s.rebalanceTablets()
go s.rebalanceTablets(opts.rebalanceInterval)
}

func (s *Server) periodicallyPostTelemetry() {
Expand Down
Loading