HDFS-9951. Use string constants for XML tags in OfflineImageReconstructor (Lin Yiqun via cmccabe)

(cherry picked from commit 680716f31e)

Conflicts:
	hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java
	hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageXmlWriter.java

(cherry picked from commit 2ce24bf218)
This commit is contained in:
Colin Patrick Mccabe 2016-03-21 11:40:37 -07:00
parent ea44650a64
commit 29872506bc
2 changed files with 493 additions and 282 deletions

View File

@ -22,6 +22,7 @@ import static org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode.XATTR_
import static org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode.XATTR_NAMESPACE_OFFSET; import static org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode.XATTR_NAMESPACE_OFFSET;
import static org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode.XATTR_NAMESPACE_EXT_OFFSET; import static org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode.XATTR_NAMESPACE_EXT_OFFSET;
import static org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode.XATTR_NAMESPACE_EXT_MASK; import static org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode.XATTR_NAMESPACE_EXT_MASK;
import static org.apache.hadoop.hdfs.tools.offlineImageViewer.PBImageXmlWriter.*;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
@ -434,36 +435,38 @@ class OfflineImageReconstructor {
Node node = new Node(); Node node = new Node();
loadNodeChildren(node, "NameSection fields"); loadNodeChildren(node, "NameSection fields");
NameSystemSection.Builder b = NameSystemSection.newBuilder(); NameSystemSection.Builder b = NameSystemSection.newBuilder();
Integer namespaceId = node.removeChildInt("namespaceId"); Integer namespaceId = node.removeChildInt(NAME_SECTION_NAMESPACE_ID);
if (namespaceId == null) { if (namespaceId == null) {
throw new IOException("<NameSection> is missing <namespaceId>"); throw new IOException("<NameSection> is missing <namespaceId>");
} }
b.setNamespaceId(namespaceId); b.setNamespaceId(namespaceId);
Long lval = node.removeChildLong("genstampV1"); Long lval = node.removeChildLong(NAME_SECTION_GENSTAMPV1);
if (lval != null) { if (lval != null) {
b.setGenstampV1(lval); b.setGenstampV1(lval);
} }
lval = node.removeChildLong("genstampV2"); lval = node.removeChildLong(NAME_SECTION_GENSTAMPV2);
if (lval != null) { if (lval != null) {
b.setGenstampV2(lval); b.setGenstampV2(lval);
} }
lval = node.removeChildLong("genstampV1Limit"); lval = node.removeChildLong(NAME_SECTION_GENSTAMPV1_LIMIT);
if (lval != null) { if (lval != null) {
b.setGenstampV1Limit(lval); b.setGenstampV1Limit(lval);
} }
lval = node.removeChildLong("lastAllocatedBlockId"); lval = node.removeChildLong(NAME_SECTION_LAST_ALLOCATED_BLOCK_ID);
if (lval != null) { if (lval != null) {
b.setLastAllocatedBlockId(lval); b.setLastAllocatedBlockId(lval);
} }
lval = node.removeChildLong("txid"); lval = node.removeChildLong(NAME_SECTION_TXID);
if (lval != null) { if (lval != null) {
b.setTransactionId(lval); b.setTransactionId(lval);
} }
lval = node.removeChildLong("rollingUpgradeStartTime"); lval = node.removeChildLong(
NAME_SECTION_ROLLING_UPGRADE_START_TIME);
if (lval != null) { if (lval != null) {
b.setRollingUpgradeStartTime(lval); b.setRollingUpgradeStartTime(lval);
} }
lval = node.removeChildLong("lastAllocatedStripedBlockId"); lval = node.removeChildLong(
NAME_SECTION_LAST_ALLOCATED_STRIPED_BLOCK_ID);
if (lval != null) { if (lval != null) {
throw new IOException("can't handle lastAllocatedStripedBlockId " + throw new IOException("can't handle lastAllocatedStripedBlockId " +
"in NameSection; XML file is too new.\n"); "in NameSection; XML file is too new.\n");
@ -487,11 +490,12 @@ class OfflineImageReconstructor {
Node headerNode = new Node(); Node headerNode = new Node();
loadNodeChildren(headerNode, "INodeSection fields", "inode"); loadNodeChildren(headerNode, "INodeSection fields", "inode");
INodeSection.Builder b = INodeSection.newBuilder(); INodeSection.Builder b = INodeSection.newBuilder();
Long lval = headerNode.removeChildLong("lastInodeId"); Long lval = headerNode.removeChildLong(INODE_SECTION_LAST_INODE_ID);
if (lval != null) { if (lval != null) {
b.setLastInodeId(lval); b.setLastInodeId(lval);
} }
Integer expectedNumINodes = headerNode.removeChildInt("numInodes"); Integer expectedNumINodes =
headerNode.removeChildInt(INODE_SECTION_NUM_INODES);
if (expectedNumINodes == null) { if (expectedNumINodes == null) {
throw new IOException("Failed to find <numInodes> in INodeSection."); throw new IOException("Failed to find <numInodes> in INodeSection.");
} }
@ -502,7 +506,7 @@ class OfflineImageReconstructor {
int actualNumINodes = 0; int actualNumINodes = 0;
while (actualNumINodes < expectedNumINodes) { while (actualNumINodes < expectedNumINodes) {
try { try {
expectTag("inode", false); expectTag(INODE_SECTION_INODE, false);
} catch (IOException e) { } catch (IOException e) {
throw new IOException("Only found " + actualNumINodes + throw new IOException("Only found " + actualNumINodes +
" <inode> entries out of " + expectedNumINodes, e); " <inode> entries out of " + expectedNumINodes, e);
@ -513,24 +517,24 @@ class OfflineImageReconstructor {
INodeSection.INode.Builder inodeBld = processINodeXml(inode); INodeSection.INode.Builder inodeBld = processINodeXml(inode);
inodeBld.build().writeDelimitedTo(out); inodeBld.build().writeDelimitedTo(out);
} }
expectTagEnd("INodeSection"); expectTagEnd(INODE_SECTION_NAME);
recordSectionLength(SectionName.INODE.name()); recordSectionLength(SectionName.INODE.name());
} }
} }
private INodeSection.INode.Builder processINodeXml(Node node) private INodeSection.INode.Builder processINodeXml(Node node)
throws IOException { throws IOException {
String type = node.removeChildStr("type"); String type = node.removeChildStr(INODE_SECTION_TYPE);
if (type == null) { if (type == null) {
throw new IOException("INode XML found with no <type> tag."); throw new IOException("INode XML found with no <type> tag.");
} }
INodeSection.INode.Builder inodeBld = INodeSection.INode.newBuilder(); INodeSection.INode.Builder inodeBld = INodeSection.INode.newBuilder();
Long id = node.removeChildLong("id"); Long id = node.removeChildLong(SECTION_ID);
if (id == null) { if (id == null) {
throw new IOException("<inode> found without <id>"); throw new IOException("<inode> found without <id>");
} }
inodeBld.setId(id); inodeBld.setId(id);
String name = node.removeChildStr("name"); String name = node.removeChildStr(SECTION_NAME);
if (name != null) { if (name != null) {
inodeBld.setName(ByteString.copyFrom(name, "UTF8")); inodeBld.setName(ByteString.copyFrom(name, "UTF8"));
} }
@ -556,46 +560,46 @@ class OfflineImageReconstructor {
throws IOException { throws IOException {
inodeBld.setType(INodeSection.INode.Type.FILE); inodeBld.setType(INodeSection.INode.Type.FILE);
INodeSection.INodeFile.Builder bld = INodeSection.INodeFile.newBuilder(); INodeSection.INodeFile.Builder bld = INodeSection.INodeFile.newBuilder();
Integer ival = node.removeChildInt("replication"); Integer ival = node.removeChildInt(SECTION_REPLICATION);
if (ival != null) { if (ival != null) {
bld.setReplication(ival); bld.setReplication(ival);
} }
Long lval = node.removeChildLong("mtime"); Long lval = node.removeChildLong(INODE_SECTION_MTIME);
if (lval != null) { if (lval != null) {
bld.setModificationTime(lval); bld.setModificationTime(lval);
} }
lval = node.removeChildLong("atime"); lval = node.removeChildLong(INODE_SECTION_ATIME);
if (lval != null) { if (lval != null) {
bld.setAccessTime(lval); bld.setAccessTime(lval);
} }
lval = node.removeChildLong("preferredBlockSize"); lval = node.removeChildLong(INODE_SECTION_PREFERRED_BLOCK_SIZE);
if (lval != null) { if (lval != null) {
bld.setPreferredBlockSize(lval); bld.setPreferredBlockSize(lval);
} }
String perm = node.removeChildStr("permission"); String perm = node.removeChildStr(INODE_SECTION_PERMISSION);
if (perm != null) { if (perm != null) {
bld.setPermission(permissionXmlToU64(perm)); bld.setPermission(permissionXmlToU64(perm));
} }
Node blocks = node.removeChild("blocks"); Node blocks = node.removeChild(INODE_SECTION_BLOCKS);
if (blocks != null) { if (blocks != null) {
while (true) { while (true) {
Node block = blocks.removeChild("block"); Node block = blocks.removeChild(INODE_SECTION_BLOCK);
if (block == null) { if (block == null) {
break; break;
} }
HdfsProtos.BlockProto.Builder blockBld = HdfsProtos.BlockProto.Builder blockBld =
HdfsProtos.BlockProto.newBuilder(); HdfsProtos.BlockProto.newBuilder();
Long id = block.removeChildLong("id"); Long id = block.removeChildLong(SECTION_ID);
if (id == null) { if (id == null) {
throw new IOException("<block> found without <id>"); throw new IOException("<block> found without <id>");
} }
blockBld.setBlockId(id); blockBld.setBlockId(id);
Long genstamp = block.removeChildLong("genstamp"); Long genstamp = block.removeChildLong(INODE_SECTION_GEMSTAMP);
if (genstamp == null) { if (genstamp == null) {
throw new IOException("<block> found without <genstamp>"); throw new IOException("<block> found without <genstamp>");
} }
blockBld.setGenStamp(genstamp); blockBld.setGenStamp(genstamp);
Long numBytes = block.removeChildLong("numBytes"); Long numBytes = block.removeChildLong(INODE_SECTION_NUM_BYTES);
if (numBytes == null) { if (numBytes == null) {
throw new IOException("<block> found without <numBytes>"); throw new IOException("<block> found without <numBytes>");
} }
@ -603,19 +607,21 @@ class OfflineImageReconstructor {
bld.addBlocks(blockBld); bld.addBlocks(blockBld);
} }
} }
Node fileUnderConstruction = node.removeChild("file-under-construction"); Node fileUnderConstruction =
node.removeChild(INODE_SECTION_FILE_UNDER_CONSTRUCTION);
if (fileUnderConstruction != null) { if (fileUnderConstruction != null) {
INodeSection.FileUnderConstructionFeature.Builder fb = INodeSection.FileUnderConstructionFeature.Builder fb =
INodeSection.FileUnderConstructionFeature.newBuilder(); INodeSection.FileUnderConstructionFeature.newBuilder();
String clientName = String clientName =
fileUnderConstruction.removeChildStr("clientName"); fileUnderConstruction.removeChildStr(INODE_SECTION_CLIENT_NAME);
if (clientName == null) { if (clientName == null) {
throw new IOException("<file-under-construction> found without " + throw new IOException("<file-under-construction> found without " +
"<clientName>"); "<clientName>");
} }
fb.setClientName(clientName); fb.setClientName(clientName);
String clientMachine = String clientMachine =
fileUnderConstruction.removeChildStr("clientMachine"); fileUnderConstruction
.removeChildStr(INODE_SECTION_CLIENT_MACHINE);
if (clientMachine == null) { if (clientMachine == null) {
throw new IOException("<file-under-construction> found without " + throw new IOException("<file-under-construction> found without " +
"<clientMachine>"); "<clientMachine>");
@ -623,23 +629,18 @@ class OfflineImageReconstructor {
fb.setClientMachine(clientMachine); fb.setClientMachine(clientMachine);
bld.setFileUC(fb); bld.setFileUC(fb);
} }
Node acls = node.removeChild("acls"); Node acls = node.removeChild(INODE_SECTION_ACLS);
if (acls != null) { if (acls != null) {
bld.setAcl(aclXmlToProto(acls)); bld.setAcl(aclXmlToProto(acls));
} }
Node xattrs = node.removeChild("xattrs"); Node xattrs = node.removeChild(INODE_SECTION_XATTRS);
if (xattrs != null) { if (xattrs != null) {
bld.setXAttrs(xattrsXmlToProto(xattrs)); bld.setXAttrs(xattrsXmlToProto(xattrs));
} }
ival = node.removeChildInt("storagePolicyId"); ival = node.removeChildInt(INODE_SECTION_STORAGE_POLICY_ID);
if (ival != null) { if (ival != null) {
bld.setStoragePolicyID(ival); bld.setStoragePolicyID(ival);
} }
Boolean bval = node.removeChildBool("isStriped");
if (bval) {
throw new IOException("Can't handle <isStriped/> in file XML; " +
"XML file is too new.");
}
inodeBld.setFile(bld); inodeBld.setFile(bld);
// Will check remaining keys and serialize in processINodeXml // Will check remaining keys and serialize in processINodeXml
} }
@ -649,40 +650,40 @@ class OfflineImageReconstructor {
inodeBld.setType(INodeSection.INode.Type.DIRECTORY); inodeBld.setType(INodeSection.INode.Type.DIRECTORY);
INodeSection.INodeDirectory.Builder bld = INodeSection.INodeDirectory.Builder bld =
INodeSection.INodeDirectory.newBuilder(); INodeSection.INodeDirectory.newBuilder();
Long lval = node.removeChildLong("mtime"); Long lval = node.removeChildLong(INODE_SECTION_MTIME);
if (lval != null) { if (lval != null) {
bld.setModificationTime(lval); bld.setModificationTime(lval);
} }
lval = node.removeChildLong("nsquota"); lval = node.removeChildLong(INODE_SECTION_NS_QUOTA);
if (lval != null) { if (lval != null) {
bld.setNsQuota(lval); bld.setNsQuota(lval);
} }
lval = node.removeChildLong("dsquota"); lval = node.removeChildLong(INODE_SECTION_DS_QUOTA);
if (lval != null) { if (lval != null) {
bld.setDsQuota(lval); bld.setDsQuota(lval);
} }
String perm = node.removeChildStr("permission"); String perm = node.removeChildStr(INODE_SECTION_PERMISSION);
if (perm != null) { if (perm != null) {
bld.setPermission(permissionXmlToU64(perm)); bld.setPermission(permissionXmlToU64(perm));
} }
Node acls = node.removeChild("acls"); Node acls = node.removeChild(INODE_SECTION_ACLS);
if (acls != null) { if (acls != null) {
bld.setAcl(aclXmlToProto(acls)); bld.setAcl(aclXmlToProto(acls));
} }
Node xattrs = node.removeChild("xattrs"); Node xattrs = node.removeChild(INODE_SECTION_XATTRS);
if (xattrs != null) { if (xattrs != null) {
bld.setXAttrs(xattrsXmlToProto(xattrs)); bld.setXAttrs(xattrsXmlToProto(xattrs));
} }
INodeSection.QuotaByStorageTypeFeatureProto.Builder qf = INodeSection.QuotaByStorageTypeFeatureProto.Builder qf =
INodeSection.QuotaByStorageTypeFeatureProto.newBuilder(); INodeSection.QuotaByStorageTypeFeatureProto.newBuilder();
while (true) { while (true) {
Node typeQuota = node.removeChild("typeQuota"); Node typeQuota = node.removeChild(INODE_SECTION_TYPE_QUOTA);
if (typeQuota == null) { if (typeQuota == null) {
break; break;
} }
INodeSection.QuotaByStorageTypeEntryProto.Builder qbld = INodeSection.QuotaByStorageTypeEntryProto.Builder qbld =
INodeSection.QuotaByStorageTypeEntryProto.newBuilder(); INodeSection.QuotaByStorageTypeEntryProto.newBuilder();
String type = typeQuota.removeChildStr("type"); String type = typeQuota.removeChildStr(INODE_SECTION_TYPE);
if (type == null) { if (type == null) {
throw new IOException("<typeQuota> was missing <type>"); throw new IOException("<typeQuota> was missing <type>");
} }
@ -692,7 +693,7 @@ class OfflineImageReconstructor {
throw new IOException("<typeQuota> had unknown <type> " + type); throw new IOException("<typeQuota> had unknown <type> " + type);
} }
qbld.setStorageType(storageType); qbld.setStorageType(storageType);
Long quota = typeQuota.removeChildLong("quota"); Long quota = typeQuota.removeChildLong(INODE_SECTION_QUOTA);
if (quota == null) { if (quota == null) {
throw new IOException("<typeQuota> was missing <quota>"); throw new IOException("<typeQuota> was missing <quota>");
} }
@ -709,19 +710,19 @@ class OfflineImageReconstructor {
inodeBld.setType(INodeSection.INode.Type.SYMLINK); inodeBld.setType(INodeSection.INode.Type.SYMLINK);
INodeSection.INodeSymlink.Builder bld = INodeSection.INodeSymlink.Builder bld =
INodeSection.INodeSymlink.newBuilder(); INodeSection.INodeSymlink.newBuilder();
String perm = node.removeChildStr("permission"); String perm = node.removeChildStr(INODE_SECTION_PERMISSION);
if (perm != null) { if (perm != null) {
bld.setPermission(permissionXmlToU64(perm)); bld.setPermission(permissionXmlToU64(perm));
} }
String target = node.removeChildStr("target"); String target = node.removeChildStr(INODE_SECTION_TARGET);
if (target != null) { if (target != null) {
bld.setTarget(ByteString.copyFrom(target, "UTF8")); bld.setTarget(ByteString.copyFrom(target, "UTF8"));
} }
Long lval = node.removeChildLong("mtime"); Long lval = node.removeChildLong(INODE_SECTION_MTIME);
if (lval != null) { if (lval != null) {
bld.setModificationTime(lval); bld.setModificationTime(lval);
} }
lval = node.removeChildLong("atime"); lval = node.removeChildLong(INODE_SECTION_ATIME);
if (lval != null) { if (lval != null) {
bld.setAccessTime(lval); bld.setAccessTime(lval);
} }
@ -740,23 +741,23 @@ class OfflineImageReconstructor {
INodeSection.XAttrFeatureProto.Builder bld = INodeSection.XAttrFeatureProto.Builder bld =
INodeSection.XAttrFeatureProto.newBuilder(); INodeSection.XAttrFeatureProto.newBuilder();
while (true) { while (true) {
Node xattr = xattrs.removeChild("xattr"); Node xattr = xattrs.removeChild(INODE_SECTION_XATTR);
if (xattr == null) { if (xattr == null) {
break; break;
} }
INodeSection.XAttrCompactProto.Builder b = INodeSection.XAttrCompactProto.Builder b =
INodeSection.XAttrCompactProto.newBuilder(); INodeSection.XAttrCompactProto.newBuilder();
String ns = xattr.removeChildStr("ns"); String ns = xattr.removeChildStr(INODE_SECTION_NS);
if (ns == null) { if (ns == null) {
throw new IOException("<xattr> had no <ns> entry."); throw new IOException("<xattr> had no <ns> entry.");
} }
int nsIdx = XAttrProtos.XAttrProto. int nsIdx = XAttrProtos.XAttrProto.
XAttrNamespaceProto.valueOf(ns).ordinal(); XAttrNamespaceProto.valueOf(ns).ordinal();
String name = xattr.removeChildStr("name"); String name = xattr.removeChildStr(SECTION_NAME);
String valStr = xattr.removeChildStr("val"); String valStr = xattr.removeChildStr(INODE_SECTION_VAL);
byte[] val = null; byte[] val = null;
if (valStr == null) { if (valStr == null) {
String valHex = xattr.removeChildStr("valHex"); String valHex = xattr.removeChildStr(INODE_SECTION_VAL_HEX);
if (valHex == null) { if (valHex == null) {
throw new IOException("<xattr> had no <val> or <valHex> entry."); throw new IOException("<xattr> had no <val> or <valHex> entry.");
} }
@ -791,24 +792,28 @@ class OfflineImageReconstructor {
loadNodeChildren(secretHeader, "SecretManager fields", loadNodeChildren(secretHeader, "SecretManager fields",
"delegationKey", "token"); "delegationKey", "token");
SecretManagerSection.Builder b = SecretManagerSection.newBuilder(); SecretManagerSection.Builder b = SecretManagerSection.newBuilder();
Integer currentId = secretHeader.removeChildInt("currentId"); Integer currentId =
secretHeader.removeChildInt(SECRET_MANAGER_SECTION_CURRENT_ID);
if (currentId == null) { if (currentId == null) {
throw new IOException("SecretManager section had no <currentId>"); throw new IOException("SecretManager section had no <currentId>");
} }
b.setCurrentId(currentId); b.setCurrentId(currentId);
Integer tokenSequenceNumber = secretHeader.removeChildInt("tokenSequenceNumber"); Integer tokenSequenceNumber = secretHeader.removeChildInt(
SECRET_MANAGER_SECTION_TOKEN_SEQUENCE_NUMBER);
if (tokenSequenceNumber == null) { if (tokenSequenceNumber == null) {
throw new IOException("SecretManager section had no " + throw new IOException("SecretManager section had no " +
"<tokenSequenceNumber>"); "<tokenSequenceNumber>");
} }
b.setTokenSequenceNumber(tokenSequenceNumber); b.setTokenSequenceNumber(tokenSequenceNumber);
Integer expectedNumKeys = secretHeader.removeChildInt("numDelegationKeys"); Integer expectedNumKeys = secretHeader.removeChildInt(
SECRET_MANAGER_SECTION_NUM_DELEGATION_KEYS);
if (expectedNumKeys == null) { if (expectedNumKeys == null) {
throw new IOException("SecretManager section had no " + throw new IOException("SecretManager section had no " +
"<numDelegationKeys>"); "<numDelegationKeys>");
} }
b.setNumKeys(expectedNumKeys); b.setNumKeys(expectedNumKeys);
Integer expectedNumTokens = secretHeader.removeChildInt("numTokens"); Integer expectedNumTokens =
secretHeader.removeChildInt(SECRET_MANAGER_SECTION_NUM_TOKENS);
if (expectedNumTokens == null) { if (expectedNumTokens == null) {
throw new IOException("SecretManager section had no " + throw new IOException("SecretManager section had no " +
"<numTokens>"); "<numTokens>");
@ -819,7 +824,7 @@ class OfflineImageReconstructor {
for (int actualNumKeys = 0; actualNumKeys < expectedNumKeys; for (int actualNumKeys = 0; actualNumKeys < expectedNumKeys;
actualNumKeys++) { actualNumKeys++) {
try { try {
expectTag("delegationKey", false); expectTag(SECRET_MANAGER_SECTION_DELEGATION_KEY, false);
} catch (IOException e) { } catch (IOException e) {
throw new IOException("Only read " + actualNumKeys + throw new IOException("Only read " + actualNumKeys +
" delegation keys out of " + expectedNumKeys, e); " delegation keys out of " + expectedNumKeys, e);
@ -828,32 +833,32 @@ class OfflineImageReconstructor {
SecretManagerSection.DelegationKey.newBuilder(); SecretManagerSection.DelegationKey.newBuilder();
Node dkey = new Node(); Node dkey = new Node();
loadNodeChildren(dkey, "Delegation key fields"); loadNodeChildren(dkey, "Delegation key fields");
Integer id = dkey.removeChildInt("id"); Integer id = dkey.removeChildInt(SECTION_ID);
if (id == null) { if (id == null) {
throw new IOException("Delegation key stanza <delegationKey> " + throw new IOException("Delegation key stanza <delegationKey> " +
"lacked an <id> field."); "lacked an <id> field.");
} }
dbld.setId(id); dbld.setId(id);
String expiry = dkey.removeChildStr("expiry"); String expiry = dkey.removeChildStr(SECRET_MANAGER_SECTION_EXPIRY);
if (expiry == null) { if (expiry == null) {
throw new IOException("Delegation key stanza <delegationKey> " + throw new IOException("Delegation key stanza <delegationKey> " +
"lacked an <expiry> field."); "lacked an <expiry> field.");
} }
dbld.setExpiryDate(dateStrToLong(expiry)); dbld.setExpiryDate(dateStrToLong(expiry));
String keyHex = dkey.removeChildStr("key"); String keyHex = dkey.removeChildStr(SECRET_MANAGER_SECTION_KEY);
if (keyHex == null) { if (keyHex == null) {
throw new IOException("Delegation key stanza <delegationKey> " + throw new IOException("Delegation key stanza <delegationKey> " +
"lacked a <key> field."); "lacked a <key> field.");
} }
byte[] key = new HexBinaryAdapter().unmarshal(keyHex); byte[] key = new HexBinaryAdapter().unmarshal(keyHex);
dkey.verifyNoRemainingKeys("delegationKey"); dkey.verifyNoRemainingKeys(SECRET_MANAGER_SECTION_DELEGATION_KEY);
dbld.setKey(ByteString.copyFrom(key)); dbld.setKey(ByteString.copyFrom(key));
dbld.build().writeDelimitedTo(out); dbld.build().writeDelimitedTo(out);
} }
for (int actualNumTokens = 0; actualNumTokens < expectedNumTokens; for (int actualNumTokens = 0; actualNumTokens < expectedNumTokens;
actualNumTokens++) { actualNumTokens++) {
try { try {
expectTag("token", false); expectTag(SECRET_MANAGER_SECTION_TOKEN, false);
} catch (IOException e) { } catch (IOException e) {
throw new IOException("Only read " + actualNumTokens + throw new IOException("Only read " + actualNumTokens +
" tokens out of " + expectedNumTokens, e); " tokens out of " + expectedNumTokens, e);
@ -862,46 +867,54 @@ class OfflineImageReconstructor {
SecretManagerSection.PersistToken.newBuilder(); SecretManagerSection.PersistToken.newBuilder();
Node token = new Node(); Node token = new Node();
loadNodeChildren(token, "PersistToken key fields"); loadNodeChildren(token, "PersistToken key fields");
Integer version = token.removeChildInt("version"); Integer version =
token.removeChildInt(SECRET_MANAGER_SECTION_VERSION);
if (version != null) { if (version != null) {
tbld.setVersion(version); tbld.setVersion(version);
} }
String owner = token.removeChildStr("owner"); String owner = token.removeChildStr(SECRET_MANAGER_SECTION_OWNER);
if (owner != null) { if (owner != null) {
tbld.setOwner(owner); tbld.setOwner(owner);
} }
String renewer = token.removeChildStr("renewer"); String renewer =
token.removeChildStr(SECRET_MANAGER_SECTION_RENEWER);
if (renewer != null) { if (renewer != null) {
tbld.setRenewer(renewer); tbld.setRenewer(renewer);
} }
String realUser = token.removeChildStr("realUser"); String realUser =
token.removeChildStr(SECRET_MANAGER_SECTION_REAL_USER);
if (realUser != null) { if (realUser != null) {
tbld.setRealUser(realUser); tbld.setRealUser(realUser);
} }
String issueDateStr = token.removeChildStr("issueDate"); String issueDateStr =
token.removeChildStr(SECRET_MANAGER_SECTION_ISSUE_DATE);
if (issueDateStr != null) { if (issueDateStr != null) {
tbld.setIssueDate(dateStrToLong(issueDateStr)); tbld.setIssueDate(dateStrToLong(issueDateStr));
} }
String maxDateStr = token.removeChildStr("maxDate"); String maxDateStr =
token.removeChildStr(SECRET_MANAGER_SECTION_MAX_DATE);
if (maxDateStr != null) { if (maxDateStr != null) {
tbld.setMaxDate(dateStrToLong(maxDateStr)); tbld.setMaxDate(dateStrToLong(maxDateStr));
} }
Integer seqNo = token.removeChildInt("sequenceNumber"); Integer seqNo =
token.removeChildInt(SECRET_MANAGER_SECTION_SEQUENCE_NUMBER);
if (seqNo != null) { if (seqNo != null) {
tbld.setSequenceNumber(seqNo); tbld.setSequenceNumber(seqNo);
} }
Integer masterKeyId = token.removeChildInt("masterKeyId"); Integer masterKeyId =
token.removeChildInt(SECRET_MANAGER_SECTION_MASTER_KEY_ID);
if (masterKeyId != null) { if (masterKeyId != null) {
tbld.setMasterKeyId(masterKeyId); tbld.setMasterKeyId(masterKeyId);
} }
String expiryDateStr = token.removeChildStr("expiryDate"); String expiryDateStr =
token.removeChildStr(SECRET_MANAGER_SECTION_EXPIRY_DATE);
if (expiryDateStr != null) { if (expiryDateStr != null) {
tbld.setExpiryDate(dateStrToLong(expiryDateStr)); tbld.setExpiryDate(dateStrToLong(expiryDateStr));
} }
token.verifyNoRemainingKeys("token"); token.verifyNoRemainingKeys("token");
tbld.build().writeDelimitedTo(out); tbld.build().writeDelimitedTo(out);
} }
expectTagEnd("SecretManagerSection"); expectTagEnd(SECRET_MANAGER_SECTION_NAME);
recordSectionLength(SectionName.SECRET_MANAGER.name()); recordSectionLength(SectionName.SECRET_MANAGER.name());
} }
@ -923,17 +936,20 @@ class OfflineImageReconstructor {
Node node = new Node(); Node node = new Node();
loadNodeChildren(node, "CacheManager fields", "pool", "directive"); loadNodeChildren(node, "CacheManager fields", "pool", "directive");
CacheManagerSection.Builder b = CacheManagerSection.newBuilder(); CacheManagerSection.Builder b = CacheManagerSection.newBuilder();
Long nextDirectiveId = node.removeChildLong("nextDirectiveId"); Long nextDirectiveId =
node.removeChildLong(CACHE_MANAGER_SECTION_NEXT_DIRECTIVE_ID);
if (nextDirectiveId == null) { if (nextDirectiveId == null) {
throw new IOException("CacheManager section had no <nextDirectiveId>"); throw new IOException("CacheManager section had no <nextDirectiveId>");
} }
b.setNextDirectiveId(nextDirectiveId); b.setNextDirectiveId(nextDirectiveId);
Integer expectedNumPools = node.removeChildInt("numPools"); Integer expectedNumPools =
node.removeChildInt(CACHE_MANAGER_SECTION_NUM_POOLS);
if (expectedNumPools == null) { if (expectedNumPools == null) {
throw new IOException("CacheManager section had no <numPools>"); throw new IOException("CacheManager section had no <numPools>");
} }
b.setNumPools(expectedNumPools); b.setNumPools(expectedNumPools);
Integer expectedNumDirectives = node.removeChildInt("numDirectives"); Integer expectedNumDirectives =
node.removeChildInt(CACHE_MANAGER_SECTION_NUM_DIRECTIVES);
if (expectedNumDirectives == null) { if (expectedNumDirectives == null) {
throw new IOException("CacheManager section had no <numDirectives>"); throw new IOException("CacheManager section had no <numDirectives>");
} }
@ -942,7 +958,7 @@ class OfflineImageReconstructor {
long actualNumPools = 0; long actualNumPools = 0;
while (actualNumPools < expectedNumPools) { while (actualNumPools < expectedNumPools) {
try { try {
expectTag("pool", false); expectTag(CACHE_MANAGER_SECTION_POOL, false);
} catch (IOException e) { } catch (IOException e) {
throw new IOException("Only read " + actualNumPools + throw new IOException("Only read " + actualNumPools +
" cache pools out of " + expectedNumPools, e); " cache pools out of " + expectedNumPools, e);
@ -955,7 +971,7 @@ class OfflineImageReconstructor {
long actualNumDirectives = 0; long actualNumDirectives = 0;
while (actualNumDirectives < expectedNumDirectives) { while (actualNumDirectives < expectedNumDirectives) {
try { try {
expectTag("directive", false); expectTag(CACHE_MANAGER_SECTION_DIRECTIVE, false);
} catch (IOException e) { } catch (IOException e) {
throw new IOException("Only read " + actualNumDirectives + throw new IOException("Only read " + actualNumDirectives +
" cache pools out of " + expectedNumDirectives, e); " cache pools out of " + expectedNumDirectives, e);
@ -965,38 +981,42 @@ class OfflineImageReconstructor {
loadNodeChildren(pool, "directive fields", ""); loadNodeChildren(pool, "directive fields", "");
processDirectiveXml(node); processDirectiveXml(node);
} }
expectTagEnd("CacheManagerSection"); expectTagEnd(CACHE_MANAGER_SECTION_NAME);
recordSectionLength(SectionName.CACHE_MANAGER.name()); recordSectionLength(SectionName.CACHE_MANAGER.name());
} }
private void processPoolXml(Node pool) throws IOException { private void processPoolXml(Node pool) throws IOException {
CachePoolInfoProto.Builder bld = CachePoolInfoProto.newBuilder(); CachePoolInfoProto.Builder bld = CachePoolInfoProto.newBuilder();
String poolName = pool.removeChildStr("poolName"); String poolName =
pool.removeChildStr(CACHE_MANAGER_SECTION_POOL_NAME);
if (poolName == null) { if (poolName == null) {
throw new IOException("<pool> found without <poolName>"); throw new IOException("<pool> found without <poolName>");
} }
bld.setPoolName(poolName); bld.setPoolName(poolName);
String ownerName = pool.removeChildStr("ownerName"); String ownerName =
pool.removeChildStr(CACHE_MANAGER_SECTION_OWNER_NAME);
if (ownerName == null) { if (ownerName == null) {
throw new IOException("<pool> found without <ownerName>"); throw new IOException("<pool> found without <ownerName>");
} }
bld.setOwnerName(ownerName); bld.setOwnerName(ownerName);
String groupName = pool.removeChildStr("groupName"); String groupName =
pool.removeChildStr(CACHE_MANAGER_SECTION_GROUP_NAME);
if (groupName == null) { if (groupName == null) {
throw new IOException("<pool> found without <groupName>"); throw new IOException("<pool> found without <groupName>");
} }
bld.setGroupName(groupName); bld.setGroupName(groupName);
Integer mode = pool.removeChildInt("mode"); Integer mode = pool.removeChildInt(CACHE_MANAGER_SECTION_MODE);
if (mode == null) { if (mode == null) {
throw new IOException("<pool> found without <mode>"); throw new IOException("<pool> found without <mode>");
} }
bld.setMode(mode); bld.setMode(mode);
Long limit = pool.removeChildLong("limit"); Long limit = pool.removeChildLong(CACHE_MANAGER_SECTION_LIMIT);
if (limit == null) { if (limit == null) {
throw new IOException("<pool> found without <limit>"); throw new IOException("<pool> found without <limit>");
} }
bld.setLimit(limit); bld.setLimit(limit);
Long maxRelativeExpiry = pool.removeChildLong("maxRelativeExpiry"); Long maxRelativeExpiry =
pool.removeChildLong(CACHE_MANAGER_SECTION_MAX_RELATIVE_EXPIRY);
if (maxRelativeExpiry == null) { if (maxRelativeExpiry == null) {
throw new IOException("<pool> found without <maxRelativeExpiry>"); throw new IOException("<pool> found without <maxRelativeExpiry>");
} }
@ -1008,37 +1028,39 @@ class OfflineImageReconstructor {
private void processDirectiveXml(Node directive) throws IOException { private void processDirectiveXml(Node directive) throws IOException {
CacheDirectiveInfoProto.Builder bld = CacheDirectiveInfoProto.Builder bld =
CacheDirectiveInfoProto.newBuilder(); CacheDirectiveInfoProto.newBuilder();
Long id = directive.removeChildLong("id"); Long id = directive.removeChildLong(SECTION_ID);
if (id == null) { if (id == null) {
throw new IOException("<directive> found without <id>"); throw new IOException("<directive> found without <id>");
} }
bld.setId(id); bld.setId(id);
String path = directive.removeChildStr("path"); String path = directive.removeChildStr(SECTION_PATH);
if (path == null) { if (path == null) {
throw new IOException("<directive> found without <path>"); throw new IOException("<directive> found without <path>");
} }
bld.setPath(path); bld.setPath(path);
Integer replication = directive.removeChildInt("replication"); Integer replication = directive.removeChildInt(SECTION_REPLICATION);
if (replication == null) { if (replication == null) {
throw new IOException("<directive> found without <replication>"); throw new IOException("<directive> found without <replication>");
} }
bld.setReplication(replication); bld.setReplication(replication);
String pool = directive.removeChildStr("pool"); String pool = directive.removeChildStr(CACHE_MANAGER_SECTION_POOL);
if (path == null) { if (path == null) {
throw new IOException("<directive> found without <pool>"); throw new IOException("<directive> found without <pool>");
} }
bld.setPool(pool); bld.setPool(pool);
Node expiration = directive.removeChild("expiration"); Node expiration =
directive.removeChild(CACHE_MANAGER_SECTION_EXPIRATION);
if (expiration != null) { if (expiration != null) {
CacheDirectiveInfoExpirationProto.Builder ebld = CacheDirectiveInfoExpirationProto.Builder ebld =
CacheDirectiveInfoExpirationProto.newBuilder(); CacheDirectiveInfoExpirationProto.newBuilder();
Long millis = expiration.removeChildLong("millis"); Long millis =
expiration.removeChildLong(CACHE_MANAGER_SECTION_MILLIS);
if (millis == null) { if (millis == null) {
throw new IOException("cache directive <expiration> found " + throw new IOException("cache directive <expiration> found " +
"without <millis>"); "without <millis>");
} }
ebld.setMillis(millis); ebld.setMillis(millis);
if (expiration.removeChildBool("relative")) { if (expiration.removeChildBool(CACHE_MANAGER_SECTION_RELATIVE)) {
ebld.setIsRelative(true); ebld.setIsRelative(true);
} else { } else {
ebld.setIsRelative(false); ebld.setIsRelative(false);
@ -1058,7 +1080,7 @@ class OfflineImageReconstructor {
// There is no header for this section. // There is no header for this section.
// We process the repeated <ref> elements. // We process the repeated <ref> elements.
while (true) { while (true) {
XMLEvent ev = expectTag("ref", true); XMLEvent ev = expectTag(INODE_REFERENCE_SECTION_REF, true);
if (ev.isEndElement()) { if (ev.isEndElement()) {
break; break;
} }
@ -1066,7 +1088,8 @@ class OfflineImageReconstructor {
FsImageProto.INodeReferenceSection.INodeReference.Builder bld = FsImageProto.INodeReferenceSection.INodeReference.Builder bld =
FsImageProto.INodeReferenceSection.INodeReference.newBuilder(); FsImageProto.INodeReferenceSection.INodeReference.newBuilder();
loadNodeChildren(inodeRef, "INodeReference"); loadNodeChildren(inodeRef, "INodeReference");
Long referredId = inodeRef.removeChildLong("referredId"); Long referredId =
inodeRef.removeChildLong(INODE_REFERENCE_SECTION_REFERRED_ID);
if (referredId != null) { if (referredId != null) {
bld.setReferredId(referredId); bld.setReferredId(referredId);
} }
@ -1074,11 +1097,13 @@ class OfflineImageReconstructor {
if (name != null) { if (name != null) {
bld.setName(ByteString.copyFrom(name, "UTF8")); bld.setName(ByteString.copyFrom(name, "UTF8"));
} }
Integer dstSnapshotId = inodeRef.removeChildInt("dstSnapshotId"); Integer dstSnapshotId = inodeRef.removeChildInt(
INODE_REFERENCE_SECTION_DST_SNAPSHOT_ID);
if (dstSnapshotId != null) { if (dstSnapshotId != null) {
bld.setDstSnapshotId(dstSnapshotId); bld.setDstSnapshotId(dstSnapshotId);
} }
Integer lastSnapshotId = inodeRef.removeChildInt("lastSnapshotId"); Integer lastSnapshotId = inodeRef.removeChildInt(
INODE_REFERENCE_SECTION_LAST_SNAPSHOT_ID);
if (lastSnapshotId != null) { if (lastSnapshotId != null) {
bld.setLastSnapshotId(lastSnapshotId); bld.setLastSnapshotId(lastSnapshotId);
} }
@ -1097,7 +1122,7 @@ class OfflineImageReconstructor {
// No header for this section // No header for this section
// Process the repeated <directory> elements. // Process the repeated <directory> elements.
while (true) { while (true) {
XMLEvent ev = expectTag("directory", true); XMLEvent ev = expectTag(INODE_DIRECTORY_SECTION_DIRECTORY, true);
if (ev.isEndElement()) { if (ev.isEndElement()) {
break; break;
} }
@ -1105,19 +1130,22 @@ class OfflineImageReconstructor {
FsImageProto.INodeDirectorySection.DirEntry.Builder bld = FsImageProto.INodeDirectorySection.DirEntry.Builder bld =
FsImageProto.INodeDirectorySection.DirEntry.newBuilder(); FsImageProto.INodeDirectorySection.DirEntry.newBuilder();
loadNodeChildren(directory, "directory"); loadNodeChildren(directory, "directory");
Long parent = directory.removeChildLong("parent"); Long parent = directory.removeChildLong(
INODE_DIRECTORY_SECTION_PARENT);
if (parent != null) { if (parent != null) {
bld.setParent(parent); bld.setParent(parent);
} }
while (true) { while (true) {
Node child = directory.removeChild("child"); Node child = directory.removeChild(
INODE_DIRECTORY_SECTION_CHILD);
if (child == null) { if (child == null) {
break; break;
} }
bld.addChildren(Long.parseLong(child.getVal())); bld.addChildren(Long.parseLong(child.getVal()));
} }
while (true) { while (true) {
Node refChild = directory.removeChild("refChild"); Node refChild = directory.removeChild(
INODE_DIRECTORY_SECTION_REF_CHILD);
if (refChild == null) { if (refChild == null) {
break; break;
} }
@ -1139,7 +1167,7 @@ class OfflineImageReconstructor {
// No header for this section type. // No header for this section type.
// Process the repeated files under construction elements. // Process the repeated files under construction elements.
while (true) { while (true) {
XMLEvent ev = expectTag("inode", true); XMLEvent ev = expectTag(INODE_SECTION_INODE, true);
if (ev.isEndElement()) { if (ev.isEndElement()) {
break; break;
} }
@ -1147,11 +1175,12 @@ class OfflineImageReconstructor {
loadNodeChildren(fileUnderConstruction, "file under construction"); loadNodeChildren(fileUnderConstruction, "file under construction");
FileUnderConstructionEntry.Builder bld = FileUnderConstructionEntry.Builder bld =
FileUnderConstructionEntry.newBuilder(); FileUnderConstructionEntry.newBuilder();
Long id = fileUnderConstruction.removeChildLong("id"); Long id = fileUnderConstruction.removeChildLong(SECTION_ID);
if (id != null) { if (id != null) {
bld.setInodeId(id); bld.setInodeId(id);
} }
String fullpath = fileUnderConstruction.removeChildStr("path"); String fullpath =
fileUnderConstruction.removeChildStr(SECTION_PATH);
if (fullpath != null) { if (fullpath != null) {
bld.setFullPath(fullpath); bld.setFullPath(fullpath);
} }
@ -1171,24 +1200,26 @@ class OfflineImageReconstructor {
FsImageProto.SnapshotSection.newBuilder(); FsImageProto.SnapshotSection.newBuilder();
Node header = new Node(); Node header = new Node();
loadNodeChildren(header, "SnapshotSection fields", "snapshot"); loadNodeChildren(header, "SnapshotSection fields", "snapshot");
Integer snapshotCounter = header.removeChildInt("snapshotCounter"); Integer snapshotCounter = header.removeChildInt(
SNAPSHOT_SECTION_SNAPSHOT_COUNTER);
if (snapshotCounter == null) { if (snapshotCounter == null) {
throw new IOException("No <snapshotCounter> entry found in " + throw new IOException("No <snapshotCounter> entry found in " +
"SnapshotSection header"); "SnapshotSection header");
} }
bld.setSnapshotCounter(snapshotCounter); bld.setSnapshotCounter(snapshotCounter);
Integer expectedNumSnapshots = header.removeChildInt("numSnapshots"); Integer expectedNumSnapshots = header.removeChildInt(
SNAPSHOT_SECTION_NUM_SNAPSHOTS);
if (expectedNumSnapshots == null) { if (expectedNumSnapshots == null) {
throw new IOException("No <numSnapshots> entry found in " + throw new IOException("No <numSnapshots> entry found in " +
"SnapshotSection header"); "SnapshotSection header");
} }
bld.setNumSnapshots(expectedNumSnapshots); bld.setNumSnapshots(expectedNumSnapshots);
while (true) { while (true) {
Node sd = header.removeChild("snapshottableDir"); Node sd = header.removeChild(SNAPSHOT_SECTION_SNAPSHOT_TABLE_DIR);
if (sd == null) { if (sd == null) {
break; break;
} }
Long dir = sd.removeChildLong("dir"); Long dir = sd.removeChildLong(SNAPSHOT_SECTION_DIR);
sd.verifyNoRemainingKeys("<dir>"); sd.verifyNoRemainingKeys("<dir>");
bld.addSnapshottableDir(dir); bld.addSnapshottableDir(dir);
} }
@ -1197,7 +1228,7 @@ class OfflineImageReconstructor {
int actualNumSnapshots = 0; int actualNumSnapshots = 0;
while (actualNumSnapshots < expectedNumSnapshots) { while (actualNumSnapshots < expectedNumSnapshots) {
try { try {
expectTag("snapshot", false); expectTag(SNAPSHOT_SECTION_SNAPSHOT, false);
} catch (IOException e) { } catch (IOException e) {
throw new IOException("Only read " + actualNumSnapshots + throw new IOException("Only read " + actualNumSnapshots +
" <snapshot> entries out of " + expectedNumSnapshots, e); " <snapshot> entries out of " + expectedNumSnapshots, e);
@ -1207,17 +1238,17 @@ class OfflineImageReconstructor {
loadNodeChildren(snapshot, "snapshot fields"); loadNodeChildren(snapshot, "snapshot fields");
FsImageProto.SnapshotSection.Snapshot.Builder s = FsImageProto.SnapshotSection.Snapshot.Builder s =
FsImageProto.SnapshotSection.Snapshot.newBuilder(); FsImageProto.SnapshotSection.Snapshot.newBuilder();
Integer snapshotId = snapshot.removeChildInt("id"); Integer snapshotId = snapshot.removeChildInt(SECTION_ID);
if (snapshotId == null) { if (snapshotId == null) {
throw new IOException("<snapshot> section was missing <id>"); throw new IOException("<snapshot> section was missing <id>");
} }
s.setSnapshotId(snapshotId); s.setSnapshotId(snapshotId);
Node snapshotRoot = snapshot.removeChild("root"); Node snapshotRoot = snapshot.removeChild(SNAPSHOT_SECTION_ROOT);
INodeSection.INode.Builder inodeBld = processINodeXml(snapshotRoot); INodeSection.INode.Builder inodeBld = processINodeXml(snapshotRoot);
s.setRoot(inodeBld); s.setRoot(inodeBld);
s.build().writeDelimitedTo(out); s.build().writeDelimitedTo(out);
} }
expectTagEnd("SnapshotSection"); expectTagEnd(SNAPSHOT_SECTION_NAME);
recordSectionLength(SectionName.SNAPSHOT.name()); recordSectionLength(SectionName.SNAPSHOT.name());
} }
} }
@ -1233,15 +1264,15 @@ class OfflineImageReconstructor {
XMLEvent ev = expectTag("[diff start tag]", true); XMLEvent ev = expectTag("[diff start tag]", true);
if (ev.isEndElement()) { if (ev.isEndElement()) {
String name = ev.asEndElement().getName().getLocalPart(); String name = ev.asEndElement().getName().getLocalPart();
if (name.equals("SnapshotDiffSection")) { if (name.equals(SNAPSHOT_DIFF_SECTION_NAME)) {
break; break;
} }
throw new IOException("Got unexpected end tag for " + name); throw new IOException("Got unexpected end tag for " + name);
} }
String tagName = ev.asStartElement().getName().getLocalPart(); String tagName = ev.asStartElement().getName().getLocalPart();
if (tagName.equals("dirDiffEntry")) { if (tagName.equals(SNAPSHOT_DIFF_SECTION_DIR_DIFF_ENTRY)) {
processDirDiffEntry(); processDirDiffEntry();
} else if (tagName.equals("fileDiffEntry")) { } else if (tagName.equals(SNAPSHOT_DIFF_SECTION_FILE_DIFF_ENTRY)) {
processFileDiffEntry(); processFileDiffEntry();
} else { } else {
throw new IOException("SnapshotDiffSection contained unexpected " + throw new IOException("SnapshotDiffSection contained unexpected " +
@ -1257,12 +1288,14 @@ class OfflineImageReconstructor {
headerBld.setType(DiffEntry.Type.DIRECTORYDIFF); headerBld.setType(DiffEntry.Type.DIRECTORYDIFF);
Node dirDiffHeader = new Node(); Node dirDiffHeader = new Node();
loadNodeChildren(dirDiffHeader, "dirDiffEntry fields", "dirDiff"); loadNodeChildren(dirDiffHeader, "dirDiffEntry fields", "dirDiff");
Long inodeId = dirDiffHeader.removeChildLong("inodeId"); Long inodeId = dirDiffHeader.removeChildLong(
SNAPSHOT_DIFF_SECTION_INODE_ID);
if (inodeId == null) { if (inodeId == null) {
throw new IOException("<dirDiffEntry> contained no <inodeId> entry."); throw new IOException("<dirDiffEntry> contained no <inodeId> entry.");
} }
headerBld.setInodeId(inodeId); headerBld.setInodeId(inodeId);
Integer expectedDiffs = dirDiffHeader.removeChildInt("count"); Integer expectedDiffs = dirDiffHeader.removeChildInt(
SNAPSHOT_DIFF_SECTION_COUNT);
if (expectedDiffs == null) { if (expectedDiffs == null) {
throw new IOException("<dirDiffEntry> contained no <count> entry."); throw new IOException("<dirDiffEntry> contained no <count> entry.");
} }
@ -1271,7 +1304,7 @@ class OfflineImageReconstructor {
headerBld.build().writeDelimitedTo(out); headerBld.build().writeDelimitedTo(out);
for (int actualDiffs = 0; actualDiffs < expectedDiffs; actualDiffs++) { for (int actualDiffs = 0; actualDiffs < expectedDiffs; actualDiffs++) {
try { try {
expectTag("dirDiff", false); expectTag(SNAPSHOT_DIFF_SECTION_DIR_DIFF, false);
} catch (IOException e) { } catch (IOException e) {
throw new IOException("Only read " + (actualDiffs + 1) + throw new IOException("Only read " + (actualDiffs + 1) +
" diffs out of " + expectedDiffs, e); " diffs out of " + expectedDiffs, e);
@ -1280,38 +1313,43 @@ class OfflineImageReconstructor {
loadNodeChildren(dirDiff, "dirDiff fields"); loadNodeChildren(dirDiff, "dirDiff fields");
FsImageProto.SnapshotDiffSection.DirectoryDiff.Builder bld = FsImageProto.SnapshotDiffSection.DirectoryDiff.Builder bld =
FsImageProto.SnapshotDiffSection.DirectoryDiff.newBuilder(); FsImageProto.SnapshotDiffSection.DirectoryDiff.newBuilder();
Integer snapshotId = dirDiff.removeChildInt("snapshotId"); Integer snapshotId = dirDiff.removeChildInt(
SNAPSHOT_DIFF_SECTION_SNAPSHOT_ID);
if (snapshotId != null) { if (snapshotId != null) {
bld.setSnapshotId(snapshotId); bld.setSnapshotId(snapshotId);
} }
Integer childrenSize = dirDiff.removeChildInt("childrenSize"); Integer childrenSize = dirDiff.removeChildInt(
SNAPSHOT_DIFF_SECTION_CHILDREN_SIZE);
if (childrenSize == null) { if (childrenSize == null) {
throw new IOException("Expected to find <childrenSize> in " + throw new IOException("Expected to find <childrenSize> in " +
"<dirDiff> section."); "<dirDiff> section.");
} }
bld.setIsSnapshotRoot(dirDiff.removeChildBool("isSnapshotRoot")); bld.setIsSnapshotRoot(dirDiff.removeChildBool(
SNAPSHOT_DIFF_SECTION_IS_SNAPSHOT_ROOT));
bld.setChildrenSize(childrenSize); bld.setChildrenSize(childrenSize);
String name = dirDiff.removeChildStr("name"); String name = dirDiff.removeChildStr(SECTION_NAME);
if (name != null) { if (name != null) {
bld.setName(ByteString.copyFrom(name, "UTF8")); bld.setName(ByteString.copyFrom(name, "UTF8"));
} }
// TODO: add missing snapshotCopy field to XML // TODO: add missing snapshotCopy field to XML
Integer expectedCreatedListSize = Integer expectedCreatedListSize = dirDiff.removeChildInt(
dirDiff.removeChildInt("createdListSize"); SNAPSHOT_DIFF_SECTION_CREATED_LIST_SIZE);
if (expectedCreatedListSize == null) { if (expectedCreatedListSize == null) {
throw new IOException("Expected to find <createdListSize> in " + throw new IOException("Expected to find <createdListSize> in " +
"<dirDiff> section."); "<dirDiff> section.");
} }
bld.setCreatedListSize(expectedCreatedListSize); bld.setCreatedListSize(expectedCreatedListSize);
while (true) { while (true) {
Node deleted = dirDiff.removeChild("deletedInode"); Node deleted = dirDiff.removeChild(
SNAPSHOT_DIFF_SECTION_DELETED_INODE);
if (deleted == null){ if (deleted == null){
break; break;
} }
bld.addDeletedINode(Long.parseLong(deleted.getVal())); bld.addDeletedINode(Long.parseLong(deleted.getVal()));
} }
while (true) { while (true) {
Node deleted = dirDiff.removeChild("deletedInoderef"); Node deleted = dirDiff.removeChild(
SNAPSHOT_DIFF_SECTION_DELETED_INODE_REF);
if (deleted == null){ if (deleted == null){
break; break;
} }
@ -1321,11 +1359,12 @@ class OfflineImageReconstructor {
// After the DirectoryDiff header comes a list of CreatedListEntry PBs. // After the DirectoryDiff header comes a list of CreatedListEntry PBs.
int actualCreatedListSize = 0; int actualCreatedListSize = 0;
while (true) { while (true) {
Node created = dirDiff.removeChild("created"); Node created = dirDiff.removeChild(
SNAPSHOT_DIFF_SECTION_CREATED);
if (created == null){ if (created == null){
break; break;
} }
String cleName = created.removeChildStr("name"); String cleName = created.removeChildStr(SECTION_NAME);
if (cleName == null) { if (cleName == null) {
throw new IOException("Expected <created> entry to have " + throw new IOException("Expected <created> entry to have " +
"a <name> field"); "a <name> field");
@ -1343,7 +1382,7 @@ class OfflineImageReconstructor {
} }
dirDiff.verifyNoRemainingKeys("dirDiff"); dirDiff.verifyNoRemainingKeys("dirDiff");
} }
expectTagEnd("dirDiffEntry"); expectTagEnd(SNAPSHOT_DIFF_SECTION_DIR_DIFF_ENTRY);
} }
private void processFileDiffEntry() throws IOException { private void processFileDiffEntry() throws IOException {
@ -1352,12 +1391,14 @@ class OfflineImageReconstructor {
headerBld.setType(DiffEntry.Type.FILEDIFF); headerBld.setType(DiffEntry.Type.FILEDIFF);
Node fileDiffHeader = new Node(); Node fileDiffHeader = new Node();
loadNodeChildren(fileDiffHeader, "fileDiffEntry fields", "fileDiff"); loadNodeChildren(fileDiffHeader, "fileDiffEntry fields", "fileDiff");
Long inodeId = fileDiffHeader.removeChildLong("inodeid"); Long inodeId = fileDiffHeader.removeChildLong(
SNAPSHOT_DIFF_SECTION_INODE_ID);
if (inodeId == null) { if (inodeId == null) {
throw new IOException("<fileDiffEntry> contained no <inodeid> entry."); throw new IOException("<fileDiffEntry> contained no <inodeid> entry.");
} }
headerBld.setInodeId(inodeId); headerBld.setInodeId(inodeId);
Integer expectedDiffs = fileDiffHeader.removeChildInt("count"); Integer expectedDiffs = fileDiffHeader.removeChildInt(
SNAPSHOT_DIFF_SECTION_COUNT);
if (expectedDiffs == null) { if (expectedDiffs == null) {
throw new IOException("<fileDiffEntry> contained no <count> entry."); throw new IOException("<fileDiffEntry> contained no <count> entry.");
} }
@ -1366,7 +1407,7 @@ class OfflineImageReconstructor {
headerBld.build().writeDelimitedTo(out); headerBld.build().writeDelimitedTo(out);
for (int actualDiffs = 0; actualDiffs < expectedDiffs; actualDiffs++) { for (int actualDiffs = 0; actualDiffs < expectedDiffs; actualDiffs++) {
try { try {
expectTag("fileDiff", false); expectTag(SNAPSHOT_DIFF_SECTION_FILE_DIFF, false);
} catch (IOException e) { } catch (IOException e) {
throw new IOException("Only read " + (actualDiffs + 1) + throw new IOException("Only read " + (actualDiffs + 1) +
" diffs out of " + expectedDiffs, e); " diffs out of " + expectedDiffs, e);
@ -1375,15 +1416,17 @@ class OfflineImageReconstructor {
loadNodeChildren(fileDiff, "fileDiff fields"); loadNodeChildren(fileDiff, "fileDiff fields");
FsImageProto.SnapshotDiffSection.FileDiff.Builder bld = FsImageProto.SnapshotDiffSection.FileDiff.Builder bld =
FsImageProto.SnapshotDiffSection.FileDiff.newBuilder(); FsImageProto.SnapshotDiffSection.FileDiff.newBuilder();
Integer snapshotId = fileDiff.removeChildInt("snapshotId"); Integer snapshotId = fileDiff.removeChildInt(
SNAPSHOT_DIFF_SECTION_SNAPSHOT_ID);
if (snapshotId != null) { if (snapshotId != null) {
bld.setSnapshotId(snapshotId); bld.setSnapshotId(snapshotId);
} }
Long size = fileDiff.removeChildLong("size"); Long size = fileDiff.removeChildLong(
SNAPSHOT_DIFF_SECTION_SIZE);
if (size != null) { if (size != null) {
bld.setFileSize(size); bld.setFileSize(size);
} }
String name = fileDiff.removeChildStr("name"); String name = fileDiff.removeChildStr(SECTION_NAME);
if (name != null) { if (name != null) {
bld.setName(ByteString.copyFrom(name, "UTF8")); bld.setName(ByteString.copyFrom(name, "UTF8"));
} }
@ -1392,7 +1435,7 @@ class OfflineImageReconstructor {
fileDiff.verifyNoRemainingKeys("fileDiff"); fileDiff.verifyNoRemainingKeys("fileDiff");
bld.build().writeDelimitedTo(out); bld.build().writeDelimitedTo(out);
} }
expectTagEnd("fileDiffEntry"); expectTagEnd(SNAPSHOT_DIFF_SECTION_FILE_DIFF_ENTRY);
} }
} }

View File

@ -77,6 +77,153 @@ import static org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode.XATTR_
*/ */
@InterfaceAudience.Private @InterfaceAudience.Private
public final class PBImageXmlWriter { public final class PBImageXmlWriter {
public static final String NAME_SECTION_NAME = "NameSection";
public static final String INODE_SECTION_NAME = "INodeSection";
public static final String SECRET_MANAGER_SECTION_NAME =
"SecretManagerSection";
public static final String CACHE_MANAGER_SECTION_NAME = "CacheManagerSection";
public static final String SNAPSHOT_DIFF_SECTION_NAME = "SnapshotDiffSection";
public static final String INODE_REFERENCE_SECTION_NAME =
"INodeReferenceSection";
public static final String INODE_DIRECTORY_SECTION_NAME =
"INodeDirectorySection";
public static final String FILE_UNDER_CONSTRUCTION_SECTION_NAME =
"FileUnderConstructionSection";
public static final String SNAPSHOT_SECTION_NAME = "SnapshotSection";
public static final String SECTION_ID = "id";
public static final String SECTION_REPLICATION = "replication";
public static final String SECTION_PATH = "path";
public static final String SECTION_NAME = "name";
public static final String NAME_SECTION_NAMESPACE_ID = "namespaceId";
public static final String NAME_SECTION_GENSTAMPV1 = "genstampV1";
public static final String NAME_SECTION_GENSTAMPV2 = "genstampV2";
public static final String NAME_SECTION_GENSTAMPV1_LIMIT = "genstampV1Limit";
public static final String NAME_SECTION_LAST_ALLOCATED_BLOCK_ID =
"lastAllocatedBlockId";
public static final String NAME_SECTION_TXID = "txid";
public static final String NAME_SECTION_ROLLING_UPGRADE_START_TIME =
"rollingUpgradeStartTime";
public static final String NAME_SECTION_LAST_ALLOCATED_STRIPED_BLOCK_ID =
"lastAllocatedStripedBlockId";
public static final String INODE_SECTION_LAST_INODE_ID = "lastInodeId";
public static final String INODE_SECTION_NUM_INODES = "numInodes";
public static final String INODE_SECTION_TYPE = "type";
public static final String INODE_SECTION_MTIME = "mtime";
public static final String INODE_SECTION_ATIME = "atime";
public static final String INODE_SECTION_PREFERRED_BLOCK_SIZE =
"preferredBlockSize";
public static final String INODE_SECTION_PERMISSION = "permission";
public static final String INODE_SECTION_BLOCKS = "blocks";
public static final String INODE_SECTION_BLOCK = "block";
public static final String INODE_SECTION_GEMSTAMP = "genstamp";
public static final String INODE_SECTION_NUM_BYTES = "numBytes";
public static final String INODE_SECTION_FILE_UNDER_CONSTRUCTION =
"file-under-construction";
public static final String INODE_SECTION_CLIENT_NAME = "clientName";
public static final String INODE_SECTION_CLIENT_MACHINE = "clientMachine";
public static final String INODE_SECTION_ACL = "acl";
public static final String INODE_SECTION_ACLS = "acls";
public static final String INODE_SECTION_XATTR = "xattr";
public static final String INODE_SECTION_XATTRS = "xattrs";
public static final String INODE_SECTION_STORAGE_POLICY_ID =
"storagePolicyId";
public static final String INODE_SECTION_NS_QUOTA = "nsquota";
public static final String INODE_SECTION_DS_QUOTA = "dsquota";
public static final String INODE_SECTION_TYPE_QUOTA = "typeQuota";
public static final String INODE_SECTION_QUOTA = "quota";
public static final String INODE_SECTION_TARGET = "target";
public static final String INODE_SECTION_NS = "ns";
public static final String INODE_SECTION_VAL = "val";
public static final String INODE_SECTION_VAL_HEX = "valHex";
public static final String INODE_SECTION_INODE = "inode";
public static final String SECRET_MANAGER_SECTION_CURRENT_ID = "currentId";
public static final String SECRET_MANAGER_SECTION_TOKEN_SEQUENCE_NUMBER =
"tokenSequenceNumber";
public static final String SECRET_MANAGER_SECTION_NUM_DELEGATION_KEYS =
"numDelegationKeys";
public static final String SECRET_MANAGER_SECTION_NUM_TOKENS = "numTokens";
public static final String SECRET_MANAGER_SECTION_EXPIRY = "expiry";
public static final String SECRET_MANAGER_SECTION_KEY = "key";
public static final String SECRET_MANAGER_SECTION_DELEGATION_KEY =
"delegationKey";
public static final String SECRET_MANAGER_SECTION_VERSION = "version";
public static final String SECRET_MANAGER_SECTION_OWNER = "owner";
public static final String SECRET_MANAGER_SECTION_RENEWER = "renewer";
public static final String SECRET_MANAGER_SECTION_REAL_USER = "realUser";
public static final String SECRET_MANAGER_SECTION_ISSUE_DATE = "issueDate";
public static final String SECRET_MANAGER_SECTION_MAX_DATE = "maxDate";
public static final String SECRET_MANAGER_SECTION_SEQUENCE_NUMBER =
"sequenceNumber";
public static final String SECRET_MANAGER_SECTION_MASTER_KEY_ID =
"masterKeyId";
public static final String SECRET_MANAGER_SECTION_EXPIRY_DATE = "expiryDate";
public static final String SECRET_MANAGER_SECTION_TOKEN = "token";
public static final String CACHE_MANAGER_SECTION_NEXT_DIRECTIVE_ID =
"nextDirectiveId";
public static final String CACHE_MANAGER_SECTION_NUM_POOLS = "numPools";
public static final String CACHE_MANAGER_SECTION_NUM_DIRECTIVES =
"numDirectives";
public static final String CACHE_MANAGER_SECTION_POOL_NAME = "poolName";
public static final String CACHE_MANAGER_SECTION_OWNER_NAME = "ownerName";
public static final String CACHE_MANAGER_SECTION_GROUP_NAME = "groupName";
public static final String CACHE_MANAGER_SECTION_MODE = "mode";
public static final String CACHE_MANAGER_SECTION_LIMIT = "limit";
public static final String CACHE_MANAGER_SECTION_MAX_RELATIVE_EXPIRY =
"maxRelativeExpiry";
public static final String CACHE_MANAGER_SECTION_POOL = "pool";
public static final String CACHE_MANAGER_SECTION_EXPIRATION = "expiration";
public static final String CACHE_MANAGER_SECTION_MILLIS = "millis";
public static final String CACHE_MANAGER_SECTION_RELATIVE = "relative";
public static final String CACHE_MANAGER_SECTION_DIRECTIVE = "directive";
public static final String SNAPSHOT_DIFF_SECTION_INODE_ID = "inodeId";
public static final String SNAPSHOT_DIFF_SECTION_COUNT = "count";
public static final String SNAPSHOT_DIFF_SECTION_SNAPSHOT_ID = "snapshotId";
public static final String SNAPSHOT_DIFF_SECTION_CHILDREN_SIZE =
"childrenSize";
public static final String SNAPSHOT_DIFF_SECTION_IS_SNAPSHOT_ROOT =
"isSnapshotRoot";
public static final String SNAPSHOT_DIFF_SECTION_CREATED_LIST_SIZE =
"createdListSize";
public static final String SNAPSHOT_DIFF_SECTION_DELETED_INODE =
"deletedInode";
public static final String SNAPSHOT_DIFF_SECTION_DELETED_INODE_REF =
"deletedInoderef";
public static final String SNAPSHOT_DIFF_SECTION_CREATED = "created";
public static final String SNAPSHOT_DIFF_SECTION_SIZE = "size";
public static final String SNAPSHOT_DIFF_SECTION_FILE_DIFF_ENTRY =
"fileDiffEntry";
public static final String SNAPSHOT_DIFF_SECTION_DIR_DIFF_ENTRY =
"dirDiffEntry";
public static final String SNAPSHOT_DIFF_SECTION_FILE_DIFF = "fileDiff";
public static final String SNAPSHOT_DIFF_SECTION_DIR_DIFF = "dirDiff";
public static final String INODE_REFERENCE_SECTION_REFERRED_ID = "referredId";
public static final String INODE_REFERENCE_SECTION_DST_SNAPSHOT_ID =
"dstSnapshotId";
public static final String INODE_REFERENCE_SECTION_LAST_SNAPSHOT_ID =
"lastSnapshotId";
public static final String INODE_REFERENCE_SECTION_REF = "ref";
public static final String INODE_DIRECTORY_SECTION_PARENT = "parent";
public static final String INODE_DIRECTORY_SECTION_CHILD = "child";
public static final String INODE_DIRECTORY_SECTION_REF_CHILD = "refChild";
public static final String INODE_DIRECTORY_SECTION_DIRECTORY = "directory";
public static final String SNAPSHOT_SECTION_SNAPSHOT_COUNTER =
"snapshotCounter";
public static final String SNAPSHOT_SECTION_NUM_SNAPSHOTS = "numSnapshots";
public static final String SNAPSHOT_SECTION_SNAPSHOT_TABLE_DIR =
"snapshottableDir";
public static final String SNAPSHOT_SECTION_DIR = "dir";
public static final String SNAPSHOT_SECTION_ROOT = "root";
public static final String SNAPSHOT_SECTION_SNAPSHOT = "snapshot";
private final Configuration conf; private final Configuration conf;
private final PrintStream out; private final PrintStream out;
private final SimpleDateFormat isoDateFormat; private final SimpleDateFormat isoDateFormat;
@ -177,98 +324,106 @@ public final class PBImageXmlWriter {
} }
private void dumpCacheManagerSection(InputStream is) throws IOException { private void dumpCacheManagerSection(InputStream is) throws IOException {
out.print("<CacheManagerSection>"); out.print("<" + CACHE_MANAGER_SECTION_NAME + ">");
CacheManagerSection s = CacheManagerSection.parseDelimitedFrom(is); CacheManagerSection s = CacheManagerSection.parseDelimitedFrom(is);
o("nextDirectiveId", s.getNextDirectiveId()); o(CACHE_MANAGER_SECTION_NEXT_DIRECTIVE_ID, s.getNextDirectiveId());
o("numDirectives", s.getNumDirectives()); o(CACHE_MANAGER_SECTION_NUM_DIRECTIVES, s.getNumDirectives());
o("numPools", s.getNumPools()); o(CACHE_MANAGER_SECTION_NUM_POOLS, s.getNumPools());
for (int i = 0; i < s.getNumPools(); ++i) { for (int i = 0; i < s.getNumPools(); ++i) {
CachePoolInfoProto p = CachePoolInfoProto.parseDelimitedFrom(is); CachePoolInfoProto p = CachePoolInfoProto.parseDelimitedFrom(is);
out.print("<pool>"); out.print("<" + CACHE_MANAGER_SECTION_POOL +">");
o("poolName", p.getPoolName()).o("ownerName", p.getOwnerName()) o(CACHE_MANAGER_SECTION_POOL_NAME, p.getPoolName()).
.o("groupName", p.getGroupName()).o("mode", p.getMode()) o(CACHE_MANAGER_SECTION_OWNER_NAME, p.getOwnerName())
.o("limit", p.getLimit()) .o(CACHE_MANAGER_SECTION_GROUP_NAME, p.getGroupName())
.o("maxRelativeExpiry", p.getMaxRelativeExpiry()); .o(CACHE_MANAGER_SECTION_MODE, p.getMode())
out.print("</pool>\n"); .o(CACHE_MANAGER_SECTION_LIMIT, p.getLimit())
.o(CACHE_MANAGER_SECTION_MAX_RELATIVE_EXPIRY,
p.getMaxRelativeExpiry());
out.print("</" + CACHE_MANAGER_SECTION_POOL + ">\n");
} }
for (int i = 0; i < s.getNumDirectives(); ++i) { for (int i = 0; i < s.getNumDirectives(); ++i) {
CacheDirectiveInfoProto p = CacheDirectiveInfoProto CacheDirectiveInfoProto p = CacheDirectiveInfoProto
.parseDelimitedFrom(is); .parseDelimitedFrom(is);
out.print("<directive>"); out.print("<" + CACHE_MANAGER_SECTION_DIRECTIVE + ">");
o("id", p.getId()).o("path", p.getPath()) o(SECTION_ID, p.getId()).o(SECTION_PATH, p.getPath())
.o("replication", p.getReplication()).o("pool", p.getPool()); .o(SECTION_REPLICATION, p.getReplication())
out.print("<expiration>"); .o(CACHE_MANAGER_SECTION_POOL, p.getPool());
out.print("<" + CACHE_MANAGER_SECTION_EXPIRATION +">");
CacheDirectiveInfoExpirationProto e = p.getExpiration(); CacheDirectiveInfoExpirationProto e = p.getExpiration();
o("millis", e.getMillis()).o("relative", e.getIsRelative()); o(CACHE_MANAGER_SECTION_MILLIS, e.getMillis())
out.print("</expiration>\n"); .o(CACHE_MANAGER_SECTION_RELATIVE, e.getIsRelative());
out.print("</directive>\n"); out.print("</" + CACHE_MANAGER_SECTION_EXPIRATION+ ">\n");
out.print("</" + CACHE_MANAGER_SECTION_DIRECTIVE + ">\n");
} }
out.print("</CacheManagerSection>\n"); out.print("</" + CACHE_MANAGER_SECTION_NAME + ">\n");
} }
private void dumpFileUnderConstructionSection(InputStream in) private void dumpFileUnderConstructionSection(InputStream in)
throws IOException { throws IOException {
out.print("<FileUnderConstructionSection>"); out.print("<" + FILE_UNDER_CONSTRUCTION_SECTION_NAME + ">");
while (true) { while (true) {
FileUnderConstructionEntry e = FileUnderConstructionEntry FileUnderConstructionEntry e = FileUnderConstructionEntry
.parseDelimitedFrom(in); .parseDelimitedFrom(in);
if (e == null) { if (e == null) {
break; break;
} }
out.print("<inode>"); out.print("<" + INODE_SECTION_INODE + ">");
o("id", e.getInodeId()).o("path", e.getFullPath()); o(SECTION_ID, e.getInodeId())
out.print("</inode>\n"); .o(SECTION_PATH, e.getFullPath());
out.print("</" + INODE_SECTION_INODE + ">\n");
} }
out.print("</FileUnderConstructionSection>\n"); out.print("</" + FILE_UNDER_CONSTRUCTION_SECTION_NAME + ">\n");
} }
private void dumpXattrs(INodeSection.XAttrFeatureProto xattrs) { private void dumpXattrs(INodeSection.XAttrFeatureProto xattrs) {
out.print("<xattrs>"); out.print("<" + INODE_SECTION_XATTRS + ">");
for (INodeSection.XAttrCompactProto xattr : xattrs.getXAttrsList()) { for (INodeSection.XAttrCompactProto xattr : xattrs.getXAttrsList()) {
out.print("<xattr>"); out.print("<" + INODE_SECTION_XATTR + ">");
int encodedName = xattr.getName(); int encodedName = xattr.getName();
int ns = (XATTR_NAMESPACE_MASK & (encodedName >> XATTR_NAMESPACE_OFFSET)) | int ns = (XATTR_NAMESPACE_MASK & (encodedName >> XATTR_NAMESPACE_OFFSET)) |
((XATTR_NAMESPACE_EXT_MASK & (encodedName >> XATTR_NAMESPACE_EXT_OFFSET)) << 2); ((XATTR_NAMESPACE_EXT_MASK & (encodedName >> XATTR_NAMESPACE_EXT_OFFSET)) << 2);
o("ns", XAttrProtos.XAttrProto. o(INODE_SECTION_NS, XAttrProtos.XAttrProto.
XAttrNamespaceProto.valueOf(ns).toString()); XAttrNamespaceProto.valueOf(ns).toString());
o("name", stringTable[XATTR_NAME_MASK & (encodedName >> XATTR_NAME_OFFSET)]); o(SECTION_NAME,
stringTable[XATTR_NAME_MASK & (encodedName >> XATTR_NAME_OFFSET)]);
ByteString val = xattr.getValue(); ByteString val = xattr.getValue();
if (val.isValidUtf8()) { if (val.isValidUtf8()) {
o("val", val.toStringUtf8()); o(INODE_SECTION_VAL, val.toStringUtf8());
} else { } else {
o("valHex", Hex.encodeHexString(val.toByteArray())); o(INODE_SECTION_VAL_HEX, Hex.encodeHexString(val.toByteArray()));
} }
out.print("</xattr>"); out.print("</" + INODE_SECTION_XATTR + ">");
} }
out.print("</xattrs>"); out.print("</" + INODE_SECTION_XATTRS + ">");
} }
private void dumpINodeDirectory(INodeDirectory d) { private void dumpINodeDirectory(INodeDirectory d) {
o("mtime", d.getModificationTime()).o("permission", o(INODE_SECTION_MTIME, d.getModificationTime())
dumpPermission(d.getPermission())); .o(INODE_SECTION_PERMISSION, dumpPermission(d.getPermission()));
if (d.hasXAttrs()) { if (d.hasXAttrs()) {
dumpXattrs(d.getXAttrs()); dumpXattrs(d.getXAttrs());
} }
dumpAcls(d.getAcl()); dumpAcls(d.getAcl());
if (d.hasDsQuota() && d.hasNsQuota()) { if (d.hasDsQuota() && d.hasNsQuota()) {
o("nsquota", d.getNsQuota()).o("dsquota", d.getDsQuota()); o(INODE_SECTION_NS_QUOTA, d.getNsQuota())
.o(INODE_SECTION_DS_QUOTA, d.getDsQuota());
} }
INodeSection.QuotaByStorageTypeFeatureProto typeQuotas = INodeSection.QuotaByStorageTypeFeatureProto typeQuotas =
d.getTypeQuotas(); d.getTypeQuotas();
if (typeQuotas != null) { if (typeQuotas != null) {
for (INodeSection.QuotaByStorageTypeEntryProto entry: for (INodeSection.QuotaByStorageTypeEntryProto entry:
typeQuotas.getQuotasList()) { typeQuotas.getQuotasList()) {
out.print("<typeQuota>"); out.print("<" + INODE_SECTION_TYPE_QUOTA + ">");
o("type", entry.getStorageType().toString()); o(INODE_SECTION_TYPE, entry.getStorageType().toString());
o("quota", entry.getQuota()); o(INODE_SECTION_QUOTA, entry.getQuota());
out.print("</typeQuota>"); out.print("</" + INODE_SECTION_TYPE_QUOTA + ">");
} }
} }
} }
private void dumpINodeDirectorySection(InputStream in) throws IOException { private void dumpINodeDirectorySection(InputStream in) throws IOException {
out.print("<INodeDirectorySection>"); out.print("<" + INODE_DIRECTORY_SECTION_NAME + ">");
while (true) { while (true) {
INodeDirectorySection.DirEntry e = INodeDirectorySection.DirEntry INodeDirectorySection.DirEntry e = INodeDirectorySection.DirEntry
.parseDelimitedFrom(in); .parseDelimitedFrom(in);
@ -276,21 +431,21 @@ public final class PBImageXmlWriter {
if (e == null) { if (e == null) {
break; break;
} }
out.print("<directory>"); out.print("<" + INODE_DIRECTORY_SECTION_DIRECTORY + ">");
o("parent", e.getParent()); o(INODE_DIRECTORY_SECTION_PARENT, e.getParent());
for (long id : e.getChildrenList()) { for (long id : e.getChildrenList()) {
o("child", id); o(INODE_DIRECTORY_SECTION_CHILD, id);
} }
for (int refId : e.getRefChildrenList()) { for (int refId : e.getRefChildrenList()) {
o("refChild", refId); o(INODE_DIRECTORY_SECTION_REF_CHILD, refId);
} }
out.print("</directory>\n"); out.print("</" + INODE_DIRECTORY_SECTION_DIRECTORY + ">\n");
} }
out.print("</INodeDirectorySection>\n"); out.print("</" + INODE_DIRECTORY_SECTION_NAME + ">\n");
} }
private void dumpINodeReferenceSection(InputStream in) throws IOException { private void dumpINodeReferenceSection(InputStream in) throws IOException {
out.print("<INodeReferenceSection>"); out.print("<" + INODE_REFERENCE_SECTION_NAME + ">");
while (true) { while (true) {
INodeReferenceSection.INodeReference e = INodeReferenceSection INodeReferenceSection.INodeReference e = INodeReferenceSection
.INodeReference.parseDelimitedFrom(in); .INodeReference.parseDelimitedFrom(in);
@ -299,46 +454,50 @@ public final class PBImageXmlWriter {
} }
dumpINodeReference(e); dumpINodeReference(e);
} }
out.print("</INodeReferenceSection>"); out.print("</" + INODE_REFERENCE_SECTION_NAME + ">");
} }
private void dumpINodeReference(INodeReferenceSection.INodeReference r) { private void dumpINodeReference(INodeReferenceSection.INodeReference r) {
out.print("<ref>"); out.print("<" + INODE_REFERENCE_SECTION_REF + ">");
o("referredId", r.getReferredId()).o("name", r.getName().toStringUtf8()) o(INODE_REFERENCE_SECTION_REFERRED_ID, r.getReferredId())
.o("dstSnapshotId", r.getDstSnapshotId()) .o(SECTION_NAME, r.getName().toStringUtf8())
.o("lastSnapshotId", r.getLastSnapshotId()); .o(INODE_REFERENCE_SECTION_DST_SNAPSHOT_ID, r.getDstSnapshotId())
out.print("</ref>\n"); .o(INODE_REFERENCE_SECTION_LAST_SNAPSHOT_ID,
r.getLastSnapshotId());
out.print("</" + INODE_REFERENCE_SECTION_REF + ">\n");
} }
private void dumpINodeFile(INodeSection.INodeFile f) { private void dumpINodeFile(INodeSection.INodeFile f) {
o("replication", f.getReplication()).o("mtime", f.getModificationTime()) o(SECTION_REPLICATION, f.getReplication())
.o("atime", f.getAccessTime()) .o(INODE_SECTION_MTIME, f.getModificationTime())
.o("preferredBlockSize", f.getPreferredBlockSize()) .o(INODE_SECTION_ATIME, f.getAccessTime())
.o("permission", dumpPermission(f.getPermission())); .o(INODE_SECTION_PREFERRED_BLOCK_SIZE, f.getPreferredBlockSize())
.o(INODE_SECTION_PERMISSION, dumpPermission(f.getPermission()));
if (f.hasXAttrs()) { if (f.hasXAttrs()) {
dumpXattrs(f.getXAttrs()); dumpXattrs(f.getXAttrs());
} }
dumpAcls(f.getAcl()); dumpAcls(f.getAcl());
if (f.getBlocksCount() > 0) { if (f.getBlocksCount() > 0) {
out.print("<blocks>"); out.print("<" + INODE_SECTION_BLOCKS + ">");
for (BlockProto b : f.getBlocksList()) { for (BlockProto b : f.getBlocksList()) {
out.print("<block>"); out.print("<" + INODE_SECTION_BLOCK + ">");
o("id", b.getBlockId()).o("genstamp", b.getGenStamp()).o("numBytes", o(SECTION_ID, b.getBlockId())
b.getNumBytes()); .o(INODE_SECTION_GEMSTAMP, b.getGenStamp())
out.print("</block>\n"); .o(INODE_SECTION_NUM_BYTES, b.getNumBytes());
out.print("</" + INODE_SECTION_BLOCK + ">\n");
} }
out.print("</blocks>\n"); out.print("</" + INODE_SECTION_BLOCKS + ">\n");
} }
if (f.hasStoragePolicyID()) { if (f.hasStoragePolicyID()) {
o("storagePolicyId", f.getStoragePolicyID()); o(INODE_SECTION_STORAGE_POLICY_ID, f.getStoragePolicyID());
} }
if (f.hasFileUC()) { if (f.hasFileUC()) {
INodeSection.FileUnderConstructionFeature u = f.getFileUC(); INodeSection.FileUnderConstructionFeature u = f.getFileUC();
out.print("<file-under-construction>"); out.print("<" + INODE_SECTION_FILE_UNDER_CONSTRUCTION + ">");
o("clientName", u.getClientName()).o("clientMachine", o(INODE_SECTION_CLIENT_NAME, u.getClientName())
u.getClientMachine()); .o(INODE_SECTION_CLIENT_MACHINE, u.getClientMachine());
out.print("</file-under-construction>\n"); out.print("</" + INODE_SECTION_FILE_UNDER_CONSTRUCTION + ">\n");
} }
} }
@ -346,31 +505,31 @@ public final class PBImageXmlWriter {
ImmutableList<AclEntry> aclEntryList = FSImageFormatPBINode.Loader ImmutableList<AclEntry> aclEntryList = FSImageFormatPBINode.Loader
.loadAclEntries(aclFeatureProto, stringTable); .loadAclEntries(aclFeatureProto, stringTable);
if (aclEntryList.size() > 0) { if (aclEntryList.size() > 0) {
out.print("<acls>"); out.print("<" + INODE_SECTION_ACLS + ">");
for (AclEntry aclEntry : aclEntryList) { for (AclEntry aclEntry : aclEntryList) {
o("acl", aclEntry.toString()); o(INODE_SECTION_ACL, aclEntry.toString());
} }
out.print("</acls>"); out.print("</" + INODE_SECTION_ACLS + ">");
} }
} }
private void dumpINodeSection(InputStream in) throws IOException { private void dumpINodeSection(InputStream in) throws IOException {
INodeSection s = INodeSection.parseDelimitedFrom(in); INodeSection s = INodeSection.parseDelimitedFrom(in);
out.print("<INodeSection>"); out.print("<" + INODE_SECTION_NAME + ">");
o("lastInodeId", s.getLastInodeId()); o(INODE_SECTION_LAST_INODE_ID, s.getLastInodeId());
o("numInodes", s.getNumInodes()); o(INODE_SECTION_NUM_INODES, s.getNumInodes());
for (int i = 0; i < s.getNumInodes(); ++i) { for (int i = 0; i < s.getNumInodes(); ++i) {
INodeSection.INode p = INodeSection.INode.parseDelimitedFrom(in); INodeSection.INode p = INodeSection.INode.parseDelimitedFrom(in);
out.print("<inode>"); out.print("<" + INODE_SECTION_INODE + ">");
dumpINodeFields(p); dumpINodeFields(p);
out.print("</inode>\n"); out.print("</" + INODE_SECTION_INODE + ">\n");
} }
out.print("</INodeSection>\n"); out.print("</" + INODE_SECTION_NAME + ">\n");
} }
private void dumpINodeFields(INodeSection.INode p) { private void dumpINodeFields(INodeSection.INode p) {
o("id", p.getId()).o("type", p.getType()).o("name", o(SECTION_ID, p.getId()).o(INODE_SECTION_TYPE, p.getType())
p.getName().toStringUtf8()); .o(SECTION_NAME, p.getName().toStringUtf8());
if (p.hasFile()) { if (p.hasFile()) {
dumpINodeFile(p.getFile()); dumpINodeFile(p.getFile());
} else if (p.hasDirectory()) { } else if (p.hasDirectory()) {
@ -381,20 +540,23 @@ public final class PBImageXmlWriter {
} }
private void dumpINodeSymlink(INodeSymlink s) { private void dumpINodeSymlink(INodeSymlink s) {
o("permission", dumpPermission(s.getPermission())) o(INODE_SECTION_PERMISSION, dumpPermission(s.getPermission()))
.o("target", s.getTarget().toStringUtf8()) .o(INODE_SECTION_TARGET, s.getTarget().toStringUtf8())
.o("mtime", s.getModificationTime()).o("atime", s.getAccessTime()); .o(INODE_SECTION_MTIME, s.getModificationTime())
.o(INODE_SECTION_ATIME, s.getAccessTime());
} }
private void dumpNameSection(InputStream in) throws IOException { private void dumpNameSection(InputStream in) throws IOException {
NameSystemSection s = NameSystemSection.parseDelimitedFrom(in); NameSystemSection s = NameSystemSection.parseDelimitedFrom(in);
out.print("<NameSection>"); out.print("<" + NAME_SECTION_NAME + ">");
o("namespaceId", s.getNamespaceId()); o(NAME_SECTION_NAMESPACE_ID, s.getNamespaceId());
o("genstampV1", s.getGenstampV1()).o("genstampV2", s.getGenstampV2()) o(NAME_SECTION_GENSTAMPV1, s.getGenstampV1())
.o("genstampV1Limit", s.getGenstampV1Limit()) .o(NAME_SECTION_GENSTAMPV2, s.getGenstampV2())
.o("lastAllocatedBlockId", s.getLastAllocatedBlockId()) .o(NAME_SECTION_GENSTAMPV1_LIMIT, s.getGenstampV1Limit())
.o("txid", s.getTransactionId()); .o(NAME_SECTION_LAST_ALLOCATED_BLOCK_ID,
out.print("</NameSection>\n"); s.getLastAllocatedBlockId())
.o(NAME_SECTION_TXID, s.getTransactionId());
out.print("</" + NAME_SECTION_NAME + ">\n");
} }
private String dumpPermission(long permission) { private String dumpPermission(long permission) {
@ -405,59 +567,63 @@ public final class PBImageXmlWriter {
} }
private void dumpSecretManagerSection(InputStream is) throws IOException { private void dumpSecretManagerSection(InputStream is) throws IOException {
out.print("<SecretManagerSection>"); out.print("<" + SECRET_MANAGER_SECTION_NAME + ">");
SecretManagerSection s = SecretManagerSection.parseDelimitedFrom(is); SecretManagerSection s = SecretManagerSection.parseDelimitedFrom(is);
int expectedNumDelegationKeys = s.getNumKeys(); int expectedNumDelegationKeys = s.getNumKeys();
int expectedNumTokens = s.getNumTokens(); int expectedNumTokens = s.getNumTokens();
o("currentId", s.getCurrentId()).o("tokenSequenceNumber", o(SECRET_MANAGER_SECTION_CURRENT_ID, s.getCurrentId())
s.getTokenSequenceNumber()). .o(SECRET_MANAGER_SECTION_TOKEN_SEQUENCE_NUMBER,
o("numDelegationKeys", expectedNumDelegationKeys). s.getTokenSequenceNumber()).
o("numTokens", expectedNumTokens); o(SECRET_MANAGER_SECTION_NUM_DELEGATION_KEYS,
expectedNumDelegationKeys).
o(SECRET_MANAGER_SECTION_NUM_TOKENS, expectedNumTokens);
for (int i = 0; i < expectedNumDelegationKeys; i++) { for (int i = 0; i < expectedNumDelegationKeys; i++) {
SecretManagerSection.DelegationKey dkey = SecretManagerSection.DelegationKey dkey =
SecretManagerSection.DelegationKey.parseDelimitedFrom(is); SecretManagerSection.DelegationKey.parseDelimitedFrom(is);
out.print("<delegationKey>"); out.print("<" + SECRET_MANAGER_SECTION_DELEGATION_KEY + ">");
o("id", dkey.getId()); o(SECTION_ID, dkey.getId());
o("key", Hex.encodeHexString(dkey.getKey().toByteArray())); o(SECRET_MANAGER_SECTION_KEY,
Hex.encodeHexString(dkey.getKey().toByteArray()));
if (dkey.hasExpiryDate()) { if (dkey.hasExpiryDate()) {
dumpDate("expiry", dkey.getExpiryDate()); dumpDate(SECRET_MANAGER_SECTION_EXPIRY, dkey.getExpiryDate());
} }
out.print("</delegationKey>"); out.print("</" + SECRET_MANAGER_SECTION_DELEGATION_KEY + ">");
} }
for (int i = 0; i < expectedNumTokens; i++) { for (int i = 0; i < expectedNumTokens; i++) {
SecretManagerSection.PersistToken token = SecretManagerSection.PersistToken token =
SecretManagerSection.PersistToken.parseDelimitedFrom(is); SecretManagerSection.PersistToken.parseDelimitedFrom(is);
out.print("<token>"); out.print("<" + SECRET_MANAGER_SECTION_TOKEN + ">");
if (token.hasVersion()) { if (token.hasVersion()) {
o("version", token.getVersion()); o(SECRET_MANAGER_SECTION_VERSION, token.getVersion());
} }
if (token.hasOwner()) { if (token.hasOwner()) {
o("owner", token.getOwner()); o(SECRET_MANAGER_SECTION_OWNER, token.getOwner());
} }
if (token.hasRenewer()) { if (token.hasRenewer()) {
o("renewer", token.getRenewer()); o(SECRET_MANAGER_SECTION_RENEWER, token.getRenewer());
} }
if (token.hasRealUser()) { if (token.hasRealUser()) {
o("realUser", token.getRealUser()); o(SECRET_MANAGER_SECTION_REAL_USER, token.getRealUser());
} }
if (token.hasIssueDate()) { if (token.hasIssueDate()) {
dumpDate("issueDate", token.getIssueDate()); dumpDate(SECRET_MANAGER_SECTION_ISSUE_DATE, token.getIssueDate());
} }
if (token.hasMaxDate()) { if (token.hasMaxDate()) {
dumpDate("maxDate", token.getMaxDate()); dumpDate(SECRET_MANAGER_SECTION_MAX_DATE, token.getMaxDate());
} }
if (token.hasSequenceNumber()) { if (token.hasSequenceNumber()) {
o("sequenceNumber", token.getSequenceNumber()); o(SECRET_MANAGER_SECTION_SEQUENCE_NUMBER,
token.getSequenceNumber());
} }
if (token.hasMasterKeyId()) { if (token.hasMasterKeyId()) {
o("masterKeyId", token.getMasterKeyId()); o(SECRET_MANAGER_SECTION_MASTER_KEY_ID, token.getMasterKeyId());
} }
if (token.hasExpiryDate()) { if (token.hasExpiryDate()) {
dumpDate("expiryDate", token.getExpiryDate()); dumpDate(SECRET_MANAGER_SECTION_EXPIRY_DATE, token.getExpiryDate());
} }
out.print("</token>"); out.print("</" + SECRET_MANAGER_SECTION_TOKEN + ">");
} }
out.print("</SecretManagerSection>"); out.print("</" + SECRET_MANAGER_SECTION_NAME + ">");
} }
private void dumpDate(String tag, long date) { private void dumpDate(String tag, long date) {
@ -466,7 +632,7 @@ public final class PBImageXmlWriter {
} }
private void dumpSnapshotDiffSection(InputStream in) throws IOException { private void dumpSnapshotDiffSection(InputStream in) throws IOException {
out.print("<SnapshotDiffSection>"); out.print("<" + SNAPSHOT_DIFF_SECTION_NAME + ">");
while (true) { while (true) {
SnapshotDiffSection.DiffEntry e = SnapshotDiffSection.DiffEntry SnapshotDiffSection.DiffEntry e = SnapshotDiffSection.DiffEntry
.parseDelimitedFrom(in); .parseDelimitedFrom(in);
@ -475,52 +641,54 @@ public final class PBImageXmlWriter {
} }
switch (e.getType()) { switch (e.getType()) {
case FILEDIFF: case FILEDIFF:
out.print("<fileDiffEntry>"); out.print("<" + SNAPSHOT_DIFF_SECTION_FILE_DIFF_ENTRY + ">");
break; break;
case DIRECTORYDIFF: case DIRECTORYDIFF:
out.print("<dirDiffEntry>"); out.print("<" + SNAPSHOT_DIFF_SECTION_DIR_DIFF_ENTRY + ">");
break; break;
default: default:
throw new IOException("unknown DiffEntry type " + e.getType()); throw new IOException("unknown DiffEntry type " + e.getType());
} }
o("inodeId", e.getInodeId()); o(SNAPSHOT_DIFF_SECTION_INODE_ID, e.getInodeId());
o("count", e.getNumOfDiff()); o(SNAPSHOT_DIFF_SECTION_COUNT, e.getNumOfDiff());
switch (e.getType()) { switch (e.getType()) {
case FILEDIFF: { case FILEDIFF: {
for (int i = 0; i < e.getNumOfDiff(); ++i) { for (int i = 0; i < e.getNumOfDiff(); ++i) {
out.print("<fileDiff>"); out.print("<" + SNAPSHOT_DIFF_SECTION_FILE_DIFF + ">");
SnapshotDiffSection.FileDiff f = SnapshotDiffSection.FileDiff SnapshotDiffSection.FileDiff f = SnapshotDiffSection.FileDiff
.parseDelimitedFrom(in); .parseDelimitedFrom(in);
o("snapshotId", f.getSnapshotId()).o("size", f.getFileSize()).o( o(SNAPSHOT_DIFF_SECTION_SNAPSHOT_ID, f.getSnapshotId())
"name", f.getName().toStringUtf8()); .o(SNAPSHOT_DIFF_SECTION_SIZE, f.getFileSize())
out.print("</fileDiff>\n"); .o(SECTION_NAME, f.getName().toStringUtf8());
out.print("</" + SNAPSHOT_DIFF_SECTION_FILE_DIFF + ">\n");
} }
} }
break; break;
case DIRECTORYDIFF: { case DIRECTORYDIFF: {
for (int i = 0; i < e.getNumOfDiff(); ++i) { for (int i = 0; i < e.getNumOfDiff(); ++i) {
out.print("<dirDiff>"); out.print("<" + SNAPSHOT_DIFF_SECTION_DIR_DIFF + ">");
SnapshotDiffSection.DirectoryDiff d = SnapshotDiffSection.DirectoryDiff SnapshotDiffSection.DirectoryDiff d = SnapshotDiffSection.DirectoryDiff
.parseDelimitedFrom(in); .parseDelimitedFrom(in);
o("snapshotId", d.getSnapshotId()) o(SNAPSHOT_DIFF_SECTION_SNAPSHOT_ID, d.getSnapshotId())
.o("childrenSize", d.getChildrenSize()) .o(SNAPSHOT_DIFF_SECTION_CHILDREN_SIZE, d.getChildrenSize())
.o("isSnapshotRoot", d.getIsSnapshotRoot()) .o(SNAPSHOT_DIFF_SECTION_IS_SNAPSHOT_ROOT, d.getIsSnapshotRoot())
.o("name", d.getName().toStringUtf8()) .o(SECTION_NAME, d.getName().toStringUtf8())
.o("createdListSize", d.getCreatedListSize()); .o(SNAPSHOT_DIFF_SECTION_CREATED_LIST_SIZE,
d.getCreatedListSize());
for (long did : d.getDeletedINodeList()) { for (long did : d.getDeletedINodeList()) {
o("deletedInode", did); o(SNAPSHOT_DIFF_SECTION_DELETED_INODE, did);
} }
for (int dRefid : d.getDeletedINodeRefList()) { for (int dRefid : d.getDeletedINodeRefList()) {
o("deletedInoderef", dRefid); o(SNAPSHOT_DIFF_SECTION_DELETED_INODE_REF, dRefid);
} }
for (int j = 0; j < d.getCreatedListSize(); ++j) { for (int j = 0; j < d.getCreatedListSize(); ++j) {
SnapshotDiffSection.CreatedListEntry ce = SnapshotDiffSection.CreatedListEntry SnapshotDiffSection.CreatedListEntry ce = SnapshotDiffSection.CreatedListEntry
.parseDelimitedFrom(in); .parseDelimitedFrom(in);
out.print("<created>"); out.print("<" + SNAPSHOT_DIFF_SECTION_CREATED + ">");
o("name", ce.getName().toStringUtf8()); o(SECTION_NAME, ce.getName().toStringUtf8());
out.print("</created>\n"); out.print("</" + SNAPSHOT_DIFF_SECTION_CREATED + ">\n");
} }
out.print("</dirDiff>\n"); out.print("</" + SNAPSHOT_DIFF_SECTION_DIR_DIFF + ">\n");
} }
break; break;
} }
@ -529,41 +697,41 @@ public final class PBImageXmlWriter {
} }
switch (e.getType()) { switch (e.getType()) {
case FILEDIFF: case FILEDIFF:
out.print("</fileDiffEntry>"); out.print("</" + SNAPSHOT_DIFF_SECTION_FILE_DIFF_ENTRY + ">");
break; break;
case DIRECTORYDIFF: case DIRECTORYDIFF:
out.print("</dirDiffEntry>"); out.print("</" + SNAPSHOT_DIFF_SECTION_DIR_DIFF_ENTRY + ">");
break; break;
default: default:
throw new IOException("unknown DiffEntry type " + e.getType()); throw new IOException("unknown DiffEntry type " + e.getType());
} }
} }
out.print("</SnapshotDiffSection>\n"); out.print("</" + SNAPSHOT_DIFF_SECTION_NAME + ">\n");
} }
private void dumpSnapshotSection(InputStream in) throws IOException { private void dumpSnapshotSection(InputStream in) throws IOException {
out.print("<SnapshotSection>"); out.print("<" + SNAPSHOT_SECTION_NAME + ">");
SnapshotSection s = SnapshotSection.parseDelimitedFrom(in); SnapshotSection s = SnapshotSection.parseDelimitedFrom(in);
o("snapshotCounter", s.getSnapshotCounter()); o(SNAPSHOT_SECTION_SNAPSHOT_COUNTER, s.getSnapshotCounter());
o("numSnapshots", s.getNumSnapshots()); o(SNAPSHOT_SECTION_NUM_SNAPSHOTS, s.getNumSnapshots());
if (s.getSnapshottableDirCount() > 0) { if (s.getSnapshottableDirCount() > 0) {
out.print("<snapshottableDir>"); out.print("<" + SNAPSHOT_SECTION_SNAPSHOT_TABLE_DIR + ">");
for (long id : s.getSnapshottableDirList()) { for (long id : s.getSnapshottableDirList()) {
o("dir", id); o(SNAPSHOT_SECTION_DIR, id);
} }
out.print("</snapshottableDir>\n"); out.print("</" + SNAPSHOT_SECTION_SNAPSHOT_TABLE_DIR + ">\n");
} }
for (int i = 0; i < s.getNumSnapshots(); ++i) { for (int i = 0; i < s.getNumSnapshots(); ++i) {
SnapshotSection.Snapshot pbs = SnapshotSection.Snapshot SnapshotSection.Snapshot pbs = SnapshotSection.Snapshot
.parseDelimitedFrom(in); .parseDelimitedFrom(in);
out.print("<snapshot>"); out.print("<" + SNAPSHOT_SECTION_SNAPSHOT + ">");
o("id", pbs.getSnapshotId()); o(SECTION_ID, pbs.getSnapshotId());
out.print("<root>"); out.print("<" + SNAPSHOT_SECTION_ROOT + ">");
dumpINodeFields(pbs.getRoot()); dumpINodeFields(pbs.getRoot());
out.print("</root>"); out.print("</" + SNAPSHOT_SECTION_ROOT + ">");
out.print("</snapshot>"); out.print("</" + SNAPSHOT_SECTION_SNAPSHOT + ">");
} }
out.print("</SnapshotSection>\n"); out.print("</" + SNAPSHOT_SECTION_NAME + ">\n");
} }
private void loadStringTable(InputStream in) throws IOException { private void loadStringTable(InputStream in) throws IOException {