Skip to content

Commit 2b9a8c1

Browse files
committed
Revert "Fix potential FSImage corruption. Contributed by Ekanth Sethuramalingam & Arpit Agarwal."
This reverts commit 53c7d82.
1 parent 273aa49 commit 2b9a8c1

File tree

3 files changed

+28
-49
lines changed

3 files changed

+28
-49
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
* [1:3) -- the type of the entry (AclEntryType) <br>
3939
* [3:6) -- the permission of the entry (FsAction) <br>
4040
* [6:7) -- A flag to indicate whether Named entry or not <br>
41-
* [7:8) -- Reserved <br>
42-
* [8:32) -- the name of the entry, which is an ID that points to a <br>
41+
* [7:32) -- the name of the entry, which is an ID that points to a <br>
4342
* string in the StringTableSection. <br>
4443
*/
4544
public enum AclEntryStatusFormat {
@@ -48,8 +47,7 @@ public enum AclEntryStatusFormat {
4847
TYPE(SCOPE.BITS, 2),
4948
PERMISSION(TYPE.BITS, 3),
5049
NAMED_ENTRY_CHECK(PERMISSION.BITS, 1),
51-
RESERVED(NAMED_ENTRY_CHECK.BITS, 1),
52-
NAME(RESERVED.BITS, 24);
50+
NAME(NAMED_ENTRY_CHECK.BITS, 25);
5351

5452
private final LongBitFormat BITS;
5553

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public abstract class INodeWithAdditionalFields extends INode
3535
implements LinkedElement {
3636
enum PermissionStatusFormat {
3737
MODE(null, 16),
38-
GROUP(MODE.BITS, 24),
39-
USER(GROUP.BITS, 24);
38+
GROUP(MODE.BITS, 25),
39+
USER(GROUP.BITS, 23);
4040

4141
final LongBitFormat BITS;
4242

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

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,56 +27,25 @@
2727

2828
import com.google.common.base.Preconditions;
2929
import com.google.common.primitives.Ints;
30-
import org.apache.hadoop.hdfs.util.LongBitFormat;
3130

3231
/**
3332
* Class to pack XAttrs into byte[].<br>
3433
* For each XAttr:<br>
3534
* The first 4 bytes represents XAttr namespace and name<br>
3635
* [0:3) - XAttr namespace<br>
37-
* [3:8) - Reserved<br>
38-
* [8:32) - The name of the entry, which is an ID that points to a
36+
* [3:32) - The name of the entry, which is an ID that points to a
3937
* string in map<br>
4038
* The following two bytes represents the length of XAttr value<br>
4139
* The remaining bytes is the XAttr value<br>
4240
*/
4341
class XAttrFormat {
44-
private enum XAttrStatusFormat {
45-
46-
NAMESPACE(null, 3),
47-
RESERVED(NAMESPACE.BITS, 5),
48-
NAME(RESERVED.BITS, 24);
49-
50-
private final LongBitFormat BITS;
51-
52-
XAttrStatusFormat(LongBitFormat previous, int length) {
53-
BITS = new LongBitFormat(name(), previous, length, 0);
54-
}
55-
56-
static XAttr.NameSpace getNamespace(int xattrStatus) {
57-
int ordinal = (int) NAMESPACE.BITS.retrieve(xattrStatus);
58-
return XAttr.NameSpace.values()[ordinal];
59-
}
60-
61-
static String getName(int xattrStatus) {
62-
int id = (int) NAME.BITS.retrieve(xattrStatus);
63-
return XAttrStorage.getName(id);
64-
}
65-
66-
static int toInt(XAttr.NameSpace namespace, String name) {
67-
long xattrStatusInt = 0;
68-
69-
xattrStatusInt = NAMESPACE.BITS
70-
.combine(namespace.ordinal(), xattrStatusInt);
71-
int nid = XAttrStorage.getNameSerialNumber(name);
72-
xattrStatusInt = NAME.BITS
73-
.combine(nid, xattrStatusInt);
74-
75-
return (int) xattrStatusInt;
76-
}
77-
}
78-
42+
private static final int XATTR_NAMESPACE_MASK = (1 << 3) - 1;
43+
private static final int XATTR_NAMESPACE_OFFSET = 29;
44+
private static final int XATTR_NAME_MASK = (1 << 29) - 1;
45+
private static final int XATTR_NAME_ID_MAX = 1 << 29;
7946
private static final int XATTR_VALUE_LEN_MAX = 1 << 16;
47+
private static final XAttr.NameSpace[] XATTR_NAMESPACE_VALUES =
48+
XAttr.NameSpace.values();
8049

8150
/**
8251
* Unpack byte[] to XAttrs.
@@ -95,8 +64,10 @@ static List<XAttr> toXAttrs(byte[] attrs) {
9564
int v = Ints.fromBytes(attrs[i], attrs[i + 1],
9665
attrs[i + 2], attrs[i + 3]);
9766
i += 4;
98-
builder.setNameSpace(XAttrStatusFormat.getNamespace(v));
99-
builder.setName(XAttrStatusFormat.getName(v));
67+
int ns = (v >> XATTR_NAMESPACE_OFFSET) & XATTR_NAMESPACE_MASK;
68+
int nid = v & XATTR_NAME_MASK;
69+
builder.setNameSpace(XATTR_NAMESPACE_VALUES[ns]);
70+
builder.setName(XAttrStorage.getName(nid));
10071
int vlen = ((0xff & attrs[i]) << 8) | (0xff & attrs[i + 1]);
10172
i += 2;
10273
if (vlen > 0) {
@@ -129,8 +100,10 @@ static XAttr getXAttr(byte[] attrs, String prefixedName) {
129100
int v = Ints.fromBytes(attrs[i], attrs[i + 1],
130101
attrs[i + 2], attrs[i + 3]);
131102
i += 4;
132-
XAttr.NameSpace namespace = XAttrStatusFormat.getNamespace(v);
133-
String name = XAttrStatusFormat.getName(v);
103+
int ns = (v >> XATTR_NAMESPACE_OFFSET) & XATTR_NAMESPACE_MASK;
104+
int nid = v & XATTR_NAME_MASK;
105+
XAttr.NameSpace namespace = XATTR_NAMESPACE_VALUES[ns];
106+
String name = XAttrStorage.getName(nid);
134107
int vlen = ((0xff & attrs[i]) << 8) | (0xff & attrs[i + 1]);
135108
i += 2;
136109
if (xAttr.getNameSpace() == namespace &&
@@ -161,7 +134,15 @@ static byte[] toBytes(List<XAttr> xAttrs) {
161134
ByteArrayOutputStream out = new ByteArrayOutputStream();
162135
try {
163136
for (XAttr a : xAttrs) {
164-
int v = XAttrStatusFormat.toInt(a.getNameSpace(), a.getName());
137+
int nsOrd = a.getNameSpace().ordinal();
138+
Preconditions.checkArgument(nsOrd < 8, "Too many namespaces.");
139+
int nid = XAttrStorage.getNameSerialNumber(a.getName());
140+
Preconditions.checkArgument(nid < XATTR_NAME_ID_MAX,
141+
"Too large serial number of the xattr name");
142+
143+
// big-endian
144+
int v = ((nsOrd & XATTR_NAMESPACE_MASK) << XATTR_NAMESPACE_OFFSET)
145+
| (nid & XATTR_NAME_MASK);
165146
out.write(Ints.toByteArray(v));
166147
int vlen = a.getValue() == null ? 0 : a.getValue().length;
167148
Preconditions.checkArgument(vlen < XATTR_VALUE_LEN_MAX,

0 commit comments

Comments
 (0)