|
@@ -81,6 +81,7 @@ import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
|
|
import org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus;
|
|
import org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus;
|
|
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
|
|
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
|
|
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
|
|
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.LocatedStripedBlock;
|
|
import org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo;
|
|
import org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo;
|
|
import org.apache.hadoop.hdfs.protocol.RollingUpgradeStatus;
|
|
import org.apache.hadoop.hdfs.protocol.RollingUpgradeStatus;
|
|
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport;
|
|
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport;
|
|
@@ -626,7 +627,7 @@ public class PBHelper {
|
|
if (b == null) {
|
|
if (b == null) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- LocatedBlockProto lb = PBHelper.convert((LocatedBlock)b);
|
|
|
|
|
|
+ LocatedBlockProto lb = PBHelper.convertLocatedBlock(b);
|
|
RecoveringBlockProto.Builder builder = RecoveringBlockProto.newBuilder();
|
|
RecoveringBlockProto.Builder builder = RecoveringBlockProto.newBuilder();
|
|
builder.setBlock(lb).setNewGenStamp(b.getNewGenerationStamp());
|
|
builder.setBlock(lb).setNewGenStamp(b.getNewGenerationStamp());
|
|
if(b.getNewBlock() != null)
|
|
if(b.getNewBlock() != null)
|
|
@@ -776,7 +777,7 @@ public class PBHelper {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static LocatedBlockProto convert(LocatedBlock b) {
|
|
|
|
|
|
+ public static LocatedBlockProto convertLocatedBlock(LocatedBlock b) {
|
|
if (b == null) return null;
|
|
if (b == null) return null;
|
|
Builder builder = LocatedBlockProto.newBuilder();
|
|
Builder builder = LocatedBlockProto.newBuilder();
|
|
DatanodeInfo[] locs = b.getLocations();
|
|
DatanodeInfo[] locs = b.getLocations();
|
|
@@ -797,21 +798,27 @@ public class PBHelper {
|
|
|
|
|
|
StorageType[] storageTypes = b.getStorageTypes();
|
|
StorageType[] storageTypes = b.getStorageTypes();
|
|
if (storageTypes != null) {
|
|
if (storageTypes != null) {
|
|
- for (int i = 0; i < storageTypes.length; ++i) {
|
|
|
|
- builder.addStorageTypes(PBHelper.convertStorageType(storageTypes[i]));
|
|
|
|
|
|
+ for (StorageType storageType : storageTypes) {
|
|
|
|
+ builder.addStorageTypes(PBHelper.convertStorageType(storageType));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
final String[] storageIDs = b.getStorageIDs();
|
|
final String[] storageIDs = b.getStorageIDs();
|
|
if (storageIDs != null) {
|
|
if (storageIDs != null) {
|
|
builder.addAllStorageIDs(Arrays.asList(storageIDs));
|
|
builder.addAllStorageIDs(Arrays.asList(storageIDs));
|
|
}
|
|
}
|
|
|
|
+ if (b instanceof LocatedStripedBlock) {
|
|
|
|
+ int[] indices = ((LocatedStripedBlock) b).getBlockIndices();
|
|
|
|
+ for (int index : indices) {
|
|
|
|
+ builder.addBlockIndex(index);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
return builder.setB(PBHelper.convert(b.getBlock()))
|
|
return builder.setB(PBHelper.convert(b.getBlock()))
|
|
.setBlockToken(PBHelper.convert(b.getBlockToken()))
|
|
.setBlockToken(PBHelper.convert(b.getBlockToken()))
|
|
.setCorrupt(b.isCorrupt()).setOffset(b.getStartOffset()).build();
|
|
.setCorrupt(b.isCorrupt()).setOffset(b.getStartOffset()).build();
|
|
}
|
|
}
|
|
|
|
|
|
- public static LocatedBlock convert(LocatedBlockProto proto) {
|
|
|
|
|
|
+ public static LocatedBlock convertLocatedBlockProto(LocatedBlockProto proto) {
|
|
if (proto == null) return null;
|
|
if (proto == null) return null;
|
|
List<DatanodeInfoProto> locs = proto.getLocsList();
|
|
List<DatanodeInfoProto> locs = proto.getLocsList();
|
|
DatanodeInfo[] targets = new DatanodeInfo[locs.size()];
|
|
DatanodeInfo[] targets = new DatanodeInfo[locs.size()];
|
|
@@ -831,6 +838,15 @@ public class PBHelper {
|
|
storageIDs = proto.getStorageIDsList().toArray(new String[storageIDsCount]);
|
|
storageIDs = proto.getStorageIDsList().toArray(new String[storageIDsCount]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ int[] indices = null;
|
|
|
|
+ final int indexCount = proto.getBlockIndexCount();
|
|
|
|
+ if (indexCount > 0) {
|
|
|
|
+ indices = new int[indexCount];
|
|
|
|
+ for (int i = 0; i < indexCount; i++) {
|
|
|
|
+ indices[i] = proto.getBlockIndex(i);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// Set values from the isCached list, re-using references from loc
|
|
// Set values from the isCached list, re-using references from loc
|
|
List<DatanodeInfo> cachedLocs = new ArrayList<DatanodeInfo>(locs.size());
|
|
List<DatanodeInfo> cachedLocs = new ArrayList<DatanodeInfo>(locs.size());
|
|
List<Boolean> isCachedList = proto.getIsCachedList();
|
|
List<Boolean> isCachedList = proto.getIsCachedList();
|
|
@@ -840,9 +856,17 @@ public class PBHelper {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- LocatedBlock lb = new LocatedBlock(PBHelper.convert(proto.getB()), targets,
|
|
|
|
- storageIDs, storageTypes, proto.getOffset(), proto.getCorrupt(),
|
|
|
|
- cachedLocs.toArray(new DatanodeInfo[0]));
|
|
|
|
|
|
+ final LocatedBlock lb;
|
|
|
|
+ if (indices == null) {
|
|
|
|
+ lb = new LocatedBlock(PBHelper.convert(proto.getB()), targets, storageIDs,
|
|
|
|
+ storageTypes, proto.getOffset(), proto.getCorrupt(),
|
|
|
|
+ cachedLocs.toArray(new DatanodeInfo[cachedLocs.size()]));
|
|
|
|
+ } else {
|
|
|
|
+ lb = new LocatedStripedBlock(PBHelper.convert(proto.getB()), targets,
|
|
|
|
+ storageIDs, storageTypes, indices, proto.getOffset(),
|
|
|
|
+ proto.getCorrupt(),
|
|
|
|
+ cachedLocs.toArray(new DatanodeInfo[cachedLocs.size()]));
|
|
|
|
+ }
|
|
lb.setBlockToken(PBHelper.convert(proto.getBlockToken()));
|
|
lb.setBlockToken(PBHelper.convert(proto.getBlockToken()));
|
|
|
|
|
|
return lb;
|
|
return lb;
|
|
@@ -1258,36 +1282,36 @@ public class PBHelper {
|
|
}
|
|
}
|
|
|
|
|
|
// Located Block Arrays and Lists
|
|
// Located Block Arrays and Lists
|
|
- public static LocatedBlockProto[] convertLocatedBlock(LocatedBlock[] lb) {
|
|
|
|
|
|
+ public static LocatedBlockProto[] convertLocatedBlocks(LocatedBlock[] lb) {
|
|
if (lb == null) return null;
|
|
if (lb == null) return null;
|
|
- return convertLocatedBlock2(Arrays.asList(lb)).toArray(
|
|
|
|
- new LocatedBlockProto[lb.length]);
|
|
|
|
|
|
+ return convertLocatedBlocks2(Arrays.asList(lb))
|
|
|
|
+ .toArray(new LocatedBlockProto[lb.length]);
|
|
}
|
|
}
|
|
|
|
|
|
- public static LocatedBlock[] convertLocatedBlock(LocatedBlockProto[] lb) {
|
|
|
|
|
|
+ public static LocatedBlock[] convertLocatedBlocks(LocatedBlockProto[] lb) {
|
|
if (lb == null) return null;
|
|
if (lb == null) return null;
|
|
- return convertLocatedBlock(Arrays.asList(lb)).toArray(
|
|
|
|
- new LocatedBlock[lb.length]);
|
|
|
|
|
|
+ return convertLocatedBlocks(Arrays.asList(lb))
|
|
|
|
+ .toArray(new LocatedBlock[lb.length]);
|
|
}
|
|
}
|
|
|
|
|
|
- public static List<LocatedBlock> convertLocatedBlock(
|
|
|
|
|
|
+ public static List<LocatedBlock> convertLocatedBlocks(
|
|
List<LocatedBlockProto> lb) {
|
|
List<LocatedBlockProto> lb) {
|
|
if (lb == null) return null;
|
|
if (lb == null) return null;
|
|
final int len = lb.size();
|
|
final int len = lb.size();
|
|
- List<LocatedBlock> result =
|
|
|
|
- new ArrayList<LocatedBlock>(len);
|
|
|
|
- for (int i = 0; i < len; ++i) {
|
|
|
|
- result.add(PBHelper.convert(lb.get(i)));
|
|
|
|
|
|
+ List<LocatedBlock> result = new ArrayList<>(len);
|
|
|
|
+ for (LocatedBlockProto aLb : lb) {
|
|
|
|
+ result.add(PBHelper.convertLocatedBlockProto(aLb));
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- public static List<LocatedBlockProto> convertLocatedBlock2(List<LocatedBlock> lb) {
|
|
|
|
|
|
+ public static List<LocatedBlockProto> convertLocatedBlocks2(
|
|
|
|
+ List<LocatedBlock> lb) {
|
|
if (lb == null) return null;
|
|
if (lb == null) return null;
|
|
final int len = lb.size();
|
|
final int len = lb.size();
|
|
- List<LocatedBlockProto> result = new ArrayList<LocatedBlockProto>(len);
|
|
|
|
- for (int i = 0; i < len; ++i) {
|
|
|
|
- result.add(PBHelper.convert(lb.get(i)));
|
|
|
|
|
|
+ List<LocatedBlockProto> result = new ArrayList<>(len);
|
|
|
|
+ for (LocatedBlock aLb : lb) {
|
|
|
|
+ result.add(PBHelper.convertLocatedBlock(aLb));
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
@@ -1297,8 +1321,9 @@ public class PBHelper {
|
|
public static LocatedBlocks convert(LocatedBlocksProto lb) {
|
|
public static LocatedBlocks convert(LocatedBlocksProto lb) {
|
|
return new LocatedBlocks(
|
|
return new LocatedBlocks(
|
|
lb.getFileLength(), lb.getUnderConstruction(),
|
|
lb.getFileLength(), lb.getUnderConstruction(),
|
|
- PBHelper.convertLocatedBlock(lb.getBlocksList()),
|
|
|
|
- lb.hasLastBlock() ? PBHelper.convert(lb.getLastBlock()) : null,
|
|
|
|
|
|
+ PBHelper.convertLocatedBlocks(lb.getBlocksList()),
|
|
|
|
+ lb.hasLastBlock() ?
|
|
|
|
+ PBHelper.convertLocatedBlockProto(lb.getLastBlock()) : null,
|
|
lb.getIsLastBlockComplete(),
|
|
lb.getIsLastBlockComplete(),
|
|
lb.hasFileEncryptionInfo() ? convert(lb.getFileEncryptionInfo()) :
|
|
lb.hasFileEncryptionInfo() ? convert(lb.getFileEncryptionInfo()) :
|
|
null);
|
|
null);
|
|
@@ -1311,14 +1336,15 @@ public class PBHelper {
|
|
LocatedBlocksProto.Builder builder =
|
|
LocatedBlocksProto.Builder builder =
|
|
LocatedBlocksProto.newBuilder();
|
|
LocatedBlocksProto.newBuilder();
|
|
if (lb.getLastLocatedBlock() != null) {
|
|
if (lb.getLastLocatedBlock() != null) {
|
|
- builder.setLastBlock(PBHelper.convert(lb.getLastLocatedBlock()));
|
|
|
|
|
|
+ builder.setLastBlock(
|
|
|
|
+ PBHelper.convertLocatedBlock(lb.getLastLocatedBlock()));
|
|
}
|
|
}
|
|
if (lb.getFileEncryptionInfo() != null) {
|
|
if (lb.getFileEncryptionInfo() != null) {
|
|
builder.setFileEncryptionInfo(convert(lb.getFileEncryptionInfo()));
|
|
builder.setFileEncryptionInfo(convert(lb.getFileEncryptionInfo()));
|
|
}
|
|
}
|
|
return builder.setFileLength(lb.getFileLength())
|
|
return builder.setFileLength(lb.getFileLength())
|
|
.setUnderConstruction(lb.isUnderConstruction())
|
|
.setUnderConstruction(lb.isUnderConstruction())
|
|
- .addAllBlocks(PBHelper.convertLocatedBlock2(lb.getLocatedBlocks()))
|
|
|
|
|
|
+ .addAllBlocks(PBHelper.convertLocatedBlocks2(lb.getLocatedBlocks()))
|
|
.setIsLastBlockComplete(lb.isLastBlockComplete()).build();
|
|
.setIsLastBlockComplete(lb.isLastBlockComplete()).build();
|
|
}
|
|
}
|
|
|
|
|