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

LookupVindex bug fix: Fix typos from PR 17301 #17423

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
)

type lookupIndex struct {
type lookupVindex struct {
typ string
name string
tableKeyspace string
Expand All @@ -42,64 +42,64 @@ type lookupIndex struct {
t *testing.T
}

func (li *lookupIndex) String() string {
return li.typ + " " + li.name + " on " + li.tableKeyspace + "." + li.table + " (" + li.columns[0] + ")"
func (lv *lookupVindex) String() string {
return lv.typ + " " + lv.name + " on " + lv.tableKeyspace + "." + lv.table + " (" + lv.columns[0] + ")"
}

func (li *lookupIndex) create() {
cols := strings.Join(li.columns, ",")
func (lv *lookupVindex) create() {
cols := strings.Join(lv.columns, ",")
args := []string{
"LookupVindex",
"--name", li.name,
"--table-keyspace=" + li.ownerTableKeyspace,
"--name", lv.name,
"--table-keyspace=" + lv.ownerTableKeyspace,
"create",
"--keyspace=" + li.tableKeyspace,
"--type=" + li.typ,
"--table-owner=" + li.ownerTable,
"--keyspace=" + lv.tableKeyspace,
"--type=" + lv.typ,
"--table-owner=" + lv.ownerTable,
"--table-owner-columns=" + cols,
"--tablet-types=PRIMARY",
}
if li.ignoreNulls {
if lv.ignoreNulls {
args = append(args, "--ignore-nulls")
}

err := vc.VtctldClient.ExecuteCommand(args...)
require.NoError(li.t, err, "error executing LookupVindex create: %v", err)
waitForWorkflowState(li.t, vc, fmt.Sprintf("%s.%s", li.ownerTableKeyspace, li.name), binlogdatapb.VReplicationWorkflowState_Running.String())
li.expectWriteOnly(true)
require.NoError(lv.t, err, "error executing LookupVindex create: %v", err)
waitForWorkflowState(lv.t, vc, fmt.Sprintf("%s.%s", lv.ownerTableKeyspace, lv.name), binlogdatapb.VReplicationWorkflowState_Running.String())
lv.expectWriteOnly(true)
}

func (li *lookupIndex) cancel() {
func (lv *lookupVindex) cancel() {
panic("not implemented")
}

func (li *lookupIndex) externalize() {
func (lv *lookupVindex) externalize() {
args := []string{
"LookupVindex",
"--name", li.name,
"--table-keyspace=" + li.ownerTableKeyspace,
"--name", lv.name,
"--table-keyspace=" + lv.ownerTableKeyspace,
"externalize",
"--keyspace=" + li.tableKeyspace,
"--keyspace=" + lv.tableKeyspace,
}
err := vc.VtctldClient.ExecuteCommand(args...)
require.NoError(li.t, err, "error executing LookupVindex externalize: %v", err)
li.expectWriteOnly(false)
require.NoError(lv.t, err, "error executing LookupVindex externalize: %v", err)
lv.expectWriteOnly(false)
}

func (li *lookupIndex) show() error {
func (lv *lookupVindex) show() error {
return nil
}

func (li *lookupIndex) expectWriteOnly(expected bool) {
vschema, err := vc.VtctldClient.ExecuteCommandWithOutput("GetVSchema", li.ownerTableKeyspace)
require.NoError(li.t, err, "error executing GetVSchema: %v", err)
vdx := gjson.Get(vschema, fmt.Sprintf("vindexes.%s", li.name))
require.NotNil(li.t, vdx, "lookup vindex %s not found", li.name)
func (lv *lookupVindex) expectWriteOnly(expected bool) {
vschema, err := vc.VtctldClient.ExecuteCommandWithOutput("GetVSchema", lv.ownerTableKeyspace)
require.NoError(lv.t, err, "error executing GetVSchema: %v", err)
vdx := gjson.Get(vschema, fmt.Sprintf("vindexes.%s", lv.name))
require.NotNil(lv.t, vdx, "lookup vindex %s not found", lv.name)
want := ""
if expected {
want = "true"
}
require.Equal(li.t, want, vdx.Get("params.write_only").String(), "expected write_only parameter to be %s", want)
require.Equal(lv.t, want, vdx.Get("params.write_only").String(), "expected write_only parameter to be %s", want)
}

func getNumRowsInQuery(t *testing.T, query string) int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ create table t1(
`,
}

func setupLookupIndexKeyspace(t *testing.T) map[string]*cluster.VttabletProcess {
func setupLookupVindexKeyspace(t *testing.T) map[string]*cluster.VttabletProcess {
tablets := make(map[string]*cluster.VttabletProcess)
if _, err := vc.AddKeyspace(t, []*Cell{vc.Cells["zone1"]}, lookupClusterSpec.keyspaceName, "-80,80-",
lookupClusterSpec.vschema, lookupClusterSpec.schema, defaultReplicas, defaultRdonly, 200, nil); err != nil {
Expand All @@ -80,14 +80,14 @@ func setupLookupIndexKeyspace(t *testing.T) map[string]*cluster.VttabletProcess

type lookupTestCase struct {
name string
li *lookupIndex
lv *lookupVindex
initQuery string
runningQuery string
postExternalizeQuery string
cleanupQuery string
}

func TestLookupIndex(t *testing.T) {
func TestLookupVindex(t *testing.T) {
setSidecarDBName("_vt")
origDefaultReplicas := defaultReplicas
origDefaultRdonly := defaultRdonly
Expand All @@ -101,7 +101,7 @@ func TestLookupIndex(t *testing.T) {
defer vc.TearDown()
vttablet.InitVReplicationConfigDefaults()

_ = setupLookupIndexKeyspace(t)
_ = setupLookupVindexKeyspace(t)

initQuery := "insert into t1 (c1, c2, val) values (1, 1, 'val1'), (2, 2, 'val2'), (3, 3, 'val3')"
runningQuery := "insert into t1 (c1, c2, val) values (4, 4, 'val4'), (5, 5, 'val5'), (6, 6, 'val6')"
Expand All @@ -111,7 +111,7 @@ func TestLookupIndex(t *testing.T) {
testCases := []lookupTestCase{
{
name: "non-unique lookup index, one column",
li: &lookupIndex{
lv: &lookupVindex{
typ: "consistent_lookup",
name: "t1_c2_lookup",
tableKeyspace: lookupClusterSpec.keyspaceName,
Expand All @@ -125,7 +125,7 @@ func TestLookupIndex(t *testing.T) {
},
{
name: "lookup index, two columns",
li: &lookupIndex{
lv: &lookupVindex{
typ: "lookup",
name: "t1_c2_val_lookup",
tableKeyspace: lookupClusterSpec.keyspaceName,
Expand All @@ -139,7 +139,7 @@ func TestLookupIndex(t *testing.T) {
},
{
name: "unique lookup index, one column",
li: &lookupIndex{
lv: &lookupVindex{
typ: "lookup_unique",
name: "t1_c2_unique_lookup",
tableKeyspace: lookupClusterSpec.keyspaceName,
Expand Down Expand Up @@ -168,7 +168,7 @@ func testLookupVindex(t *testing.T, tc *lookupTestCase) {
vtgateConn, cancel := getVTGateConn()
defer cancel()
var totalRows int
li := tc.li
lv := tc.lv

t.Run("init data", func(t *testing.T) {
totalRows += getNumRowsInQuery(t, tc.initQuery)
Expand All @@ -177,28 +177,28 @@ func testLookupVindex(t *testing.T, tc *lookupTestCase) {
})

t.Run("create", func(t *testing.T) {
tc.li.create()
tc.lv.create()

lks := li.tableKeyspace
vindexName := li.name
lks := lv.tableKeyspace
vindexName := lv.name
waitForRowCount(t, vtgateConn, lks, vindexName, totalRows)
totalRows += getNumRowsInQuery(t, tc.runningQuery)
_, err := vtgateConn.ExecuteFetch(tc.runningQuery, 1000, false)
require.NoError(t, err)
waitForRowCount(t, vtgateConn, tc.li.ownerTableKeyspace, li.name, totalRows)
waitForRowCount(t, vtgateConn, tc.lv.ownerTableKeyspace, lv.name, totalRows)
})

t.Run("externalize", func(t *testing.T) {
tc.li.externalize()
tc.lv.externalize()
totalRows += getNumRowsInQuery(t, tc.postExternalizeQuery)
_, err := vtgateConn.ExecuteFetch(tc.postExternalizeQuery, 1000, false)
require.NoError(t, err)
waitForRowCount(t, vtgateConn, tc.li.ownerTableKeyspace, li.name, totalRows)
waitForRowCount(t, vtgateConn, tc.lv.ownerTableKeyspace, lv.name, totalRows)
})

t.Run("cleanup", func(t *testing.T) {
_, err := vtgateConn.ExecuteFetch(tc.cleanupQuery, 1000, false)
require.NoError(t, err)
waitForRowCount(t, vtgateConn, tc.li.ownerTableKeyspace, li.name, 0)
waitForRowCount(t, vtgateConn, tc.lv.ownerTableKeyspace, lv.name, 0)
})
}
Loading