Skip to content

Commit

Permalink
testing: allow upgrade all in logic tests
Browse files Browse the repository at this point in the history
`upgrade all` upgrades all nodes in the cluster. It has the same behavior as
using `upgrade <idx>` for each index in the cluster.

Release note: None
  • Loading branch information
ecwall committed Sep 12, 2023
1 parent b5cef20 commit 48b0df4
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions pkg/sql/logictest/logic.go
Expand Up @@ -3109,34 +3109,45 @@ func (t *logicTest) processSubtest(
if t.testserverCluster == nil {
return errors.Errorf(`could not perform "upgrade", not a cockroach-go/testserver cluster`)
}
nodeIdx, err := strconv.Atoi(fields[1])
if err != nil {
t.Fatal(err)
}
if err := t.testserverCluster.UpgradeNode(nodeIdx); err != nil {
t.Fatal(err)
}
for i := 0; i < t.cfg.NumNodes; i++ {
// Wait for each node to be reachable, since UpgradeNode uses `kill`
// to terminate nodes, and may introduce temporary unavailability in
// the system range.
if err := t.testserverCluster.WaitForInitFinishForNode(i); err != nil {
upgradeNode := func(nodeIdx int) {
if err := t.testserverCluster.UpgradeNode(nodeIdx); err != nil {
t.Fatal(err)
}
}
// The port may have changed, so we must remove all the cached connections
// to this node.
for _, m := range t.clients {
if c, ok := m[nodeIdx]; ok {
_ = c.Close()
for i := 0; i < t.cfg.NumNodes; i++ {
// Wait for each node to be reachable, since UpgradeNode uses `kill`
// to terminate nodes, and may introduce temporary unavailability in
// the system range.
if err := t.testserverCluster.WaitForInitFinishForNode(i); err != nil {
t.Fatal(err)
}
}
// The port may have changed, so we must remove all the cached connections
// to this node.
for _, m := range t.clients {
if c, ok := m[nodeIdx]; ok {
_ = c.Close()
}
delete(m, nodeIdx)
}
// If we upgraded the node we are currently on, we need to open a new
// connection since the previous one might now be invalid.
if t.nodeIdx == nodeIdx {
t.setSessionUser(t.user, nodeIdx, false /* newSession */)
}
delete(m, nodeIdx)
}
// If we upgraded the node we are currently on, we need to open a new
// connection since the previous one might now be invalid.
if t.nodeIdx == nodeIdx {
t.setSessionUser(t.user, nodeIdx, false /* newSession */)
nodeStr := fields[1]
if nodeStr == "all" {
for i := 0; i < t.cfg.NumNodes; i++ {
upgradeNode(i)
}
} else {
nodeIdx, err := strconv.Atoi(nodeStr)
if err != nil {
t.Fatal(err)
}
upgradeNode(nodeIdx)
}

default:
return errors.Errorf("%s:%d: unknown command: %s",
path, s.Line+subtest.lineLineIndexIntoFile, cmd,
Expand Down

0 comments on commit 48b0df4

Please sign in to comment.