-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli: use zone configs to disable replication #39492
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2019 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package cli | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/server" | ||
"github.com/cockroachdb/cockroach/pkg/sql" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree" | ||
) | ||
|
||
// cliDisableReplication changes the replication factor on | ||
// all defined zones to become 1. This is used by start-single-node | ||
// and demo to define single-node clusters, so as to avoid | ||
// churn in the log files. | ||
// | ||
// The change is effected using the internal SQL interface of the | ||
// given server object. | ||
func cliDisableReplication(ctx context.Context, s *server.Server) error { | ||
return s.RunLocalSQL(ctx, | ||
func(ctx context.Context, ie *sql.InternalExecutor) error { | ||
rows, err := ie.Query(ctx, "get-zones", nil, | ||
"SELECT target FROM crdb_internal.zones") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, row := range rows { | ||
zone := string(*row[0].(*tree.DString)) | ||
if _, err := ie.Exec(ctx, "set-zone", nil, | ||
fmt.Sprintf("ALTER %s CONFIGURE ZONE USING num_replicas = 1", zone)); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#! /usr/bin/env expect -f | ||
|
||
source [file join [file dirname $argv0] common.tcl] | ||
|
||
spawn /bin/bash | ||
send "PS1=':''/# '\r" | ||
eexpect ":/# " | ||
|
||
start_test "Check that demo disables replication properly" | ||
send "$argv demo -e 'show zone configuration for range default'\r" | ||
eexpect "num_replicas = 1" | ||
eexpect ":/# " | ||
end_test | ||
|
||
start_test "Check that start-single-node disables replication properly" | ||
system "rm -rf logs/db" | ||
start_server $argv | ||
send "$argv sql -e 'show zone configuration for range default'\r" | ||
eexpect "num_replicas = 1" | ||
eexpect ":/# " | ||
end_test | ||
|
||
start_test "Check that it remains possible to reset the replication factor" | ||
send "$argv sql -e 'alter range default configure zone using num_replicas = 3'\r" | ||
eexpect "CONFIGURE ZONE" | ||
eexpect ":/# " | ||
stop_server $argv | ||
start_server $argv | ||
send "$argv sql -e 'show zone configuration for range default'\r" | ||
eexpect "num_replicas = 3" | ||
eexpect ":/# " | ||
end_test | ||
|
||
stop_server $argv | ||
|
||
start_test "Check that start-single-node on a regular cluster does not reset the replication factor" | ||
# make a fresh server but using the regular 'start' | ||
system "rm -rf logs/db" | ||
system "$argv start --insecure --pid-file=server_pid --background -s=path=logs/db >>logs/expect-cmd.log 2>&1; | ||
$argv sql -e 'select 1'" | ||
# restart with start-single-node | ||
stop_server $argv | ||
start_server $argv | ||
# check that the replication factor was unchanged | ||
send "$argv sql -e 'show zone configuration for range default'\r" | ||
eexpect "num_replicas = 3" | ||
eexpect ":/# " | ||
end_test | ||
|
||
send "exit 0\r" | ||
eexpect eof |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#! /usr/bin/env expect -f | ||
|
||
source [file join [file dirname $argv0] common.tcl] | ||
|
||
start_server $argv | ||
|
||
start_test "Check that it is possible to add nodes to a server started with start-single-node" | ||
|
||
system "$argv start --insecure --port=26258 --http-port=8083 --pid-file=server_pid2 --background -s=path=logs/db2 --join=:26257 >>logs/expect-cmd.log 2>&1; | ||
$argv sql -e 'select 1' --port=26258" | ||
|
||
system "$argv start --insecure --port=26259 --http-port=8084 --pid-file=server_pid3 --background -s=path=logs/db3 --join=:26257 >>logs/expect-cmd.log 2>&1; | ||
$argv sql -e 'select 1' --port=26259" | ||
|
||
# Check the number of nodes | ||
spawn $argv node ls | ||
eexpect id | ||
eexpect "3 rows" | ||
eexpect eof | ||
|
||
# Remove the additional nodes. | ||
system "$argv quit --port=26258" | ||
system "$argv quit --port=26259" | ||
|
||
end_test | ||
|
||
stop_server $argv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I start a non-single node three node cluster with nodes 2 and 3 pointing at node 1 (which itself joins to nobody), and then I restart node one as a single-node instance? Will it just work, error out, or erroneously overwrite my zone configs?