jrwest commented on code in PR #3751:
URL: https://github.com/apache/cassandra/pull/3751#discussion_r1915345357


##########
src/java/org/apache/cassandra/service/snapshot/TableSnapshot.java:
##########
@@ -490,8 +496,110 @@ private void loadMetadataFromManifest(File manifestFile)
 
         TableSnapshot build()
         {
+            maybeCreateOrEnrichManifest();
             return new TableSnapshot(keyspaceName, tableName, tableId, tag, 
createdAt, expiresAt, snapshotDirs, ephemeral);
         }
+
+        private void maybeCreateOrEnrichManifest()
+        {
+            boolean oldManifestExists = false;
+
+            if 
(!CassandraRelevantProperties.SNAPSHOT_MANIFEST_ENRICH_OR_CREATE_ENABLED.getBoolean())
+                return;
+
+            // this is caused by not reading any manifest or that snapshot had 
a basic manifest just with sstables
+            // enumerated (pre CASSANDRA-16789), so we just go ahead and 
enrich it in each snapshot dir
+
+            if (createdAt != null)
+                return;
+
+            for (File snapshotDir : snapshotDirs)
+            {
+                File maybeManifest = new 
File(snapshotDir.toPath().resolve("manifest.json"));
+                if (maybeManifest.exists())
+                {
+                    oldManifestExists = true;
+                    break;
+                }
+            }
+
+            if (oldManifestExists)
+                logger.debug("Manifest in the old format for snapshot {} was 
detected, going to enrich it.", this);
+            else
+                logger.debug("There is no manifest for {}, going to create 
it.", this);
+
+            long lastModified = -1;
+
+            List<String> allDataFiles = new ArrayList<>();
+            for (File snapshotDir : snapshotDirs)
+            {
+                // we will consider time of the creation the oldest last 
modified
+                // timestamp on any snapshot directory
+                long currentLastModified = snapshotDir.lastModified();
+                if (currentLastModified < lastModified || lastModified == -1)

Review Comment:
   small nit: this could just be a call to `Math.min` which imo would make it 
more clear



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

Reply via email to