Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
139698: catalog/lease: optimize WaitForInitialVersion for multiple objects r=fqazi a=fqazi

Previously, the WaitForInitialVersion serially went over objects one at
time, which was sub-optimal. This meant that a lot of round trips were
required to wait when a large number of objects were generated within a
single txn. To address this, this patch changes WaitForInitialVersion to
iterate on a per-schema basis and to be able to combine waits for
multiple descriptors.

This patch also adds extra testing for concurrent WaitForInitalVersion calls
```
benchdiff with these changes:
name                                old time/op    new time/op    delta
GenerateObjects/10000_tables-10        5.83s ± 1%     0.73s ± 2%  -87.51%  (p=0.000 n=8+9)
GenerateObjects/1000_tables-10         517ms ± 3%      76ms ± 3%  -85.39%  (p=0.000 n=9+10)
GenerateObjects/10x100_tables-10       519ms ± 3%      89ms ± 1%  -82.85%  (p=0.000 n=10+10)
GenerateObjects/10x10x10_tables-10     572ms ± 7%     170ms ± 3%  -70.26%  (p=0.000 n=9+9)

name                                old alloc/op   new alloc/op   delta
GenerateObjects/10000_tables-10       6.24GB ± 2%    1.24GB ±10%  -80.20%  (p=0.000 n=8+10)
GenerateObjects/1000_tables-10         343MB ± 1%     116MB ± 0%  -66.09%  (p=0.000 n=9+10)
GenerateObjects/10x100_tables-10       344MB ± 0%     130MB ± 1%  -62.25%  (p=0.000 n=8+10)
GenerateObjects/10x10x10_tables-10     365MB ± 0%     175MB ± 1%  -52.21%  (p=0.000 n=8+10)

name                                old allocs/op  new allocs/op  delta
GenerateObjects/10000_tables-10        38.5M ± 4%      6.5M ±15%  -83.04%  (p=0.000 n=9+10)
GenerateObjects/1000_tables-10         2.06M ± 0%     0.60M ± 0%  -70.87%  (p=0.000 n=8+10)
```
Fixes: #139495
Release note: None



139715: cli/pgx: Update pgx versions in go.mod r=spilchen a=spilchen

This commit updates the versions of specific packages from the github.com/jackc repository in go.mod to address known security vulnerabilities. The updated versions include fixes for these vulnerabilities.

Notably, the signature of the Encode() function in the pgx library has changed. It now returns both the encoded message and an error. Most of the changes in this commit are updates to handle the new function signature appropriately.

Epic: none
Release note: none

Informs #137595

139736: workload/schemachanger: limit size of datums during insert r=fqazi a=fqazi

Previously, the insert statement in the randomized schema changer workload could have unbounded sizes for individual datums. This patch adds size limit for datums in the insert operation, where datums will be regenerated a limited number of times until they are below a maximum size.

Fixes: #139494

Release note: None

Co-authored-by: Faizan Qazi <[email protected]>
Co-authored-by: Matt Spilchen <[email protected]>
  • Loading branch information
