quantranhong1999 commented on code in PR #2902:
URL: https://github.com/apache/james-project/pull/2902#discussion_r2680866834
##########
mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreDeletedMessageVault.java:
##########
@@ -235,4 +240,30 @@ private Mono<Void> deleteBucketData(BucketName bucketName)
{
return Mono.from(blobStore.deleteBucket(bucketName))
.then(Mono.from(messageMetadataVault.removeMetadataRelatedToBucket(bucketName)));
}
+
+ Mono<Void> deleteUserExpiredMessages(ZonedDateTime
beginningOfRetentionPeriod) {
Review Comment:
Maybe a better name? It is not easy to understand that this is to clean the
v2 single bucket IMO.
##########
mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreDeletedMessageVault.java:
##########
@@ -235,4 +240,30 @@ private Mono<Void> deleteBucketData(BucketName bucketName)
{
return Mono.from(blobStore.deleteBucket(bucketName))
.then(Mono.from(messageMetadataVault.removeMetadataRelatedToBucket(bucketName)));
}
+
+ Mono<Void> deleteUserExpiredMessages(ZonedDateTime
beginningOfRetentionPeriod) {
+ BucketName bucketName =
BucketName.of(vaultConfiguration.getSingleBucketName());
+
+ return Flux.from(metricFactory.decoratePublisherWithTimerMetric(
+ DELETE_EXPIRED_MESSAGES_METRIC_NAME,
+ Flux.from(usersRepository.listReactive())
+ .flatMap(username ->
Flux.from(messageMetadataVault.listMessages(bucketName, username))
+ .filter(deletedMessage ->
isMessageFullyExpired(beginningOfRetentionPeriod, deletedMessage))
+ .flatMap(deletedMessage ->
messageMetadataVault.remove(bucketName, username,
deletedMessage.getDeletedMessage().getMessageId())))))
+ .then();
+ }
+
+
+
+ private boolean isMessageFullyExpired(ZonedDateTime
beginningOfRetentionPeriod, DeletedMessageWithStorageInformation
deletedMessage) {
+ BlobId blobId = deletedMessage.getStorageInformation().getBlobId();
+ Optional<ZonedDateTime> maybeEndDate =
blobIdTimeGenerator.blobIdEndTime(blobId);
+
+ if (maybeEndDate.isEmpty()) {
+ LOGGER.error("Pattern used for blobId used in deletedMessageVault
is invalid and end date cannot be parsed {}", blobId);
Review Comment:
Q: we still log error if the BlobId is the old ones (resulting empty
maybeEndDate)?
##########
mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/blob/BlobStoreDeletedMessageVaultTest.java:
##########
@@ -185,7 +185,7 @@ void
deleteExpiredMessagesTaskShouldPublishRetentionTimerMetrics() throws Except
getVault().deleteExpiredMessagesTask().run();
assertThat(metricFactory.executionTimesFor(DELETE_EXPIRED_MESSAGES_METRIC_NAME))
- .hasSize(1);
+ .hasSize(2);
Review Comment:
Maybe we should find a way to merge them into the same metric? Because the
deletion metric should reflect the old one + the new one IMO.
##########
mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreDeletedMessageVault.java:
##########
@@ -235,4 +240,30 @@ private Mono<Void> deleteBucketData(BucketName bucketName)
{
return Mono.from(blobStore.deleteBucket(bucketName))
.then(Mono.from(messageMetadataVault.removeMetadataRelatedToBucket(bucketName)));
}
+
+ Mono<Void> deleteUserExpiredMessages(ZonedDateTime
beginningOfRetentionPeriod) {
+ BucketName bucketName =
BucketName.of(vaultConfiguration.getSingleBucketName());
+
+ return Flux.from(metricFactory.decoratePublisherWithTimerMetric(
+ DELETE_EXPIRED_MESSAGES_METRIC_NAME,
+ Flux.from(usersRepository.listReactive())
+ .flatMap(username ->
Flux.from(messageMetadataVault.listMessages(bucketName, username))
+ .filter(deletedMessage ->
isMessageFullyExpired(beginningOfRetentionPeriod, deletedMessage))
+ .flatMap(deletedMessage ->
messageMetadataVault.remove(bucketName, username,
deletedMessage.getDeletedMessage().getMessageId())))))
+ .then();
+ }
+
+
Review Comment:
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]