Skip to content

Commit df7138e

Browse files
committed
Replace bucket_id_strcrc32() with bucket_id_mpcrc32()
Function `bucket_id_mpcrc32()` is safer than `bucket_id_strcrc32()` [1]. It takes a CRC32 from a MessagePack encoded value. That is, bucket id of integers does not depend on their Lua type. In case of a string key, it does not encode it into MessagePack, but takes a hash right from the string. Actually we already had `bucket_id_mpcrc32()` but in commit "Change bucket_id function" (97835b9) hash function has been changed to `bucket_id_strcrc32()`. 1. https://www.tarantool.io/en/doc/latest/reference/reference_rock/vshard/vshard_api/#lua-function.vshard.router.bucket_id_mpcrc32
1 parent 27e6eac commit df7138e

File tree

8 files changed

+8
-8
lines changed

8 files changed

+8
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ crud.unflatten_rows(res.rows, res.metadata)
4949
**Notes:**
5050

5151
* A space should have a format.
52-
* By default, `bucket_id` is computed as `vshard.router.bucket_id_strcrc32(key)`,
52+
* By default, `bucket_id` is computed as `vshard.router.bucket_id_mpcrc32(key)`,
5353
where `key` is the primary key value.
5454
Custom bucket ID can be specified as `opts.bucket_id` for each operation.
5555
For operations that accepts tuple/object bucket ID can be specified as

crud/common/sharding.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function sharding.key_get_bucket_id(key, specified_bucket_id)
1212
return specified_bucket_id
1313
end
1414

15-
return vshard.router.bucket_id_strcrc32(key)
15+
return vshard.router.bucket_id_mpcrc32(key)
1616
end
1717

1818
function sharding.tuple_get_bucket_id(tuple, space, specified_bucket_id)

crud/delete.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ end
9494
--
9595
-- @tparam ?number opts.bucket_id
9696
-- Bucket ID
97-
-- (by default, it's vshard.router.bucket_id_strcrc32 of primary key)
97+
-- (by default, it's vshard.router.bucket_id_mpcrc32 of primary key)
9898
--
9999
-- @return[1] object
100100
-- @treturn[2] nil

crud/get.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ end
104104
--
105105
-- @tparam ?number opts.bucket_id
106106
-- Bucket ID
107-
-- (by default, it's vshard.router.bucket_id_strcrc32 of primary key)
107+
-- (by default, it's vshard.router.bucket_id_mpcrc32 of primary key)
108108
--
109109
-- @tparam ?boolean opts.prefer_replica
110110
-- Call on replica if it's possible

crud/insert.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ end
107107
--
108108
-- @tparam ?number opts.bucket_id
109109
-- Bucket ID
110-
-- (by default, it's vshard.router.bucket_id_strcrc32 of primary key)
110+
-- (by default, it's vshard.router.bucket_id_mpcrc32 of primary key)
111111
--
112112
-- @return[1] tuple
113113
-- @treturn[2] nil

crud/replace.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ end
111111
--
112112
-- @tparam ?number opts.bucket_id
113113
-- Bucket ID
114-
-- (by default, it's vshard.router.bucket_id_strcrc32 of primary key)
114+
-- (by default, it's vshard.router.bucket_id_mpcrc32 of primary key)
115115
--
116116
-- @return[1] object
117117
-- @treturn[2] nil

crud/update.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ end
134134
--
135135
-- @tparam ?number opts.bucket_id
136136
-- Bucket ID
137-
-- (by default, it's vshard.router.bucket_id_strcrc32 of primary key)
137+
-- (by default, it's vshard.router.bucket_id_mpcrc32 of primary key)
138138
--
139139
-- @return[1] object
140140
-- @treturn[2] nil

crud/upsert.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ end
116116
--
117117
-- @tparam ?number opts.bucket_id
118118
-- Bucket ID
119-
-- (by default, it's vshard.router.bucket_id_strcrc32 of primary key)
119+
-- (by default, it's vshard.router.bucket_id_mpcrc32 of primary key)
120120
--
121121
-- @return[1] tuple
122122
-- @treturn[2] nil

0 commit comments

Comments
 (0)