HDFS-10764. Fix INodeFile#getBlocks to not return null. Contributed by Arpit Agarwal.
(cherry picked from commit 0faee62a0c8c1b8fd83227babfd00fbc2b26bddf)
This commit is contained in:
parent
a299146b6d
commit
fff0418458
@ -136,14 +136,14 @@ static long toLong(long preferredBlockSize, short replication,
|
|||||||
super(id, name, permissions, mtime, atime);
|
super(id, name, permissions, mtime, atime);
|
||||||
header = HeaderFormat.toLong(preferredBlockSize, replication,
|
header = HeaderFormat.toLong(preferredBlockSize, replication,
|
||||||
storagePolicyID);
|
storagePolicyID);
|
||||||
this.blocks = blklist;
|
setBlocks(blklist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public INodeFile(INodeFile that) {
|
public INodeFile(INodeFile that) {
|
||||||
super(that);
|
super(that);
|
||||||
this.header = that.header;
|
this.header = that.header;
|
||||||
this.blocks = that.blocks;
|
|
||||||
this.features = that.features;
|
this.features = that.features;
|
||||||
|
setBlocks(that.blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public INodeFile(INodeFile that, FileDiffList diffs) {
|
public INodeFile(INodeFile that, FileDiffList diffs) {
|
||||||
@ -213,9 +213,6 @@ void toCompleteFile(long mtime, int numCommittedAllowed, short minReplication) {
|
|||||||
/** Assert all blocks are complete. */
|
/** Assert all blocks are complete. */
|
||||||
private void assertAllBlocksComplete(int numCommittedAllowed,
|
private void assertAllBlocksComplete(int numCommittedAllowed,
|
||||||
short minReplication) {
|
short minReplication) {
|
||||||
if (blocks == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < blocks.length; i++) {
|
for (int i = 0; i < blocks.length; i++) {
|
||||||
final String err = checkBlockComplete(blocks, i, numCommittedAllowed,
|
final String err = checkBlockComplete(blocks, i, numCommittedAllowed,
|
||||||
minReplication);
|
minReplication);
|
||||||
@ -284,7 +281,7 @@ void setLastBlock(BlockInfo blk) {
|
|||||||
BlockInfo removeLastBlock(Block oldblock) {
|
BlockInfo removeLastBlock(Block oldblock) {
|
||||||
Preconditions.checkState(isUnderConstruction(),
|
Preconditions.checkState(isUnderConstruction(),
|
||||||
"file is no longer under construction");
|
"file is no longer under construction");
|
||||||
if (blocks == null || blocks.length == 0) {
|
if (blocks.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int size_1 = blocks.length - 1;
|
int size_1 = blocks.length - 1;
|
||||||
@ -503,7 +500,7 @@ void concatBlocks(INodeFile[] inodes, BlockManager bm) {
|
|||||||
* add a block to the block list
|
* add a block to the block list
|
||||||
*/
|
*/
|
||||||
void addBlock(BlockInfo newblock) {
|
void addBlock(BlockInfo newblock) {
|
||||||
if (this.blocks == null) {
|
if (this.blocks.length == 0) {
|
||||||
this.setBlocks(new BlockInfo[]{newblock});
|
this.setBlocks(new BlockInfo[]{newblock});
|
||||||
} else {
|
} else {
|
||||||
int size = this.blocks.length;
|
int size = this.blocks.length;
|
||||||
@ -516,12 +513,12 @@ void addBlock(BlockInfo newblock) {
|
|||||||
|
|
||||||
/** Set the blocks. */
|
/** Set the blocks. */
|
||||||
private void setBlocks(BlockInfo[] blocks) {
|
private void setBlocks(BlockInfo[] blocks) {
|
||||||
this.blocks = blocks;
|
this.blocks = (blocks != null ? blocks : BlockInfo.EMPTY_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Clear all blocks of the file. */
|
/** Clear all blocks of the file. */
|
||||||
public void clearBlocks() {
|
public void clearBlocks() {
|
||||||
setBlocks(BlockInfo.EMPTY_ARRAY);
|
this.blocks = BlockInfo.EMPTY_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -705,7 +702,7 @@ public final long computeFileSizeNotIncludingLastUcBlock() {
|
|||||||
*/
|
*/
|
||||||
public final long computeFileSize(boolean includesLastUcBlock,
|
public final long computeFileSize(boolean includesLastUcBlock,
|
||||||
boolean usePreferredBlockSize4LastUcBlock) {
|
boolean usePreferredBlockSize4LastUcBlock) {
|
||||||
if (blocks == null || blocks.length == 0) {
|
if (blocks.length == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
final int last = blocks.length - 1;
|
final int last = blocks.length - 1;
|
||||||
@ -770,7 +767,7 @@ public final QuotaCounts storagespaceConsumed(BlockStoragePolicy bsp) {
|
|||||||
* Return the penultimate allocated block for this file.
|
* Return the penultimate allocated block for this file.
|
||||||
*/
|
*/
|
||||||
BlockInfo getPenultimateBlock() {
|
BlockInfo getPenultimateBlock() {
|
||||||
if (blocks == null || blocks.length <= 1) {
|
if (blocks.length <= 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return blocks[blocks.length - 2];
|
return blocks[blocks.length - 2];
|
||||||
@ -778,12 +775,12 @@ BlockInfo getPenultimateBlock() {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockInfo getLastBlock() {
|
public BlockInfo getLastBlock() {
|
||||||
return blocks == null || blocks.length == 0? null: blocks[blocks.length-1];
|
return blocks.length == 0 ? null: blocks[blocks.length-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int numBlocks() {
|
public int numBlocks() {
|
||||||
return blocks == null ? 0 : blocks.length;
|
return blocks.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@ -794,7 +791,7 @@ public void dumpTreeRecursively(PrintWriter out, StringBuilder prefix,
|
|||||||
out.print(", fileSize=" + computeFileSize(snapshotId));
|
out.print(", fileSize=" + computeFileSize(snapshotId));
|
||||||
// only compare the first block
|
// only compare the first block
|
||||||
out.print(", blocks=");
|
out.print(", blocks=");
|
||||||
out.print(blocks == null || blocks.length == 0? null: blocks[0]);
|
out.print(blocks.length == 0 ? null: blocks[0]);
|
||||||
out.println();
|
out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -842,7 +839,7 @@ void computeQuotaDeltaForTruncate(
|
|||||||
long newLength, BlockStoragePolicy bsps,
|
long newLength, BlockStoragePolicy bsps,
|
||||||
QuotaCounts delta) {
|
QuotaCounts delta) {
|
||||||
final BlockInfo[] blocks = getBlocks();
|
final BlockInfo[] blocks = getBlocks();
|
||||||
if (blocks == null || blocks.length == 0) {
|
if (blocks.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user