TDengine icon indicating copy to clipboard operation
TDengine copied to clipboard

使用websocket插入数据的时候,tdengine报错

Open mayomeng opened this issue 2 months ago • 2 comments

TDengine版本:3.3.7.0/3.3.8.0 JDBC客户端版本:taos-jdbcdriver:3.7.2 Bug现象:通过websocket连接器进行高频率数据插入的时候报如下错误:

Image

我的代码就是很普通的websocket数据插入,代码如下:

package com.taos.example.highvolume;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.time.LocalDateTime;
import java.util.concurrent.ThreadLocalRandom;

@Slf4j
public class Test {
    private final static int batchSizeByRow = 100;
    private final static int cacheSizeByRow = 1000;
    private final static int writeThreadCount = 3;

    public static void main(String[] args) {
        String equipmentPrefix = "e";
        String propertyPrefix = "p";

        for (int i = 0 ; i < 1 ; i++) {
            int finalI = i;
            new Thread(() -> {
                try (Connection connection = Util.getConnection(batchSizeByRow, cacheSizeByRow, writeThreadCount);
                     PreparedStatement pstmt = connection.prepareStatement("INSERT INTO iot_platform.? using iot_platform.equipment TAGS (?) VALUES (now(), ?, ?, ?)")) {
                    for (int j = 0 ; j < 100000 ; j++) {
                        pstmt.setString(1, equipmentPrefix + finalI);
                        pstmt.setString(2, propertyPrefix + j);
                        pstmt.setString(3, propertyPrefix + j);
                        pstmt.setString(4, String.valueOf(ThreadLocalRandom.current().nextInt(10000)));
                        pstmt.setString(5, DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss.SSS"));
                        pstmt.addBatch();
                        if (j % batchSizeByRow == 0) {
                            pstmt.executeBatch();
                        }
                    }
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }).start();
        }
    }
}

获取数据库连接的代码如下:

    private final static String JDBC_URL = "jdbc:TAOS-WS://10.216.36.64:6041/?user=root&password=taosdata";

    public static Connection getConnection(int batchSize, int cacheSize, int writeThreadNum) throws SQLException {
        String jdbcURL = System.getenv("TDENGINE_JDBC_URL");
        if (jdbcURL == null || jdbcURL == "") {
            jdbcURL = JDBC_URL;
        }
        Properties properties = new Properties();
        properties.setProperty(TSDBDriver.PROPERTY_KEY_ASYNC_WRITE, "stmt");
        properties.setProperty(TSDBDriver.PROPERTY_KEY_BATCH_SIZE_BY_ROW, String.valueOf(batchSize));
        properties.setProperty(TSDBDriver.PROPERTY_KEY_CACHE_SIZE_BY_ROW, String.valueOf(cacheSize));
        properties.setProperty(TSDBDriver.PROPERTY_KEY_BACKEND_WRITE_THREAD_NUM, String.valueOf(writeThreadNum));
        properties.setProperty(TSDBDriver.PROPERTY_KEY_ENABLE_AUTO_RECONNECT, "true");
        return DriverManager.getConnection(jdbcURL, properties);
    }

服务器配置为8c16g,如果使用jdbc:TAOS-RS连接器则能够正常插入数据,只要使用websocket连接器就会报错。

mayomeng avatar Oct 20 '25 08:10 mayomeng

好的 我们看下。

yu285 avatar Oct 20 '25 09:10 yu285

已经在处理中,处理完毕会通知我们

yu285 avatar Oct 21 '25 01:10 yu285