Search in sources :

Example 1 with AbstractTsKvEntity

use of org.thingsboard.server.dao.model.sql.AbstractTsKvEntity in project thingsboard by thingsboard.

the class TimescaleTimeseriesDao method init.

@PostConstruct
protected void init() {
    TbSqlBlockingQueueParams tsParams = TbSqlBlockingQueueParams.builder().logName("TS Timescale").batchSize(tsBatchSize).maxDelay(tsMaxDelay).statsPrintIntervalMs(tsStatsPrintIntervalMs).statsNamePrefix("ts.timescale").batchSortEnabled(batchSortEnabled).build();
    Function<TimescaleTsKvEntity, Integer> hashcodeFunction = entity -> entity.getEntityId().hashCode();
    tsQueue = new TbSqlBlockingQueueWrapper<>(tsParams, hashcodeFunction, timescaleBatchThreads, statsFactory);
    tsQueue.init(logExecutor, v -> insertRepository.saveOrUpdate(v), Comparator.comparing((Function<TimescaleTsKvEntity, UUID>) AbstractTsKvEntity::getEntityId).thenComparing(AbstractTsKvEntity::getKey).thenComparing(AbstractTsKvEntity::getTs));
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) java.util(java.util) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TbSqlBlockingQueueWrapper(org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) SettableFuture(com.google.common.util.concurrent.SettableFuture) StatsFactory(org.thingsboard.server.common.stats.StatsFactory) Function(java.util.function.Function) TenantId(org.thingsboard.server.common.data.id.TenantId) Value(org.springframework.beans.factory.annotation.Value) PreDestroy(javax.annotation.PreDestroy) SQLException(java.sql.SQLException) AbstractTsKvEntity(org.thingsboard.server.dao.model.sql.AbstractTsKvEntity) AbstractSqlTimeseriesDao(org.thingsboard.server.dao.sqlts.AbstractSqlTimeseriesDao) TimescaleTsKvEntity(org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvEntity) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) EntityId(org.thingsboard.server.common.data.id.EntityId) Sort(org.springframework.data.domain.Sort) InsertTsRepository(org.thingsboard.server.dao.sqlts.insert.InsertTsRepository) TimescaleDBTsDao(org.thingsboard.server.dao.util.TimescaleDBTsDao) Aggregation(org.thingsboard.server.common.data.kv.Aggregation) PageRequest(org.springframework.data.domain.PageRequest) DeleteTsKvQuery(org.thingsboard.server.common.data.kv.DeleteTsKvQuery) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) CollectionUtils(org.springframework.util.CollectionUtils) TimeseriesDao(org.thingsboard.server.dao.timeseries.TimeseriesDao) PostConstruct(javax.annotation.PostConstruct) DaoUtil(org.thingsboard.server.dao.DaoUtil) CallableStatement(java.sql.CallableStatement) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery) ModelConstants(org.thingsboard.server.dao.model.ModelConstants) Types(java.sql.Types) Function(java.util.function.Function) TimescaleTsKvEntity(org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvEntity) AbstractTsKvEntity(org.thingsboard.server.dao.model.sql.AbstractTsKvEntity) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) PostConstruct(javax.annotation.PostConstruct)

Example 2 with AbstractTsKvEntity

use of org.thingsboard.server.dao.model.sql.AbstractTsKvEntity in project thingsboard by thingsboard.

the class SqlTimeseriesLatestDao method init.

@PostConstruct
protected void init() {
    TbSqlBlockingQueueParams tsLatestParams = TbSqlBlockingQueueParams.builder().logName("TS Latest").batchSize(tsLatestBatchSize).maxDelay(tsLatestMaxDelay).statsPrintIntervalMs(tsLatestStatsPrintIntervalMs).statsNamePrefix("ts.latest").batchSortEnabled(false).build();
    java.util.function.Function<TsKvLatestEntity, Integer> hashcodeFunction = entity -> entity.getEntityId().hashCode();
    tsLatestQueue = new TbSqlBlockingQueueWrapper<>(tsLatestParams, hashcodeFunction, tsLatestBatchThreads, statsFactory);
    tsLatestQueue.init(logExecutor, v -> {
        Map<TsKey, TsKvLatestEntity> trueLatest = new HashMap<>();
        v.forEach(ts -> {
            TsKey key = new TsKey(ts.getEntityId(), ts.getKey());
            trueLatest.merge(key, ts, (oldTs, newTs) -> oldTs.getTs() <= newTs.getTs() ? newTs : oldTs);
        });
        List<TsKvLatestEntity> latestEntities = new ArrayList<>(trueLatest.values());
        if (batchSortEnabled) {
            latestEntities.sort(Comparator.comparing((Function<TsKvLatestEntity, UUID>) AbstractTsKvEntity::getEntityId).thenComparingInt(AbstractTsKvEntity::getKey));
        }
        insertLatestTsRepository.saveOrUpdate(latestEntities);
    }, (l, r) -> 0);
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TbSqlBlockingQueueWrapper(org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper) Autowired(org.springframework.beans.factory.annotation.Autowired) DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) TsKvLatestCompositeKey(org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestCompositeKey) HashMap(java.util.HashMap) ScheduledLogExecutorComponent(org.thingsboard.server.dao.sql.ScheduledLogExecutorComponent) StatsFactory(org.thingsboard.server.common.stats.StatsFactory) Function(java.util.function.Function) TenantId(org.thingsboard.server.common.data.id.TenantId) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) PreDestroy(javax.annotation.PreDestroy) Lists(com.google.common.collect.Lists) AbstractTsKvEntity(org.thingsboard.server.dao.model.sql.AbstractTsKvEntity) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) Map(java.util.Map) EntityId(org.thingsboard.server.common.data.id.EntityId) TsKvLatestRemovingResult(org.thingsboard.server.common.data.kv.TsKvLatestRemovingResult) TsKvLatestEntity(org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestEntity) BaseReadTsKvQuery(org.thingsboard.server.common.data.kv.BaseReadTsKvQuery) InsertLatestTsRepository(org.thingsboard.server.dao.sqlts.insert.latest.InsertLatestTsRepository) TimeseriesLatestDao(org.thingsboard.server.dao.timeseries.TimeseriesLatestDao) SqlTsLatestAnyDao(org.thingsboard.server.dao.util.SqlTsLatestAnyDao) Aggregation(org.thingsboard.server.common.data.kv.Aggregation) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) DeleteTsKvQuery(org.thingsboard.server.common.data.kv.DeleteTsKvQuery) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) TsKvLatestRepository(org.thingsboard.server.dao.sqlts.latest.TsKvLatestRepository) PostConstruct(javax.annotation.PostConstruct) DaoUtil(org.thingsboard.server.dao.DaoUtil) SearchTsKvLatestRepository(org.thingsboard.server.dao.sqlts.latest.SearchTsKvLatestRepository) Optional(java.util.Optional) Comparator(java.util.Comparator) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) TsKvLatestEntity(org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UUID(java.util.UUID) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) PostConstruct(javax.annotation.PostConstruct)

