[Bug] PD TTL cleanup deletes the marker-shaped name instead of the expired key, so expired values stay in the store until read
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Java
- Stelle
- 3.2k
- Fork
- 640
- Merge medio
- 1g 12h
- PR unite (30g)
- 98
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/hugegraph
-
[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 answerForse già presa @pallavithegod l’ha presa 6 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
apache/hugegraph#3231 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
[Task] Establish systematic performance baselines and optimization trackingForse già presa @contrueCT l’ha presa 6 giorni fa. Apertahelp wanted improvement rust
Difficoltà 5/5 Più di una settimana Idoneità per principianti 12/100
apache/hugegraph#3346 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] CI accepts obsolete PR targets after retargeting or force-pushForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di apache/hugegraph
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
checkstyle/checkstyle#22145 ·
I maintainer di solito rispondono entro 1 giorno
-
rset command throws NPE in ResultsFormat.guessSyntaxForse già presa @Ostrzyciel l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
objectionary/eo#9593 ·
I maintainer di solito rispondono entro 1 giorno
-
release bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
OpenLiberty/open-liberty#36124 ·
I maintainer di solito rispondono entro 1 giorno