From 40d04aa56f4542ca59232978b7de546f4224ae9c Mon Sep 17 00:00:00 2001 From: Lucas Weitzendorf Date: Tue, 10 Dec 2024 10:16:52 +0100 Subject: [PATCH] OAK-11299: Missing Segments With Oak Run Segment Copy --- .../jackrabbit/oak/segment/azure/tool/SegmentCopy.java | 2 +- .../oak/segment/azure/tool/SegmentStoreMigrator.java | 10 +++++++--- .../jackrabbit/oak/segment/file/tar/TarReader.java | 8 ++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentCopy.java b/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentCopy.java index d14d95084b5..fb7f40e35fc 100644 --- a/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentCopy.java +++ b/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentCopy.java @@ -393,7 +393,7 @@ public int run() { } catch (Exception e) { watch.stop(); - printMessage(errWriter, "A problem occured while copying archives from {0} to {1} ", source, + printMessage(errWriter, "A problem occurred while copying archives from {0} to {1} ", source, destination); e.printStackTrace(errWriter); return 1; diff --git a/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentStoreMigrator.java b/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentStoreMigrator.java index 43677b62efb..9588c03e2f0 100644 --- a/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentStoreMigrator.java +++ b/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentStoreMigrator.java @@ -165,9 +165,13 @@ private void migrateArchives() throws IOException, ExecutionException, Interrupt List targetArchives = targetManager.listArchives(); if (appendMode && !targetArchives.isEmpty()) { - //last archive can be updated since last copy and needs to be recopied - String lastArchive = targetArchives.get(targetArchives.size() - 1); - targetArchives.remove(lastArchive); + // last archive could have been updated since last copy and needs to be recopied + try { + targetArchives.sort(String::compareTo); + targetArchives.remove(targetArchives.size() - 1); + } catch (UnsupportedOperationException e) { + targetArchives = targetArchives.subList(0, targetArchives.size() - 1); + } } for (String archiveName : sourceManager.listArchives()) { diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java index c1cd30e4cd4..9d9d2277955 100644 --- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java +++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java @@ -351,8 +351,11 @@ SegmentArchiveEntry[] getEntries() { */ @NotNull private static List getReferences(UUID id, Map> graph) { - List references = graph.get(id); + if (graph == null) { + return Collections.emptyList(); + } + List references = graph.get(id); if (references == null) { return Collections.emptyList(); } @@ -550,8 +553,9 @@ TarReader sweep(@NotNull Set reclaim, @NotNull Set reclaimed) throws // Reconstruct the graph index for non-cleaned segments. Map> graph = getGraph(); + Set>> entrySet = (graph == null) ? Collections.emptySet() : graph.entrySet(); - for (Entry> e : graph.entrySet()) { + for (Entry> e : entrySet) { if (cleaned.contains(e.getKey())) { continue; }