Browse Source

Merge aa4dcbecf0 into be70822bc6

pull/15605/merge
Sergii Matviienko 3 days ago
committed by GitHub
parent
commit
2f6036dfc5
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 28
      application/src/main/java/org/thingsboard/server/service/state/DefaultDeviceStateService.java

28
application/src/main/java/org/thingsboard/server/service/state/DefaultDeviceStateService.java

@ -358,16 +358,26 @@ public class DefaultDeviceStateService extends AbstractPartitionBasedService<Dev
Futures.addCallback(fetchDeviceState(device), new FutureCallback<>() {
@Override
public void onSuccess(DeviceStateData state) {
TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, device.getId());
Set<DeviceId> deviceIds = partitionedEntities.get(tpi);
boolean isMyPartition = deviceIds != null;
if (isMyPartition) {
deviceIds.add(state.getDeviceId());
initializeActivityState(deviceId, state);
try {
TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, device.getId());
Set<DeviceId> deviceIds = partitionedEntities.get(tpi);
boolean isMyPartition = deviceIds != null;
if (isMyPartition) {
deviceIds.add(state.getDeviceId());
initializeActivityState(deviceId, state);
callback.onSuccess();
} else {
log.debug("[{}][{}] Device belongs to external partition. Probably rebalancing is in progress. Topic: {}", tenantId, deviceId, tpi.getFullTopicName());
callback.onFailure(new RuntimeException("Device belongs to external partition " + tpi.getFullTopicName() + "!"));
}
} catch (TenantNotFoundException e) {
// Tenant was removed (e.g. during shutdown / test tearDown) between fetchDeviceState completing
// and partition resolution. Device-state registration is moot in that case.
log.debug("[{}][{}] Tenant not found while registering device to the state service; skipping.", tenantId, deviceId);
callback.onSuccess();
} else {
log.debug("[{}][{}] Device belongs to external partition. Probably rebalancing is in progress. Topic: {}", tenantId, deviceId, tpi.getFullTopicName());
callback.onFailure(new RuntimeException("Device belongs to external partition " + tpi.getFullTopicName() + "!"));
} catch (Throwable t) {
log.warn("[{}][{}] Failed to register device to the state service", tenantId, deviceId, t);
callback.onFailure(t);
}
}

Loading…
Cancel
Save