Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vindexes: return unknown params #12951

Merged
merged 24 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
19 changes: 12 additions & 7 deletions go/vt/vtgate/vindexes/cfc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ import (
"vitess.io/vitess/go/vt/vterrors"
)

const (
cfcParamHash = "hash"
cfcParamOffsets = "offsets"
)

var (
_ ParamValidating = (*CFC)(nil)
)

var cfcParams = []string{
"hash",
"offsets",
}
cfcParams = []string{
cfcParamHash,
cfcParamOffsets,
}
)

// CFC is Concatenated Fixed-width Composite Vindex.
//
Expand Down Expand Up @@ -124,7 +129,7 @@ func newCFC(name string, params map[string]string) (Vindex, error) {
return cfc, nil
}

switch h := params["hash"]; h {
switch h := params[cfcParamHash]; h {
case "":
return cfc, nil
case "md5":
Expand All @@ -136,7 +141,7 @@ func newCFC(name string, params map[string]string) (Vindex, error) {
}

var offsets []int
if p := params["offsets"]; p == "" {
if p := params[cfcParamOffsets]; p == "" {
return nil, vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "CFC vindex requires offsets when hash is defined")
} else if err := json.Unmarshal([]byte(p), &offsets); err != nil || !validOffsets(offsets) {
return nil, vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "invalid offsets %s to CFC vindex %s. expected sorted positive ints in brackets", p, name)
Expand Down
8 changes: 6 additions & 2 deletions go/vt/vtgate/vindexes/consistent_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import (
"vitess.io/vitess/go/vt/sqlparser"
)

const (
consistentLookupParamWriteOnly = "write_only"
)

var (
_ SingleColumn = (*ConsistentLookupUnique)(nil)
_ Lookup = (*ConsistentLookupUnique)(nil)
Expand All @@ -49,7 +53,7 @@ var (

consistentLookupParams = append(
append(make([]string, 0), lookupInternalParams...),
"write_only",
consistentLookupParamWriteOnly,
)
)

Expand Down Expand Up @@ -291,7 +295,7 @@ type clCommon struct {
func newCLCommon(name string, m map[string]string) (*clCommon, error) {
lu := &clCommon{name: name}
var err error
lu.writeOnly, err = boolFromMap(m, "write_only")
lu.writeOnly, err = boolFromMap(m, consistentLookupParamWriteOnly)
if err != nil {
return nil, err
}
Expand Down
17 changes: 11 additions & 6 deletions go/vt/vtgate/vindexes/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import (
vtgatepb "vitess.io/vitess/go/vt/proto/vtgate"
)

const (
lookupParamNoVerify = "no_verify"
lookupParamWriteOnly = "write_only"
)

var (
_ SingleColumn = (*LookupUnique)(nil)
_ Lookup = (*LookupUnique)(nil)
Expand All @@ -39,8 +44,8 @@ var (

lookupParams = append(
append(make([]string, 0), lookupCommonParams...),
"no_verify",
"write_only",
lookupParamNoVerify,
lookupParamWriteOnly,
)
)

Expand Down Expand Up @@ -208,12 +213,12 @@ func newLookup(name string, m map[string]string) (Vindex, error) {
if err != nil {
return nil, err
}
lookup.writeOnly, err = boolFromMap(m, "write_only")
lookup.writeOnly, err = boolFromMap(m, lookupParamWriteOnly)
if err != nil {
return nil, err
}

lookup.noVerify, err = boolFromMap(m, "no_verify")
lookup.noVerify, err = boolFromMap(m, lookupParamNoVerify)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -280,12 +285,12 @@ func newLookupUnique(name string, m map[string]string) (Vindex, error) {
if err != nil {
return nil, err
}
lu.writeOnly, err = boolFromMap(m, "write_only")
lu.writeOnly, err = boolFromMap(m, lookupParamWriteOnly)
if err != nil {
return nil, err
}

lu.noVerify, err = boolFromMap(m, "no_verify")
lu.noVerify, err = boolFromMap(m, lookupParamNoVerify)
if err != nil {
return nil, err
}
Expand Down
10 changes: 7 additions & 3 deletions go/vt/vtgate/vindexes/lookup_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import (
vtgatepb "vitess.io/vitess/go/vt/proto/vtgate"
)

const (
lookupHashParamWriteOnly = "write_only"
)

var (
_ SingleColumn = (*LookupHash)(nil)
_ Lookup = (*LookupHash)(nil)
Expand All @@ -41,7 +45,7 @@ var (

lookupHashParams = append(
append(make([]string, 0), lookupCommonParams...),
"write_only",
lookupHashParamWriteOnly,
)
)

Expand Down Expand Up @@ -84,7 +88,7 @@ func newLookupHash(name string, m map[string]string) (Vindex, error) {
if err != nil {
return nil, err
}
lh.writeOnly, err = boolFromMap(m, "write_only")
lh.writeOnly, err = boolFromMap(m, lookupHashParamWriteOnly)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -294,7 +298,7 @@ func newLookupHashUnique(name string, m map[string]string) (Vindex, error) {
if err != nil {
return nil, err
}
lhu.writeOnly, err = boolFromMap(m, "write_only")
lhu.writeOnly, err = boolFromMap(m, lookupHashParamWriteOnly)
if err != nil {
return nil, err
}
Expand Down
48 changes: 30 additions & 18 deletions go/vt/vtgate/vindexes/lookup_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,24 @@ import (
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
)

var (
const (
readLockExclusive = "exclusive"
readLockShared = "shared"
readLockNone = "none"
readLockDefault = readLockExclusive

lookupCommonParamAutocommit = "autocommit"
lookupCommonParamMultiShardAutocommit = "multi_shard_autocommit"

lookupInternalParamTable = "table"
lookupInternalParamFrom = "from"
lookupInternalParamTo = "to"
lookupInternalParamIgnoreNulls = "ignore_nulls"
lookupInternalParamBatchLookup = "batch_lookup"
lookupInternalParamReadLock = "read_lock"
)

var (
readLockExprs = map[string]string{
readLockExclusive: "for update",
readLockShared: "lock in share mode",
Expand All @@ -48,19 +60,19 @@ var (
// lookupCommonParams are used only by lookup_* vindexes.
lookupCommonParams = append(
append(make([]string, 0), lookupInternalParams...),
"autocommit",
"multi_shard_autocommit",
lookupCommonParamAutocommit,
lookupCommonParamMultiShardAutocommit,
)

// lookupInternalParams are used by both lookup_* vindexes and the newer
// consistent_lookup_* vindexes.
lookupInternalParams = []string{
"table",
"from",
"to",
"ignore_nulls",
"batch_lookup",
"read_lock",
lookupInternalParamTable,
lookupInternalParamFrom,
lookupInternalParamTo,
lookupInternalParamIgnoreNulls,
lookupInternalParamBatchLookup,
lookupInternalParamReadLock,
}
)

Expand All @@ -79,26 +91,26 @@ type lookupInternal struct {
}

func (lkp *lookupInternal) Init(lookupQueryParams map[string]string, autocommit, upsert, multiShardAutocommit bool) error {
lkp.Table = lookupQueryParams["table"]
lkp.To = lookupQueryParams["to"]
lkp.Table = lookupQueryParams[lookupInternalParamTable]
lkp.To = lookupQueryParams[lookupInternalParamTo]
var fromColumns []string
for _, from := range strings.Split(lookupQueryParams["from"], ",") {
for _, from := range strings.Split(lookupQueryParams[lookupInternalParamFrom], ",") {
fromColumns = append(fromColumns, strings.TrimSpace(from))
}
lkp.FromColumns = fromColumns

var err error
lkp.IgnoreNulls, err = boolFromMap(lookupQueryParams, "ignore_nulls")
lkp.IgnoreNulls, err = boolFromMap(lookupQueryParams, lookupInternalParamIgnoreNulls)
if err != nil {
return err
}
lkp.BatchLookup, err = boolFromMap(lookupQueryParams, "batch_lookup")
lkp.BatchLookup, err = boolFromMap(lookupQueryParams, lookupInternalParamBatchLookup)
if err != nil {
return err
}
if readLock, ok := lookupQueryParams["read_lock"]; ok {
if readLock, ok := lookupQueryParams[lookupInternalParamReadLock]; ok {
if _, valid := readLockExprs[readLock]; !valid {
return vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid read_lock value: %s", readLock)
return vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid %s value: %s", lookupInternalParamReadLock, readLock)
}
lkp.ReadLock = readLock
}
Expand Down Expand Up @@ -417,10 +429,10 @@ type commonConfig struct {
func parseCommonConfig(m map[string]string) (*commonConfig, error) {
var c commonConfig
var err error
if c.autocommit, err = boolFromMap(m, "autocommit"); err != nil {
if c.autocommit, err = boolFromMap(m, lookupCommonParamAutocommit); err != nil {
return nil, err
}
if c.multiShardAutocommit, err = boolFromMap(m, "multi_shard_autocommit"); err != nil {
if c.multiShardAutocommit, err = boolFromMap(m, lookupCommonParamMultiShardAutocommit); err != nil {
return nil, err
}
return &c, nil
Expand Down
10 changes: 7 additions & 3 deletions go/vt/vtgate/vindexes/lookup_unicodeloosemd5_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import (
vtgatepb "vitess.io/vitess/go/vt/proto/vtgate"
)

const (
lookupUnicodeLooseMD5HashParamWriteOnly = "write_only"
)

var (
_ SingleColumn = (*LookupUnicodeLooseMD5Hash)(nil)
_ Lookup = (*LookupUnicodeLooseMD5Hash)(nil)
Expand All @@ -42,7 +46,7 @@ var (

lookupUnicodeLooseMD5HashParams = append(
append(make([]string, 0), lookupCommonParams...),
"write_only",
lookupUnicodeLooseMD5HashParamWriteOnly,
)
)

Expand Down Expand Up @@ -85,7 +89,7 @@ func newLookupUnicodeLooseMD5Hash(name string, m map[string]string) (Vindex, err
if err != nil {
return nil, err
}
lh.writeOnly, err = boolFromMap(m, "write_only")
lh.writeOnly, err = boolFromMap(m, lookupUnicodeLooseMD5HashParamWriteOnly)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -320,7 +324,7 @@ func newLookupUnicodeLooseMD5HashUnique(name string, m map[string]string) (Vinde
if err != nil {
return nil, err
}
lhu.writeOnly, err = boolFromMap(m, "write_only")
lhu.writeOnly, err = boolFromMap(m, lookupUnicodeLooseMD5HashParamWriteOnly)
if err != nil {
return nil, err
}
Expand Down
16 changes: 16 additions & 0 deletions go/vt/vtgate/vindexes/main_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2023 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 vindexes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need license header


import (
Expand Down
18 changes: 12 additions & 6 deletions go/vt/vtgate/vindexes/numeric_static_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@ import (
"vitess.io/vitess/go/vt/key"
)

const (
numericStaticMapParamJSON = "json"
numericStaticMapParamJSONPath = "json_path"
numericStaticMapParamFallbackType = "fallback_type"
)

var (
_ SingleColumn = (*NumericStaticMap)(nil)
_ Hashing = (*NumericStaticMap)(nil)
_ ParamValidating = (*NumericStaticMap)(nil)

numericStaticMapParams = []string{
"json",
"json_path",
"fallback_type",
numericStaticMapParamJSON,
numericStaticMapParamJSONPath,
numericStaticMapParamFallbackType,
}
)

Expand All @@ -62,8 +68,8 @@ func init() {

// newNumericStaticMap creates a NumericStaticMap vindex.
func newNumericStaticMap(name string, params map[string]string) (Vindex, error) {
jsonStr, jsok := params["json"]
jsonPath, jpok := params["json_path"]
jsonStr, jsok := params[numericStaticMapParamJSON]
jsonPath, jpok := params[numericStaticMapParamJSONPath]

if !jsok && !jpok {
return nil, vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "NumericStaticMap: Could not find either `json_path` or `json` params in vschema")
Expand Down Expand Up @@ -92,7 +98,7 @@ func newNumericStaticMap(name string, params map[string]string) (Vindex, error)

var hashVdx Hashing

if s, ok := params["fallback_type"]; ok {
if s, ok := params[numericStaticMapParamFallbackType]; ok {
vindex, err := CreateVindex(s, name+"_hash", map[string]string{})
if err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion go/vt/vtgate/vindexes/region_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ import (
"vitess.io/vitess/go/vt/key"
)

const (
regionExperimentalParamRegionBytes = "region_bytes"
)

var (
_ MultiColumn = (*RegionExperimental)(nil)
_ ParamValidating = (*RegionExperimental)(nil)

regionExperimentalParams = []string{
"region_bytes",
regionExperimentalParamRegionBytes,
}
)

Expand Down
Loading