Skip to content

Commit 89dd933

Browse files
authored
Merge pull request #19 from vitessio/wait
wait_authoritative can figure out the ks
2 parents e9f56a7 + a8944cd commit 89dd933

File tree

1 file changed

+45
-14
lines changed

1 file changed

+45
-14
lines changed

src/vitess-tester/tester.go

+45-14
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,7 @@ func (t *Tester) Run() error {
167167

168168
t.vexplain = strs[1]
169169
case Q_WAIT_FOR_AUTHORITATIVE:
170-
strs := strings.Split(q.Query, " ")
171-
if len(strs) != 3 {
172-
t.reporter.AddFailure(t.vschema, fmt.Errorf("expected table name and keyspace for wait_authoritative in: %v", q.Query))
173-
continue
174-
}
175-
176-
tblName := strs[1]
177-
ksName := strs[2]
178-
log.Infof("Waiting for authoritative schema for table %s", tblName)
179-
err := utils.WaitForAuthoritative(t, ksName, tblName, t.clusterInstance.VtgateProcess.ReadVSchema)
180-
if err != nil {
181-
t.reporter.AddFailure(t.vschema, fmt.Errorf("failed to wait for authoritative schema for table %s: %v", tblName, err))
182-
continue
183-
}
170+
t.waitAuthoritative(q.Query)
184171
case Q_QUERY:
185172
if t.skipNext {
186173
t.skipNext = false
@@ -224,6 +211,50 @@ func (t *Tester) Run() error {
224211
return nil
225212
}
226213

214+
func (t *Tester) findTable(name string) (ks string, err error) {
215+
for ksName, ksSchema := range t.vschema.Keyspaces {
216+
for _, table := range ksSchema.Tables {
217+
if table.Name.String() == name {
218+
if ks != "" {
219+
return "", fmt.Errorf("table %s found in multiple keyspaces", name)
220+
}
221+
ks = ksName
222+
}
223+
}
224+
}
225+
if ks == "" {
226+
return "", fmt.Errorf("table %s not found in any keyspace", name)
227+
}
228+
return ks, nil
229+
}
230+
231+
func (t *Tester) waitAuthoritative(query string) {
232+
var tblName, ksName string
233+
strs := strings.Split(query, " ")
234+
switch len(strs) {
235+
case 2:
236+
tblName = strs[1]
237+
var err error
238+
ksName, err = t.findTable(tblName)
239+
if err != nil {
240+
t.reporter.AddFailure(t.vschema, err)
241+
return
242+
}
243+
case 3:
244+
tblName = strs[1]
245+
ksName = strs[2]
246+
247+
default:
248+
t.reporter.AddFailure(t.vschema, fmt.Errorf("expected table name and keyspace for wait_authoritative in: %v", query))
249+
}
250+
251+
log.Infof("Waiting for authoritative schema for table %s", tblName)
252+
err := utils.WaitForAuthoritative(t, ksName, tblName, t.clusterInstance.VtgateProcess.ReadVSchema)
253+
if err != nil {
254+
t.reporter.AddFailure(t.vschema, fmt.Errorf("failed to wait for authoritative schema for table %s: %v", tblName, err))
255+
}
256+
}
257+
227258
func (t *Tester) loadQueries() ([]query, error) {
228259
data, err := t.readData()
229260
if err != nil {

0 commit comments

Comments
 (0)