cassandra-pr mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jasobrown <...@git.apache.org>
Subject [GitHub] cassandra pull request #236: 9608 trunk
Date Mon, 23 Jul 2018 11:58:41 GMT
Github user jasobrown commented on a diff in the pull request:

    https://github.com/apache/cassandra/pull/236#discussion_r204369082
  
    --- Diff: src/java/org/apache/cassandra/io/util/FileUtils.java ---
    @@ -106,11 +117,46 @@ public static void createHardLink(File from, File to)
             }
         }
     
    +    private static final File tempDir = new File(System.getProperty("java.io.tmpdir"));
    +    private static final AtomicLong tempFileNum = new AtomicLong();
    +
    +    public static File getTempDir()
    +    {
    +        return tempDir;
    +    }
    +
    +    /**
    +     * Pretty much like {@link File#createTempFile(String, String, File)}, but with
    +     * the guarantee that the "random" part of the generated file name between
    +     * {@code prefix} and {@code suffix} is a positive, increasing {@code long} value.
    +     */
         public static File createTempFile(String prefix, String suffix, File directory)
         {
             try
             {
    -            return File.createTempFile(prefix, suffix, directory);
    +            // Do not use java.io.File.createTempFile(), because some tests rely on the
    +            // behavior that the "random" part in the temp file name is a positive 'long'.
    +            // However, at least since Java 9 the code to generate the "random" part
    +            // uses an _unsigned_ random long generated like this:
    +            // Long.toUnsignedString(new java.util.Random.nextLong())
    +
    +            while (true)
    +            {
    +                // The contract of File.createTempFile() says, that it must not return
    +                // the same file name again. We do that here in a very simple way,
    +                // that probably doesn't cover all edge cases. Just rely on system
    +                // wall clock and return strictly increasing values from that.
    +                long num = tempFileNum.getAndIncrement();
    +
    +                // We have a positive long here, which is safe to use for example
    +                // for CommitLogTest.
    +                String timePart = Long.toString(num);
    --- End diff --
    
    rename this variable, or maybe just move `Long.toString(num)` into the next line.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Mime
View raw message