Skip to content

Commit 061c2ab

Browse files
craig[bot]kyle-a-wongyuzefovichstevendanna
committed
148001: server,ui: increase max result size for sql over http requests r=dhartunian a=kyle-a-wong The default for max result size for the sql over http v2 API was previously set to 10kb, which was frequently resulting in incomplete results / error messages in db console. Additionally, db console used 50kb to as the "LARGE_RESULT_SIZE" value for many of db consoles sql over http requests. This has also been seen to result in errors like "Not all insights are displayed because the maximum number of insights was reached in the console." in the db console insights page. This change increases the default on the server side from 10kb to 100kb and the value of "LARGE_RESULT_SIZE" from 50kb to 1Mb Resolves: #146875 Epic: None Release note: None 148700: sql: always wait for all goroutines in fingerprintSpan r=yuzefovich a=yuzefovich This commit fixes an oversight from 1cf6236. In particular, in that change we ensured that we never leak the worker goroutines in fingerprintSpan by cancelling the context in the coordinator and checking for that in the workers. However, it was possible for the coordinator to exit before the workers which can lead to undefined behavior down the line (in a test failure we just saw usage of the trace span after finish). This commit fixes the oversight by always blocking the coordinator until all its workers exit. Fixes: #148602. Release note: None 148743: sql: version-gate sql.txn.write_buffering_for_weak_isolation.enabled r=yuzefovich a=stevendanna Buffering writes in weak isolation levels such as read committed requires lock loss detection to avoid intra-statement anomalies. Lock loss detection is only available when all nodes are on 25.3 or greater. Epic: none Release note: None Co-authored-by: Kyle Wong <[email protected]> Co-authored-by: Yahor Yuzefovich <[email protected]> Co-authored-by: Steven Danna <[email protected]>
4 parents 6d30ef4 + 9e59e52 + c61e6b4 + 37e29dc commit 061c2ab

File tree

11 files changed

+57
-26
lines changed

11 files changed

+57
-26
lines changed

pkg/ccl/logictestccl/testdata/logic_test/buffered_writes_lock_loss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# LogicTest: !3node-tenant
1+
# LogicTest: !3node-tenant !local-mixed-25.2
22
# cluster-opt: disable-mvcc-range-tombstones-for-point-deletes
33

44
statement ok

