smiroslav commented on code in PR #3301:
URL: https://github.com/apache/jackrabbit-oak/pull/3301#discussion_r4599887688


##########
oak-segment-aws/src/main/java/org/apache/jackrabbit/oak/segment/aws/tool/AwsSegmentStoreMigrator.java:
##########
@@ -198,18 +209,42 @@
             }, 16, 5)));
         }
 
+        Map<UUID, ByteBuffer> segments = new LinkedHashMap<>();
         for (Future<Segment> future : futures) {
             Segment segment = future.get();
             segment.write(writer);
+            segments.put(segment.id(), segment.data);
         }
+        return segments;
     }
 
-    private void migrateBinaryRef(SegmentArchiveReader reader, 
SegmentArchiveWriter writer) throws IOException {
+    private void migrateBinaryRef(String archiveName, Map<UUID, ByteBuffer> 
segments, SegmentArchiveReader reader,
+                                  SegmentArchiveWriter writer) throws 
IOException {
         ByteBuffer binaryReferences = reader.getBinaryReferences();
+        byte[] array;
         if (binaryReferences != null) {
-            byte[] array = fetchByteArray(binaryReferences);
-            writer.writeBinaryReferences(array);
+            array = fetchByteArray(binaryReferences);
+        } else {
+            log.warn("{}/{} has no binary references, recovering them from its 
segments", sourceName, archiveName);
+            array = sourceStore().recoverBinaryReferences(segments);
         }
+        writer.writeBinaryReferences(array);
+    }
+
+    /**
+     * Opened only when an archive without binary references is migrated. It 
must be read-only:
+     * a writable store would recover the source archives and modify the 
source.
+     */
+    private ReadOnlyFileStore sourceStore() throws IOException {
+        if (sourceStore == null) {
+            sourceStoreDirectory = 
Files.createTempDirectory("segment-store-migrator").toFile();

Review Comment:
   False positive: the directory is only required by `FileStoreBuilder`, which 
checks that it exists. The read-only store uses the custom (Azure/AWS) 
persistence, so nothing is read from or written to the directory, and it's 
deleted in `close()`. Same pattern as `AzureCompact`, `AzureCheck` and 
`AwsCompact`.
   



##########
oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentStoreMigrator.java:
##########
@@ -205,19 +216,43 @@
             })));
         }
 
+        Map<UUID, ByteBuffer> segments = new LinkedHashMap<>();
         for (Future<Segment> future : futures) {
             Segment segment = future.get();
             RETRIER.execute(() -> segment.write(writer));
+            segments.put(segment.id(), segment.data);
         }
+        return segments;
     }
 
-    private void migrateBinaryRef(SegmentArchiveReader reader, 
SegmentArchiveWriter writer) throws IOException, ExecutionException, 
InterruptedException {
+    private void migrateBinaryRef(String archiveName, Map<UUID, ByteBuffer> 
segments, SegmentArchiveReader reader,
+                                  SegmentArchiveWriter writer) throws 
IOException, ExecutionException, InterruptedException {
         Future<ByteBuffer> future = executor.submit(() -> 
RETRIER.execute(reader::getBinaryReferences));
         ByteBuffer binaryReferences = future.get();
+        byte[] array;
         if (binaryReferences != null) {
-            byte[] array = fetchByteArray(binaryReferences);
-            RETRIER.execute(() -> writer.writeBinaryReferences(array));
+            array = fetchByteArray(binaryReferences);
+        } else {
+            log.warn("{}/{} has no binary references, recovering them from its 
segments", sourceName, archiveName);
+            array = sourceStore().recoverBinaryReferences(segments);
         }
+        RETRIER.execute(() -> writer.writeBinaryReferences(array));
+    }
+
+    /**
+     * Opened only when an archive without binary references is migrated. It 
must be read-only:
+     * a writable store would recover the source archives and modify the 
source.
+     */
+    private ReadOnlyFileStore sourceStore() throws IOException {
+        if (sourceStore == null) {
+            sourceStoreDirectory = 
Files.createTempDirectory("segment-store-migrator").toFile();

Review Comment:
   False positive: the directory is only required by `FileStoreBuilder`, which 
checks that it exists. The read-only store uses the custom (Azure/AWS) 
persistence, so nothing is read from or written to the directory, and it's 
deleted in `close()`. Same pattern as `AzureCompact`, `AzureCheck` and 
`AwsCompact`.
   



-- 
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]

Reply via email to