[Bug] PD TTL cleanup deletes the marker-shaped name instead of the expired key, so expired values stay in the store until read
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
調査の方向性
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
masterat86c05ef9c(1.8.0-SNAPSHOT); the code below is unchanged since43cae1d2e(#2478, 2024-04-19) - Backend: PD's own RocksDB metadata store (the KV service), checked without raft as the
pd-core-testsuite 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:
- Reads are not affected:
getandscanWithPrefixgo throughgetValue, which returns nothing for an expired value and removes it then. So a reader never sees an expired value. - An expired value that nobody reads again stays in the store for good, with no marker left that would ever delete it.
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.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時間
- マージ済み PR(30日)
- 98
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/hugegraph のほかの issue
-
[Bug] PD task REST: balanceLeaders throws a bare HTTP 500 during the balance-shard window, and task responses cannot be told apart from a no-op or a follower answer対応中かも @pallavithegod が 6 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
apache/hugegraph#3231 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
[Task] Establish systematic performance baselines and optimization tracking対応中かも @contrueCT が 6 日前に担当しました。 オープンhelp wanted improvement rust
難易度 5/5 1週間以上 初心者へのやさしさ 12/100
apache/hugegraph#3346 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] CI accepts obsolete PR targets after retargeting or force-push再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
メンテナーはふだん 1 日以内に返信
apache/hugegraph の issue をすべて見る
似ている issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 61/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ReChronoRain/HyperCeiler#1743 ·
メンテナーはふだん 6 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ControlSystemStudio/phoebus#3979 ·
メンテナーはふだん 2 日以内に返信
-
Cannot find symbol CTypedef対応中かも @pellico が今日担当しました。 オープンbug
難易度 1/5 1時間未満 初心者へのやさしさ 82/100