You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Francesco Bellomi <be...@sci.univr.it> on 2004/04/28 19:06:21 UTC

Re: locking problems with NFS

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 <cu...@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