Skip to content

Commit

Permalink
Merge pull request #127673 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-24.1-127670

release-24.1: sql/sessiondatapb: fix parsing/formatting of sql_sequence_cached_node
  • Loading branch information
rafiss authored Jul 25, 2024
2 parents 3436a92 + f85980f commit 9d08ab4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/sql/sessiondatapb/local_only_session_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,20 @@ const (
// can impact performance negatively.
SerialUsesSQLSequences SerialNormalizationMode = 2
// SerialUsesCachedSQLSequences is identical to SerialUsesSQLSequences with
// the exception that nodes can cache sequence values. This significantly
// the exception that sessions can cache sequence values. This significantly
// reduces contention and distributed calls to kv, which results in better
// performance. Gaps between sequences may be larger as a result of cached
// values being lost to errors and/or node failures.
SerialUsesCachedSQLSequences SerialNormalizationMode = 3
// SerialUsesUnorderedRowID means use INT NOT NULL DEFAULT unordered_unique_rowid().
SerialUsesUnorderedRowID SerialNormalizationMode = 4
SerialUsesUnorderedRowID SerialNormalizationMode = 4
// SerialUsesCachedNodeSQLSequences is identical to
// SerialUsesCachedSQLSequences, except the sequence values are cached per
// node instead of per session.
SerialUsesCachedNodeSQLSequences SerialNormalizationMode = 5
// maxSerialNormalizationMode should always be one larger than the last
// public value.
maxSerialNormalizationMode = 6
)

func (m SerialNormalizationMode) String() string {
Expand All @@ -155,6 +161,8 @@ func (m SerialNormalizationMode) String() string {
return "sql_sequence"
case SerialUsesCachedSQLSequences:
return "sql_sequence_cached"
case SerialUsesCachedNodeSQLSequences:
return "sql_sequence_cached_node"
default:
return fmt.Sprintf("invalid (%d)", m)
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/sql/sessiondatapb/session_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ func TestSessionDataJsonCompat(t *testing.T) {
require.NoError(t, err)
require.Equal(t, expectedSessionData, actualSessionData)
}

func TestSerialNormalizationRoundTrip(t *testing.T) {
for s := range maxSerialNormalizationMode {
expectedVal := SerialNormalizationMode(s)
str := expectedVal.String()
actualVal, ok := SerialNormalizationModeFromString(str)
require.True(t, ok)
require.Equal(t, expectedVal, actualVal)
}
}

0 comments on commit 9d08ab4

Please sign in to comment.