|
|
|
@ -39,6 +39,7 @@ import org.thingsboard.server.queue.discovery.event.PartitionChangeEvent; |
|
|
|
import org.thingsboard.server.queue.discovery.event.ServiceListChangedEvent; |
|
|
|
import org.thingsboard.server.queue.util.AfterStartUp; |
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collections; |
|
|
|
@ -559,7 +560,15 @@ public class HashPartitionService implements PartitionService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public int resolvePartitionIndex(UUID entityId, int partitions) { |
|
|
|
int hash = hash(entityId); |
|
|
|
return resolvePartitionIndex(hash(entityId), partitions); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int resolvePartitionIndex(String key, int partitions) { |
|
|
|
return resolvePartitionIndex(hash(key), partitions); |
|
|
|
} |
|
|
|
|
|
|
|
private int resolvePartitionIndex(int hash, int partitions) { |
|
|
|
return Math.abs(hash % partitions); |
|
|
|
} |
|
|
|
|
|
|
|
@ -725,6 +734,12 @@ public class HashPartitionService implements PartitionService { |
|
|
|
.hash().asInt(); |
|
|
|
} |
|
|
|
|
|
|
|
private int hash(String key) { |
|
|
|
return hashFunction.newHasher() |
|
|
|
.putString(key, StandardCharsets.UTF_8) |
|
|
|
.hash().asInt(); |
|
|
|
} |
|
|
|
|
|
|
|
public static HashFunction forName(String name) { |
|
|
|
return switch (name) { |
|
|
|
case "murmur3_32" -> Hashing.murmur3_32(); |
|
|
|
|