Skip to content

Commit

Permalink
demo: fix --global option
Browse files Browse the repository at this point in the history
The --global option broke somewhere during the 20.2 cycle. This patch
revives it. --global simulates geo-latencies between nodes. Best used
with `--global --geo-partitioned-replicas`.

Release note (cli change): fix cockroach demo --global from crashing
with "didn't get expected magic bytes header".
  • Loading branch information
jordanlewis authored and otan committed Jan 8, 2021
1 parent 36a7014 commit 513d3c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/cli/interactive_tests/test_demo_global.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

source [file join [file dirname $argv0] common.tcl]

# Set a larger timeout since we are going global.
set timeout 90

start_test "Check --global flag runs as expected"

# Start a demo with --global set
spawn $argv demo movr --global
spawn $argv demo movr --nodes 9 --global

# Ensure db is movr.
eexpect "movr>"
Expand Down
17 changes: 17 additions & 0 deletions pkg/rpc/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,23 @@ func (ctx *Context) grpcDialOptions(
dialOpts = append(dialOpts, grpc.WithStreamInterceptor(testingStreamInterceptor))
}
}
if ctx.Knobs.ArtificialLatencyMap != nil {
dialerFunc := func(ctx context.Context, target string) (net.Conn, error) {
dialer := net.Dialer{
LocalAddr: sourceAddr,
}
return dialer.DialContext(ctx, "tcp", target)
}
latency := ctx.Knobs.ArtificialLatencyMap[target]
log.VEventf(ctx.masterCtx, 1, "connecting to node %s with simulated latency %dms", target, latency)
dialer := artificialLatencyDialer{
dialerFunc: dialerFunc,
latencyMS: latency,
}
dialerFunc = dialer.dial
dialOpts = append(dialOpts, grpc.WithContextDialer(dialerFunc))
}

return dialOpts, nil
}

Expand Down

0 comments on commit 513d3c3

Please sign in to comment.