HDFS-16933. A race in SerialNumberMap will cause wrong owner, group and XATTR. (#5430). Contributed by ZanderXu.
Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
This commit is contained in:
parent
c40a6bd46a
commit
7c941e00b4
@ -61,17 +61,22 @@ public int get(T t) {
|
||||
}
|
||||
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");
|
||||
synchronized (this) {
|
||||
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) {
|
||||
current.getAndDecrement();
|
||||
return old;
|
||||
}
|
||||
i2t.put(sn, t);
|
||||
}
|
||||
}
|
||||
Integer old = t2i.putIfAbsent(t, sn);
|
||||
if (old != null) {
|
||||
current.getAndDecrement();
|
||||
return old;
|
||||
}
|
||||
i2t.put(sn, t);
|
||||
}
|
||||
return sn;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user