|
@@ -54,7 +54,8 @@ import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_SET_OWN
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_SET_PERMISSIONS;
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_SET_QUOTA;
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_SET_REPLICATION;
|
|
|
-import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_SET_XATTRS;
|
|
|
+import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_SET_XATTR;
|
|
|
+import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_REMOVE_XATTR;
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_START_LOG_SEGMENT;
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_SYMLINK;
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_TIMES;
|
|
@@ -190,7 +191,8 @@ public abstract class FSEditLogOp {
|
|
|
OP_ROLLING_UPGRADE_START, "start"));
|
|
|
inst.put(OP_ROLLING_UPGRADE_FINALIZE, new RollingUpgradeOp(
|
|
|
OP_ROLLING_UPGRADE_FINALIZE, "finalize"));
|
|
|
- inst.put(OP_SET_XATTRS, new SetXAttrsOp());
|
|
|
+ inst.put(OP_SET_XATTR, new SetXAttrOp());
|
|
|
+ inst.put(OP_REMOVE_XATTR, new RemoveXAttrOp());
|
|
|
}
|
|
|
|
|
|
public FSEditLogOp get(FSEditLogOpCodes opcode) {
|
|
@@ -3496,23 +3498,23 @@ public abstract class FSEditLogOp {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- static class SetXAttrsOp extends FSEditLogOp {
|
|
|
- List<XAttr> xAttrs = Lists.newArrayList();
|
|
|
+ static class RemoveXAttrOp extends FSEditLogOp {
|
|
|
+ XAttr xAttr;
|
|
|
String src;
|
|
|
|
|
|
- private SetXAttrsOp() {
|
|
|
- super(OP_SET_XATTRS);
|
|
|
+ private RemoveXAttrOp() {
|
|
|
+ super(OP_REMOVE_XATTR);
|
|
|
}
|
|
|
|
|
|
- static SetXAttrsOp getInstance() {
|
|
|
- return new SetXAttrsOp();
|
|
|
+ static RemoveXAttrOp getInstance() {
|
|
|
+ return new RemoveXAttrOp();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
void readFields(DataInputStream in, int logVersion) throws IOException {
|
|
|
XAttrEditLogProto p = XAttrEditLogProto.parseDelimitedFrom(in);
|
|
|
src = p.getSrc();
|
|
|
- xAttrs = PBHelper.convertXAttrs(p.getXAttrsList());
|
|
|
+ xAttr = PBHelper.convertXAttr(p.getXAttr());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -3521,23 +3523,62 @@ public abstract class FSEditLogOp {
|
|
|
if (src != null) {
|
|
|
b.setSrc(src);
|
|
|
}
|
|
|
- b.addAllXAttrs(PBHelper.convertXAttrProto(xAttrs));
|
|
|
+ b.setXAttr(PBHelper.convertXAttrProto(xAttr));
|
|
|
b.build().writeDelimitedTo(out);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void toXml(ContentHandler contentHandler) throws SAXException {
|
|
|
XMLUtils.addSaxString(contentHandler, "SRC", src);
|
|
|
- appendXAttrsToXml(contentHandler, xAttrs);
|
|
|
+ appendXAttrToXml(contentHandler, xAttr);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
void fromXml(Stanza st) throws InvalidXmlException {
|
|
|
src = st.getValue("SRC");
|
|
|
- xAttrs = readXAttrsFromXml(st);
|
|
|
- if (xAttrs == null) {
|
|
|
- xAttrs = Lists.newArrayList();
|
|
|
+ xAttr = readXAttrFromXml(st);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static class SetXAttrOp extends FSEditLogOp {
|
|
|
+ XAttr xAttr;
|
|
|
+ String src;
|
|
|
+
|
|
|
+ private SetXAttrOp() {
|
|
|
+ super(OP_SET_XATTR);
|
|
|
+ }
|
|
|
+
|
|
|
+ static SetXAttrOp getInstance() {
|
|
|
+ return new SetXAttrOp();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ void readFields(DataInputStream in, int logVersion) throws IOException {
|
|
|
+ XAttrEditLogProto p = XAttrEditLogProto.parseDelimitedFrom(in);
|
|
|
+ src = p.getSrc();
|
|
|
+ xAttr = PBHelper.convertXAttr(p.getXAttr());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void writeFields(DataOutputStream out) throws IOException {
|
|
|
+ XAttrEditLogProto.Builder b = XAttrEditLogProto.newBuilder();
|
|
|
+ if (src != null) {
|
|
|
+ b.setSrc(src);
|
|
|
}
|
|
|
+ b.setXAttr(PBHelper.convertXAttrProto(xAttr));
|
|
|
+ b.build().writeDelimitedTo(out);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void toXml(ContentHandler contentHandler) throws SAXException {
|
|
|
+ XMLUtils.addSaxString(contentHandler, "SRC", src);
|
|
|
+ appendXAttrToXml(contentHandler, xAttr);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ void fromXml(Stanza st) throws InvalidXmlException {
|
|
|
+ src = st.getValue("SRC");
|
|
|
+ xAttr = readXAttrFromXml(st);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -4157,42 +4198,41 @@ public abstract class FSEditLogOp {
|
|
|
return aclEntries;
|
|
|
}
|
|
|
|
|
|
- private static void appendXAttrsToXml(ContentHandler contentHandler,
|
|
|
- List<XAttr> xAttrs) throws SAXException {
|
|
|
- for (XAttr a : xAttrs) {
|
|
|
- contentHandler.startElement("", "", "XATTR", new AttributesImpl());
|
|
|
- XMLUtils.addSaxString(contentHandler, "NAMESPACE",
|
|
|
- a.getNameSpace().toString());
|
|
|
- XMLUtils.addSaxString(contentHandler, "NAME", a.getName());
|
|
|
+ private static void appendXAttrToXml(ContentHandler contentHandler,
|
|
|
+ XAttr xAttr) throws SAXException {
|
|
|
+ contentHandler.startElement("", "", "XATTR", new AttributesImpl());
|
|
|
+ XMLUtils.addSaxString(contentHandler, "NAMESPACE",
|
|
|
+ xAttr.getNameSpace().toString());
|
|
|
+ XMLUtils.addSaxString(contentHandler, "NAME", xAttr.getName());
|
|
|
+ if (xAttr.getValue() != null) {
|
|
|
try {
|
|
|
XMLUtils.addSaxString(contentHandler, "VALUE",
|
|
|
- XAttrCodec.encodeValue(a.getValue(), XAttrCodec.HEX));
|
|
|
+ XAttrCodec.encodeValue(xAttr.getValue(), XAttrCodec.HEX));
|
|
|
} catch (IOException e) {
|
|
|
throw new SAXException(e);
|
|
|
}
|
|
|
- contentHandler.endElement("", "", "XATTR");
|
|
|
}
|
|
|
+ contentHandler.endElement("", "", "XATTR");
|
|
|
}
|
|
|
|
|
|
- private static List<XAttr> readXAttrsFromXml(Stanza st)
|
|
|
+ private static XAttr readXAttrFromXml(Stanza st)
|
|
|
throws InvalidXmlException {
|
|
|
- List<XAttr> xAttrs = Lists.newArrayList();
|
|
|
if (!st.hasChildren("XATTR")) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- try {
|
|
|
- List<Stanza> stanzas = st.getChildren("XATTR");
|
|
|
- for (Stanza s : stanzas) {
|
|
|
- XAttr a = new XAttr.Builder()
|
|
|
- .setNameSpace(XAttr.NameSpace.valueOf(s.getValue("NAMESPACE")))
|
|
|
- .setName(s.getValue("NAME"))
|
|
|
- .setValue(XAttrCodec.decodeValue(s.getValue("VALUE"))).build();
|
|
|
- xAttrs.add(a);
|
|
|
+ Stanza a = st.getChildren("XATTR").get(0);
|
|
|
+ XAttr.Builder builder = new XAttr.Builder();
|
|
|
+ builder.setNameSpace(XAttr.NameSpace.valueOf(a.getValue("NAMESPACE"))).
|
|
|
+ setName(a.getValue("NAME"));
|
|
|
+ String v = a.getValueOrNull("VALUE");
|
|
|
+ if (v != null) {
|
|
|
+ try {
|
|
|
+ builder.setValue(XAttrCodec.decodeValue(v));
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new InvalidXmlException(e.toString());
|
|
|
}
|
|
|
- return xAttrs;
|
|
|
- } catch (IOException e) {
|
|
|
- throw new InvalidXmlException(e.toString());
|
|
|
}
|
|
|
+ return builder.build();
|
|
|
}
|
|
|
}
|