Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
93054: roachtest: add `failover/system-non-liveness` r=erikgrinaker a=erikgrinaker

This patch adds a roachtest measuring the pMax latency impact on user ranges when system range leaseholders fail (excluding the liveness range, which is tested individually in `failover/liveness`). Ideally, this should not affect user traffic at all, and the results confirm this.

Epic: none
Release note: None

93057: cli/sql: properly support special COPY input mode r=otan a=knz

Fixes cockroachdb#93031.

When in COPY mode, multi-line input is disabled and the tab key inputs raw ASCII TAB characters.

This commit achieves this by redirecting the input to either the interactive editor or the bufio-based editor, depending on whether the current mode is COPY.

NB: using ctrl+c while in COPY mode will not work with this patch, but that is caused by a separate issue cockroachdb#93053 and the behavior will be restored when that separate issue is fixed. In the meantime the user can use `\.` or ctrl+d to terminate their input.

Release note: None

93081: ui: prevent additional RPC fanout in insights api r=xinhaoz a=xinhaoz

Previously the query used to fetch insights was triggering 2 cluster-wide RPC fanouts by doing a self-join on `crdb_internal.cluster_execution_insights`.
We should buffer the insights virtual table to prevent an additional fanout to construct the table again.

Epic: none

Release note: None

Co-authored-by: Erik Grinaker <[email protected]>
Co-authored-by: Raphael 'kena' Poss <[email protected]>
Co-authored-by: Xin Hao Zhang <[email protected]>
  • Loading branch information
4 people committed Dec 6, 2022
4 parents 61af1b5 + 4550fcf + 3fd75b4 + cc4728a commit 52145a4
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 27 deletions.
1 change: 1 addition & 0 deletions pkg/cli/clisqlshell/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go_library(
"context.go",
"doc.go",
"editor.go",
"editor_bimodal.go",
"editor_bubbline.go",
"editor_bufio.go",
"editor_editline.go",
Expand Down
5 changes: 4 additions & 1 deletion pkg/cli/clisqlshell/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ func getEditor(useEditor bool, displayPrompt bool) editor {
if useLibEdit {
return &editlineReader{}
}
return &bubblineReader{}
return &bimodalEditor{
main: &bubblineReader{},
copy: &bufioReader{displayPrompt: displayPrompt},
}
}

var useLibEdit = envutil.EnvOrDefaultBool("COCKROACH_SQL_FORCE_LIBEDIT", false)
83 changes: 83 additions & 0 deletions pkg/cli/clisqlshell/editor_bimodal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2022 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 clisqlshell

import (
"os"

"github.com/cockroachdb/errors"
)

// bimodalEditor redirects the input to either a "main" editor
// (outside of COPY mode) or a "copy" editor (inside COPY).
// This is because the main editor may be multi-line and
// thus inadequate for input of COPY data.
type bimodalEditor struct {
sql sqlShell
main editor
copy editor
}

var _ editor = (*bimodalEditor)(nil)

func (e *bimodalEditor) init(
win, wout, werr *os.File, sqlS sqlShell, maxHistEntries int, histFile string,
) (cleanupFn func(), err error) {
e.sql = sqlS
c1, err := e.main.init(win, wout, werr, sqlS, maxHistEntries, histFile)
if err != nil {
return c1, err
}
c2, err := e.copy.init(win, wout, werr, sqlS, maxHistEntries, histFile)
cleanupFn = func() {
c1()
c2()
}
return cleanupFn, err
}

func (e *bimodalEditor) selected() editor {
if e.sql.inCopy() {
return e.copy
}
return e.main
}

func (e *bimodalEditor) errInterrupted() error {
return e.selected().errInterrupted()
}

func (e *bimodalEditor) getOutputStream() *os.File {
return e.selected().getOutputStream()
}

func (e *bimodalEditor) getLine() (string, error) {
return e.selected().getLine()
}

func (e *bimodalEditor) addHistory(line string) error {
return errors.CombineErrors(
e.copy.addHistory(line),
e.main.addHistory(line))
}

func (e *bimodalEditor) canPrompt() bool {
return e.main.canPrompt()
}

func (e *bimodalEditor) setPrompt(prompt string) {
e.copy.setPrompt(prompt)
e.main.setPrompt(prompt)
}

func (e *bimodalEditor) multilineEdit() bool {
return e.selected().multilineEdit()
}
62 changes: 39 additions & 23 deletions pkg/cli/interactive_tests/test_copy.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ source [file join [file dirname $argv0] common.tcl]

start_server $argv

spawn $argv sql --no-line-editor
spawn $argv sql
eexpect root@

send "DROP TABLE IF EXISTS t;\r"
send "CREATE TABLE t (id INT PRIMARY KEY, t TEXT);\r"
send "drop table if exists t;\r"
eexpect "DROP TABLE"
eexpect root@
send "create table t (id INT PRIMARY KEY, t TEXT);\r"
eexpect "CREATE TABLE"
eexpect root@

start_test "Check that errors are reported as appropriate."

Expand Down Expand Up @@ -98,26 +102,30 @@ eexpect eof
spawn $argv sql
eexpect root@

start_test "check CTRL+C during COPY exits the COPY mode as appropriate"

send "COPY t FROM STDIN CSV;\r"
eexpect ">>"
send "5,cancel me\r"

interrupt

eexpect "ERROR: COPY canceled by user"
eexpect root@

send "SELECT * FROM t ORDER BY id ASC;\r"
eexpect "(6 rows)"
## The following test can be re-enabled after fixing this issue:
# https://github.com/cockroachdb/cockroach/issues/93053

# start_test "check CTRL+C during COPY exits the COPY mode as appropriate"
#
# send "COPY t FROM STDIN CSV;\r"
# eexpect ">>"
# send "5,cancel me\r"
#
# interrupt
#
# eexpect "ERROR: COPY canceled by user"
# eexpect root@
#
# send "SELECT * FROM t ORDER BY id ASC;\r"
# eexpect "(6 rows)"
# eexpect root@
#
# end_test

send "truncate table t;\r"
eexpect "TRUNCATE"
eexpect root@

send "TRUNCATE TABLE t;\r"
eexpect root@

end_test

send_eof
eexpect eof

Expand All @@ -128,7 +136,10 @@ eexpect ":/# "

start_test "Test file input invalid"

send "cat >/tmp/test_copy.sql <<EOF\rCOPY t FROM STDIN CSV;\rinvalid text;,t\rEOF\r"
send "cat >/tmp/test_copy.sql <<EOF\r"
send "COPY t FROM STDIN CSV;\r"
send "invalid text;,t\r"
send "EOF\r"
eexpect ":/# "
send "$argv sql --insecure -f /tmp/test_copy.sql\r"
eexpect "ERROR: could not parse"
Expand All @@ -141,7 +152,12 @@ end_test

start_test "Test file input with valid content"

send "cat >/tmp/test_copy.sql <<EOF\rCOPY t FROM STDIN CSV;\r1,a\r\\.\r\rCOPY t FROM STDIN;\rEOF\r"
send "cat >/tmp/test_copy.sql <<EOF\r"
send "COPY t FROM STDIN CSV;\r"
send "1,a\r"
send "\\.\r\r"
send "COPY t FROM STDIN;\r"
send "EOF\r"
# Tab doesn't work nicely in cat<<EOF, so use echo to append the character with tab.
send "echo -e '2\\tb' >> /tmp/test_copy.sql\r"
eexpect ":/# "
Expand Down
Loading

0 comments on commit 52145a4

Please sign in to comment.