Skip to content

Commit 60cd2b1

Browse files
craig[bot]bghalherkolategan
committed
148290: sql: default to node-level cache for sequences r=bghal a=bghal The session-level cache was implemented first and shared node-level cache was added in #118546. The better behaving node-level cache is not the default option. Changes the default for `CACHE` option to set node-level cache. A new option to allows the session-level cache to be set. Epic: CRDB-42587 Fixes: #131531 Release note (sql change): Changed the basic sequence cache option to set cache at the node-level. The PER SESSION NODE sequence option (syntax is is [ PER SESSION CACHE # ]) provides the previous behavior to set session-level cache. 148596: roachtest: remove error assertion from panic node mutator r=stevendann,DarrylWong a=herkolategan The panic node mutator error assertion is causing flakes, as the error is not always the specific TCP error that is expected even if the panic is working as it should. Given that we are not testing the panic implementation here, asserting on the node being down should be enough. Fixes: #148586 Epic: None Release note: None Co-authored-by: Brendan Gerrity <[email protected]> Co-authored-by: Herko Lategan <[email protected]>
3 parents fb045f3 + f41dde4 + 17cba3a commit 60cd2b1

File tree

51 files changed

+195
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+195
-179
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
alter_sequence_stmt ::=
22
( 'ALTER' 'SEQUENCE' sequence_name 'RENAME' 'TO' sequence_name | 'ALTER' 'SEQUENCE' 'IF' 'EXISTS' sequence_name 'RENAME' 'TO' sequence_name )
3-
| ( 'ALTER' 'SEQUENCE' sequence_name ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) | 'ALTER' 'SEQUENCE' 'IF' 'EXISTS' sequence_name ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) )
3+
| ( 'ALTER' 'SEQUENCE' sequence_name ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'PER' 'SESSION' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'PER' 'SESSION' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) | 'ALTER' 'SEQUENCE' 'IF' 'EXISTS' sequence_name ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'PER' 'SESSION' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'PER' 'SESSION' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) )
44
| ( 'ALTER' 'SEQUENCE' sequence_name 'SET' 'SCHEMA' schema_name | 'ALTER' 'SEQUENCE' 'IF' 'EXISTS' sequence_name 'SET' 'SCHEMA' schema_name )
55
| ( 'ALTER' 'SEQUENCE' sequence_name 'OWNER' 'TO' role_spec | 'ALTER' 'SEQUENCE' 'IF' 'EXISTS' sequence_name 'OWNER' 'TO' role_spec )
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
create_sequence_stmt ::=
2-
'CREATE' opt_temp 'SEQUENCE' sequence_name ( ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) | )
3-
| 'CREATE' opt_temp 'SEQUENCE' 'IF' 'NOT' 'EXISTS' sequence_name ( ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) | )
2+
'CREATE' opt_temp 'SEQUENCE' sequence_name ( ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'PER' 'SESSION' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'PER' 'SESSION' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) | )
3+
| 'CREATE' opt_temp 'SEQUENCE' 'IF' 'NOT' 'EXISTS' sequence_name ( ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'PER' 'SESSION' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) ( ( ( 'AS' typename | 'NO' 'CYCLE' | 'OWNED' 'BY' 'NONE' | 'OWNED' 'BY' column_name | 'CACHE' integer | 'PER' 'NODE' 'CACHE' integer | 'PER' 'SESSION' 'CACHE' integer | 'INCREMENT' integer | 'INCREMENT' 'BY' integer | 'MINVALUE' integer | 'NO' 'MINVALUE' | 'MAXVALUE' integer | 'NO' 'MAXVALUE' | 'START' integer | 'START' 'WITH' integer | 'RESTART' | 'RESTART' integer | 'RESTART' 'WITH' integer | 'VIRTUAL' ) ) )* ) | )

docs/generated/sql/bnf/stmt_block.bnf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,6 +3743,7 @@ sequence_option_elem ::=
37433743
| 'OWNED' 'BY' column_path
37443744
| 'CACHE' signed_iconst64
37453745
| 'PER' 'NODE' 'CACHE' signed_iconst64
3746+
| 'PER' 'SESSION' 'CACHE' signed_iconst64
37463747
| 'INCREMENT' signed_iconst64
37473748
| 'INCREMENT' 'BY' signed_iconst64
37483749
| 'MINVALUE' signed_iconst64
@@ -4939,6 +4940,8 @@ col_qual_list ::=
49394940
identity_option_elem ::=
49404941
'SET' 'NO' 'CYCLE'
49414942
| 'SET' 'CACHE' signed_iconst64
4943+
| 'SET' 'PER' 'NODE' 'CACHE' signed_iconst64
4944+
| 'SET' 'PER' 'SESSION' 'CACHE' signed_iconst64
49424945
| 'SET' 'INCREMENT' signed_iconst64
49434946
| 'SET' 'INCREMENT' 'BY' signed_iconst64
49444947
| 'SET' 'MINVALUE' signed_iconst64

pkg/cmd/roachtest/roachtestutil/mixedversion/steps.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"fmt"
1111
"math"
1212
"math/rand"
13-
"regexp"
1413
"strings"
1514
"time"
1615

@@ -804,8 +803,6 @@ func (s panicNodeStep) Description() string {
804803
return fmt.Sprintf("panicking system interface on node %d", s.targetNode[0])
805804
}
806805

807-
var connectionRefusedRegex = regexp.MustCompile(`dial tcp .*: connect: connection refused`)
808-
809806
func (s panicNodeStep) Run(ctx context.Context, l *logger.Logger, rng *rand.Rand, h *Helper) error {
810807
nodeVersion, err := h.System.NodeVersion(s.targetNode[0])
811808
if err != nil {
@@ -831,14 +828,6 @@ func (s panicNodeStep) Run(ctx context.Context, l *logger.Logger, rng *rand.Rand
831828
return errors.Errorf("expected panic statement to fail, but it succeeded on %s", s.targetNode)
832829
}
833830

834-
isTCPError := connectionRefusedRegex.MatchString(err.Error())
835-
836-
// The expected behavior is that the panic statement will fail with a TCP connection error,
837-
// so any other error is unexpected and should cause the test to fail.
838-
if !isTCPError {
839-
return errors.Wrapf(err, "unexpected error when executing panic statement on %s", s.targetNode)
840-
}
841-
842831
startCtx, cancel := context.WithTimeout(ctx, startTimeout)
843832
defer cancel()
844833

pkg/sql/alter_table.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,8 +1252,11 @@ func applyColumnMutation(
12521252

12531253
opts := seqDesc.GetSequenceOpts()
12541254
optsNode := tree.SequenceOptions{}
1255-
if opts.CacheSize > 1 {
1256-
optsNode = append(optsNode, tree.SequenceOption{Name: tree.SeqOptCache, IntVal: &opts.CacheSize})
1255+
if opts.SessionCacheSize > 1 {
1256+
optsNode = append(optsNode, tree.SequenceOption{Name: tree.SeqOptCacheSession, IntVal: &opts.SessionCacheSize})
1257+
}
1258+
if opts.NodeCacheSize > 1 {
1259+
optsNode = append(optsNode, tree.SequenceOption{Name: tree.SeqOptCacheNode, IntVal: &opts.NodeCacheSize})
12571260
}
12581261
optsNode = append(optsNode, tree.SequenceOption{Name: tree.SeqOptMinValue, IntVal: &opts.MinValue})
12591262
optsNode = append(optsNode, tree.SequenceOption{Name: tree.SeqOptMaxValue, IntVal: &opts.MaxValue})

pkg/sql/catalog/descpb/structured.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func (opts *TableDescriptor_SequenceOpts) HasOwner() bool {
302302
//
303303
// Note: An unset cache size is considered disabled.
304304
func (opts *TableDescriptor_SequenceOpts) EffectiveCacheSize() int64 {
305-
switch sessionCacheSize := opts.CacheSize; sessionCacheSize {
305+
switch sessionCacheSize := opts.SessionCacheSize; sessionCacheSize {
306306
case 0, 1:
307307
default:
308308
return sessionCacheSize

pkg/sql/catalog/descpb/structured.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,8 +1194,8 @@ message TableDescriptor {
11941194
optional SequenceOwner sequence_owner = 6 [(gogoproto.nullable) = false];
11951195

11961196
// The number of values (which have already been created in KV)
1197-
// that a node can cache locally.
1198-
optional int64 cache_size = 7 [(gogoproto.nullable) = false];
1197+
// that a session can cache locally.
1198+
optional int64 session_cache_size = 7 [(gogoproto.nullable) = false];
11991199
// AS option value for CREATE SEQUENCE, which specifies the default
12001200
// min and max values a sequence can take on.
12011201
optional string as_integer_type = 8 [(gogoproto.nullable) = false];

pkg/sql/catalog/descpb/structured_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ func TestEffectiveCacheSize(t *testing.T) {
132132
for _, tt := range testCases {
133133
t.Run(tt.name, func(t *testing.T) {
134134
opts := TableDescriptor_SequenceOpts{
135-
CacheSize: tt.session,
136-
NodeCacheSize: tt.node,
135+
SessionCacheSize: tt.session,
136+
NodeCacheSize: tt.node,
137137
}
138138
result := opts.EffectiveCacheSize()
139139
if result != tt.expectedResult {

pkg/sql/catalog/schemaexpr/sequence_options.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func AssignSequenceOptions(
111111
opts.MaxValue = -1
112112
opts.Start = opts.MaxValue
113113
}
114-
opts.CacheSize = 1
114+
opts.SessionCacheSize = 1
115115
}
116116

117117
// Set Minvalue and Maxvalue to new types bounds if at current bounds.
@@ -148,19 +148,19 @@ func AssignSequenceOptions(
148148
"CYCLE option is not supported")
149149
case tree.SeqOptNoCycle:
150150
// Do nothing; this is the default.
151-
case tree.SeqOptCache:
151+
case tree.SeqOptCacheNode:
152152
if v := *option.IntVal; v >= 1 {
153-
opts.CacheSize = v
153+
opts.NodeCacheSize = v
154154
} else {
155155
return errors.Newf(
156-
"CACHE (%d) must be greater than zero", v)
156+
"PER NODE CACHE (%d) must be greater than zero", v)
157157
}
158-
case tree.SeqOptCacheNode:
158+
case tree.SeqOptCacheSession:
159159
if v := *option.IntVal; v >= 1 {
160-
opts.NodeCacheSize = v
160+
opts.SessionCacheSize = v
161161
} else {
162162
return errors.Newf(
163-
"PER NODE CACHE (%d) must be greater than zero", v)
163+
"PER SESSION CACHE (%d) must be greater than zero", v)
164164
}
165165
case tree.SeqOptIncrement:
166166
// Do nothing; this has already been set.

pkg/sql/catalog/serial_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func SequenceOptionsFromNormalizationMode(
6161
case sessiondatapb.SerialUsesCachedSQLSequences:
6262
cacheValue := sqlclustersettings.CachedSequencesCacheSizeSetting.Get(&st.SV)
6363
seqOpts = append(seqOpts, tree.SequenceOption{
64-
Name: tree.SeqOptCache,
64+
Name: tree.SeqOptCacheSession,
6565
IntVal: &cacheValue,
6666
})
6767
case sessiondatapb.SerialUsesCachedNodeSQLSequences:

0 commit comments

Comments
 (0)