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


##########
src/java/org/apache/cassandra/service/snapshot/TableSnapshot.java:
##########
@@ -138,11 +152,21 @@ public boolean isExpiring()
 
     public long computeSizeOnDiskBytes()
     {
-        return snapshotDirs.stream().mapToLong(FileUtils::folderSize).sum();
+        long sum = sizeOnDisk;
+        if (sum == 0)
+        {
+            for (File snapshotDir : snapshotDirs)
+                sizeOnDisk = sum += FileUtils.folderSize(snapshotDir);
+        }

Review Comment:
   BTW we hit this recently in HintsDescriptor too. That variable is volatile 
but there we do not have any loop so the fact that two threads compute it twice 
does not matter ... The probability is also super low when it is just 
effectively "cached".
   
   This makes the most sense to me, when we make `SizeOnDisk` to be `volatile`.
   
       public long computeSizeOnDiskBytes()
       {
           long sum = sizeOnDisk;
           if (sum == 0)
           {
               for (File snapshotDir : snapshotDirs)
                   sum += FileUtils.folderSize(snapshotDir);
   
               sizeOnDisk = sum;
           }
   
           return sum;
       }
   
   (1) 
https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/hints/HintsDescriptor.java#L233-L239



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