forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 10
/
router.go
646 lines (607 loc) · 19.5 KB
/
router.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
// Copyright 2014, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package vtgate
import (
"encoding/hex"
"fmt"
"strconv"
"github.com/youtube/vitess/go/sqltypes"
"github.com/youtube/vitess/go/vt/sqlannotation"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/vtgate/engine"
"github.com/youtube/vitess/go/vt/vtgate/vindexes"
"golang.org/x/net/context"
querypb "github.com/youtube/vitess/go/vt/proto/query"
topodatapb "github.com/youtube/vitess/go/vt/proto/topodata"
vtgatepb "github.com/youtube/vitess/go/vt/proto/vtgate"
)
// Router is the layer to route queries to the correct shards
// based on the values in the query.
type Router struct {
serv topo.SrvTopoServer
cell string
planner *Planner
scatterConn *ScatterConn
}
type scatterParams struct {
ks string
shardVars map[string]map[string]interface{}
}
func newScatterParams(ks string, bv map[string]interface{}, shards []string) *scatterParams {
shardVars := make(map[string]map[string]interface{}, len(shards))
for _, shard := range shards {
shardVars[shard] = bv
}
return &scatterParams{
ks: ks,
shardVars: shardVars,
}
}
// NewRouter creates a new Router.
func NewRouter(ctx context.Context, serv topo.SrvTopoServer, cell, statsName string, scatterConn *ScatterConn) *Router {
return &Router{
serv: serv,
cell: cell,
planner: NewPlanner(ctx, serv, cell, 5000),
scatterConn: scatterConn,
}
}
// Execute routes a non-streaming query.
func (rtr *Router) Execute(ctx context.Context, sql string, bindVars map[string]interface{}, keyspace string, tabletType topodatapb.TabletType, session *vtgatepb.Session, notInTransaction bool, options *querypb.ExecuteOptions) (*sqltypes.Result, error) {
if bindVars == nil {
bindVars = make(map[string]interface{})
}
vcursor := newRequestContext(ctx, sql, bindVars, keyspace, tabletType, session, notInTransaction, options, rtr)
plan, err := rtr.planner.GetPlan(sql, keyspace)
if err != nil {
return nil, err
}
return plan.Instructions.Execute(vcursor, make(map[string]interface{}), true)
}
// StreamExecute executes a streaming query.
func (rtr *Router) StreamExecute(ctx context.Context, sql string, bindVars map[string]interface{}, keyspace string, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions, sendReply func(*sqltypes.Result) error) error {
if bindVars == nil {
bindVars = make(map[string]interface{})
}
vcursor := newRequestContext(ctx, sql, bindVars, keyspace, tabletType, nil, false, options, rtr)
plan, err := rtr.planner.GetPlan(sql, keyspace)
if err != nil {
return err
}
return plan.Instructions.StreamExecute(vcursor, make(map[string]interface{}), true, sendReply)
}
// ExecuteRoute executes the route query for all route opcodes.
func (rtr *Router) ExecuteRoute(vcursor *requestContext, route *engine.Route, joinvars map[string]interface{}) (*sqltypes.Result, error) {
saved := copyBindVars(vcursor.bindVars)
defer func() { vcursor.bindVars = saved }()
for k, v := range joinvars {
vcursor.bindVars[k] = v
}
switch route.Opcode {
case engine.UpdateEqual:
return rtr.execUpdateEqual(vcursor, route)
case engine.DeleteEqual:
return rtr.execDeleteEqual(vcursor, route)
case engine.InsertSharded:
return rtr.execInsertSharded(vcursor, route)
}
var err error
var params *scatterParams
switch route.Opcode {
case engine.SelectUnsharded, engine.UpdateUnsharded,
engine.DeleteUnsharded, engine.InsertUnsharded:
params, err = rtr.paramsUnsharded(vcursor, route)
case engine.SelectEqual, engine.SelectEqualUnique:
params, err = rtr.paramsSelectEqual(vcursor, route)
case engine.SelectIN:
params, err = rtr.paramsSelectIN(vcursor, route)
case engine.SelectScatter:
params, err = rtr.paramsSelectScatter(vcursor, route)
default:
// TODO(sougou): improve error.
return nil, fmt.Errorf("unsupported query route: %v", route)
}
if err != nil {
return nil, err
}
return rtr.scatterConn.ExecuteMulti(
vcursor.ctx,
route.Query+vcursor.comments,
params.ks,
params.shardVars,
vcursor.tabletType,
NewSafeSession(vcursor.session),
vcursor.notInTransaction,
vcursor.options,
)
}
func copyBindVars(bindVars map[string]interface{}) map[string]interface{} {
out := make(map[string]interface{})
for k, v := range bindVars {
out[k] = v
}
return out
}
// GetRouteFields fetches the field info for the route.
func (rtr *Router) GetRouteFields(vcursor *requestContext, route *engine.Route, joinvars map[string]interface{}) (*sqltypes.Result, error) {
saved := copyBindVars(vcursor.bindVars)
defer func() { vcursor.bindVars = saved }()
for k := range joinvars {
vcursor.bindVars[k] = nil
}
ks, shard, err := getAnyShard(vcursor.ctx, rtr.serv, rtr.cell, route.Keyspace.Name, vcursor.tabletType)
if err != nil {
return nil, err
}
return rtr.scatterConn.Execute(
vcursor.ctx,
route.FieldQuery,
vcursor.bindVars,
ks,
[]string{shard},
vcursor.tabletType,
NewSafeSession(vcursor.session),
vcursor.notInTransaction,
vcursor.options,
)
}
// StreamExecuteRoute performs a streaming route. Only selects are allowed.
func (rtr *Router) StreamExecuteRoute(vcursor *requestContext, route *engine.Route, joinvars map[string]interface{}, sendReply func(*sqltypes.Result) error) error {
saved := copyBindVars(vcursor.bindVars)
defer func() { vcursor.bindVars = saved }()
for k, v := range joinvars {
vcursor.bindVars[k] = v
}
var err error
var params *scatterParams
switch route.Opcode {
case engine.SelectUnsharded:
params, err = rtr.paramsUnsharded(vcursor, route)
case engine.SelectEqual, engine.SelectEqualUnique:
params, err = rtr.paramsSelectEqual(vcursor, route)
case engine.SelectIN:
params, err = rtr.paramsSelectIN(vcursor, route)
case engine.SelectScatter:
params, err = rtr.paramsSelectScatter(vcursor, route)
default:
return fmt.Errorf("query %q cannot be used for streaming", route.Query)
}
if err != nil {
return err
}
return rtr.scatterConn.StreamExecuteMulti(
vcursor.ctx,
route.Query+vcursor.comments,
params.ks,
params.shardVars,
vcursor.tabletType,
vcursor.options,
sendReply,
)
}
// IsKeyspaceRangeBasedSharded returns true if the keyspace in the vschema is
// marked as sharded.
func (rtr *Router) IsKeyspaceRangeBasedSharded(keyspace string) bool {
vschema := rtr.planner.VSchema()
ks, ok := vschema.Keyspaces[keyspace]
if !ok {
return false
}
if ks.Keyspace == nil {
return false
}
return ks.Keyspace.Sharded
}
func (rtr *Router) paramsUnsharded(vcursor *requestContext, route *engine.Route) (*scatterParams, error) {
ks, _, allShards, err := getKeyspaceShards(vcursor.ctx, rtr.serv, rtr.cell, route.Keyspace.Name, vcursor.tabletType)
if err != nil {
return nil, fmt.Errorf("paramsUnsharded: %v", err)
}
if len(allShards) != 1 {
return nil, fmt.Errorf("unsharded keyspace %s has multiple shards", ks)
}
return newScatterParams(ks, vcursor.bindVars, []string{allShards[0].Name}), nil
}
func (rtr *Router) paramsSelectEqual(vcursor *requestContext, route *engine.Route) (*scatterParams, error) {
keys, err := rtr.resolveKeys([]interface{}{route.Values}, vcursor.bindVars)
if err != nil {
return nil, fmt.Errorf("paramsSelectEqual: %v", err)
}
ks, routing, err := rtr.resolveShards(vcursor, keys, route)
if err != nil {
return nil, fmt.Errorf("paramsSelectEqual: %v", err)
}
return newScatterParams(ks, vcursor.bindVars, routing.Shards()), nil
}
func (rtr *Router) paramsSelectIN(vcursor *requestContext, route *engine.Route) (*scatterParams, error) {
vals, err := rtr.resolveList(route.Values, vcursor.bindVars)
if err != nil {
return nil, fmt.Errorf("paramsSelectIN: %v", err)
}
keys, err := rtr.resolveKeys(vals, vcursor.bindVars)
if err != nil {
return nil, fmt.Errorf("paramsSelectIN: %v", err)
}
ks, routing, err := rtr.resolveShards(vcursor, keys, route)
if err != nil {
return nil, fmt.Errorf("paramsSelectEqual: %v", err)
}
return &scatterParams{
ks: ks,
shardVars: routing.ShardVars(vcursor.bindVars),
}, nil
}
func (rtr *Router) paramsSelectScatter(vcursor *requestContext, route *engine.Route) (*scatterParams, error) {
ks, _, allShards, err := getKeyspaceShards(vcursor.ctx, rtr.serv, rtr.cell, route.Keyspace.Name, vcursor.tabletType)
if err != nil {
return nil, fmt.Errorf("paramsSelectScatter: %v", err)
}
var shards []string
for _, shard := range allShards {
shards = append(shards, shard.Name)
}
return newScatterParams(ks, vcursor.bindVars, shards), nil
}
func (rtr *Router) execUpdateEqual(vcursor *requestContext, route *engine.Route) (*sqltypes.Result, error) {
keys, err := rtr.resolveKeys([]interface{}{route.Values}, vcursor.bindVars)
if err != nil {
return nil, fmt.Errorf("execUpdateEqual: %v", err)
}
ks, shard, ksid, err := rtr.resolveSingleShard(vcursor, keys[0], route)
if err != nil {
return nil, fmt.Errorf("execUpdateEqual: %v", err)
}
if len(ksid) == 0 {
return &sqltypes.Result{}, nil
}
rewritten := sqlannotation.AddKeyspaceID(route.Query, ksid, vcursor.comments)
return rtr.scatterConn.Execute(
vcursor.ctx,
rewritten,
vcursor.bindVars,
ks,
[]string{shard},
vcursor.tabletType,
NewSafeSession(vcursor.session),
vcursor.notInTransaction,
vcursor.options)
}
func (rtr *Router) execDeleteEqual(vcursor *requestContext, route *engine.Route) (*sqltypes.Result, error) {
keys, err := rtr.resolveKeys([]interface{}{route.Values}, vcursor.bindVars)
if err != nil {
return nil, fmt.Errorf("execDeleteEqual: %v", err)
}
ks, shard, ksid, err := rtr.resolveSingleShard(vcursor, keys[0], route)
if err != nil {
return nil, fmt.Errorf("execDeleteEqual: %v", err)
}
if len(ksid) == 0 {
return &sqltypes.Result{}, nil
}
if route.Subquery != "" {
err = rtr.deleteVindexEntries(vcursor, route, ks, shard, ksid)
if err != nil {
return nil, fmt.Errorf("execDeleteEqual: %v", err)
}
}
rewritten := sqlannotation.AddKeyspaceID(route.Query, ksid, vcursor.comments)
return rtr.scatterConn.Execute(
vcursor.ctx,
rewritten,
vcursor.bindVars,
ks,
[]string{shard},
vcursor.tabletType,
NewSafeSession(vcursor.session),
vcursor.notInTransaction,
vcursor.options)
}
func (rtr *Router) execInsertSharded(vcursor *requestContext, route *engine.Route) (*sqltypes.Result, error) {
var firstKsid []byte
var firstAutoGenInsertID int64
inputs := route.Values.([]interface{})
for rowNum, input := range inputs {
insertid, err := rtr.handleGenerate(vcursor, route.Generate, rowNum)
if firstAutoGenInsertID == 0 && insertid != 0 {
firstAutoGenInsertID = insertid
}
if err != nil {
return nil, fmt.Errorf("execInsertSharded: %v", err)
}
keys, err := rtr.resolveKeys(input.([]interface{}), vcursor.bindVars)
if err != nil {
return nil, fmt.Errorf("execInsertSharded: %v", err)
}
for colNum := 0; colNum < len(keys); colNum++ {
if rowNum == 0 && colNum == 0 {
ksid, err := rtr.handlePrimary(vcursor, keys[0], route.Table.ColumnVindexes[0], vcursor.bindVars, rowNum)
if err != nil {
return nil, fmt.Errorf("execInsertSharded: %v", err)
}
firstKsid = ksid
} else {
err := rtr.handleNonPrimary(vcursor, keys[colNum], route.Table.ColumnVindexes[colNum], vcursor.bindVars, firstKsid, rowNum)
if err != nil {
return nil, fmt.Errorf("execInsertSharded: %v", err)
}
}
}
}
ks, shard, err := rtr.getRouting(vcursor.ctx, route.Keyspace.Name, vcursor.tabletType, firstKsid)
if err != nil {
return nil, fmt.Errorf("execInsertSharded: %v", err)
}
rewritten := sqlannotation.AddKeyspaceID(route.Query, firstKsid, vcursor.comments)
result, err := rtr.scatterConn.Execute(
vcursor.ctx,
rewritten,
vcursor.bindVars,
ks,
[]string{shard},
vcursor.tabletType,
NewSafeSession(vcursor.session),
vcursor.notInTransaction,
vcursor.options)
if err != nil {
return nil, fmt.Errorf("execInsertSharded: %v", err)
}
if firstAutoGenInsertID != 0 {
if result.InsertID != 0 {
return nil, fmt.Errorf("sequence and db generated a value each for insert")
}
result.InsertID = uint64(firstAutoGenInsertID)
}
return result, nil
}
// resloveList returns a list of values, typically for an IN clause. If the input
// is a bind var name, it uses the list provided in the bind var. If the input is
// already a list, it returns just that.
func (rtr *Router) resolveList(val interface{}, bindVars map[string]interface{}) (vals []interface{}, err error) {
switch v := val.(type) {
case []interface{}:
vals = v
case string:
// It can only be a list bind var.
list, ok := bindVars[v[2:]]
if !ok {
return nil, fmt.Errorf("could not find bind var %s", v)
}
vals, ok = list.([]interface{})
if !ok {
return nil, fmt.Errorf("expecting list for bind var %s: %v", v, list)
}
default:
panic("unexpected")
}
return vals, nil
}
// resolveKeys takes a list as input that may have values or bind var names.
// It returns a new list with all the bind vars resolved.
func (rtr *Router) resolveKeys(vals []interface{}, bindVars map[string]interface{}) (keys []interface{}, err error) {
keys = make([]interface{}, 0, len(vals))
for _, val := range vals {
if v, ok := val.(string); ok {
val, ok = bindVars[v[1:]]
if !ok {
return nil, fmt.Errorf("could not find bind var %s", v)
}
}
keys = append(keys, val)
}
return keys, nil
}
func (rtr *Router) resolveShards(vcursor *requestContext, vindexKeys []interface{}, route *engine.Route) (newKeyspace string, routing routingMap, err error) {
newKeyspace, _, allShards, err := getKeyspaceShards(vcursor.ctx, rtr.serv, rtr.cell, route.Keyspace.Name, vcursor.tabletType)
if err != nil {
return "", nil, err
}
routing = make(routingMap)
switch mapper := route.Vindex.(type) {
case vindexes.Unique:
ksids, err := mapper.Map(vcursor, vindexKeys)
if err != nil {
return "", nil, err
}
for i, ksid := range ksids {
if len(ksid) == 0 {
continue
}
shard, err := getShardForKeyspaceID(allShards, ksid)
if err != nil {
return "", nil, err
}
routing.Add(shard, vindexKeys[i])
}
case vindexes.NonUnique:
ksidss, err := mapper.Map(vcursor, vindexKeys)
if err != nil {
return "", nil, err
}
for i, ksids := range ksidss {
for _, ksid := range ksids {
shard, err := getShardForKeyspaceID(allShards, ksid)
if err != nil {
return "", nil, err
}
routing.Add(shard, vindexKeys[i])
}
}
default:
panic("unexpected")
}
return newKeyspace, routing, nil
}
func (rtr *Router) resolveSingleShard(vcursor *requestContext, vindexKey interface{}, route *engine.Route) (newKeyspace, shard string, ksid []byte, err error) {
newKeyspace, _, allShards, err := getKeyspaceShards(vcursor.ctx, rtr.serv, rtr.cell, route.Keyspace.Name, vcursor.tabletType)
if err != nil {
return "", "", nil, err
}
mapper := route.Vindex.(vindexes.Unique)
ksids, err := mapper.Map(vcursor, []interface{}{vindexKey})
if err != nil {
return "", "", nil, err
}
ksid = ksids[0]
if len(ksid) == 0 {
return "", "", ksid, nil
}
shard, err = getShardForKeyspaceID(allShards, ksid)
if err != nil {
return "", "", nil, err
}
return newKeyspace, shard, ksid, nil
}
func (rtr *Router) deleteVindexEntries(vcursor *requestContext, route *engine.Route, ks, shard string, ksid []byte) error {
result, err := rtr.scatterConn.Execute(
vcursor.ctx,
route.Subquery,
vcursor.bindVars,
ks,
[]string{shard},
vcursor.tabletType,
NewSafeSession(vcursor.session),
vcursor.notInTransaction,
vcursor.options)
if err != nil {
return err
}
if len(result.Rows) == 0 {
return nil
}
for i, colVindex := range route.Table.Owned {
keys := make(map[interface{}]bool)
for _, row := range result.Rows {
switch k := row[i].ToNative().(type) {
case []byte:
keys[string(k)] = true
default:
keys[k] = true
}
}
var ids []interface{}
for k := range keys {
ids = append(ids, k)
}
switch vindex := colVindex.Vindex.(type) {
case vindexes.Lookup:
if err = vindex.Delete(vcursor, ids, ksid); err != nil {
return err
}
default:
panic("unexpceted")
}
}
return nil
}
func (rtr *Router) handleGenerate(vcursor *requestContext, gen *engine.Generate, rowNum int) (insertid int64, err error) {
if gen == nil {
return 0, nil
}
val := gen.Value.([]interface{})[rowNum]
if v, ok := val.(string); ok {
val, ok = vcursor.bindVars[v[1:]]
if !ok {
return 0, fmt.Errorf("handleGenerate: could not find bind var %s", v)
}
}
if val != nil {
vcursor.bindVars[engine.SeqVarName+strconv.Itoa(rowNum)] = val
return 0, nil
}
// TODO(sougou): This is similar to paramsUnsharded.
ks, _, allShards, err := getKeyspaceShards(vcursor.ctx, rtr.serv, rtr.cell, gen.Keyspace.Name, vcursor.tabletType)
if err != nil {
return 0, fmt.Errorf("handleGenerate: %v", err)
}
if len(allShards) != 1 {
return 0, fmt.Errorf("unsharded keyspace %s has multiple shards", ks)
}
params := newScatterParams(ks, nil, []string{allShards[0].Name})
// We nil out the transaction context for this particular call.
// TODO(sougou): Use ExecuteShard instead.
qr, err := rtr.scatterConn.ExecuteMulti(
vcursor.ctx,
gen.Query,
params.ks,
params.shardVars,
vcursor.tabletType,
NewSafeSession(nil),
false,
vcursor.options,
)
if err != nil {
return 0, err
}
// If no rows are returned, it's an internal error, and the code
// must panic, which will caught and reported.
num, err := qr.Rows[0][0].ParseInt64()
if err != nil {
return 0, err
}
vcursor.bindVars[engine.SeqVarName+strconv.Itoa(rowNum)] = num
return num, nil
}
func (rtr *Router) handlePrimary(vcursor *requestContext, vindexKey interface{}, colVindex *vindexes.ColumnVindex, bv map[string]interface{}, rowNum int) (ksid []byte, err error) {
if vindexKey == nil {
return nil, fmt.Errorf("value must be supplied for column %v", colVindex.Column)
}
mapper := colVindex.Vindex.(vindexes.Unique)
ksids, err := mapper.Map(vcursor, []interface{}{vindexKey})
if err != nil {
return nil, err
}
ksid = ksids[0]
if len(ksid) == 0 {
return nil, fmt.Errorf("could not map %v to a keyspace id", vindexKey)
}
bv["_"+colVindex.Column.Original()+strconv.Itoa(rowNum)] = vindexKey
return ksid, nil
}
func (rtr *Router) handleNonPrimary(vcursor *requestContext, vindexKey interface{}, colVindex *vindexes.ColumnVindex, bv map[string]interface{}, ksid []byte, rowNum int) error {
if colVindex.Owned {
if vindexKey == nil {
return fmt.Errorf("value must be supplied for column %v", colVindex.Column)
}
err := colVindex.Vindex.(vindexes.Lookup).Create(vcursor, vindexKey, ksid)
if err != nil {
return err
}
} else {
if vindexKey == nil {
reversible, ok := colVindex.Vindex.(vindexes.Reversible)
if !ok {
return fmt.Errorf("value must be supplied for column %v", colVindex.Column)
}
var err error
vindexKey, err = reversible.ReverseMap(vcursor, ksid)
if err != nil {
return err
}
if vindexKey == nil {
return fmt.Errorf("could not compute value for column %v", colVindex.Column)
}
} else {
ok, err := colVindex.Vindex.Verify(vcursor, vindexKey, ksid)
if err != nil {
return err
}
if !ok {
return fmt.Errorf("value %v for column %v does not map to keyspace id %v", vindexKey, colVindex.Column, hex.EncodeToString(ksid))
}
}
}
bv["_"+colVindex.Column.Original()+strconv.Itoa(rowNum)] = vindexKey
return nil
}
func (rtr *Router) getRouting(ctx context.Context, keyspace string, tabletType topodatapb.TabletType, ksid []byte) (newKeyspace, shard string, err error) {
newKeyspace, _, allShards, err := getKeyspaceShards(ctx, rtr.serv, rtr.cell, keyspace, tabletType)
if err != nil {
return "", "", err
}
shard, err = getShardForKeyspaceID(allShards, ksid)
if err != nil {
return "", "", err
}
return newKeyspace, shard, nil
}