influxdb-java: org.influxdb.InfluxDBIOException: java.net.SocketException: Connection reset by peer: socket write error

馋奶兔 提交于 2021-02-05 09:36:21

问题


I'm testing InfluxDB to store sensor time series. I'm using the influxdb-java client library (version 2.15) and I'm running InfluxDB 1.7.6 locally for test purpose.

All my points are stored .csv files (one per sensor) which are themselves stored in .zip files (one per dataset). My code run through each line of each csv files. Points are written in batch mode.

/**
 * Get the connection to the database
 */
InfluxDB influxDB = InfluxDBFactory.connect("http://192.168.51.51:8086");
influxDB.query(new Query("CREATE DATABASE theia_in_situ"));
influxDB.setDatabase("theia_in_situ");
influxDB.enableBatch();
influxDB.setLogLevel(InfluxDB.LogLevel.BASIC);
/**
 * Create batch point to write each measure of the time serie more efficiently
 */
BatchPoints batchPoints = BatchPoints
        .database("theia_in_situ")
        .build();

For each CSV data file the following method is executed:

public static void createAndImportTimeSeriesDocuments(InputStream txtFileIn, String observationId, String producerId,
        InfluxDB influxDB, BatchPoints batchPoints) throws IOException, ParseException {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    /**
     * Store the variable name
     */
    String observedProperty = null;
    try (BufferedReader br = new BufferedReader(new InputStreamReader(txtFileIn));) {
        String line = null;
        /**
         * Read the headers
         */
        while ((line = br.readLine()).substring(0, 1).equals("#")) {
            if (line.substring(0, 15).equals("#Variable_name;")) {
                observedProperty = line.split(";")[1];
            }
        }
        /**
         * Read the data
         */
        while ((line = br.readLine()) != null) {
            String[] lineSplitted = line.split(";", -1);
            Point point = Point.measurement(observedProperty)
                    .tag("producerId", producerId)
                    .tag("observationId", observationId)
                    .time(df.parse(lineSplitted[1]).getTime(), TimeUnit.MILLISECONDS)
                    .addField("value", lineSplitted[5])
                    .addField("flag", lineSplitted[6])
                    .build();
            batchPoints.point(point);
        }
        influxDB.write(batchPoints);
    }
}

I can write one or few measurement but soon enough I get the following exception:

Exception in thread "main" org.influxdb.InfluxDBIOException: java.net.SocketException: Connection reset by peer: socket write error at org.influxdb.impl.InfluxDBImpl.execute(InfluxDBImpl.java:812) at org.influxdb.impl.InfluxDBImpl.write(InfluxDBImpl.java:463)

I have already disabled max-concurrent-write-limit, max-enqueued-write-limit, enqueued-write-timeout (setting each value to 0 in /etc/influxdb/influxdb.conf) as mentionned here. Even though this issue is mentionned as FAQ in the Github page, I can't find any issue reproducing my problem.

Any help would be appreciated.


回答1:


This exception seems to occur when trying to write BatchPoint in batch mode.

The influxdb-java client is storing your writes into an internal buffer and flushes them asynchronously to InfluxDB at a fixed flush interval to achieve good performance on both client and server side.

Here is the updated piece of code.

/**
 * Read the data
 */
while ((line = br.readLine()) != null) {
    String[] lineSplitted = line.split(";", -1);
    Point point = Point.measurement(observedProperty)
            .tag("producerId", producerId)
            .tag("observationId", observationId)
            .time(df.parse(lineSplitted[1]).getTime(), TimeUnit.MILLISECONDS)
            .addField("value", lineSplitted[5])
            .addField("flag", lineSplitted[6])
            .build();
    influxDB.write(point);
  //  batchPoints.point(point);
}
//influxDB.write(batchPoints);


来源:https://stackoverflow.com/questions/55851725/influxdb-java-org-influxdb-influxdbioexception-java-net-socketexception-conne

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!