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). [](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) [](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) [](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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
