oracle / opengrok

OpenGrok is a fast and usable source code search and cross reference engine, written in Java
http://oracle.github.io/opengrok/
Other
4.33k stars 746 forks source link

during indexing, timestamp cannot be created sometimes #1128

Closed vladak closed 5 years ago

vladak commented 8 years ago

When indexing some 600+ projects from scratch, this message appeared on the console couple of times:

22:48:44 WARNING: Failed to create file '/var/opengrok/data/timestamp', used for timestamping the index database.

It looks that there is some code calling timestamp.createNewFile() in IndexDatabase.java#update after it was created.

tulinkry commented 8 years ago

For me this looks more like race condition. I'm able to reproduce this even with 2 projects (every project is checked with separate thread).

Code I used to reproduce it is:

private static long thr1ID = -1;
            synchronized (lock) {
                if (thr1ID == -1) {
                    thr1ID = Thread.currentThread().getId();
                }
            }

            if (timestamp.exists()) {
                if (!timestamp.setLastModified(System.currentTimeMillis())) {
                    LOGGER.log(Level.WARNING, "Failed to set last modified time on ''{0}'', {1}",
                        new Object[]{timestamp.getAbsolutePath(), purpose});
                }
            } else {
                if (Thread.currentThread().getId() == thr1ID) {
                    try {
                        Thread.currentThread().sleep(3000);
                    } catch (InterruptedException ex) {
                    }
                }
                if (!timestamp.createNewFile()) {
                    LOGGER.log(Level.WARNING, "Failed to create file ''{0}'', {1}",
                        new Object[]{timestamp.getAbsolutePath(), purpose});
                }
            }

This produces the warning: WARNING: Failed to create file '/var/opengrok/data/timestamp', used for timestamping the index database.

It might be the problem, the creation of the file should be synchronized. However there might be also something different.

tulinkry commented 5 years ago

Is this still relevant?

vladak commented 5 years ago

Just indexed large-ish code base from scratch with 1.1-rc, need to check the logs.

vladak commented 5 years ago

The log does not contain the warning message anymore.

tulinkry commented 5 years ago

A candidate for closing.