hello, I listen to the following the appended drawings configuration sharding - by - stringhash (IO) mycat. The route. The function. PartitionByString) subdivision strategy, I according to the way of thinking in a string of four Numbers, pictured above 256, 1536 and 3621, in addition to partitionLength modulus, namely 1536% by 256 and 3621% by 256, the remainder were 0 and 37, but why is assigned the same partition node db3 (dn4)? could you please tell me again after the modulus, the logic of fragmentation is how to allocate? Not sure what exactly which shard to? To be advise, thank you! /illustrated as follows: CodePudding user response:
You have a total of four subdivision, N % 256 a total of 256 possible results:
1. The results of 0-63 allocated to the same subdivision;
2. The result is assigned to the same shard, 64-127;
3. The result is assigned to the same shard, 128-191;
4. The result is assigned to the same shard, 192-255,
CodePudding user response:
reference 1st floor Dong Xuyang TonyDong response: you a total of four subdivision, N % 256 a total of 256 possible results: 1. The results of 0-63 allocated to the same subdivision; 2. The result is assigned to the same shard, 64-127; 3. The result is assigned to the same shard, 128-191; 4. The result is assigned to the same shard, 192-255 -- -- -- -- -- -- -- -- -- Hello, thank you for your enthusiasm to solve! You mean 256 divided by the number of fragmentation, 256/4=64, keep 64 range for each shard? I looked at it and do as you say so, the results are wrong oh, below, take a column value in the first four digits % 256, the remainder is 0 and 87, and why are assigned to the same shard? CodePudding user response:
reference 1st floor Dong Xuyang TonyDong response: you a total of four subdivision, N % 256 a total of 256 possible results: 1. The results of 0-63 allocated to the same subdivision; 2. The result is assigned to the same shard, 64-127; 3. The result is assigned to the same shard, 128-191; 4. The result is assigned to the same shard, 192-255 -- -- -- -- -- -- -- -- -- Hello, thank you for your enthusiasm to solve! You mean 256 divided by the number of fragmentation, 256/4=64, keep 64 range for each shard? I looked at it and do as you say so, the results are wrong oh, below, take a column value in the first four digits % 256, the remainder is 0 and 87, and why are assigned to the same shard? [] the appended drawings: CodePudding user response:
Correct once, a total of four subdivision, length 256, each divided partitionCount * partitionLength=1024, calculate N binary & amp; 1111111111: 1. The results of 0-255 allocated to the same subdivision; 2. The result is assigned to the same shard, 256-511; 3. The result is assigned to the same shard, 512-767; 4. The result is assigned to the same shard, 768-1023 Mycat have a official website: http://www.mycat.io/ This is to use the guide: http://www.mycat.io/document/mycat-definitive-guide.pdf CodePudding user response:
reference 4 floor Dong Xuyang TonyDong response: correct once, a total of four subdivision, length 256, each divided partitionCount * partitionLength=1024, calculate N binary & amp; 1111111111: 1. The results of 0-255 allocated to the same subdivision; 2. The result is assigned to the same shard, 256-511; 3. The result is assigned to the same shard, 512-767; 4. The result is assigned to the same shard, 768-1023 Mycat have a official website: http://www.mycat.io/ This is to use the guide: http://www.mycat.io/document/mycat-definitive-guide.pdf -- -- -- -- -- Thank Dong Xiong keen to solve! Website I have ever seen, as if she had not updated tutorial version is very old, It seems wrong oh, according to what you say, I calculate the each node model, after the 256 remainders are for 0, 0, why not on the same node? As follows: Root @ db1 * localhost 12:55:43 & gt; Select * from bystringhash; + -- -- -- -- -- -- -- -- -- -- -- -- -- -- + | code | + -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 1111 afafaa | | 10240 ikalaaa | | 11115 afafaa | | 1024 ikalaaa | | 10240 afasfaa | | + -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 5 rows in the set (0.00 SEC) Root @ db1 * localhost 12:55:47 & gt; The select 1024% 256; + -- -- -- -- -- -- -- -- -- -- -- -- + 256 | | 1024% + -- -- -- -- -- -- -- -- -- -- -- -- + | | 0 + -- -- -- -- -- -- -- -- -- -- -- -- + 1 row in the set (0.00 SEC) Root @ db2 * localhost 12:53:49 & gt; Select * from bystringhash; + -- -- -- -- -- -- -- -- -- -- -- -- + | code | + -- -- -- -- -- -- -- -- -- -- -- -- + 2048 akuccc | | 65536 afafa | | 5123 KKKKK | | + -- -- -- -- -- -- -- -- -- -- -- -- + 3 rows in the set (0.00 SEC) Root @ * localhost 12:55:26 & gt; The select 2048% 256; + -- -- -- -- -- -- -- -- -- -- -- -- + 256 | | 2048% + -- -- -- -- -- -- -- -- -- -- -- -- + | | 0 + -- -- -- -- -- -- -- -- -- -- -- -- + 1 row in the set (0.00 SEC) CodePudding user response:
I look at the source: PartitionByString. Java is: @ Override Public Integer calculate (String key) { Int start=hashSliceStart & gt;=0? HashSliceStart: key length () + hashSliceStart; Int the end=hashSliceEnd & gt; 0? HashSliceEnd: key length () + hashSliceEnd; Long hash=StringUtil. Hash (key, start, end); Return partitionUtil. Partition (hash); } First called StringUtil. Hash computing the hash value, and then call partitionUtil. Partition calculate hash value corresponding partition, StringUtil. Java is: /* ** string hash algorithm: 31 ^ s [0] * (n - 1) + s [1] 31 ^ * (n - 2) +... + s/n - 1] * the string of characters in [] s array, conversion into the expression of the program are: & lt; Br> 31 * * h=h + s.c harAt (I);=& gt; H=(h & lt; <5) - h + s.c harAt (I); * * @ param start * the hash for s.s ubstring (start, end) * @ param end * the hash for s.s ubstring (start, end) */ Public static long hash (String s, int start, int the end) { If (start & lt; 0 { Start=0; } If (end & gt; S.l ength ()) { End=s.l ength (); } Long h=0; For (int I=start; I & lt; end; + + I) { H=(h & lt; <5) - h + s.c harAt (I); } Return h; } PartitionUtil is: nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull