【问题标题】:Is QuestDB (embedded) TableWriter thread-safe?QuestDB(嵌入式)TableWriter 线程安全吗?
【发布时间】:2021-09-10 14:30:48
【问题描述】:

我正在使用 questdb(嵌入式)来存储一堆时间序列。 我想在并行流中运行我的存储方法,但我不知道 TableWriter 是否是线程安全的。

代码如下:

        SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 1);

        try (TableWriter writer = engine.getWriter(ctx.getCairoSecurityContext(), name, "writing")) {
            tickerData.stream().parallel().forEach(
                r -> {
                        Instant         i   = r.getDateTime("DateTime")
                                               .atZone(EST)
                                               .toInstant();
                        long            ts  =  TimestampFormatUtils.parseTimestamp(i.toString());
                        TableWriter.Row row = writer.newRow(ts);

                        row.putDouble(0, r.getDouble("x1"));
                        row.putDouble(1, r.getDouble("x2"));
                        row.putDouble(2, r.getDouble("y1"));
                        row.putDouble(3, r.getDouble("y2"));
                        row.putDouble(4, r.getDouble("z"));
                        row.append();
                        writer.commit();
                    } catch (NumericException ex) {
                        log.error("Cannot parse the date {}", r.getDateTime("DateTime"));
                    } catch (Exception ex) {
                        log.error("Cannot write to table {}!", name, ex);
                    }
                });
        }

这会引发各种错误,有没有办法让存储过程并行?

谢谢,

胡安

【问题讨论】:

    标签: questdb


    【解决方案1】:

    简短的回答是TableWriter 不是线程安全的。您将负责不在并行线程中使用它。

    更长一点的答案是,即使在独立的 QuestDB 中并行写入也受到限制。目前只能通过多个 ILP 连接实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-24
      • 1970-01-01
      • 2020-04-15
      • 1970-01-01
      • 2023-03-26
      • 2011-07-04
      • 2014-04-26
      相关资源
      最近更新 更多