Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Bug] PD TTL cleanup deletes the marker-shaped name instead of the expired key, so expired values stay in the store until read

未关闭
#3,378 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@bitflicker64 已经在做这个了。

开始于 2026年10月20日。

  • #3382 来自 @bitflicker64 —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
java

调研方向

Read hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/KvService.java, especially clearTTLData and getValue, then inspect core/KvServiceTest. Run the reported KvServiceTest#testTtlCleanupDeletesTheExpiredKey case and review how cleanup interacts with keepAlive and putTTL. Done means expired values and markers are removed safely without deleting a renewed value.

由索引模型根据 Issue 内容生成。

描述

Bug Type (问题类型)

logic (逻辑设计问题)

Before submit
  • I have confirmed and searched that there are no similar problems in the historical issue and documents
Environment (环境信息)
  • Server Version: PD on master at 86c05ef9c (1.8.0-SNAPSHOT); the code below is unchanged since 43cae1d2e (#2478, 2024-04-19)
  • Backend: PD's own RocksDB metadata store (the KV service), checked without raft as the pd-core-test suite runs it
  • OS: macOS, JDK 17.0.20.1
  • Data Size: one key
Expected & Actual behavior (期望与实际表现)

A key written with a TTL (KvService.put(key, value, ttl), the KV putTTL RPC, PD locks, the KV watch registrations, the balance-shard flag) gets a marker K@T@<expireAt>@<key> next to it. TaskScheduleService runs KvService.clearTTLData() every second on the leader, and it should delete the expired key and its marker.

It deletes a different key. clearTTLData takes the key from the marker after key.indexOf(KV_DELIMITER, 2), which is the @ right after T, so it deletes <expireAt>@<key>, a key that never exists, and then removes the marker. hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/KvService.java at 86c05ef9c, lines 300 to 306:

for (KV kv : kvList) {
    String key = new String(kv.getKey());
    int index = key.indexOf(KV_DELIMITER, 2);
    String delKey = key.substring(index + 1);
    delete(delKey);
    meta.remove(kv.getKey());
}

The same expression on a real marker key:

key    = "K@T@1729430000000@ttl-test/a"
index  = 3
delKey = "1729430000000@ttl-test/a"

Measured 2026-10-20 on master 86c05ef9c with JDK 17.0.20.1, by adding this test to hg-pd-test's core/KvServiceTest and running mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-core-test -Dtest='org.apache.hugegraph.pd.core.KvServiceTest#testTtlCleanupDeletesTheExpiredKey':

KvService service = new KvService(getPdConfig());
service.put("ttl-test/a", "old", 1L);
byte[] storeKey = service.getStoreKey("ttl-test/a");
Thread.sleep(20L);
service.clearTTLData();
Assert.assertNull(service.getMeta().getOne(storeKey));   // fails: the value is still stored
java.lang.AssertionError: expected null, but was:<[B@1b18fa79>
	at org.apache.hugegraph.pd.core.KvServiceTest.testTtlCleanupDeletesTheExpiredKey(KvServiceTest.java:75)

What this does and does not break:

  1. Reads are not affected: get and scanWithPrefix go through getValue, which returns nothing for an expired value and removes it then. So a reader never sees an expired value.
  2. An expired value that nobody reads again stays in the store for good, with no marker left that would ever delete it.
  3. keepAlive(key) does not check the expiry, so it revives an expired lease that nobody has read yet, which the cleanup was meant to have deleted within a second.
  4. getValue (line 130) removes the marker under a wrong name too (getTTLStoreKey(new String(keyBytes), ...) passes the store key, K@<key>, where the key is expected), so its marker is left for the cleanup.

The parse fix is small (start the search after K@T@), but the cleanup then deletes keys that writers may be renewing at that moment: a keepAlive or a putTTL of the same key that lands between the cleanup's read and its delete would be deleted. The delete should be conditional at the apply: only while the marker still exists and the key still holds the expired value it read.

Vertex/Edge example (问题点 / 边数据举例)

N/A

Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

N/A

主要语言
Java
星标
3.2k
派生
640
平均合并
1 天 12 小时
30 天内合并 PR
98

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/hugegraph 的其他 Issue

查看 apache/hugegraph 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。