pkg/ccl/logictestccl/tests/local-mixed-25.2/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ go_test(
99
"//pkg/ccl/logictestccl:testdata", # keep
1010
],
1111
exec_properties = {"test.Pool": "large"},
12-
shard_count = 34,
12+
shard_count = 33,
1313
tags = ["cpu:1"],
1414
deps = [
1515
"//pkg/base",

pkg/ccl/logictestccl/tests/local-mixed-25.2/generated_test.go

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/serverccl/testdata/api_v2_sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sql admin
1212
"application_name": "$ api-v2-sql",
1313
"database": "system",
1414
"execute": false,
15-
"max_result_size": 10000,
15+
"max_result_size": 100000,
1616
"separate_txns": false,
1717
"statements": [
1818
{

pkg/server/api_v2_sql.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ func (a *apiV2Server) execSQL(w http.ResponseWriter, r *http.Request) {
306306
return
307307
}
308308
if requestPayload.MaxResultSize == 0 {
309-
requestPayload.MaxResultSize = 10000
309+
// Default to 100 kb if no MaxResultSize is provided.
310+
requestPayload.MaxResultSize = 100_000
310311
}
311312
if len(requestPayload.Statements) == 0 {
312313
topLevelError(errors.New("no statements specified"), http.StatusBadRequest)

pkg/server/testdata/api_v2_sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ sql admin
1010
"application_name": "$ api-v2-sql",
1111
"database": "system",
1212
"execute": false,
13-
"max_result_size": 10000,
13+
"max_result_size": 100000,
1414
"separate_txns": false,
1515
"statements": [
1616
{

pkg/sql/conn_executor.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/cockroachdb/cockroach/pkg/server/serverpb"
3131
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
3232
"github.com/cockroachdb/cockroach/pkg/settings"
33+
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
3334
"github.com/cockroachdb/cockroach/pkg/sql/appstatspb"
3435
"github.com/cockroachdb/cockroach/pkg/sql/auditlogging"
3536
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
@@ -3543,9 +3544,7 @@ func (ex *connExecutor) setTransactionModes(
35433544
if err := ex.state.setIsolationLevel(level); err != nil {
35443545
return pgerror.WithCandidateCode(err, pgcode.ActiveSQLTransaction)
35453546
}
3546-
if (level != isolation.Serializable) && !allowBufferedWritesForWeakIsolation.Get(&ex.server.cfg.Settings.SV) {
3547-
// TODO(#143497): we currently only support buffered writes under
3548-
// serializable isolation.
3547+
if !ex.bufferedWritesIsAllowedForIsolationLevel(ctx, level) {
35493548
ex.state.mu.txn.SetBufferedWritesEnabled(false)
35503549
}
35513550
}
@@ -3731,6 +3730,28 @@ func (ex *connExecutor) bufferedWritesEnabled(ctx context.Context) bool {
37313730
return ex.sessionData().BufferedWritesEnabled && ex.server.cfg.Settings.Version.IsActive(ctx, clusterversion.V25_2)
37323731
}
37333732

3733+
func (ex *connExecutor) bufferedWritesIsAllowedForIsolationLevel(
3734+
ctx context.Context, isoLevel isolation.Level,
3735+
) bool {
3736+
return bufferedWritesIsAllowedForIsolationLevel(ctx, ex.server.cfg.Settings, isoLevel)
3737+
}
3738+
3739+
func bufferedWritesIsAllowedForIsolationLevel(
3740+
ctx context.Context, st *cluster.Settings, isoLevel isolation.Level,
3741+
) bool {
3742+
if isoLevel == isolation.Serializable {
3743+
return true
3744+
}
3745+
3746+
// We are at a weaker isolation level that requires lock loss detection which
3747+
// is only available on 25.3 or greater.
3748+
if !st.Version.IsActive(ctx, clusterversion.V25_3) {
3749+
return false
3750+
}
3751+
3752+
return allowBufferedWritesForWeakIsolation.Get(&st.SV)
3753+
}
3754+
37343755
// initEvalCtx initializes the fields of an extendedEvalContext that stay the
37353756
// same across multiple statements. resetEvalCtx must also be called before each
37363757
// statement, to reinitialize other fields.

pkg/sql/fingerprint_span.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,12 @@ func (p *planner) fingerprintSpanFanout(
133133
fingerprintPartition := func(
134134
partition roachpb.Spans,
135135
) func(ctx context.Context) error {
136-
return func(ctx context.Context) error {
136+
return func(ctx context.Context) (retErr error) {
137137
// workCh is used to divide up the partition between workers. It is
138138
// closed whenever there is no work to do. It might not be closed if
139139
// the coordinator encounters an error.
140140
workCh := make(chan roachpb.Span)
141-
// The context will be canceled when the coordinator exits
142-
// guaranteeing that the worker goroutines aren't leaked.
143141
ctx, cancel := context.WithCancel(ctx)
144-
defer cancel()
145142

146143
grp := ctxgroup.WithContext(ctx)
147144
for range maxWorkerCount {
@@ -169,6 +166,27 @@ func (p *planner) fingerprintSpanFanout(
169166
}
170167
})
171168
}
169+
defer func() {
170+
// Either workCh is closed (meaning that we've processed all the
171+
// work), or we hit an error in the loop below. If it's the
172+
// latter, we need to cancel the context to signal to the
173+
// workers to shutdown ASAP.
174+
if retErr != nil {
175+
cancel()
176+
}
177+
// Regardless of how we got here, ensure that we always block
178+
// until all workers exit.
179+
// TODO(yuzefovich): refactor the logic here so that the
180+
// coordinator goroutine had a single return point. This will
181+
// also allow us to prevent a hypothetical scenario where we're
182+
// blocked forever (i.e. until the context is canceled) writing
183+
// into workCh which can happen if all worker goroutines exit
184+
// due to an error.
185+
grpErr := grp.Wait()
186+
if retErr == nil {
187+
retErr = grpErr
188+
}
189+
}()
172190

173191
for _, part := range partition {
174192
rdi, err := p.execCfg.RangeDescIteratorFactory.NewLazyIterator(ctx, part, 64)
@@ -195,7 +213,7 @@ func (p *planner) fingerprintSpanFanout(
195213
}
196214
}
197215
close(workCh)
198-
return grp.Wait()
216+
return nil
199217
}
200218
}
201219

pkg/sql/txn_state.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,7 @@ func (ts *txnState) resetForNewSQLTxn(
252252
if err := ts.setIsolationLevelLocked(isoLevel); err != nil {
253253
panic(err)
254254
}
255-
if isoLevel != isolation.Serializable && !allowBufferedWritesForWeakIsolation.Get(&tranCtx.settings.SV) {
256-
// TODO(#143497): we currently only support buffered writes
257-
// under serializable isolation.
255+
if !bufferedWritesIsAllowedForIsolationLevel(connCtx, tranCtx.settings, isoLevel) {
258256
bufferedWritesEnabled = false
259257
}
260258
if bufferedWritesEnabled {

pkg/ui/workspaces/cluster-ui/src/api/schedulesApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { RequestError } from "../util";
1010

1111
import {
1212
executeInternalSql,
13-
MAX_RESULT_SIZE,
13+
LARGE_RESULT_SIZE,
1414
SqlExecutionRequest,
1515
sqlResultsAreEmpty,
1616
} from "./sqlApi";
@@ -74,7 +74,7 @@ export function getSchedules(req: {
7474
arguments: args,
7575
},
7676
],
77-
max_result_size: MAX_RESULT_SIZE,
77+
max_result_size: LARGE_RESULT_SIZE,
7878
execute: true,
7979
};
8080
return executeInternalSql<ScheduleColumns>(request).then(result => {

0 commit comments

Comments
 (0)