首页 > 其他分享 >influxdb field type冲突问题

influxdb field type冲突问题

时间:2024-04-15 17:16:24浏览次数:27  
标签:com influxdb field go type op

问题描述

2024-04-14T14:59:51Z E! [outputs.influxdb_v2] Failed to write metric to iot (will be dropped: 422 Unprocessable Entity): unprocessable entity: failure writing points to database: partial write: field type conflict: input field "longitude" on measurement "device_metric" is type float, already exists as type string dropped=1224

写入influxdb时,报错类型冲突:表中字段longitude的类型是string,要写入的值类型是float,不允许这样。

问题分析

https://docs.influxdata.com/influxdb/v2/reference/faq/#how-does-influxdb-handle-field-type-discrepancies-across-shards

Field values can be floats, integers, strings, or Booleans. Field value types cannot differ within a shard, but they can differ across shards.

在同一个分片(shard)内同一个字段只能有一个类型。不同分片同一个字段可以使用不同的类型。

因此,上面的报错,只能说明部分分区中有类型冲突的问题。 并不是所有数据都无法写入,只是特定分区的数据会因为类型冲突无法写入。

下面看看到底是哪个分区存在类型冲突的问题

cd /mnt/data/influxdb/engine/data
influxd inspect check-schema

输出:

Processing 62ea4f9dbf724d07/autogen/401/fields.idx
{"level":"info","ts":1713171034.145333,"caller":"logger/fields.go:131","msg":"loading changes (start)","op_name":"field indices","op_event":"start"}
{"level":"info","ts":1713171034.1453714,"caller":"logger/fields.go:133","msg":"loading changes (end)","op_name":"field indices","op_event":"end","op_elapsed":0.000035632}
Processing 62ea4f9dbf724d07/autogen/41/fields.idx
{"level":"info","ts":1713171034.1477647,"caller":"logger/fields.go:131","msg":"loading changes (start)","op_name":"field indices","op_event":"start"}
{"level":"info","ts":1713171034.147799,"caller":"logger/fields.go:133","msg":"loading changes (end)","op_name":"field indices","op_event":"end","op_elapsed":0.000037203}
Processing 62ea4f9dbf724d07/autogen/42/fields.idx
{"level":"info","ts":1713171034.1485324,"caller":"logger/fields.go:131","msg":"loading changes (start)","op_name":"field indices","op_event":"start"}
{"level":"info","ts":1713171034.1485918,"caller":"logger/fields.go:133","msg":"loading changes (end)","op_name":"field indices","op_event":"end","op_elapsed":0.000071106}
Processing 62ea4f9dbf724d07/autogen/43/fields.idx
{"level":"info","ts":1713171034.149207,"caller":"logger/fields.go:131","msg":"loading changes (start)","op_name":"field indices","op_event":"start"}
{"level":"info","ts":1713171034.1492457,"caller":"logger/fields.go:133","msg":"loading changes (end)","op_name":"field indices","op_event":"end","op_elapsed":0.000041647}
Processing 62ea4f9dbf724d07/autogen/65/fields.idx
{"level":"error","ts":1713171034.182047,"caller":"tsdb/shard.go:2544","msg":"field creation","op_name":"field indices","error":"failed creating \"device_metric\".\"acc\": field type conflict","stacktrace":"github.com/influxdata/influxdb/v2/tsdb.(*MeasurementFieldSet).ApplyChanges\n\t/root/project/tsdb/shard.go:2544\ngithub.com/influxdata/influxdb/v2/tsdb.(*MeasurementFieldSet).load\n\t/root/project/tsdb/shard.go:2417\ngithub.com/influxdata/influxdb/v2/tsdb.NewMeasurementFieldSet\n\t/root/project/tsdb/shard.go:1968\ngithub.com/influxdata/influxdb/v2/cmd/influxd/inspect/type_conflicts.(*TypeConflictChecker).readFields.func1\n\t/root/project/cmd/influxd/inspect/type_conflicts/check_schema.go:135\nio/fs.walkDir\n\t/go/src/io/fs/walk.go:73\nio/fs.walkDir\n\t/go/src/io/fs/walk.go:95\nio/fs.walkDir\n\t/go/src/io/fs/walk.go:95\nio/fs.walkDir\n\t/go/src/io/fs/walk.go:95\nio/fs.walkDir\n\t/go/src/io/fs/walk.go:95\nio/fs.WalkDir\n\t/go/src/io/fs/walk.go:122\ngithub.com/influxdata/influxdb/v2/cmd/influxd/inspect/type_conflicts.(*TypeConflictChecker).readFields\n\t/root/project/cmd/influxd/inspect/type_conflicts/check_schema.go:113\ngithub.com/influxdata/influxdb/v2/cmd/influxd/inspect/type_conflicts.checkSchemaRunE\n\t/root/project/cmd/influxd/inspect/type_conflicts/check_schema.go:85\ngithub.com/influxdata/influxdb/v2/cmd/influxd/inspect/type_conflicts.NewCheckSchemaCommand.func1\n\t/root/project/cmd/influxd/inspect/type_conflicts/check_schema.go:38\ngithub.com/spf13/cobra.(*Command).execute\n\t/go/pkg/mod/github.com/spf13/[email protected]/command.go:842\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\t/go/pkg/mod/github.com/spf13/[email protected]/command.go:950\ngithub.com/spf13/cobra.(*Command).Execute\n\t/go/pkg/mod/github.com/spf13/[email protected]/command.go:887\nmain.main\n\t/root/project/cmd/influxd/main.go:61\nruntime.main\n\t/go/src/runtime/proc.go:250"}
Error: unable to open file "62ea4f9dbf724d07/autogen/65/fields.idx": failed creating "device_metric"."acc": field type conflict

