apache / apache/rocketmq

[Bug] CheckpointFile cannot persist empty checkpoints

Open Beginner friendly
#10,863 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
22.6k
Forks
12k
Avg merge
3d 1h
Merged PRs (30d)
27

Description

## Runtime platform environment
macOS; reproduced with a temporary checkpoint file in the `common` module.

## RocketMQ version
Branch: `develop`
Git commit: `fd0c95920e0deac96ce2ae27442747cc5e65e930`

## JDK Version
Eclipse Temurin 17.0.19+10

## Describe the Bug
`CheckpointFile.write` returns immediately for an empty entry list, leaving old entries on disk. In addition, `read()` treats a valid empty primary file as a reason to load the backup, so stale backup entries can be restored instead of an intentionally empty state.

## Steps to Reproduce
1. Write a checkpoint containing entries.
2. Write an empty entry list to the same `CheckpointFile`.
3. Read the checkpoint.
4. Observe that old entries remain. A valid empty primary file also causes `read()` to return entries from its older backup.

## What Did You Expect to See?
An empty list should be persisted as a valid zero-entry checkpoint, and reading that valid primary should return an empty list. Backup fallback should only occur when the primary is missing or invalid.

## What Did You See Instead?
Empty writes are ignored, and a valid empty primary can be replaced in memory by stale backup content.

## Additional Context
The existing count and CRC format can represent an empty checkpoint without a format change.

Contributor guide

Open the contributing guide

Research direction

Locate CheckpointFile in the common module and inspect its write and read entry points. Reproduce the sequence of writing entries, writing an empty list, and reading the checkpoint. Done means an empty list is persisted and returned, while backup content is used only when the primary file is missing or invalid.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.