Skip to content

Commit

Permalink
vtctl: WaitForFilteredReplication: Remove special handling for tolera…
Browse files Browse the repository at this point in the history
…ted negative delays.

A negative delay should never be sent back by the tablet. It always sends a minimum value of 0.
  • Loading branch information
michael-berlin committed Aug 18, 2015
1 parent 0d7f7a0 commit a207187
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 45 deletions.
6 changes: 2 additions & 4 deletions go/vt/vtctl/vtctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1335,8 +1335,6 @@ func commandShardReplicationFix(ctx context.Context, wr *wrangler.Wrangler, subF
}

func commandWaitForFilteredReplication(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
// Allowed tolerance up to which the local clock may run ahead. Otherwise, the command will fail.
const allowedAheadTime = 2 * time.Second
maxDelay := subFlags.Duration("max_delay", 30*time.Second,
"Specifies the maximum delay, in seconds, the filtered replication of the"+
" given destination shard should lag behind the source shard. When"+
Expand Down Expand Up @@ -1403,8 +1401,8 @@ func commandWaitForFilteredReplication(ctx context.Context, wr *wrangler.Wrangle

delaySecs := shr.RealtimeStats.SecondsBehindMasterFilteredReplication
lastSeenDelay := time.Duration(delaySecs) * time.Second
if lastSeenDelay < -allowedAheadTime {
return fmt.Errorf("cannot reliably wait for the filtered replication to catch up. The tablet clock (runs ahead) is not synchronized. seen delay: %v on tablet: %v", lastSeenDelay, alias)
if lastSeenDelay < 0 {
return fmt.Errorf("last seen delay should never be negative. tablet: %v delay: %v", alias, lastSeenDelay)
}
if lastSeenDelay <= *maxDelay {
wr.Logger().Printf("Filtered replication on tablet: %v has caught up. Last seen delay: %.1f seconds\n", alias, lastSeenDelay.Seconds())
Expand Down
41 changes: 0 additions & 41 deletions go/vt/wrangler/testlib/wait_for_filtered_replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,47 +52,6 @@ func TestWaitForFilteredReplication_wrongTarget(t *testing.T) {
waitForFilteredReplicationDefaultDelay(t, target, "received health record for wrong tablet")
}

// TestWaitForFilteredReplication_unsyncClocks tests that
// vtctl WaitForFilteredReplication fails if the calculated delay is negative.
func TestWaitForFilteredReplication_unsyncClocks(t *testing.T) {
target := &pbq.Target{Keyspace: keyspace, Shard: destShard, TabletType: pbt.TabletType_MASTER}

// Replication is lagging behind.
oneHourDelay := &pbq.RealtimeStats{
SecondsBehindMasterFilteredReplication: 3600,
}

// Receiving master's clock is running one hour ahead of the sending master.
negativeDelayFunc := func() *pbq.RealtimeStats {
return &pbq.RealtimeStats{
SecondsBehindMasterFilteredReplication: -3600,
}
}

waitForFilteredReplication(t, target, "cannot reliably wait for the filtered replication to catch up", oneHourDelay, negativeDelayFunc)
}

// TestWaitForFilteredReplication_unsyncClocksTolerance tests that
// vtctl WaitForFilteredReplication succeeds as long as the calculated
// negative delay is above a certain tolerance.
func TestWaitForFilteredReplication_unsyncClocksTolerance(t *testing.T) {
target := &pbq.Target{Keyspace: keyspace, Shard: destShard, TabletType: pbt.TabletType_MASTER}

// Replication is lagging behind.
oneHourDelay := &pbq.RealtimeStats{
SecondsBehindMasterFilteredReplication: 3600,
}

// Tablet is a second ahead of the local clock.
slightNegativeDelayFunc := func() *pbq.RealtimeStats {
return &pbq.RealtimeStats{
SecondsBehindMasterFilteredReplication: -1,
}
}

waitForFilteredReplication(t, target, "", oneHourDelay, slightNegativeDelayFunc)
}

func waitForFilteredReplicationDefaultDelay(t *testing.T, target *pbq.Target, expectedErr string) {
// Replication is lagging behind.
oneHourDelay := &pbq.RealtimeStats{
Expand Down

0 comments on commit a207187

Please sign in to comment.