HDFS-7761. cleanup unnecssary code logic in LocatedBlock. (yliu)
This commit is contained in:
parent
c9266132ee
commit
f8d0825f39
|
@ -320,6 +320,8 @@ Release 2.7.0 - UNRELEASED
|
||||||
|
|
||||||
HDFS-7760. Document truncate for WebHDFS. (shv)
|
HDFS-7760. Document truncate for WebHDFS. (shv)
|
||||||
|
|
||||||
|
HDFS-7761. cleanup unnecssary code logic in LocatedBlock. (yliu)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HDFS-7454. Reduce memory footprint for AclEntries in NameNode.
|
HDFS-7454. Reduce memory footprint for AclEntries in NameNode.
|
||||||
|
|
|
@ -33,6 +33,10 @@ public class DatanodeInfoWithStorage extends DatanodeInfo {
|
||||||
super(from);
|
super(from);
|
||||||
this.storageID = storageID;
|
this.storageID = storageID;
|
||||||
this.storageType = storageType;
|
this.storageType = storageType;
|
||||||
|
setSoftwareVersion(from.getSoftwareVersion());
|
||||||
|
setDependentHostNames(from.getDependentHostNames());
|
||||||
|
setLevel(from.getLevel());
|
||||||
|
setParent(from.getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStorageID() {
|
public String getStorageID() {
|
||||||
|
|
|
@ -43,8 +43,6 @@ public class LocatedBlock {
|
||||||
private final ExtendedBlock b;
|
private final ExtendedBlock b;
|
||||||
private long offset; // offset of the first byte of the block in the file
|
private long offset; // offset of the first byte of the block in the file
|
||||||
private final DatanodeInfoWithStorage[] locs;
|
private final DatanodeInfoWithStorage[] locs;
|
||||||
private final boolean hasStorageIDs;
|
|
||||||
private final boolean hasStorageTypes;
|
|
||||||
/** Cached storage ID for each replica */
|
/** Cached storage ID for each replica */
|
||||||
private String[] storageIDs;
|
private String[] storageIDs;
|
||||||
/** Cached storage type for each replica, if reported. */
|
/** Cached storage type for each replica, if reported. */
|
||||||
|
@ -104,16 +102,11 @@ public class LocatedBlock {
|
||||||
DatanodeInfoWithStorage storage = new DatanodeInfoWithStorage(di,
|
DatanodeInfoWithStorage storage = new DatanodeInfoWithStorage(di,
|
||||||
storageIDs != null ? storageIDs[i] : null,
|
storageIDs != null ? storageIDs[i] : null,
|
||||||
storageTypes != null ? storageTypes[i] : null);
|
storageTypes != null ? storageTypes[i] : null);
|
||||||
storage.setDependentHostNames(di.getDependentHostNames());
|
|
||||||
storage.setLevel(di.getLevel());
|
|
||||||
storage.setParent(di.getParent());
|
|
||||||
this.locs[i] = storage;
|
this.locs[i] = storage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.storageIDs = storageIDs;
|
this.storageIDs = storageIDs;
|
||||||
this.storageTypes = storageTypes;
|
this.storageTypes = storageTypes;
|
||||||
this.hasStorageIDs = storageIDs != null;
|
|
||||||
this.hasStorageTypes = storageTypes != null;
|
|
||||||
|
|
||||||
if (cachedLocs == null || cachedLocs.length == 0) {
|
if (cachedLocs == null || cachedLocs.length == 0) {
|
||||||
this.cachedLocs = EMPTY_LOCS;
|
this.cachedLocs = EMPTY_LOCS;
|
||||||
|
@ -137,48 +130,36 @@ public class LocatedBlock {
|
||||||
/**
|
/**
|
||||||
* Returns the locations associated with this block. The returned array is not
|
* Returns the locations associated with this block. The returned array is not
|
||||||
* expected to be modified. If it is, caller must immediately invoke
|
* expected to be modified. If it is, caller must immediately invoke
|
||||||
* {@link org.apache.hadoop.hdfs.protocol.LocatedBlock#invalidateCachedStorageInfo}
|
* {@link org.apache.hadoop.hdfs.protocol.LocatedBlock#updateCachedStorageInfo}
|
||||||
* to invalidate the cached Storage ID/Type arrays.
|
* to update the cached Storage ID/Type arrays.
|
||||||
*/
|
*/
|
||||||
public DatanodeInfo[] getLocations() {
|
public DatanodeInfo[] getLocations() {
|
||||||
return locs;
|
return locs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageType[] getStorageTypes() {
|
public StorageType[] getStorageTypes() {
|
||||||
if(!hasStorageTypes) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if(storageTypes != null) {
|
|
||||||
return storageTypes;
|
|
||||||
}
|
|
||||||
storageTypes = new StorageType[locs.length];
|
|
||||||
for(int i = 0; i < locs.length; i++) {
|
|
||||||
storageTypes[i] = locs[i].getStorageType();
|
|
||||||
}
|
|
||||||
return storageTypes;
|
return storageTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getStorageIDs() {
|
public String[] getStorageIDs() {
|
||||||
if(!hasStorageIDs) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if(storageIDs != null) {
|
|
||||||
return storageIDs;
|
|
||||||
}
|
|
||||||
storageIDs = new String[locs.length];
|
|
||||||
for(int i = 0; i < locs.length; i++) {
|
|
||||||
storageIDs[i] = locs[i].getStorageID();
|
|
||||||
}
|
|
||||||
return storageIDs;
|
return storageIDs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidates the cached StorageID and StorageType information. Must be
|
* Updates the cached StorageID and StorageType information. Must be
|
||||||
* called when the locations array is modified.
|
* called when the locations array is modified.
|
||||||
*/
|
*/
|
||||||
public void invalidateCachedStorageInfo() {
|
public void updateCachedStorageInfo() {
|
||||||
storageIDs = null;
|
if (storageIDs != null) {
|
||||||
storageTypes = null;
|
for(int i = 0; i < locs.length; i++) {
|
||||||
|
storageIDs[i] = locs[i].getStorageID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (storageTypes != null) {
|
||||||
|
for(int i = 0; i < locs.length; i++) {
|
||||||
|
storageTypes[i] = locs[i].getStorageType();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getStartOffset() {
|
public long getStartOffset() {
|
||||||
|
|
|
@ -391,8 +391,8 @@ public class DatanodeManager {
|
||||||
}
|
}
|
||||||
int activeLen = lastActiveIndex + 1;
|
int activeLen = lastActiveIndex + 1;
|
||||||
networktopology.sortByDistance(client, b.getLocations(), activeLen);
|
networktopology.sortByDistance(client, b.getLocations(), activeLen);
|
||||||
// must invalidate cache since we modified locations array
|
// must update cache since we modified locations array
|
||||||
b.invalidateCachedStorageInfo();
|
b.updateCachedStorageInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue