HDFS-6690. Deduplicate xattr names in memory. (wang)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1611226 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bda23181bf
commit
ca52cb01c4
@ -294,6 +294,8 @@ Release 2.6.0 - UNRELEASED
|
|||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
|
HDFS-6690. Deduplicate xattr names in memory. (wang)
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
||||||
HDFS-6617. Flake TestDFSZKFailoverController.testManualFailoverWithDFSHAAdmin
|
HDFS-6617. Flake TestDFSZKFailoverController.testManualFailoverWithDFSHAAdmin
|
||||||
|
@ -19,13 +19,14 @@
|
|||||||
package org.apache.hadoop.hdfs.server.namenode;
|
package org.apache.hadoop.hdfs.server.namenode;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.fs.XAttr;
|
import org.apache.hadoop.fs.XAttr;
|
||||||
import org.apache.hadoop.hdfs.protocol.QuotaExceededException;
|
import org.apache.hadoop.hdfs.protocol.QuotaExceededException;
|
||||||
import org.apache.hadoop.hdfs.server.namenode.INode;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XAttrStorage is used to read and set xattrs for an inode.
|
* XAttrStorage is used to read and set xattrs for an inode.
|
||||||
@ -33,10 +34,15 @@
|
|||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public class XAttrStorage {
|
public class XAttrStorage {
|
||||||
|
|
||||||
|
private static final Map<String, String> internedNames = Maps.newHashMap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the existing extended attributes of an inode. If the
|
* Reads the existing extended attributes of an inode. If the
|
||||||
* inode does not have an <code>XAttr</code>, then this method
|
* inode does not have an <code>XAttr</code>, then this method
|
||||||
* returns an empty list.
|
* returns an empty list.
|
||||||
|
* <p/>
|
||||||
|
* Must be called while holding the FSDirectory read lock.
|
||||||
|
*
|
||||||
* @param inode INode to read
|
* @param inode INode to read
|
||||||
* @param snapshotId
|
* @param snapshotId
|
||||||
* @return List<XAttr> <code>XAttr</code> list.
|
* @return List<XAttr> <code>XAttr</code> list.
|
||||||
@ -48,6 +54,9 @@ public static List<XAttr> readINodeXAttrs(INode inode, int snapshotId) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the existing extended attributes of an inode.
|
* Reads the existing extended attributes of an inode.
|
||||||
|
* <p/>
|
||||||
|
* Must be called while holding the FSDirectory read lock.
|
||||||
|
*
|
||||||
* @param inode INode to read.
|
* @param inode INode to read.
|
||||||
* @return List<XAttr> <code>XAttr</code> list.
|
* @return List<XAttr> <code>XAttr</code> list.
|
||||||
*/
|
*/
|
||||||
@ -58,6 +67,9 @@ public static List<XAttr> readINodeXAttrs(INode inode) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update xattrs of inode.
|
* Update xattrs of inode.
|
||||||
|
* <p/>
|
||||||
|
* Must be called while holding the FSDirectory write lock.
|
||||||
|
*
|
||||||
* @param inode INode to update
|
* @param inode INode to update
|
||||||
* @param xAttrs to update xAttrs.
|
* @param xAttrs to update xAttrs.
|
||||||
* @param snapshotId id of the latest snapshot of the inode
|
* @param snapshotId id of the latest snapshot of the inode
|
||||||
@ -70,8 +82,24 @@ public static void updateINodeXAttrs(INode inode,
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Dedupe the xAttr name and save them into a new interned list
|
||||||
ImmutableList<XAttr> newXAttrs = ImmutableList.copyOf(xAttrs);
|
List<XAttr> internedXAttrs = Lists.newArrayListWithCapacity(xAttrs.size());
|
||||||
|
for (XAttr xAttr : xAttrs) {
|
||||||
|
final String name = xAttr.getName();
|
||||||
|
String internedName = internedNames.get(name);
|
||||||
|
if (internedName == null) {
|
||||||
|
internedName = name;
|
||||||
|
internedNames.put(internedName, internedName);
|
||||||
|
}
|
||||||
|
XAttr internedXAttr = new XAttr.Builder()
|
||||||
|
.setName(internedName)
|
||||||
|
.setNameSpace(xAttr.getNameSpace())
|
||||||
|
.setValue(xAttr.getValue())
|
||||||
|
.build();
|
||||||
|
internedXAttrs.add(internedXAttr);
|
||||||
|
}
|
||||||
|
// Save the list of interned xattrs
|
||||||
|
ImmutableList<XAttr> newXAttrs = ImmutableList.copyOf(internedXAttrs);
|
||||||
if (inode.getXAttrFeature() != null) {
|
if (inode.getXAttrFeature() != null) {
|
||||||
inode.removeXAttrFeature(snapshotId);
|
inode.removeXAttrFeature(snapshotId);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user