说明分区 65 存在类型冲突。
influxdb是根据时序数据的时间,进行分区的。如 2024.4月、2024.5月数据各一个分区。

类型冲突之后怎么办?

1、修改类型。
https://docs.influxdata.com/influxdb/v2/reference/faq/#can-i-change-a-fields-data-type

2、查询特定类型的 value
https://docs.influxdata.com/influxdb/v2/reference/faq/#how-does-influxdb-handle-field-type-discrepancies-across-shards

实际上可操作性不强,那么尽量从源头避免(数据写入时)保证类型不会冲突吧。

标签:com,influxdb,field,go,type,op
From: https://www.cnblogs.com/xushengbin/p/18136462

相关文章

  • 鸿蒙开发TypeScript语言:【运算符】
    运算符用于执行程序代码运算,会针对一个以上操作数项目来进行运算。考虑以下计算:7+5=12以上实例中7、5和12是操作数。运算符 + 用于加值。运算符 = 用于赋值。TypeScript主要包含以下几种运算:算术运算符逻辑运算符关系运算符按位运算符赋值运算符三元/......
  • 鸿蒙开发TypeScript语言:【变量声明】
    变量是一种使用方便的占位符,用于引用计算机内存地址。我们可以把变量看做存储数据的容器。TypeScript变量的命名规则:变量名称可以包含数字和字母。除了下划线 _ 和美元 $ 符号外,不能包含其他特殊字符,包括空格。变量名不能以数字开头。变量使用前必须先声明,我们可以使......
  • 一对一 typeorm
    一对一一对一是一种A只包含一个B实例,而B只包含一个A实例的关系。我们以User和Profile实体为例。用户只能拥有一个配置文件,并且一个配置文件仅由一个用户拥有。import{Entity,PrimaryGeneratedColumn,Column}from"typeorm";@Entity()exportclassProfile{......
  • InfluxDB时序数据库图形用户界面可视化工具(influxdb-gui)
    说明之前开发了一款TDengine的GUI程序,出于兴趣,简单搞个InfluxDB的复制版,类似Navicat,目前基础操作功能已满足,后续看情况,可以继续扩展功能。介绍InfluxDB-GUI是一款功能全面、操作简便的influxdb时序数据库图形界面工具,V1.0.0目前支持influxdb版本列表如下:influxdb1.8.10版本......
  • SystemVerilog -- 2.1 Data Types ~ New Data types
    SystemVeriloglogicandbit在上一篇文章中,概述了主要数据类型。在本会话中,我们将研究4-state和2-state变量以及两种名为logic和bit的新数据类型。4-statedatatypes除了0和1之外,还可以具有未知(X)和高阻态(Z)值的类型称为4态类型。请注意,只能在过程快中驱动,例如,数据类......
  • SystemVerilog -- 2.0 Data Types ~ Introduction
    SystemVerilogDataTypesSystemVerilog是Verilog的扩展,也用作HDL。Verilog具有和数据类型来描述硬件行为。由于硬件验证可能变的更加复杂和苛刻,Verilog中的数据类型不足以开发高效的测试平台和测试用例。因此,SystemVerilog通过添加更多类似C的数据类型和扩展Verilog,以......
  • MathType如何自动化公式编号?
    右编号如果不设置的话就直接是按照常规序列那么如果你想要跟着章编号章节要在章前边加一个这个符号编号格式......
  • 鸿蒙开发TypeScript语言:【基础类型】
    TypeScript包含的数据类型如下表:注意:TypeScript和JavaScript没有整数类型。Any类型任意值是TypeScript针对编程时类型不明确的变量使用的一种数据类型,它常用于以下三种情况。1、变量的值会动态改变时,比如来自用户的输入,任意值类型可以让这些变量跳过编译阶段的类型......
  • 41 Typescript面向对象
    简介程序之中所有的操作都需要通过对象来完成举例来说:操作浏览器要使用window对象操作网页要使用document对象操作控制台要使用console对象一切操作都要通过对象,也就是所谓的面向对象,那么对象到底是什么呢?这就要先说到程序是什么,计算机程序的本质就是对现实事物的抽象,抽象......
  • 42 Typescript编译配置-webpack-babel
    TS编译配置自动编译单个文件tsc1.ts#如果想要自动监视文件的变化,需要添加`-W`配置tsc1.ts-W自动编译整个项目初始化,会自动生成一个tsconfig.json文件,然后直接执行tsc命令,就可以对当前目录的所有ts文件进行编译,生成对应的js文件#初始化项目tsc--init#编译......