Skip to content

Commit

Permalink
Merge #56346
Browse files Browse the repository at this point in the history
56346: testcluster: minor logging improvements r=andreimatei a=andreimatei

Log when TestCluster quiescing starts, and add a node log tag to each
node's quiescing ctx so messages from different nodes can be
disambiguated.

Release note: None

Co-authored-by: Andrei Matei <[email protected]>
  • Loading branch information
craig[bot] and andreimatei committed Nov 13, 2020
2 parents e68a1de + 8949b6e commit 2d34be7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions pkg/testutils/testcluster/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ go_library(
"//pkg/util/syncutil",
"//pkg/util/timeutil",
"//vendor/github.com/cockroachdb/errors",
"//vendor/github.com/cockroachdb/logtags",
],
)

Expand Down
15 changes: 9 additions & 6 deletions pkg/testutils/testcluster/testcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/logtags"
)

// TestCluster represents a set of TestServers. The hope is that it can be used
Expand Down Expand Up @@ -82,23 +83,25 @@ func (tc *TestCluster) Stopper() *stop.Stopper {
// stopServers stops the stoppers for each individual server in the cluster.
// This method ensures that servers that were previously stopped explicitly are
// not double-stopped.
func (tc *TestCluster) stopServers() {
func (tc *TestCluster) stopServers(ctx context.Context) {
tc.mu.Lock()
defer tc.mu.Unlock()

// Quiesce the servers in parallel to avoid deadlocks. If we stop servers
// serially when we lose quorum (2 out of 3 servers have stopped) the last
// server may never finish due to waiting for a Raft command that can't
// commit due to the lack of quorum.
log.Infof(ctx, "TestCluster quiescing nodes")
var wg sync.WaitGroup
wg.Add(len(tc.mu.serverStoppers))
for _, s := range tc.mu.serverStoppers {
go func(s *stop.Stopper) {
for i, s := range tc.mu.serverStoppers {
go func(i int, s *stop.Stopper) {
defer wg.Done()
if s != nil {
s.Quiesce(context.TODO())
quiesceCtx := logtags.AddTag(ctx, "n", tc.Servers[i].NodeID())
s.Quiesce(quiesceCtx)
}
}(s)
}(i, s)
}
wg.Wait()

Expand Down Expand Up @@ -282,7 +285,7 @@ func (tc *TestCluster) Start(t testing.TB) {

// Create a closer that will stop the individual server stoppers when the
// cluster stopper is stopped.
tc.stopper.AddCloser(stop.CloserFn(tc.stopServers))
tc.stopper.AddCloser(stop.CloserFn(func() { tc.stopServers(context.TODO()) }))

if tc.clusterArgs.ReplicationMode == base.ReplicationAuto {
if err := tc.WaitForFullReplication(); err != nil {
Expand Down

0 comments on commit 2d34be7

Please sign in to comment.