File tree Expand file tree Collapse file tree 1 file changed +0
-21
lines changed Expand file tree Collapse file tree 1 file changed +0
-21
lines changed Original file line number Diff line number Diff line change 1
- use sha1:: { Digest , Sha1 } ;
2
-
3
1
// https://github.com/postgres/postgres/blob/27b77ecf9f4d5be211900eda54d8155ada50d696/src/include/catalog/partition.h#L20
4
2
const PARTITION_HASH_SEED : u64 = 0x7A5B22367996DCFD ;
5
3
@@ -12,17 +10,6 @@ impl Sharder {
12
10
Sharder { shards : shards }
13
11
}
14
12
15
- /// Use SHA1 to pick a shard for the key. The key can be anything,
16
- /// including an int or a string.
17
- pub fn _sha1 ( & self , key : & [ u8 ] ) -> usize {
18
- let mut hasher = Sha1 :: new ( ) ;
19
- hasher. update ( key) ;
20
- let result = hasher. finalize_reset ( ) ;
21
-
22
- let i = u32:: from_le_bytes ( result[ result. len ( ) - 4 ..result. len ( ) ] . try_into ( ) . unwrap ( ) ) ;
23
- i as usize % self . shards
24
- }
25
-
26
13
/// Hash function used by Postgres to determine which partition
27
14
/// to put the row in when using HASH(column) partitioning.
28
15
/// Source: https://github.com/postgres/postgres/blob/27b77ecf9f4d5be211900eda54d8155ada50d696/src/common/hashfn.c#L631
@@ -117,14 +104,6 @@ impl Sharder {
117
104
mod test {
118
105
use super :: * ;
119
106
120
- #[ test]
121
- fn test_sha1 ( ) {
122
- let sharder = Sharder :: new ( 12 ) ;
123
- let key = b"1234" ;
124
- let shard = sharder. sha1 ( key) ;
125
- assert_eq ! ( shard, 1 ) ;
126
- }
127
-
128
107
// See tests/sharding/partition_hash_test_setup.sql
129
108
// The output of those SELECT statements will match this test,
130
109
// confirming that we implemented Postgres BIGINT hashing correctly.
You can’t perform that action at this time.
0 commit comments