[ 
https://issues.apache.org/jira/browse/HDFS-16798?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

ZanderXu updated HDFS-16798:
----------------------------
    Description: 
During looking into some code related XATTR, I found there is a bug in 
SerialNumberMap, as bellow:
{code:java}
public int get(T t) {
  if (t == null) {
    return 0;
  }
  Integer sn = t2i.get(t);
  if (sn == null) {
    sn = current.getAndIncrement();
    if (sn > max) {
      current.getAndDecrement();
      throw new IllegalStateException(name + ": serial number map is full");
    }
    Integer old = t2i.putIfAbsent(t, sn);
    if (old != null) {
      // here: if the old is not null, we should decrease the current value.
      return old;
    }
    i2t.put(sn, t);
  }
  return sn;
} {code}
This bug will only cause that the capacity of serialNumberMap is less than 
expected, no other impact.

  was:
During looking into some code related XATTR, I found there is a bug in 
SerialNumberMap, as bellow:
{code:java}
public int get(T t) {
  if (t == null) {
    return 0;
  }
  Integer sn = t2i.get(t);
  if (sn == null) {
    sn = current.getAndIncrement();
    if (sn > max) {
      current.getAndDecrement();
      throw new IllegalStateException(name + ": serial number map is full");
    }
    Integer old = t2i.putIfAbsent(t, sn);
    if (old != null) {
      // here: if the old is not null, we should decrease the current value.
      return old;
    }
    i2t.put(sn, t);
  }
  return sn;
} {code}


> SerialNumberMap should decrease the current if the old already exist
> --------------------------------------------------------------------
>
>                 Key: HDFS-16798
>                 URL: https://issues.apache.org/jira/browse/HDFS-16798
>             Project: Hadoop HDFS
>          Issue Type: Bug
>            Reporter: ZanderXu
>            Assignee: ZanderXu
>            Priority: Major
>              Labels: pull-request-available
>
> During looking into some code related XATTR, I found there is a bug in 
> SerialNumberMap, as bellow:
> {code:java}
> public int get(T t) {
>   if (t == null) {
>     return 0;
>   }
>   Integer sn = t2i.get(t);
>   if (sn == null) {
>     sn = current.getAndIncrement();
>     if (sn > max) {
>       current.getAndDecrement();
>       throw new IllegalStateException(name + ": serial number map is full");
>     }
>     Integer old = t2i.putIfAbsent(t, sn);
>     if (old != null) {
>       // here: if the old is not null, we should decrease the current value.
>       return old;
>     }
>     i2t.put(sn, t);
>   }
>   return sn;
> } {code}
> This bug will only cause that the capacity of serialNumberMap is less than 
> expected, no other impact.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to