-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Tool to determine mapping from vindex and value to shard #17290
Tool to determine mapping from vindex and value to shard #17290
Conversation
…ndex and shard ranges Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
… reported for a keyspace id Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #17290 +/- ##
==========================================
- Coverage 67.40% 67.39% -0.02%
==========================================
Files 1574 1574
Lines 253205 253251 +46
==========================================
- Hits 170676 170673 -3
- Misses 82529 82578 +49 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Do we have to print the ksid? |
func getValue(valueStr string) (sqltypes.Value, int64, error) { | ||
var value sqltypes.Value | ||
valueInt, err := strconv.ParseInt(valueStr, 10, 64) | ||
if err == nil { | ||
value = sqltypes.NewInt64(int64(valueInt)) | ||
} else { | ||
valueUint, err := strconv.ParseUint(valueStr, 10, 64) | ||
if err == nil { | ||
value = sqltypes.NewUint64(valueUint) | ||
} else { | ||
value = sqltypes.NewVarChar(valueStr) | ||
} | ||
} | ||
return value, valueInt, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should take value type as input using cli
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
allShards := make([]*topodata.ShardReference, 0, len(shards)) | ||
for shard, keyRange := range shards { | ||
allShards = append(allShards, &topodata.ShardReference{ | ||
Name: shard, | ||
KeyRange: keyRange, | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done as part of a struct init and passed along to methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
foundShard, err := mapShard(shards, ksid) | ||
if err != nil { | ||
return "", nil, fmt.Errorf("failed to map shard: %w", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add the original value as well to the error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
var start, end []byte | ||
if len(parts) > 0 && parts[0] != "" { | ||
start, err = hex.DecodeString(parts[0]) | ||
if err != nil { | ||
log.Fatalf("failed to decode shard start: %v", err) | ||
} | ||
} | ||
if len(parts) > 1 && parts[1] != "" { | ||
end, err = hex.DecodeString(parts[1]) | ||
if err != nil { | ||
log.Fatalf("failed to decode shard end: %v", err) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use method key.ParseKeyRangeParts
to create *topodatapb.KeyRange
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also look at topo.ValidateShardName
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used topo.ValidateShardName
certainly not needed, but it doesn't hurt, easy enough to work around like this:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense to move this to vt
. We should also add some unit tests, seems like they would be easy to add.
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Refactored code and added a unit test. I would prefer to keep this in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, not sure how that got committed. Good catch, removed!
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Description
This is a separate tool in the vitess
tools
directory which can be used as a separate binary without needing to setup a cluster. It can be used to map a list of values from the stdin and outputs a csv format giving you the relatedkeyspace id
and theshard
in which it will reside. The inputs are the vindex type and the sharding scheme.I tested this by comparing about 2K results of vexplain by specifying a test vschema file like
vtexplain --shards 128 --vschema-file test-vschema.json --sql "select * from users where id = $1" --schema-file "test-schema.sql" --output-mode json | jq -r '.[].TabletActions | keys[] | split("/") | .[1]' | awk -v id="$id" '{print id "," $0}'
.Features
hash
,xxhash
).stdin
and outputs the corresponding shard information, so it can beused to map values from a file or another program.
Usage
Flags
--vindex
: Specifies the name of the vindex to use (e.g.,hash
,xxhash
) (defaultxxhash
)One (and only one) of these is required:
--shards
: Comma-separated list of shard ranges--total_shards
: Total number of shards, only if shards are uniformly distributedRelated Issue(s)
#17292
Checklist
Deployment Notes