@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.TenantProfileId ;
import org.thingsboard.server.common.data.id.TenantProfileId ;
import org.thingsboard.server.common.data.integration.IntegrationType ;
import org.thingsboard.server.common.data.integration.IntegrationType ;
import org.thingsboard.server.common.data.job.JobType ;
import org.thingsboard.server.common.data.job.JobType ;
import org.thingsboard.server.common.data.util.CollectionsUtil ;
import org.thingsboard.server.common.msg.queue.ServiceType ;
import org.thingsboard.server.common.msg.queue.ServiceType ;
import org.thingsboard.server.common.msg.queue.TopicPartitionInfo ;
import org.thingsboard.server.common.msg.queue.TopicPartitionInfo ;
import org.thingsboard.server.gen.transport.TransportProtos ;
import org.thingsboard.server.gen.transport.TransportProtos ;
@ -108,6 +107,7 @@ public class HashPartitionService implements PartitionService {
private List < ServiceInfo > currentOtherServices ;
private List < ServiceInfo > currentOtherServices ;
private final Map < String , List < ServiceInfo > > tbTransportServicesByType = new HashMap < > ( ) ;
private final Map < String , List < ServiceInfo > > tbTransportServicesByType = new HashMap < > ( ) ;
private volatile Map < TenantProfileId , List < ServiceInfo > > responsibleServices = Collections . emptyMap ( ) ;
private volatile Map < TenantProfileId , List < ServiceInfo > > responsibleServices = Collections . emptyMap ( ) ;
private volatile Set < TenantProfileId > profilesWithDedicatedServices = Collections . emptySet ( ) ;
private HashFunction hashFunction ;
private HashFunction hashFunction ;
@ -319,7 +319,7 @@ public class HashPartitionService implements PartitionService {
TenantRoutingInfo routingInfo = getRoutingInfo ( tenantId ) ;
TenantRoutingInfo routingInfo = getRoutingInfo ( tenantId ) ;
if ( isRegular ) {
if ( isRegular ) {
if ( routingInfo . isIsolated ( ) ) {
if ( routingInfo . isIsolated ( ) ) {
isManaged = has DedicatedService ( routingInfo . getProfileId ( ) ) ;
isManaged = ! profilesWit hDedicatedServices . contains ( routingInfo . getProfileId ( ) ) ;
} else {
} else {
isManaged = true ;
isManaged = true ;
}
}
@ -334,10 +334,6 @@ public class HashPartitionService implements PartitionService {
return isManaged ;
return isManaged ;
}
}
private boolean hasDedicatedService ( TenantProfileId profileId ) {
return CollectionsUtil . isEmpty ( responsibleServices . get ( profileId ) ) ;
}
@Override
@Override
public TopicPartitionInfo resolve ( ServiceType serviceType , String queueName , TenantId tenantId , EntityId entityId ) {
public TopicPartitionInfo resolve ( ServiceType serviceType , String queueName , TenantId tenantId , EntityId entityId ) {
QueueKey queueKey = getQueueKey ( serviceType , queueName , tenantId ) ;
QueueKey queueKey = getQueueKey ( serviceType , queueName , tenantId ) ;
@ -447,6 +443,8 @@ public class HashPartitionService implements PartitionService {
}
}
queueServicesMap . values ( ) . forEach ( list - > list . sort ( Comparator . comparing ( ServiceInfo : : getServiceId ) ) ) ;
queueServicesMap . values ( ) . forEach ( list - > list . sort ( Comparator . comparing ( ServiceInfo : : getServiceId ) ) ) ;
responsibleServices . values ( ) . forEach ( list - > list . sort ( Comparator . comparing ( ServiceInfo : : getServiceId ) ) ) ;
responsibleServices . values ( ) . forEach ( list - > list . sort ( Comparator . comparing ( ServiceInfo : : getServiceId ) ) ) ;
// resolveByPartitionIdx adds the fallback servers for profiles without dedicated services to responsibleServices
Set < TenantProfileId > profilesWithDedicatedServices = Set . copyOf ( responsibleServices . keySet ( ) ) ;
final ConcurrentMap < QueueKey , List < Integer > > newPartitions = new ConcurrentHashMap < > ( ) ;
final ConcurrentMap < QueueKey , List < Integer > > newPartitions = new ConcurrentHashMap < > ( ) ;
partitionSizesMap . forEach ( ( queueKey , size ) - > {
partitionSizesMap . forEach ( ( queueKey , size ) - > {
@ -463,6 +461,7 @@ public class HashPartitionService implements PartitionService {
}
}
} ) ;
} ) ;
this . responsibleServices = responsibleServices ;
this . responsibleServices = responsibleServices ;
this . profilesWithDedicatedServices = profilesWithDedicatedServices ;
final ConcurrentMap < QueueKey , List < Integer > > oldPartitions = myPartitions ;
final ConcurrentMap < QueueKey , List < Integer > > oldPartitions = myPartitions ;
myPartitions = newPartitions ;
myPartitions = newPartitions ;