lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Francesco Bellomi" <bell...@sci.univr.it>
Subject Re: locking problems with NFS
Date Wed, 28 Apr 2004 17:06:21 GMT
Hi,

I am trying to develop a NFS-compatible locking for Lucene, using the
approach described in the link below, that combines the default Lucene
dot-locking with fcntl()-locking using NIO,

Doug Cutting <cutting@apache.org> wrote:
> http://www.spinnaker.de/linux/nfs-locking.html

but I couldn't manage to make it work.
I'm using the following implementation of the Lock interface:

-------------------------------

    public final Lock makeLock(String name) {
      final StringBuffer buf = getLockPrefix();
      buf.append("-");
      buf.append(name);

      final File lockFile = new File(directory, name);

        return new Lock() {

          private FileOutputStream os;

          private FileLock lock;

          public boolean obtain() throws IOException {
            if (DISABLE_LOCKS)
              return true;
              final boolean newFile = lockFile.createNewFile();
              if (newFile)
              {
                  try
                  {
                      os = new FileOutputStream(lockFile);
                      lock = os.getChannel().tryLock();
                  }
                  catch (IOException e)
                  {
                      Log.error("locking failed: " + e);
                      if (os != null)
                        os.close();
                      lockFile.delete();
                      return false;
                  }
              }
              return newFile;
          }
          public void release() {
            if (DISABLE_LOCKS)
              return;
              try
              {
                  if (lock != null)
                    lock.release();
                  if (os != null)
                    os.close();
              }
              catch (IOException e)
              {
                  Log.error("lock release failed: " + e);
              }
              lockFile.delete();
          }
          public boolean isLocked() {
            if (DISABLE_LOCKS)
              return false;
            return lock.isValid();
          }

          public String toString() {
            return "Lock@" + lockFile;
          }
        };
    }

-------------------------------

The problem with the above code is that, when running over NFS or Samba, the
call to FileChannel#tryLock() never returns, despite the fact that the
method is supposed to return immediately. The call does not return even if
there's no lock. It works if used on the local filesystem.

Any suggestions?

Thanks in advance,
Francesco

-
Francesco Bellomi
"Use truth to show illusion,
and illusion to show truth."

-
Francesco Bellomi
"Use truth to show illusion,
and illusion to show truth."



---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message