nfsantos commented on code in PR #2574:
URL: https://github.com/apache/jackrabbit-oak/pull/2574#discussion_r2428004625
##########
oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureArchiveManager.java:
##########
@@ -91,16 +94,21 @@ public List<String> listArchives() throws IOException {
.filter(blobName -> blobName.endsWith(".tar"))
.collect(Collectors.toList());
- Iterator<String> it = archiveNames.iterator();
- while (it.hasNext()) {
- String archiveName = it.next();
- if (deleteInProgress(archiveName)) {
- if (writeAccessController.isWritingAllowed()) {
- delete(archiveName);
- }
- it.remove();
- }
- }
+ Set<String> archivesToDelete = ForkJoinUtils.invokeInCustomPool(
+ "AzureArchiveManager-deleted-archive-handler",
+ Math.min(64, Math.max(1, archiveNames.size())),
+ () -> archiveNames.stream()
+ .parallel()
+ .filter(this::deleteInProgress)
+ .peek(archiveName -> {
+ if (writeAccessController.isWritingAllowed()) {
+ delete(archiveName);
+ }
+ })
+ .collect(Collectors.toUnmodifiableSet()));
+
+ archiveNames.removeAll(archivesToDelete);
Review Comment:
What about this? It avoid calling peek, which I feel is not intended for
this type of situations. And it also checks only once if writing is allowed.
The code is likely not syntactically valid, I did not check it on a IDE.
```suggestion
() -> archiveNames.stream()
.parallel() // Maybe not needed if
deleteInProgress is fast?
.filter(this::deleteInProgress)
.collect(Collectors.toUnmodifiableSet()));
if (writeAccessController.isWritingAllowed()) {
archiveNames.stream().parallel().forEach(archiveName ->
delete(archiveName));
}
archiveNames.removeAll(archivesToDelete);
```
##########
oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureArchiveManager.java:
##########
@@ -91,16 +94,21 @@ public List<String> listArchives() throws IOException {
.filter(blobName -> blobName.endsWith(".tar"))
.collect(Collectors.toList());
- Iterator<String> it = archiveNames.iterator();
- while (it.hasNext()) {
- String archiveName = it.next();
- if (deleteInProgress(archiveName)) {
- if (writeAccessController.isWritingAllowed()) {
- delete(archiveName);
- }
- it.remove();
- }
- }
+ Set<String> archivesToDelete = ForkJoinUtils.invokeInCustomPool(
+ "AzureArchiveManager-deleted-archive-handler",
+ Math.min(64, Math.max(1, archiveNames.size())),
+ () -> archiveNames.stream()
+ .parallel()
+ .filter(this::deleteInProgress)
+ .peek(archiveName -> {
+ if (writeAccessController.isWritingAllowed()) {
+ delete(archiveName);
+ }
+ })
+ .collect(Collectors.toUnmodifiableSet()));
+
+ archiveNames.removeAll(archivesToDelete);
Review Comment:
What about this? It avoids calling peek, which I feel is not intended for
this type of situations. And it also checks only once if writing is allowed.
The code is likely not syntactically valid, I did not check it on a IDE.
```suggestion
() -> archiveNames.stream()
.parallel() // Maybe not needed if
deleteInProgress is fast?
.filter(this::deleteInProgress)
.collect(Collectors.toUnmodifiableSet()));
if (writeAccessController.isWritingAllowed()) {
archiveNames.stream().parallel().forEach(archiveName ->
delete(archiveName));
}
archiveNames.removeAll(archivesToDelete);
```
--
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]