Uploaded image for project: 'Hadoop HDFS'
  1. Hadoop HDFS
  2. HDFS-566

INode.permissions should be marked as volatile to avoid synchronization problems

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 0.21.0
    • None
    • namenode
    • None

    Description

      Looking at INode, I can see that the long permissions field is updated in the synchronized updatePermissions, read in other non-synchronized contexts

      I believe that to avoid race conditions and other synchronisation problems, the field should be marked volatile

      1. The Java language specification declares that long and double can be written as two 32-bit writes, unless the field is volatile http://java.sun.com/docs/books/jls/second_edition/html/memory.doc.html#28733
      2. The JVM is free to re-order accesses to non-volatile data; reads of the permission may pick up out of date values
      3. Volatile data may be cached/optimised out, changes may not propagate

      I don't think its enough to make the write operation synchronised, as the reads are still unsynchronized, and in other threads can pick up values midway through the update, or cache the value.

      It's a simple fix: declare permissions as volatile.

      private volatile long permissions;
      

      Attachments

        Issue Links

          Activity

            People

              szetszwo Tsz-wo Sze
              stevel@apache.org Steve Loughran
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: