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


##########
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:
   @jrwest 
   
   It is a little bit more complicated, because `snapshotDir.lastModified()` 
can return 0 or something "implementation specific" when it is not possible to 
resolve it.
   
   I have rewritten it to this
   
   ````
   long currentLastModified = snapshotDir.lastModified();
   if ((currentLastModified < lastModified || lastModified == -1) && 
currentLastModified > 0)
       lastModified = currentLastModified;
   ````
   
   and then at the end:
   
   ````
   // in any case of not being able to resolve it, set it to current time
   if (lastModified < 0)
       createdAt = Instant.ofEpochMilli(Clock.Global.currentTimeMillis());
   else
       createdAt = Instant.ofEpochMilli(lastModified);
   ````



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