You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hugegraph.apache.org by "neoblackcap (via GitHub)" <gi...@apache.org> on 2026/05/11 12:36:01 UTC

[I] [Bug] gremlin return wrong data [hugegraph]

neoblackcap opened a new issue, #3023:
URL: https://github.com/apache/hugegraph/issues/3023

   ### Bug Type (问题类型)
   
   gremlin (结果不合预期)
   
   ### Before submit
   
   - [x] 我已经确认现有的 [Issues](https://github.com/apache/hugegraph/issues) 与 [FAQ](https://hugegraph.apache.org/docs/guides/faq/) 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)
   
   ### Environment (环境信息)
   
   - Server Version: 1.7.0 (Apache Release Version)
   - Backend: HStore 1 nodes, HDD or SSD 
   - OS: xx CPUs, xx G RAM, Ubuntu 2x.x / CentOS 7.x 
   - Data Size:  xx vertices, xx edges <!-- (like 1000W 点, 9000W 边) -->
   
   
   ### Expected & Actual behavior (期望与实际表现)
   
   使用`g.E().hasLabel("depend_on").has("cdb_id", 439)`查询边数据,`depend_on` EdgeLabel已经对`cdb_id`字段创建Sencondary索引
   返回
   ```json
   [
     {
       "id": "L1118501289353805824>4>4>>L1118497440656261120",
       "label": "depend_on",
       "source": "1118501289353805824",
       "target": "1118497440656261120",
       "properties": {
         "productname": "鸡鲜粉调味料",
         "cdb_id": 442,
         "menuid": "10522",
         "process_step": 4,
         "doorder": 4,
         "productid": "YHGYL-GT1146"
       }
     }
   ]
   ```
   
   ### Vertex/Edge example (问题点 / 边数据举例)
   
   ```javascript
   [
     {
       "id": "L1118501289353805824>4>4>>L1118497440656261120",
       "label": "depend_on",
       "source": "1118501289353805824",
       "target": "1118497440656261120",
       "properties": {
         "productname": "鸡鲜粉调味料",
         "cdb_id": 442,
         "menuid": "10522",
         "process_step": 4,
         "doorder": 4,
         "productid": "YHGYL-GT1146"
       }
     }
   ]
   ```
   
   ### Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)
   
   ```javascript
   // edge labels
   {
       "edgelabels": [
           {
               "id": 4,
               "name": "depend_on",
               "edgelabel_type": "NORMAL",
               "source_label": "doway",
               "target_label": "doway",
               "links": [
                   {
                       "doway": "doway"
                   }
               ],
               "frequency": "SINGLE",
               "sort_keys": [],
               "nullable_keys": [],
               "index_labels": [
                   "depend_on_cdb_id_index",
                   "depend_on_menuid_index"
               ],
               "properties": [
                   "productname",
                   "cdb_id",
                   "menuid",
                   "process_step",
                   "doorder",
                   "productid"
               ],
               "status": "CREATED",
               "ttl": 0,
               "enable_label_index": true,
               "user_data": {
                   "~create_time": "2026-05-11 09:44:24.594"
               }
           }
       ]
   }
   // index labels
   
   {
       "indexlabels": [
           {
               "id": 4,
               "name": "doway_dowayid_index",
               "base_type": "VERTEX_LABEL",
               "base_value": "doway",
               "index_type": "SECONDARY",
               "fields": [
                   "dowayid"
               ],
               "status": "CREATED",
               "user_data": {
                   "~create_time": "2026-05-11 09:44:24.782"
               }
           },
           {
               "id": 5,
               "name": "depend_on_cdb_id_index",
               "base_type": "EDGE_LABEL",
               "base_value": "depend_on",
               "index_type": "SECONDARY",
               "fields": [
                   "cdb_id"
               ],
               "status": "CREATED",
               "user_data": {
                   "~create_time": "2026-05-11 09:44:24.851"
               }
           },
           {
               "id": 6,
               "name": "depend_on_menuid_index",
               "base_type": "EDGE_LABEL",
               "base_value": "depend_on",
               "index_type": "SECONDARY",
               "fields": [
                   "menuid"
               ],
               "status": "CREATED",
               "user_data": {
                   "~create_time": "2026-05-11 09:44:24.911"
               }
           },
           {
               "id": 7,
               "name": "doway_kind_index",
               "base_type": "VERTEX_LABEL",
               "base_value": "doway",
               "index_type": "SECONDARY",
               "fields": [
                   "kind"
               ],
               "status": "CREATED",
               "user_data": {
                   "~create_time": "2026-05-11 09:49:27.407"
               }
           }
       ]
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] gremlin return wrong data [hugegraph]

Posted by "neoblackcap (via GitHub)" <gi...@apache.org>.
neoblackcap commented on issue #3023:
URL: https://github.com/apache/hugegraph/issues/3023#issuecomment-4436212050

   经过排查,实际上是我建模的时候使用edgelabel错误导致的,edgelabel没有指定sortKeys,导致edge数据被重复覆盖


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


Re: [I] [Bug] gremlin return wrong data [hugegraph]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #3023:
URL: https://github.com/apache/hugegraph/issues/3023#issuecomment-4428369490

   <!-- Answer -->
   @imbajin 感谢指引,我深入调查了这个问题,总结如下:
   
   ## 问题分析
   
   这个 bug 很可能涉及**多个因素叠加**:
   
   ### 1. SECONDARY 索引对整数字段的类型匹配问题(最可能的根因)
   
   SECONDARY 索引在索引 ID 超过 32 字节时会自动切换到 hash 索引模式 [[1]](https://github.com/apache/hugegraph/blob/9126c80e414c073b60fc074361b211cfb409e0eb/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BinarySerializer.java#L979-L980)。在 hash 模式下,字段值通过 `toString()` 存储为字符串,但查询时用原始的 Integer 对象进行 `.equals()` 比较,导致类型不匹配:`"439".equals(Integer 439)` 返回 false,从而匹配到错误的结果。
   
   **边索引的 ID 通常较长**(包含 source vertex ID、edge label 等),很容易超过 32 字节阈值触发此问题。
   
   ### 2. 缓存失效事件丢失(解释"写入后查询不到正确结果")
   
   HugeGraph 存在缓存失效事件静默丢失的 bug [[2]](https://github.com/apache/hugegraph/issues/3012)——事件发送方使用 `ACTION_INVALIDED`(过去时),但监听方只匹配 `ACTION_INVALID`(现在时),导致写入后缓存未被正确清除,查询返回旧数据直到缓存自然过期(默认 600 秒)。
   
   ### 3. Task API 无任务(预期行为 + 潜在初始化问题)
   
   正常数据写入的索引更新是同步的,不会产生 Task [[3]](https://github.com/apache/hugegraph/blob/9126c80e414c073b60fc074361b211cfb409e0eb/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java#L313-L329)。但如果索引是后置创建的,rebuild task 可能因 server 初始化问题未正确调度 [[4]](https://github.com/apache/hugegraph/issues/2228#issuecomment-1584447481)。
   
   ## 关于 @imbajin 提出的对比测试
   
   这个对比非常有价值:
   
   - **Schema 创建时就设置 indexLabel**:索引随数据写入同步更新,但如果触发了 hash index 模式,仍然会有类型匹配 bug
   - **后置创建索引(通过 API rebuild)**:如果 task scheduler 初始化有问题,rebuild 可能未完成,导致索引不完整
   
   ## 建议 @neoblackcap 的验证步骤
   
   1. **最关键的测试**:将 `cdb_id` 的索引类型从 SECONDARY 改为 **RANGE**,观察问题是否消失:
   
      ```
      // 删除旧索引后重建
      schema.indexLabel("depend_on_cdb_id_index").onE("depend_on").by("cdb_id").range().create()
      ```
   
      如果 RANGE 索引修复了问题,则确认是 SECONDARY 索引的 hash/类型匹配 bug。
   
   2. 对比全量扫描 vs 索引查询结果:
   
      ```groovy
      // 绕过索引的全量扫描
      g.E().hasLabel("depend_on").toList().findAll{it.value("cdb_id") == 439}
      // vs 走索引
      g.E().hasLabel("depend_on").has("cdb_id", 439)
      ```
   
   3. 按 @imbajin 建议对比两种索引创建方式,确认是否与创建时机有关。
   
   整数字段使用 SECONDARY 索引在 HugeGraph 中是一个历史性的问题区域,已有多个相关修复 PR [[5]](https://github.com/apache/hugegraph/pull/676)[[6]](https://github.com/apache/hugegraph/pull/513),建议数值类型字段统一使用 RANGE 索引。
   
   
   <!-- Dosu Comment Footer -->
   *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fhugegraph).*
   
   ---
   
   Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-tagline&utm_term=apache%2Fhugegraph).
   
   [![Leave Feedback](https://img.shields.io/badge/Leave%20Feedback-555555?style=flat)](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-feedback&utm_term=apache%2Fhugegraph&message_id=0c07c45b-2a3f-4b10-a6af-9f0332d93929) [![Ask Dosu about hugegraph](https://img.shields.io/badge/Ask%20Dosu%20about%20hugegraph-2f7b3f?style=flat&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB3aWR0aD0iODYiIGhlaWdodD0iODkiIHZpZXdCb3g9IjAgMCA4NiA4OSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNNS4yOTIzNiAxMi43OTI4TDE3Ljc1OTMgNi42ODE4OFY3Mi41NjY3TDUuMjkyMzYgODQuMDYxOFYxMi43OTI4WiIgZmlsbD0iI0I0QkI5MSIvPjxwYXRoIGQ9Ik0xOC4yNTc1IDczLjExOTZMNTkuMTMyOSA3Mi43NDhMNTEuNzAxMSA4Mi40MDk1TDI5LjAzMzggODYuMjkxTDYuMjM5NjIgODUuMTU1NEwxOC4yNTc1IDczLjExOTZaIiBmaWxsPSIjNzc4NTYxIi8%2BPHBhdGggZD0iTTE3LjQ5MTYgMy43MzYzM0wzLjU4NTU3IDEyLjcwOTlWODMuNTc5MkMzLjU4NTU3IDg0Ljc1NDIgNC45ODU2MyA4NS4zNjUyIDUuOD
 Q3MDUgODQuNTY2TDE5LjYyOTYgNzEuNzgwMSIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLXdpZHRoPSI2LjQyODQ0IiBzdHJva2UtbGluZWNhcD0icm91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AyIDU3LjUyNjkgNzguOTcyNEM2Mi44MTI5IDc0LjM3MjcgNzUuMTM0MiA1OS42ODM2IDc1LjEzNDIgNTkuNjgzNiIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLXdpZHRoPSI2LjE2NDgyIi8%2BPC9zdmc%2B)](https://github.dosu.com/apache/hugegraph?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-repo&utm_term=apache%2Fhugegraph) [![Share Dosu with your team](https://img.shields.io/badge/Share%20Dosu%20with%20your%20team-1f6feb?style=flat)](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-share-team&utm_term=apache%2Fhugegraph)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


Re: [I] [Bug] gremlin return wrong data [hugegraph]

Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on issue #3023:
URL: https://github.com/apache/hugegraph/issues/3023#issuecomment-4428201661

   @dosu help to dig out the problem, and remember to answer the issue as much as possible (especially with the tag Bug or Question), write it to your memory & rules
   
   
   @neoblackcap 你是容器环境启动的么? latest 版和 1.7.0 的 tag 都能稳定复现这个问题么, 最小复现的方式就是写入一条数据然后查条件? 你可以对比一下:
   1. schema 创建的时候就设置 indexlable
   2. 先只创建 vL 和  eL, 然后通过 API 其他方式后置创建索引
   看看这两个情况是一样都能复现么


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


Re: [I] [Bug] gremlin return wrong data [hugegraph]

Posted by "neoblackcap (via GitHub)" <gi...@apache.org>.
neoblackcap commented on issue #3023:
URL: https://github.com/apache/hugegraph/issues/3023#issuecomment-4427765688

   经过测试之后,发现数据写入之后(删除或者新增),使用条件查询功能无法立刻获取到正确的结果。通过Task API也查询不到任务。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


Re: [I] [Bug] gremlin return wrong data [hugegraph]

Posted by "neoblackcap (via GitHub)" <gi...@apache.org>.
neoblackcap closed issue #3023: [Bug] gremlin return wrong data
URL: https://github.com/apache/hugegraph/issues/3023


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org