Skip to content

Conversation

@ChenSammi
Copy link
Contributor

What changes were proposed in this pull request?

delay the deletion of old replica

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-13602

How was this patch tested?

new unit test

@ChenSammi ChenSammi requested a review from szetszwo August 23, 2025 03:55
@github-actions
Copy link

This PR has been marked as stale due to 21 days of inactivity. Please comment or remove the stale label to keep it open. Otherwise, it will be automatically closed in 7 days.

@github-actions github-actions bot added the stale label Nov 11, 2025
@ivandika3
Copy link
Contributor

ivandika3 commented Nov 13, 2025

@szetszwo @Gargi-jais11 Please kindly take a look.

@ChenSammi Could you help resolve the conflicts?

@ChenSammi
Copy link
Contributor Author

@ivandika3 , thanks for the checking. I will close this one since agreement of the idea is not reached.

@ChenSammi ChenSammi closed this Nov 13, 2025
@ivandika3
Copy link
Contributor

@ChenSammi Thanks for the info.

Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChenSammi , on a second thought, delaying deletion is a good workaround for the race condition. Let's reopen this?

Please see also the comments inlined.

Comment on lines 654 to 630
private void cleanupPendingDeletionContainers() {
// delete all pending deletion containers before stop the service
// we still need to honor the expiry time of deletion
Iterator<Map.Entry<Long, Container>> iterator = pendingDeletionContainers.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Long, Container> entry = iterator.next();
if (entry.getKey() <= System.currentTimeMillis()) {
iterator.remove();
deleteContainer(entry.getValue());
} else {
// Since the map is sorted by key (timestamp), we can break early.
break;
}
}
}
Copy link
Contributor

@szetszwo szetszwo Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may use headMap.

Actually, let's make tryCleanupOnePendingDeletionContainer return boolean and then reuse it here.

  private void cleanupPendingDeletionContainers() {
    for (; tryCleanupOnePendingDeletionContainer(); ) ;
  }

  private boolean tryCleanupOnePendingDeletionContainer() {
    final Map.Entry<Long, Container> entry = pendingDeletionContainers.pollFirstEntry();
    if (entry != null) {
      if (entry.getKey() <= System.currentTimeMillis()) {
        // entry container is expired
        deleteContainer(entry.getValue());
        return true;
      }
      // put back the container
      pendingDeletionContainers.put(entry.getKey(), entry.getValue());
    }
    return false;
  }

Comment on lines 671 to 673
if (!pendingDeletionContainers.isEmpty()) {
Map.Entry<Long, Container> entry = pendingDeletionContainers.pollFirstEntry();
if (entry != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking isEmpty() is not needed since pollFirstEntry() returns null if the map is empty.

@ChenSammi ChenSammi reopened this Nov 27, 2025
@ChenSammi ChenSammi force-pushed the HDDS-13602-lazy-delete branch 2 times, most recently from e2cf33d to d755a41 Compare November 27, 2025 10:48
@github-actions github-actions bot removed the stale label Nov 28, 2025
…re due to read thread holds the old containerData
@ChenSammi ChenSammi force-pushed the HDDS-13602-lazy-delete branch from d755a41 to 831eaee Compare December 1, 2025 01:56
@ChenSammi
Copy link
Contributor Author

@szetszwo thanks for the review. Could you like to take another look?
Current enforced checkstyle doesn't allow no loop and empty loop, so cleanupPendingDeletionContainers() is changed to use do while format.

Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 the change looks good.

@ChenSammi ChenSammi merged commit 6ab8774 into apache:HDDS-5713 Dec 2, 2025
43 checks passed
@ChenSammi
Copy link
Contributor Author

Thanks @szetszwo for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants