Skip to content

Commit 3c827d6

Browse files
authored
fix: 18795: HDHM repair mechanism can be improved to clean stale buckets (#18796)
Fixes: #18795 Reviewed-by: Anthony Petrov <[email protected]>, Ivan Malygin <[email protected]>, Nikita Lebedev <[email protected]> Signed-off-by: Artem Ananev <[email protected]>
1 parent 013f5d1 commit 3c827d6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

platform-sdk/swirlds-merkledb/src/main/java/com/swirlds/merkledb/files/hashmap/HalfDiskHashMap.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -333,19 +333,26 @@ public void repair(final long firstLeafPath, final long lastLeafPath, final Memo
333333
}
334334
try (final ParsedBucket bucket = new ParsedBucket()) {
335335
bucket.readFrom(bucketData);
336+
if (bucket.getBucketIndex() != bucketId) {
337+
logger.warn(MERKLE_DB.getMarker(), "Delete bucket (stale): {}", bucketId);
338+
bucketIndexToBucketLocation.remove(bucketId);
339+
continue;
340+
}
336341
bucket.forEachEntry(entry -> {
337342
final Bytes keyBytes = entry.getKeyBytes();
338343
final long path = entry.getValue();
339344
try {
340345
boolean removeKey = true;
341346
if ((path < firstLeafPath) || (path > lastLeafPath)) {
342-
logger.warn("Delete key (path range): key={}, path={}", keyBytes, path);
347+
logger.warn(
348+
MERKLE_DB.getMarker(), "Delete key (path range): key={}, path={}", keyBytes, path);
343349
} else {
344350
final BufferedData recordBytes = store.get(path);
345351
assert recordBytes != null;
346352
final VirtualLeafBytes record = VirtualLeafBytes.parseFrom(recordBytes);
347353
if (!record.keyBytes().equals(keyBytes)) {
348354
logger.warn(
355+
MERKLE_DB.getMarker(),
349356
"Delete key (stale): path={}, expected={}, actual={}",
350357
path,
351358
record.keyBytes(),

0 commit comments

Comments
 (0)