Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

[cherry pick] Apply GRPC error processing change from upstream #188

Open
wants to merge 96 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 95 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
7cf6517
[java] bump java version to 7.0 for release-7.0
harshit-gangal Jul 27, 2020
b53e1a2
Merge pull request #6479 from planetscale/java-7.0
deepthi Jul 27, 2020
695c8ba
Update user-facing terminology + copyright dates in tools/web_*
doeg Jul 27, 2020
6af7703
Regenerate static files to pick up terminology changes
doeg Jul 27, 2020
ec83346
More terminology updates: replica -> replication
doeg Jul 27, 2020
02eb3b8
Regenerate vtctld2 assets
doeg Jul 27, 2020
10b0928
Merge pull request #6484 from planetscale/ds-7.0-backport-6481
deepthi Jul 28, 2020
61875d8
Add more system settings
systay Jul 28, 2020
404d357
fix executor set unit test
harshit-gangal Jul 28, 2020
a3a5232
Merge pull request #6488 from planetscale/settings-tweak-backport
deepthi Jul 28, 2020
e2c2413
HandleSet in executor to handle multiple settings in single set state…
harshit-gangal Jul 29, 2020
9dc92db
extreact lookup tests into own file
systay Jul 30, 2020
e46fa60
make sure to query consisten lookup vindexes on the correct connection
systay Jul 30, 2020
2e7252d
Add diagnostic logging to healthcheck.
deepthi Jul 31, 2020
1f7e775
backport #6514 to 7.0 release branch
harshit-gangal Aug 12, 2020
2ff46c9
Merge pull request #6512 from planetscale/ds-hchk-logging
deepthi Aug 12, 2020
d6c4333
Merge pull request #6505 from planetscale/bp-6499
deepthi Aug 12, 2020
5ec5c71
Merge pull request #6555 from planetscale/7.0-bp-6514
deepthi Aug 12, 2020
f2c350c
remove single shard session fom session shardSessions
harshit-gangal Jul 31, 2020
945eb59
reserved non transaction - removes the reserved shard session on conn…
harshit-gangal Jul 31, 2020
6f67c0b
added endtoend to mock reserved connection closing
harshit-gangal Jul 31, 2020
db38174
use new healthcheck gateway in tx_conn test for reserved connection
harshit-gangal Jul 31, 2020
11da205
added additional e2e test for reserved conn with partial shard with tx
harshit-gangal Jul 31, 2020
f8bf23f
added unit test on reserved conn failure
harshit-gangal Jul 31, 2020
b466a32
addressed review comments
harshit-gangal Aug 13, 2020
8b56bbf
Merge pull request #6563 from planetscale/7.0-bp-6522
harshit-gangal Aug 13, 2020
b787d87
tablet_picker: keep trying to find a tablet until context expires (#6…
deepthi Aug 14, 2020
7c7c068
Merge pull request #6504 from planetscale/bp-6495
harshit-gangal Aug 14, 2020
8db7fc3
support vindex update or delete when destination is provided by clien…
harshit-gangal Aug 12, 2020
33a98ce
added sysvarset flag to disable set passthrough by default
harshit-gangal Aug 13, 2020
8609af5
use sysvarenabled flag to create checkAndIgnore plan if dissabled
harshit-gangal Aug 13, 2020
ba5047e
added plan test for sysvar disabled
harshit-gangal Aug 13, 2020
4671cff
updated e2e test ot use target destination
harshit-gangal Aug 12, 2020
c0b957b
resolve lookup e2e test conflict
harshit-gangal Aug 14, 2020
e92fead
Make sure to handle EXPLAIN on vttablet
systay Aug 17, 2020
6c611e4
Merge pull request #6581 from systay/explain-regression-backport
harshit-gangal Aug 17, 2020
24494eb
Merge pull request #6572 from planetscale/fp-6554
deepthi Aug 17, 2020
f105114
Merge pull request #6567 from planetscale/ds-backport-6546
deepthi Aug 17, 2020
241bb0e
close idle reserved connections and rollback idle transactions
harshit-gangal Aug 11, 2020
ad7da76
added endtoend tests
systay Aug 14, 2020
9d4a1c5
use unlockUpdateTime when a transaction is started
harshit-gangal Aug 14, 2020
e43d98c
vtcompose/docker-compose: fix InitShardMaster
shlomi-noach Aug 18, 2020
e9ca16e
Merge pull request #6587 from vitessio/release-7.0-fix-docker-compose
deepthi Aug 18, 2020
e935f9d
Merge pull request #6583 from planetscale/bp-6552
systay Aug 19, 2020
6f960c8
add a hack to enable routing to RDONLY tablets for REPLICA queries
demmer Mar 5, 2020
6fa4555
Patch sqltypes.MakeRowTrusted to lean on field count (#126)
setassociative Feb 25, 2019
e42f46a
Docker - allow BUILD_NUMBER variable override
Jul 2, 2020
c9266d8
Fix #6597 by adding mysqld port display back to vtctld web UI.
aquarapid Aug 20, 2020
c3c1dde
Regenerate vtctld2 for #6597 fix.
aquarapid Aug 20, 2020
dafec91
Merge remote-tracking branch 'upstream/release-7.0' into slack-vitess…
ameetkotian Aug 20, 2020
886104d
Merge pull request #6600 from planetscale/backport_6597
deepthi Aug 20, 2020
bb07a19
Materialize: Only get schema from source tablets if target is missing…
rohit-nayak-ps Aug 20, 2020
791ac7c
Address review comments
rohit-nayak-ps Aug 22, 2020
19c92a5
Merge pull request #6623 from planetscale/backport_6601
deepthi Aug 25, 2020
9f472c4
sync2: Add AcquireContext to sema
sougou Aug 26, 2020
d9ed3ad
tm: deadlock: PromoteReplica vs replmanager
sougou Aug 26, 2020
1e0b4b3
tm: address review comments
sougou Aug 26, 2020
9f6b69c
Merge pull request #6633 from planetscale/ss-tm4-backport-tm-fix
deepthi Aug 26, 2020
fe78b23
Merge tag 'v7.0.1' into slack-vitess-2020.08.19.r0
ameetkotian Aug 27, 2020
2b339a8
Updates enforcement policy to match the one from the client
ameetkotian Aug 27, 2020
a8260ae
Merge remote-tracking branch 'upstream/release-7.0' into slack-vitess…
ameetkotian Aug 27, 2020
aeb96b6
tm: checkMastership: handle more corner cases
sougou Aug 25, 2020
8e3134a
tm: add more logging to checkMastership
sougou Aug 25, 2020
04e899d
restore: do not change tablet type to RESTORE if not actually perform…
deepthi Sep 9, 2020
db4837a
Merge pull request #6685 from planetscale/ds-backport-6618
deepthi Sep 9, 2020
2996c15
tm init: publish displayState
deepthi Aug 29, 2020
fa432ce
Merge pull request #6686 from planetscale/ds-backport-6648
deepthi Sep 9, 2020
60b65c6
Merge pull request #6687 from planetscale/ds-backport-6679
deepthi Sep 9, 2020
258485e
Merge remote-tracking branch 'upstream/release-7.0' into slack-vitess…
ameetkotian Sep 10, 2020
0c8c5ac
Handle FuncExpr columns
rohit-nayak-ps Aug 27, 2020
a3359a1
Add collation to e2e test to table with unicode_loose_md5
rohit-nayak-ps Aug 27, 2020
272226e
Turn off schema tracker by default
rohit-nayak-ps Sep 13, 2020
a5eacbc
Merge pull request #6746 from planetscale/rn-backport-6712
deepthi Sep 18, 2020
2ae1bc0
Merge pull request #6745 from planetscale/rn-backport-6640
deepthi Sep 18, 2020
7b075b6
end to end test for reserved connection in autocommit mode
harshit-gangal Sep 19, 2020
3b73b84
handle reserved connection in autocommit enabled
harshit-gangal Sep 21, 2020
7f918ea
Merge pull request #6760 from planetscale/bp-6748
deepthi Sep 21, 2020
937dd29
operator precedence must take associativity into consideration
systay Sep 21, 2020
9af279d
add more precedence tests
systay Sep 21, 2020
aea21dc
Merge pull request #6764 from GuptaManan100/release-7.0
systay Sep 22, 2020
0ac6a3d
sort tabledefinitions before comparing them
systay Sep 22, 2020
ec88581
restore: checkNoDB should not require tables to be present when the d…
deepthi Sep 10, 2020
635c0c6
tests: disable schema tracking in reparent tests for now, fix spare t…
deepthi Sep 10, 2020
ee6db6a
Merge pull request #6788 from planetscale/ds-backport-6695
deepthi Sep 25, 2020
b5651b7
Merge pull request #6784 from planetscale/backport-6765
deepthi Sep 28, 2020
61ab6e0
Merge remote-tracking branch 'upstream/release-7.0' into slack-vitess…
ameetkotian Sep 29, 2020
87ee0ee
This is a squashed rebase of am_show_filtered_tablets without the fin…
ajm188 Sep 19, 2020
6682c70
Regenerate parser post-cherry-pick, fix govet error in tests
ajm188 Sep 29, 2020
3d2ed67
tm: call SetReadOnly inside ChangeTabletType so that a tablet doesn't…
deepthi Sep 30, 2020
07d0bad
Merge pull request #6804 from planetscale/ds-backport-6762-6786
deepthi Sep 30, 2020
58eb423
Merge remote-tracking branch 'upstream/release-7.0' into slack-vitess…
ameetkotian Oct 1, 2020
9c14b62
Merge pull request #6766 from GuptaManan100/warning-for-context
systay Sep 22, 2020
b8901b9
Merge pull request #6721 from tinyspeck/fixes-long-wait-filter-keyspa…
deepthi Sep 18, 2020
86a5bd9
Merge pull request #183 from tinyspeck/slack-vitess-2020.09.29.r0
ajm188 Oct 20, 2020
adc03bf
Change GRPC message limit SQL error type (#6630)
setassociative Sep 17, 2020
3018928
Adds better error when there are timeouts in resource pools
rafael Nov 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ FROM vitess/bootstrap:mysql57
# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree
USER root
COPY . /vt/src/vitess.io/vitess
Expand Down
6 changes: 6 additions & 0 deletions docker/base/Dockerfile.mariadb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
FROM vitess/bootstrap:mariadb

# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree
USER root
COPY . /vt/src/vitess.io/vitess
Expand Down
6 changes: 6 additions & 0 deletions docker/base/Dockerfile.mariadb103
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
FROM vitess/bootstrap:mariadb103

# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree
USER root
COPY . /vt/src/vitess.io/vitess
Expand Down
6 changes: 6 additions & 0 deletions docker/base/Dockerfile.mysql56
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
FROM vitess/bootstrap:mysql56

# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree
USER root
COPY . /vt/src/vitess.io/vitess
Expand Down
6 changes: 6 additions & 0 deletions docker/base/Dockerfile.mysql80
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
FROM vitess/bootstrap:mysql80

# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree
USER root
COPY . /vt/src/vitess.io/vitess
Expand Down
6 changes: 6 additions & 0 deletions docker/base/Dockerfile.percona
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
FROM vitess/bootstrap:percona

# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree
USER root
COPY . /vt/src/vitess.io/vitess
Expand Down
6 changes: 6 additions & 0 deletions docker/base/Dockerfile.percona57
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
FROM vitess/bootstrap:percona57

# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree
USER root
COPY . /vt/src/vitess.io/vitess
Expand Down
6 changes: 6 additions & 0 deletions docker/base/Dockerfile.percona80
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
FROM vitess/bootstrap:percona80

# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree
USER root
COPY . /vt/src/vitess.io/vitess
Expand Down
3 changes: 3 additions & 0 deletions docker/lite/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ FROM vitess/bootstrap:mariadb103 AS builder
# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree.
COPY --chown=vitess:vitess . /vt/src/vitess.io/vitess

Expand Down
3 changes: 3 additions & 0 deletions docker/lite/Dockerfile.mariadb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ FROM vitess/bootstrap:mariadb AS builder
# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree.
COPY --chown=vitess:vitess . /vt/src/vitess.io/vitess

Expand Down
3 changes: 3 additions & 0 deletions docker/lite/Dockerfile.mariadb103
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ FROM vitess/bootstrap:mariadb103 AS builder
# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree.
COPY --chown=vitess:vitess . /vt/src/vitess.io/vitess

Expand Down
3 changes: 3 additions & 0 deletions docker/lite/Dockerfile.mysql56
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ FROM vitess/bootstrap:mysql56 AS builder
# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree.
COPY --chown=vitess:vitess . /vt/src/vitess.io/vitess

Expand Down
3 changes: 3 additions & 0 deletions docker/lite/Dockerfile.mysql57
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ FROM vitess/bootstrap:mysql57 AS builder
# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree.
COPY --chown=vitess:vitess . /vt/src/vitess.io/vitess

Expand Down
3 changes: 3 additions & 0 deletions docker/lite/Dockerfile.mysql80
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ FROM vitess/bootstrap:mysql80 AS builder
# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree.
COPY --chown=vitess:vitess . /vt/src/vitess.io/vitess

Expand Down
3 changes: 3 additions & 0 deletions docker/lite/Dockerfile.percona
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ FROM vitess/bootstrap:percona AS builder
# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree.
COPY --chown=vitess:vitess . /vt/src/vitess.io/vitess

Expand Down
3 changes: 3 additions & 0 deletions docker/lite/Dockerfile.percona57
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ FROM vitess/bootstrap:percona57 AS builder
# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree.
COPY --chown=vitess:vitess . /vt/src/vitess.io/vitess

Expand Down
3 changes: 3 additions & 0 deletions docker/lite/Dockerfile.percona80
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ FROM vitess/bootstrap:percona80 AS builder
# Allows some docker builds to disable CGO
ARG CGO_ENABLED=0

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER

# Re-copy sources from working tree.
COPY --chown=vitess:vitess . /vt/src/vitess.io/vitess

Expand Down
37 changes: 36 additions & 1 deletion examples/compose/vtcompose/vtcompose.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ func applyKeyspaceDependentPatches(
if keyspaceData.shards < 2 {
tabAlias = tabAlias + 100
dockerComposeFile = applyTabletPatches(dockerComposeFile, tabAlias, shard, keyspaceData, externalDbInfoMap, opts)
dockerComposeFile = applyShardPatches(dockerComposeFile, tabAlias, shard, keyspaceData, opts)
} else {
// Determine shard range
for i := 0; i < keyspaceData.shards; i++ {
Expand All @@ -446,6 +447,7 @@ func applyKeyspaceDependentPatches(
}
tabAlias = tabAlias + 100
dockerComposeFile = applyTabletPatches(dockerComposeFile, tabAlias, shard, keyspaceData, externalDbInfoMap, opts)
dockerComposeFile = applyShardPatches(dockerComposeFile, tabAlias, shard, keyspaceData, opts)
}
}

Expand Down Expand Up @@ -475,6 +477,39 @@ func applyDockerComposePatches(
return dockerComposeFile
}

func applyShardPatches(
dockerComposeFile []byte,
tabAlias int,
shard string,
keyspaceData keyspaceInfo,
opts vtOptions,
) []byte {
dockerComposeFile = applyInMemoryPatch(dockerComposeFile, generateDefaultShard(tabAlias, shard, keyspaceData, opts))
return dockerComposeFile
}

func generateDefaultShard(tabAlias int, shard string, keyspaceData keyspaceInfo, opts vtOptions) string {
aliases := []int{tabAlias + 1} // master alias, e.g. 201
for i := 0; i < keyspaceData.replicaTablets; i++ {
aliases = append(aliases, tabAlias+2+i) // replica aliases, e.g. 202, 203, ...
}
tabletDepends := make([]string, len(aliases))
for i, tabletId := range aliases {
tabletDepends[i] = fmt.Sprintf("vttablet%d: {condition : service_healthy}", tabletId)
}
// Wait on all shard tablets to be healthy
dependsOn := "depends_on: {" + strings.Join(tabletDepends, ", ") + "}"

return fmt.Sprintf(`
- op: add
path: /services/init_shard_master%[2]d
value:
image: vitess/base
command: ["sh", "-c", "$$VTROOT/bin/vtctl %[5]s InitShardMaster -force %[4]s/%[3]s %[6]s-%[2]d "]
%[1]s
`, dependsOn, aliases[0], shard, keyspaceData.keyspace, opts.topologyFlags, opts.cell)
}

func applyTabletPatches(
dockerComposeFile []byte,
tabAlias int,
Expand Down Expand Up @@ -674,7 +709,7 @@ func generatePrimaryVIndex(tableName, column, name string) string {
return fmt.Sprintf(`
[{"op": "add",
"path": "/tables/%[1]s",
"value":
"value":
{"column_vindexes": [
{
"column": "%[2]s",
Expand Down
8 changes: 3 additions & 5 deletions examples/compose/vttablet-up.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash

# Copyright 2019 The Vitess Authors.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -120,8 +120,6 @@ $VTROOT/bin/vtctl $TOPOLOGY_FLAGS AddCellInfo -root vitess/$CELL -server_address
$VTROOT/bin/vtctl $TOPOLOGY_FLAGS CreateKeyspace $keyspace || true
$VTROOT/bin/vtctl $TOPOLOGY_FLAGS CreateShard $keyspace/$shard || true

$VTROOT/bin/vtctl $TOPOLOGY_FLAGS InitTablet -shard $shard -keyspace $keyspace -grpc_port $grpc_port -port $web_port -allow_master_override $alias $tablet_role

#Populate external db conditional args
if [ "$external" = "1" ]; then
if [ $role = "master" ]; then
Expand Down
2 changes: 0 additions & 2 deletions go/cmd/vtbackup/vtbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,6 @@ func takeBackup(ctx context.Context, topoServer *topo.Server, backupStorage back
return fmt.Errorf("no backup found; not starting up empty since -initial_backup flag was not enabled")
}
restorePos = mysql.Position{}
case mysqlctl.ErrExistingDB:
return fmt.Errorf("can't run vtbackup because data directory is not empty")
default:
return fmt.Errorf("can't restore from backup: %v", err)
}
Expand Down
13 changes: 12 additions & 1 deletion go/mysql/sql_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func NewSQLErrorFromError(err error) error {
case vtrpcpb.Code_UNAUTHENTICATED:
num = ERAccessDeniedError
case vtrpcpb.Code_RESOURCE_EXHAUSTED:
num = ERTooManyUserConnections
num = demuxResourceExhaustedErrors(err.Error())
case vtrpcpb.Code_FAILED_PRECONDITION:
num = ERUnknownError
case vtrpcpb.Code_ABORTED:
Expand Down Expand Up @@ -161,3 +161,14 @@ func NewSQLErrorFromError(err error) error {
}
return serr
}

var isGRPCOverflowRE = regexp.MustCompile(`.*grpc: received message larger than max \(\d+ vs. \d+\)`)

func demuxResourceExhaustedErrors(msg string) int {
switch {
case isGRPCOverflowRE.Match([]byte(msg)):
return ERNetPacketTooLarge
default:
return ERTooManyUserConnections
}
}
45 changes: 45 additions & 0 deletions go/mysql/sql_error_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright 2020 The Vitess Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package mysql

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestDumuxResourceExhaustedErrors(t *testing.T) {
type testCase struct {
msg string
want int
}

cases := []testCase{
testCase{"misc", ERTooManyUserConnections},
testCase{"grpc: received message larger than max (99282 vs. 1234): trailer", ERNetPacketTooLarge},
testCase{"grpc: received message larger than max (1234 vs. 1234)", ERNetPacketTooLarge},
testCase{"header: grpc: received message larger than max (1234 vs. 1234)", ERNetPacketTooLarge},
// This should be explicitly handled by returning ERNetPacketTooLarge from the execturo directly
// and therefore shouldn't need to be teased out of another error.
testCase{"in-memory row count exceeded allowed limit of 13", ERTooManyUserConnections},
}

for _, c := range cases {
got := demuxResourceExhaustedErrors(c.msg)
assert.Equalf(t, c.want, got, c.msg)
}
}
8 changes: 5 additions & 3 deletions go/pools/numbered.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,15 @@ func (nu *Numbered) Get(id int64, purpose string) (val interface{}, err error) {
}

// Put unlocks a resource for someone else to use.
func (nu *Numbered) Put(id int64) {
func (nu *Numbered) Put(id int64, updateTime bool) {
nu.mu.Lock()
defer nu.mu.Unlock()
if nw, ok := nu.resources[id]; ok {
nw.inUse = false
nw.purpose = ""
nw.timeUsed = time.Now()
if updateTime {
nw.timeUsed = time.Now()
}
}
}

Expand All @@ -162,7 +164,7 @@ func (nu *Numbered) GetOutdated(age time.Duration, purpose string) (vals []inter
if nw.inUse || !nw.enforceTimeout {
continue
}
if nw.timeCreated.Add(age).Sub(now) <= 0 {
if nw.timeUsed.Add(age).Sub(now) <= 0 {
nw.inUse = true
nw.purpose = purpose
vals = append(vals, nw.val)
Expand Down
Loading