3 people committed Jan 24, 2025
4 parents 6ff1a78 + f112ef2 + 2713739 + a86c17d commit 5bcfd2a
Show file tree
Hide file tree
Showing 22 changed files with 432 additions and 218 deletions.
30 changes: 15 additions & 15 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5155,10 +5155,10 @@ def go_deps():
name = "com_github_jackc_pgconn",
build_file_proto_mode = "disable_global",
importpath = "github.com/jackc/pgconn",
sha256 = "d7935c04e5ee85f2dcab090692d2c24008071865a3af3581580bcc331a8f41d5",
strip_prefix = "github.com/jackc/[email protected].0",
sha256 = "164dbb661090368062498701530fcb1f62d6acc06558859646b62d97128ac06f",
strip_prefix = "github.com/jackc/[email protected].3",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgconn/com_github_jackc_pgconn-v1.14.0.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgconn/com_github_jackc_pgconn-v1.14.3.zip",
],
)
go_repository(
Expand Down Expand Up @@ -5205,10 +5205,10 @@ def go_deps():
name = "com_github_jackc_pgproto3_v2",
build_file_proto_mode = "disable_global",
importpath = "github.com/jackc/pgproto3/v2",
sha256 = "e6bafa5c3522534557a818f56939dde7b496c6669a5db9a74a0c91ab5290612c",
strip_prefix = "github.com/jackc/pgproto3/[email protected].2",
sha256 = "53ea236cbfe241693b439092e2d51b404c2a635ee3fe64ea7aad1527cb715189",
strip_prefix = "github.com/jackc/pgproto3/[email protected].3",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgproto3/v2/com_github_jackc_pgproto3_v2-v2.3.2.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgproto3/v2/com_github_jackc_pgproto3_v2-v2.3.3.zip",
],
)
go_repository(
Expand All @@ -5225,10 +5225,10 @@ def go_deps():
name = "com_github_jackc_pgtype",
build_file_proto_mode = "disable_global",
importpath = "github.com/jackc/pgtype",
sha256 = "7e67f5b944cbd401025c6473e624ef61ed196e3ed0f77ed437b0621cf820c0c9",
strip_prefix = "github.com/jackc/[email protected].0",
sha256 = "3acb69a66e7e432c010d503425810620d04c304166c45083fa8a96feca13054d",
strip_prefix = "github.com/jackc/[email protected].1",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgtype/com_github_jackc_pgtype-v1.14.0.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgtype/com_github_jackc_pgtype-v1.14.1.zip",
],
)
go_repository(
Expand All @@ -5245,10 +5245,10 @@ def go_deps():
name = "com_github_jackc_pgx_v5",
build_file_proto_mode = "disable_global",
importpath = "github.com/jackc/pgx/v5",
sha256 = "198eebac7e875b51616090fe2e3694e6f27e335afcc3c47ae9991497ade7f52a",
strip_prefix = "github.com/jackc/pgx/v5@v5.4.2",
sha256 = "003bc28d696865bd7cb2819d3902c0415bee4d276b129f92a8438330e6619f4d",
strip_prefix = "github.com/jackc/pgx/v5@v5.5.4",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgx/v5/com_github_jackc_pgx_v5-v5.4.2.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgx/v5/com_github_jackc_pgx_v5-v5.5.4.zip",
],
)
go_repository(
Expand All @@ -5265,10 +5265,10 @@ def go_deps():
name = "com_github_jackc_puddle_v2",
build_file_proto_mode = "disable_global",
importpath = "github.com/jackc/puddle/v2",
sha256 = "b99ea95df0c0298caf2be786c9eba511bfde2046eccfaa06e89b3e460ab406b0",
strip_prefix = "github.com/jackc/puddle/[email protected].0",
sha256 = "6698895617fabb929fa1ac868ad5253e02a997888bf5c6004379c5b29eedee58",
strip_prefix = "github.com/jackc/puddle/[email protected].1",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/puddle/v2/com_github_jackc_puddle_v2-v2.2.0.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/puddle/v2/com_github_jackc_puddle_v2-v2.2.1.zip",
],
)
go_repository(
Expand Down
10 changes: 5 additions & 5 deletions build/bazelutil/distdir_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -675,18 +675,18 @@ DISTDIR_FILES = {
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/j-keck/arping/com_github_j_keck_arping-v0.0.0-20160618110441-2cf9dc699c56.zip": "6001c94a8c4eed55718f627346cb685cce67369ca5c29ae059f58f7abd8bd8a7",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/chunkreader/com_github_jackc_chunkreader-v1.0.0.zip": "e204c917e2652ffe047f5c8b031192757321f568654e3df8408bf04178df1408",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/chunkreader/v2/com_github_jackc_chunkreader_v2-v2.0.1.zip": "6e3f4b7d9647f31061f6446ae10de71fc1407e64f84cd0949afac0cd231e8dd2",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgconn/com_github_jackc_pgconn-v1.14.0.zip": "d7935c04e5ee85f2dcab090692d2c24008071865a3af3581580bcc331a8f41d5",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgconn/com_github_jackc_pgconn-v1.14.3.zip": "164dbb661090368062498701530fcb1f62d6acc06558859646b62d97128ac06f",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgio/com_github_jackc_pgio-v1.0.0.zip": "1a83c03d53f6a40339364cafcbbabb44238203c79ca0c9b98bf582d0df0e0468",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgmock/com_github_jackc_pgmock-v0.0.0-20210724152146-4ad1a8207f65.zip": "0fffd0a7a67dbdfafa04297e51028c6d2d08cd6691f3b6d78d7ae6502d3d4cf2",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgpassfile/com_github_jackc_pgpassfile-v1.0.0.zip": "1cc79fb0b80f54b568afd3f4648dd1c349f746ad7c379df8d7f9e0eb1cac938b",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgproto3/com_github_jackc_pgproto3-v1.1.0.zip": "e3766bee50ed74e49a067b2c4797a2c69015cf104bf3f3624cd483a9e940b4ee",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgproto3/v2/com_github_jackc_pgproto3_v2-v2.3.2.zip": "e6bafa5c3522534557a818f56939dde7b496c6669a5db9a74a0c91ab5290612c",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgproto3/v2/com_github_jackc_pgproto3_v2-v2.3.3.zip": "53ea236cbfe241693b439092e2d51b404c2a635ee3fe64ea7aad1527cb715189",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgservicefile/com_github_jackc_pgservicefile-v0.0.0-20221227161230-091c0ba34f0a.zip": "1f8bdf75b2a0d750e56c2a94b1d1b0b5be4b29d6df056aebd997162c29bfd8ab",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgtype/com_github_jackc_pgtype-v1.14.0.zip": "7e67f5b944cbd401025c6473e624ef61ed196e3ed0f77ed437b0621cf820c0c9",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgtype/com_github_jackc_pgtype-v1.14.1.zip": "3acb69a66e7e432c010d503425810620d04c304166c45083fa8a96feca13054d",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgx/v4/com_github_jackc_pgx_v4-v4.18.1.zip": "5ca92c5bf58979d9e978f6b849e02eb319d2587565375fe875a29d10d84cfadc",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgx/v5/com_github_jackc_pgx_v5-v5.4.2.zip": "198eebac7e875b51616090fe2e3694e6f27e335afcc3c47ae9991497ade7f52a",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgx/v5/com_github_jackc_pgx_v5-v5.5.4.zip": "003bc28d696865bd7cb2819d3902c0415bee4d276b129f92a8438330e6619f4d",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/puddle/com_github_jackc_puddle-v1.3.0.zip": "b1eb42bb3cf9a430146af79cb183860b9dddfca51844c2d4b447dc2f43becc55",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/puddle/v2/com_github_jackc_puddle_v2-v2.2.0.zip": "b99ea95df0c0298caf2be786c9eba511bfde2046eccfaa06e89b3e460ab406b0",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/puddle/v2/com_github_jackc_puddle_v2-v2.2.1.zip": "6698895617fabb929fa1ac868ad5253e02a997888bf5c6004379c5b29eedee58",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jaegertracing/jaeger/com_github_jaegertracing_jaeger-v1.18.1.zip": "256a95b2a52a66494aca6d354224bb450ff38ce3ea1890af46a7c8dc39203891",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jawher/mow.cli/com_github_jawher_mow_cli-v1.2.0.zip": "4f8d43c8f2aa44524480ab57d8fbb63a607569ea11ff6a2eea7b46622104f717",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jcmturner/aescts/v2/com_github_jcmturner_aescts_v2-v2.0.0.zip": "717a211ad4aac248cf33cadde73059c13f8e9462123a0ab2fed5c5e61f7739d7",
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ require (
// the SQL team.
require (
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.0
github.com/jackc/pgconn v1.14.3
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.2
github.com/jackc/pgproto3/v2 v2.3.3
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.14.0
github.com/jackc/pgtype v1.14.1
github.com/jackc/pgx/v4 v4.18.1
)

Expand Down Expand Up @@ -179,7 +179,7 @@ require (
github.com/guptarohit/asciigraph v0.7.3
github.com/influxdata/influxdb-client-go/v2 v2.3.1-0.20210518120617-5d1fff431040
github.com/irfansharif/recorder v0.0.0-20211218081646-a21b46510fd6
github.com/jackc/pgx/v5 v5.4.2
github.com/jackc/pgx/v5 v5.5.4
github.com/jaegertracing/jaeger v1.18.1
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
github.com/jordanlewis/gcassert v0.0.0-20240401195008-3141cbd028c0
Expand Down Expand Up @@ -365,7 +365,7 @@ require (
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
github.com/jackc/puddle/v2 v2.2.0 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.7.6 // indirect
Expand Down
17 changes: 10 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1456,8 +1456,9 @@ github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsU
github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o=
github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY=
github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI=
github.com/jackc/pgconn v1.14.0 h1:vrbA9Ud87g6JdFWkHTJXppVce58qPIdP7N8y0Ml/A7Q=
github.com/jackc/pgconn v1.14.0/go.mod h1:9mBNlny0UvkgJdCDvdVHYSjI+8tD2rnKK69Wz8ti++E=
github.com/jackc/pgconn v1.14.3 h1:bVoTr12EGANZz66nZPkMInAV/KHD2TxH9npjXXgiB3w=
github.com/jackc/pgconn v1.14.3/go.mod h1:RZbme4uasqzybK2RK5c65VsHxoyaml09lx3tXOcO/VM=
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
Expand All @@ -1473,31 +1474,33 @@ github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvW
github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
github.com/jackc/pgproto3/v2 v2.3.2 h1:7eY55bdBeCz1F2fTzSz69QC+pG46jYq9/jtSPiJ5nn0=
github.com/jackc/pgproto3/v2 v2.3.2/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
github.com/jackc/pgproto3/v2 v2.3.3 h1:1HLSx5H+tXR9pW3in3zaztoEwQYRC9SQaYUHjTSUOag=
github.com/jackc/pgproto3/v2 v2.3.3/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg=
github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc=
github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw=
github.com/jackc/pgtype v1.8.1-0.20210724151600-32e20a603178/go.mod h1:C516IlIV9NKqfsMCXTdChteoXmwgUceqaLfjg2e3NlM=
github.com/jackc/pgtype v1.14.0 h1:y+xUdabmyMkJLyApYuPj38mW+aAIqCe5uuBB51rH3Vw=
github.com/jackc/pgtype v1.14.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4=
github.com/jackc/pgtype v1.14.1 h1:LyDar7M2K0tShCWqzJ/ctzF1QC3Wzc9c8a6cHE0PFdc=
github.com/jackc/pgtype v1.14.1/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4=
github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y=
github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM=
github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc=
github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs=
github.com/jackc/pgx/v4 v4.18.1 h1:YP7G1KABtKpB5IHrO9vYwSrCOhs7p3uqhvhhQBptya0=
github.com/jackc/pgx/v4 v4.18.1/go.mod h1:FydWkUyadDmdNH/mHnGob881GawxeEm7TcMCzkb+qQE=
github.com/jackc/pgx/v5 v5.4.2 h1:u1gmGDwbdRUZiwisBm/Ky2M14uQyUP65bG8+20nnyrg=
github.com/jackc/pgx/v5 v5.4.2/go.mod h1:q6iHT8uDNXWiFNOlRqJzBTaSH3+2xCXkokxHZC5qWFY=
github.com/jackc/pgx/v5 v5.5.4 h1:Xp2aQS8uXButQdnCMWNmvx6UysWQQC+u1EoizjguY+8=
github.com/jackc/pgx/v5 v5.5.4/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle/v2 v2.2.0 h1:RdcDk92EJBuBS55nQMMYFXTxwstHug4jkhT5pq8VxPk=
github.com/jackc/puddle/v2 v2.2.0/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jaegertracing/jaeger v1.18.1 h1:eFqjEpTKq2FfiZ/YX53oxeCePdIZyWvDfXaTAGj0r5E=
github.com/jaegertracing/jaeger v1.18.1/go.mod h1:WRzMFH62rje1VgbShlgk6UbWUNoo08uFFvs/x50aZKk=
github.com/jawher/mow.cli v1.0.4/go.mod h1:5hQj2V8g+qYmLUVWqu4Wuja1pI57M83EChYLVZ0sMKk=
Expand Down
24 changes: 18 additions & 6 deletions pkg/ccl/sqlproxyccl/authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ func TestReadTokenAuthResult(t *testing.T) {
cli, srv := net.Pipe()

go func() {
_, err := srv.Write((&pgproto3.BindComplete{}).Encode(nil))
buf, err := (&pgproto3.BindComplete{}).Encode(nil)
require.NoError(t, err)
_, err = srv.Write(buf)
require.NoError(t, err)
}()

Expand All @@ -280,7 +282,9 @@ func TestReadTokenAuthResult(t *testing.T) {
cli, srv := net.Pipe()

go func() {
_, err := srv.Write((&pgproto3.ErrorResponse{Severity: "FATAL", Code: "foo"}).Encode(nil))
buf, err := (&pgproto3.ErrorResponse{Severity: "FATAL", Code: "foo"}).Encode(nil)
require.NoError(t, err)
_, err = srv.Write(buf)
require.NoError(t, err)
}()

Expand All @@ -294,16 +298,24 @@ func TestReadTokenAuthResult(t *testing.T) {
crdbBackendKeyData := &pgproto3.BackendKeyData{ProcessID: 42, SecretKey: 99}

go func() {
_, err := srv.Write((&pgproto3.AuthenticationOk{}).Encode(nil))
buf, err := (&pgproto3.AuthenticationOk{}).Encode(nil)
require.NoError(t, err)
_, err = srv.Write(buf)
require.NoError(t, err)

_, err = srv.Write((&pgproto3.ParameterStatus{Name: "Server Version", Value: "1.3"}).Encode(nil))
buf, err = (&pgproto3.ParameterStatus{Name: "Server Version", Value: "1.3"}).Encode(nil)
require.NoError(t, err)
_, err = srv.Write(buf)
require.NoError(t, err)

_, err = srv.Write(crdbBackendKeyData.Encode(nil))
buf, err = crdbBackendKeyData.Encode(nil)
require.NoError(t, err)
_, err = srv.Write(buf)
require.NoError(t, err)

_, err = srv.Write((&pgproto3.ReadyForQuery{}).Encode(nil))
buf, err = (&pgproto3.ReadyForQuery{}).Encode(nil)
require.NoError(t, err)
_, err = srv.Write(buf)
require.NoError(t, err)
}()

Expand Down
6 changes: 5 additions & 1 deletion pkg/ccl/sqlproxyccl/backend_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ var BackendDial = func(
}

// Forward startup message to the backend connection.
if _, err := conn.Write(msg.Encode(nil)); err != nil {
buf, err := msg.Encode(nil)
if err != nil {
return errors.Wrapf(err, "encoding StartingMessage for target server %v", serverAddress)
}
if _, err := conn.Write(buf); err != nil {
return errors.Wrapf(err, "relaying StartupMessage to target server %v", serverAddress)
}
return nil
Expand Down
30 changes: 20 additions & 10 deletions pkg/ccl/sqlproxyccl/conn_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,18 +400,18 @@ var waitForShowTransferState = func(
}

// 2. Read DataRow.
if err := expectDataRow(ctx, serverConn, func(msg *pgproto3.DataRow, size int) bool {
if err := expectDataRow(ctx, serverConn, func(msg *pgproto3.DataRow, size int) (bool, error) {
// This has to be 4 since we validated RowDescription earlier.
if len(msg.Values) != 4 {
return false
return false, nil
}

// Validate transfer key. It is possible that the end-user uses the SHOW
// TRANSFER STATE WITH 'transfer_key' statement, but that isn't designed
// for external usage, so it is fine to just terminate here if the
// transfer key does not match.
if string(msg.Values[3]) != transferKey {
return false
return false, nil
}

// NOTE: We have to cast to string and copy here since the slice
Expand All @@ -423,7 +423,7 @@ var waitForShowTransferState = func(
if metrics != nil {
metrics.ConnMigrationTransferResponseMessageSize.RecordValue(int64(size))
}
return true
return true, nil
}); err != nil {
return "", "", "", errors.Wrap(err, "expecting DataRow")
}
Expand Down Expand Up @@ -490,8 +490,8 @@ var runAndWaitForDeserializeSession = func(
}

// 2. Read DataRow.
if err := expectDataRow(ctx, serverConn, func(msg *pgproto3.DataRow, _ int) bool {
return len(msg.Values) == 1 && string(msg.Values[0]) == "t"
if err := expectDataRow(ctx, serverConn, func(msg *pgproto3.DataRow, _ int) (bool, error) {
return len(msg.Values) == 1 && string(msg.Values[0]) == "t", nil
}); err != nil {
return errors.Wrap(err, "expecting DataRow")
}
Expand All @@ -512,7 +512,11 @@ var runAndWaitForDeserializeSession = func(
// writeQuery writes a SimpleQuery to the given writer w.
func writeQuery(w io.Writer, format string, a ...interface{}) error {
query := &pgproto3.Query{String: fmt.Sprintf(format, a...)}
_, err := w.Write(query.Encode(nil))
buf, err := query.Encode(nil)
if err != nil {
return errors.Wrap(err, "encoding SimpleQuery")
}
_, err = w.Write(buf)
return err
}

Expand Down Expand Up @@ -587,7 +591,11 @@ func waitForSmallRowDescription(

// Matching fails, so forward the message back to the client, and
// continue searching.
if _, err := clientConn.Write(msg.Encode(nil)); err != nil {
buf, err := msg.Encode(nil)
if err != nil {
return errors.Wrap(err, "encoding message")
}
if _, err := clientConn.Write(buf); err != nil {
return errors.Wrap(err, "writing message")
}
}
Expand All @@ -607,7 +615,7 @@ func waitForSmallRowDescription(
func expectDataRow(
ctx context.Context,
serverConn *interceptor.FrontendConn,
validateFn func(*pgproto3.DataRow, int) bool,
validateFn func(*pgproto3.DataRow, int) (bool, error),
) error {
if ctx.Err() != nil {
return ctx.Err()
Expand All @@ -624,7 +632,9 @@ func expectDataRow(
if !ok {
return errors.Newf("unexpected message: %v", jsonOrRaw(msg))
}
if !validateFn(pgMsg, size) {
if valid, err := validateFn(pgMsg, size); err != nil {
return errors.Wrap(err, "validation failure")
} else if !valid {
return errors.Newf("validation failed for message: %v", jsonOrRaw(msg))
}
return nil
Expand Down
Loading

0 comments on commit 5bcfd2a

Please sign in to comment.