Skip to content

Commit c81af4c

Browse files
committed
HDFS-16933. A race in SerialNumberMap will cause wrong owner, group and XATTR
1 parent 4067fac commit c81af4c

File tree

1 file changed

+15
-10
lines changed
  • hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode

1 file changed

+15
-10
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SerialNumberMap.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,22 @@ public int get(T t) {
6161
}
6262
Integer sn = t2i.get(t);
6363
if (sn == null) {
64-
sn = current.getAndIncrement();
65-
if (sn > max) {
66-
current.getAndDecrement();
67-
throw new IllegalStateException(name + ": serial number map is full");
64+
synchronized (this) {
65+
sn = t2i.get(t);
66+
if (sn == null) {
67+
sn = current.getAndIncrement();
68+
if (sn > max) {
69+
current.getAndDecrement();
70+
throw new IllegalStateException(name + ": serial number map is full");
71+
}
72+
Integer old = t2i.putIfAbsent(t, sn);
73+
if (old != null) {
74+
current.getAndDecrement();
75+
return old;
76+
}
77+
i2t.put(sn, t);
78+
}
6879
}
69-
Integer old = t2i.putIfAbsent(t, sn);
70-
if (old != null) {
71-
current.getAndDecrement();
72-
return old;
73-
}
74-
i2t.put(sn, t);
7580
}
7681
return sn;
7782
}

0 commit comments

Comments
 (0)