Search in sources :

Example 1 with LogException

use of io.mycat.backend.mysql.xa.recovery.LogException in project Mycat-Server by MyCATApache.

the class LogFileLock method acquireLock.

public void acquireLock() throws LogException {
    try {
        File parent = new File(dir);
        if (!parent.exists()) {
            parent.mkdir();
        }
        lockfileToPreventDoubleStartup_ = new File(dir, fileName + ".lck");
        lockfilestream_ = new FileOutputStream(lockfileToPreventDoubleStartup_);
        lock_ = lockfilestream_.getChannel().tryLock();
        lockfileToPreventDoubleStartup_.deleteOnExit();
    } catch (OverlappingFileLockException failedToGetLock) {
        // happens on windows
        lock_ = null;
    } catch (IOException failedToGetLock) {
        // happens on windows
        lock_ = null;
    }
    if (lock_ == null) {
        logger.error("ERROR: the specified log seems to be in use already: " + fileName + " in " + dir + ". Make sure that no other instance is running, or kill any pending process if needed.");
        throw new LogException("Log already in use? " + fileName + " in " + dir);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) OverlappingFileLockException(java.nio.channels.OverlappingFileLockException) LogException(io.mycat.backend.mysql.xa.recovery.LogException)

Aggregations

LogException (io.mycat.backend.mysql.xa.recovery.LogException)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OverlappingFileLockException (java.nio.channels.OverlappingFileLockException)1