Browse Source
Merge pull request #6840 from volodymyr-babak/bug/fix-edge-black-box-tests
[3.4][Bug] Saving of edge event in batches should be single threaded
pull/6845/head
Andrew Shvayka
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
5 additions and
5 deletions
-
application/src/main/java/org/thingsboard/server/service/edge/rpc/sync/DefaultEdgeRequestsService.java
-
application/src/main/resources/thingsboard.yml
-
dao/src/main/java/org/thingsboard/server/dao/sql/edge/JpaBaseEdgeEventDao.java
|
|
|
@ -74,6 +74,7 @@ import org.thingsboard.server.gen.edge.v1.UserCredentialsRequestMsg; |
|
|
|
import org.thingsboard.server.gen.edge.v1.WidgetBundleTypesRequestMsg; |
|
|
|
import org.thingsboard.server.service.entitiy.entityview.TbEntityViewService; |
|
|
|
import org.thingsboard.server.service.executors.DbCallbackExecutorService; |
|
|
|
import org.thingsboard.server.service.state.DefaultDeviceStateService; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
@ -162,6 +163,9 @@ public class DefaultEdgeRequestsService implements EdgeRequestsService { |
|
|
|
Map<String, Object> entityData = new HashMap<>(); |
|
|
|
ObjectNode attributes = mapper.createObjectNode(); |
|
|
|
for (AttributeKvEntry attr : ssAttributes) { |
|
|
|
if (DefaultDeviceStateService.PERSISTENT_ATTRIBUTES.contains(attr.getKey())) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (attr.getDataType() == DataType.BOOLEAN && attr.getBooleanValue().isPresent()) { |
|
|
|
attributes.put(attr.getKey(), attr.getBooleanValue().get()); |
|
|
|
} else if (attr.getDataType() == DataType.DOUBLE && attr.getDoubleValue().isPresent()) { |
|
|
|
|
|
|
|
@ -266,7 +266,6 @@ sql: |
|
|
|
batch_size: "${SQL_EDGE_EVENTS_BATCH_SIZE:1000}" |
|
|
|
batch_max_delay: "${SQL_EDGE_EVENTS_BATCH_MAX_DELAY_MS:100}" |
|
|
|
stats_print_interval_ms: "${SQL_EDGE_EVENTS_BATCH_STATS_PRINT_MS:10000}" |
|
|
|
batch_threads: "${SQL_EDGE_EVENTS_BATCH_THREADS:3}" # batch thread count have to be a prime number like 3 or 5 to gain perfect hash distribution |
|
|
|
# Specify whether to sort entities before batch update. Should be enabled for cluster mode to avoid deadlocks |
|
|
|
batch_sort: "${SQL_BATCH_SORT:false}" |
|
|
|
# Specify whether to remove null characters from strValue of attributes and timeseries before insert |
|
|
|
|
|
|
|
@ -72,9 +72,6 @@ public class JpaBaseEdgeEventDao extends JpaAbstractSearchTextDao<EdgeEventEntit |
|
|
|
@Value("${sql.edge_events.stats_print_interval_ms:10000}") |
|
|
|
private long statsPrintIntervalMs; |
|
|
|
|
|
|
|
@Value("${sql.edge_events.batch_threads:3}") |
|
|
|
private int batchThreads; |
|
|
|
|
|
|
|
private TbSqlBlockingQueueWrapper<EdgeEventEntity> queue; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
@ -110,7 +107,7 @@ public class JpaBaseEdgeEventDao extends JpaAbstractSearchTextDao<EdgeEventEntit |
|
|
|
return NULL_UUID.hashCode(); |
|
|
|
} |
|
|
|
}; |
|
|
|
queue = new TbSqlBlockingQueueWrapper<>(params, hashcodeFunction, batchThreads, statsFactory); |
|
|
|
queue = new TbSqlBlockingQueueWrapper<>(params, hashcodeFunction, 1, statsFactory); |
|
|
|
queue.init(logExecutor, v -> edgeEventInsertRepository.save(v), |
|
|
|
Comparator.comparing(EdgeEventEntity::getTs) |
|
|
|
); |
|
|
|
|