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:
ZanderXu 2023-09-06 10:27:52 +08:00 committed by GitHub
parent c40a6bd46a
commit 7c941e00b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}