Skip to content

Commit c79d388

Browse files
committed
Use custom sharding key to calculate bucket id
Previously there were two different ways to obtain bucket id in CRUD: - calculate bucket id automatically using primary key (default) - pass it from outside explicitly in options on CRUD operation call Users who uses DDL module [1] may specify sharding key (that are actually names of tuple fields), but it was not possible to use DDL sharding key for bucket id calculation. Now CRUD allows to use that custom sharding key to calculate bucket id, it will be done automatically when used DDL schema with non-empty sharding_key [1] or when space _ddl_sharding_key contains a tuple with space name and it's sharding key. Table below describe what operations supports custom sharding key: | CRUD method | Added sharding key support | | ---------------------------- | -------------------------- | | get() | Yes | | insert() / insert_object() | Yes | | delete() | Yes | | replace() / replace_object() | Yes | | upsert() / upsert_object() | Yes | | select() / pairs() | Yes | | update() | Yes | | upsert() / upsert_object() | Yes | | replace() / replace_object() | Yes | | min() / max() | No (not required) | | cut_rows() / cut_objects() | No (not required) | | truncate() | No (not required) | | len() | No (not required) | Limitations: - It's not possible to update sharding keys automatically when schema is updated on storages, see [2]. However it is possible to do it manually with sharding_key.update_sharding_keys_cache(). - CRUD select may lead map reduce in some cases, see [3]. 1. https://github.com/tarantool/ddl 2. #212 3. #213 Closes #166
1 parent 6ce04a5 commit c79d388

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2424
* `crud.len()` function to calculate the number of tuples
2525
in the space for memtx engine and calculate the maximum
2626
approximate number of tuples in the space for vinyl engine.
27+
* CRUD operations calculates bucket id automatically using sharding
28+
key specified with DDL schema or in `_ddl_sharding_key` space.
2729

2830
## [0.8.0] - 02-07-21
2931

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ crud.unflatten_rows(res.rows, res.metadata)
5454

5555
* A space should have a format.
5656
* By default, `bucket_id` is computed as `vshard.router.bucket_id_strcrc32(key)`,
57-
where `key` is the primary key value.
58-
Custom bucket ID can be specified as `opts.bucket_id` for each operation.
59-
For operations that accepts tuple/object bucket ID can be specified as
60-
tuple/object field as well as `opts.bucket_id` value.
57+
where `key` is a value of sharding key. Sharding key can be set with [DDL
58+
schema](https://github.com/tarantool/ddl#input-data-format) (see
59+
`sharding_key` option) or in a space `_ddl_sharding_key`. By default sharding
60+
key is a primary key. Custom bucket ID can be specified as `opts.bucket_id`
61+
for each operation. For operations that accepts tuple/object bucket ID can be
62+
specified as tuple/object field as well as `opts.bucket_id` value.
6163

6264
### Insert
6365

0 commit comments

Comments
 (0)