Example 3 with AbstractTsKvEntity

use of org.thingsboard.server.dao.model.sql.AbstractTsKvEntity in project thingsboard by thingsboard.

the class AbstractChunkedAggregationTimeseriesDao method init.

@PostConstruct
protected void init() {
    TbSqlBlockingQueueParams tsParams = TbSqlBlockingQueueParams.builder().logName("TS").batchSize(tsBatchSize).maxDelay(tsMaxDelay).statsPrintIntervalMs(tsStatsPrintIntervalMs).statsNamePrefix("ts").batchSortEnabled(batchSortEnabled).build();
    Function<TsKvEntity, Integer> hashcodeFunction = entity -> entity.getEntityId().hashCode();
    tsQueue = new TbSqlBlockingQueueWrapper<>(tsParams, hashcodeFunction, tsBatchThreads, statsFactory);
    tsQueue.init(logExecutor, v -> insertRepository.saveOrUpdate(v), Comparator.comparing((Function<TsKvEntity, UUID>) AbstractTsKvEntity::getEntityId).thenComparing(AbstractTsKvEntity::getKey).thenComparing(AbstractTsKvEntity::getTs));
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) java.util(java.util) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TbSqlBlockingQueueWrapper(org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) SettableFuture(com.google.common.util.concurrent.SettableFuture) StatsFactory(org.thingsboard.server.common.stats.StatsFactory) Function(java.util.function.Function) TenantId(org.thingsboard.server.common.data.id.TenantId) Value(org.springframework.beans.factory.annotation.Value) PreDestroy(javax.annotation.PreDestroy) AbstractTsKvEntity(org.thingsboard.server.dao.model.sql.AbstractTsKvEntity) TsKvEntity(org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) EntityId(org.thingsboard.server.common.data.id.EntityId) Sort(org.springframework.data.domain.Sort) InsertTsRepository(org.thingsboard.server.dao.sqlts.insert.InsertTsRepository) TsKvRepository(org.thingsboard.server.dao.sqlts.ts.TsKvRepository) Aggregation(org.thingsboard.server.common.data.kv.Aggregation) PageRequest(org.springframework.data.domain.PageRequest) Collectors(java.util.stream.Collectors) DeleteTsKvQuery(org.thingsboard.server.common.data.kv.DeleteTsKvQuery) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) TimeseriesDao(org.thingsboard.server.dao.timeseries.TimeseriesDao) PostConstruct(javax.annotation.PostConstruct) DaoUtil(org.thingsboard.server.dao.DaoUtil) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery) Function(java.util.function.Function) AbstractTsKvEntity(org.thingsboard.server.dao.model.sql.AbstractTsKvEntity) TsKvEntity(org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity) AbstractTsKvEntity(org.thingsboard.server.dao.model.sql.AbstractTsKvEntity) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Futures (com.google.common.util.concurrent.Futures)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)3 Function (java.util.function.Function)3 PostConstruct (javax.annotation.PostConstruct)3 PreDestroy (javax.annotation.PreDestroy)3 Slf4j (lombok.extern.slf4j.Slf4j)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Value (org.springframework.beans.factory.annotation.Value)3 EntityId (org.thingsboard.server.common.data.id.EntityId)3 TenantId (org.thingsboard.server.common.data.id.TenantId)3 Aggregation (org.thingsboard.server.common.data.kv.Aggregation)3 DeleteTsKvQuery (org.thingsboard.server.common.data.kv.DeleteTsKvQuery)3 ReadTsKvQuery (org.thingsboard.server.common.data.kv.ReadTsKvQuery)3 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)3 StatsFactory (org.thingsboard.server.common.stats.StatsFactory)3 DaoUtil (org.thingsboard.server.dao.DaoUtil)3 AbstractTsKvEntity (org.thingsboard.server.dao.model.sql.AbstractTsKvEntity)3 TbSqlBlockingQueueParams (org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams)3 TbSqlBlockingQueueWrapper (org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper)3