You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+53Lines changed: 53 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -244,6 +244,59 @@ class Scratch {
244
244
}
245
245
```
246
246
247
+
#### Using custom sharding function
248
+
249
+
You can use your own sharding function to determine bucket id - location in cluster and use it in cluster operations.
250
+
For this purpose you need:
251
+
1) hash function
252
+
For the example, equality of function from tarantool - [crc32](https://www.tarantool.io/en/doc/latest/reference/reference_lua/digest/#lua-function.digest.crc32) with specific polynomial value.
253
+
Java doesn't have crc32 out of the box with the ability to pass polynomial value, then we'll implement our own:
254
+
```java
255
+
privatestaticlong crc32(byte[] data) {
256
+
BitSet bitSet =BitSet.valueOf(data);
257
+
int crc32 =0xFFFFFFFF; // initial value
258
+
for (int i =0; i < data.length *8; i++) {
259
+
if (((crc32 >>>31) &1) != (bitSet.get(i) ?1:0)) {
260
+
crc32 = (crc32 <<1) ^0x1EDC6F41; // xor with polynomial
261
+
} else {
262
+
crc32 = crc32 <<1;
263
+
}
264
+
}
265
+
crc32 =Integer.reverse(crc32); // result reflect
266
+
return crc32 &0x00000000ffffffffL; // the unsigned java problem
267
+
}
268
+
```
269
+
2) number of buckets
270
+
We can obtain number from tarantool via `vshard.router.bucket_count` function out of [vshard module](https://github.com/tarantool/vshard)
271
+
```java
272
+
publicstatic<T extends Packable, R extends Collection<T>>Integer getBucketCount(
0 commit comments