lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dawid Weiss (JIRA)" <>
Subject [jira] [Commented] (LUCENE-4639) Improving _TestUtil.getTempDir
Date Fri, 21 Dec 2012 07:49:25 GMT


Dawid Weiss commented on LUCENE-4639:

I looked at that code in Harmony and I sustain my opinion that this code fragment is irrelevant.
They pick a per-vm seed and then a counter starting from that. If you create enough files
the counter will roll over to next digits anyway so they add the 10000 for aesthetic reasons
more than anything. More: if the seeds for two or more vm's are picked close to each other
they'll soon enter a tight race to allocate new files. This isn't something you want to reproduce,
it's something you want to avoid.

The process of generating temporary file names should avoid conflicts with other processes
and with itself. A congruential random generator with a long cycle should be more than fine
to avoid such conflicts (the probability of picking an identical seed in the master generator
is unavoidable but very tiny), I don't think there is any need to have a "vm-identification"
string as they do in Harmony.

> Improving _TestUtil.getTempDir
> ------------------------------
>                 Key: LUCENE-4639
>                 URL:
>             Project: Lucene - Core
>          Issue Type: Bug
>            Reporter: Shai Erera
>            Assignee: Shai Erera
>            Priority: Minor
>         Attachments: LUCENE-4639.patch, LUCENE-4639.patch, LUCENE-4639.patch, LUCENE-4639.patch
> Spinoff from here:
> _TestUtil.getTempDir uses createTempFile and then deletes the file. While this usually
works, if someone runs tests by multiple JVMs and does not ensure each JVM gets an isolated
temp.dir to work in, that my result in two JVMs sharing the same directory.
> Also, on Windows, if you call getTempDir on an existing directory, you get an "Access
is denied" exception.
> Dawid proposed a simple solution to just call mkdirs() continuously until success. I'd
like to try that.
> Also, I think that genTempFile could use some house cleaning, e.g.:
> * tempFileLocker can be just an Object instance? Why do we need a class?
> * If we initialize counter and counterBase in a static clause, we can avoid checking
if counter==0 as well as passing Random to genTempFile (that will remove any suspicion that
it does anything randomly)
> ** Also, instead of synchronizing on tempFileLocker, can we just use AtomicInteger for
the counter?
> I'll modify getTempDir first. It documents "does not create the directory", I want to
make sure no test fails due that.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message