bitShiftRight(offset, 20)
public static long getShardNumByOffset(long offset) {
long shardKey = offset >> 20;
int totalWeight = 20;
long divider = Integer.toUnsignedLong(totalWeight);
long shardNum = (long) shardKey - (long) shardKey / divider * totalWeight + 1;
return shardNum;
}
网友评论